ReactOS  0.4.14-dev-41-g31d7680
afd.h File Reference
#include <ntifs.h>
#include <ndk/obtypes.h>
#include <tdi.h>
#include <tcpioctl.h>
#include <windef.h>
#include <winsock2.h>
#include <afd/shared.h>
#include <pseh/pseh2.h>
#include "tdi_proto.h"
#include "tdiconn.h"
#include "debug.h"
Include dependency graph for afd.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  IPADDR_ENTRY
 
struct  _AFD_MAPBUF
 
struct  _AFD_DEVICE_EXTENSION
 
struct  _AFD_ACTIVE_POLL
 
struct  _IRP_LIST
 
struct  _AFD_TDI_OBJECT
 
struct  _AFD_TDI_OBJECT_QELT
 
struct  _AFD_IN_FLIGHT_REQUEST
 
struct  _AFD_DATA_WINDOW
 
struct  _AFD_STORED_DATAGRAM
 
struct  _AFD_FCB
 

Macros

#define _WINBASE_
 
#define _WINDOWS_H
 
#define _INC_WINDOWS
 
#define MIN(x, y)   (((x)<(y))?(x):(y))
 
#define TL_INSTANCE   0
 
#define IP_MIB_STATS_ID   1
 
#define IP_MIB_ADDRTABLE_ENTRY_ID   0x102
 
#define TAG_AFD_DATA_BUFFER   'BdfA'
 
#define TAG_AFD_TRANSPORT_ADDRESS   'tdfA'
 
#define TAG_AFD_SOCKET_CONTEXT   'XdfA'
 
#define TAG_AFD_CONNECT_DATA   'cdfA'
 
#define TAG_AFD_DISCONNECT_DATA   'ddfA'
 
#define TAG_AFD_CONNECT_OPTIONS   'ocfA'
 
#define TAG_AFD_DISCONNECT_OPTIONS   'odfA'
 
#define TAG_AFD_ACCEPT_QUEUE   'qafA'
 
#define TAG_AFD_POLL_HANDLE   'hpfA'
 
#define TAG_AFD_FCB   'cffA'
 
#define TAG_AFD_ACTIVE_POLL   'pafA'
 
#define TAG_AFD_EA_INFO   'aefA'
 
#define TAG_AFD_STORED_DATAGRAM   'gsfA'
 
#define TAG_AFD_SNMP_ADDRESS_INFO   'asfA'
 
#define TAG_AFD_TDI_CONNECTION_INFORMATION   'cTfA'
 
#define TAG_AFD_WSA_BUFFER   'bWfA'
 
#define DN2H(dw)
 
#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_EOF_READ   0x20000000
 
#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_PREACCEPT   3
 
#define FUNCTION_ACCEPT   4
 
#define FUNCTION_DISCONNECT   5
 
#define FUNCTION_CLOSE   6
 
#define MAX_FUNCTIONS   7
 
#define IN_FLIGHT_REQUESTS   5
 
#define EXTRA_LOCK_BUFFERS
 
#define AFD_HANDLES(x)   ((PAFD_HANDLE)(x)->Exclusive)
 
#define SET_AFD_HANDLES(x, y)   (((x)->Exclusive) = (ULONG_PTR)(y))
 

Typedefs

typedef struct IPADDR_ENTRY IPADDR_ENTRY
 
typedef struct IPADDR_ENTRYPIPADDR_ENTRY
 
typedef struct _AFD_MAPBUF AFD_MAPBUF
 
typedef struct _AFD_MAPBUFPAFD_MAPBUF
 
typedef struct _AFD_DEVICE_EXTENSION AFD_DEVICE_EXTENSION
 
typedef struct _AFD_DEVICE_EXTENSIONPAFD_DEVICE_EXTENSION
 
typedef struct _AFD_ACTIVE_POLL AFD_ACTIVE_POLL
 
typedef struct _AFD_ACTIVE_POLLPAFD_ACTIVE_POLL
 
typedef struct _IRP_LIST IRP_LIST
 
typedef struct _IRP_LISTPIRP_LIST
 
typedef struct _AFD_TDI_OBJECT AFD_TDI_OBJECT
 
typedef struct _AFD_TDI_OBJECTPAFD_TDI_OBJECT
 
typedef struct _AFD_TDI_OBJECT_QELT AFD_TDI_OBJECT_QELT
 
typedef struct _AFD_TDI_OBJECT_QELTPAFD_TDI_OBJECT_QELT
 
typedef struct _AFD_IN_FLIGHT_REQUEST AFD_IN_FLIGHT_REQUEST
 
typedef struct _AFD_IN_FLIGHT_REQUESTPAFD_IN_FLIGHT_REQUEST
 
typedef struct _AFD_DATA_WINDOW AFD_DATA_WINDOW
 
typedef struct _AFD_DATA_WINDOWPAFD_DATA_WINDOW
 
typedef struct _AFD_STORED_DATAGRAM AFD_STORED_DATAGRAM
 
typedef struct _AFD_STORED_DATAGRAMPAFD_STORED_DATAGRAM
 
typedef struct _AFD_FCB AFD_FCB
 
typedef struct _AFD_FCBPAFD_FCB
 

Functions

NTSTATUS WarmSocketForBind (PAFD_FCB FCB, ULONG ShareType)
 
NTSTATUS NTAPI AfdBindSocket (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS MakeSocketIntoConnection (PAFD_FCB FCB)
 
NTSTATUS WarmSocketForConnection (PAFD_FCB FCB)
 
NTSTATUS NTAPI AfdStreamSocketConnect (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 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 AfdGetContext (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI AfdGetContextSize (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI AfdSetContext (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI AfdGetInfo (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI AfdSetInfo (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI AfdGetSockName (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI AfdGetPeerName (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS AfdWaitForListen (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS AfdListenSocket (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS AfdAccept (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
PAFD_WSABUF LockBuffers (PAFD_WSABUF Buf, UINT Count, PVOID AddressBuf, PINT AddressLen, BOOLEAN Write, BOOLEAN LockAddress, KPROCESSOR_MODE LockMode)
 
VOID UnlockBuffers (PAFD_WSABUF Buf, UINT Count, BOOL Address)
 
BOOLEAN SocketAcquireStateLock (PAFD_FCB FCB)
 
NTSTATUS NTAPI UnlockAndMaybeComplete (PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
 
VOID SocketStateUnlock (PAFD_FCB FCB)
 
NTSTATUS LostSocket (PIRP Irp)
 
PAFD_HANDLE LockHandles (PAFD_HANDLE HandleArray, UINT HandleCount)
 
VOID UnlockHandles (PAFD_HANDLE HandleArray, UINT HandleCount)
 
PVOID LockRequest (PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
 
VOID UnlockRequest (PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
PVOID GetLockedData (PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS LeaveIrpUntilLater (PAFD_FCB FCB, PIRP Irp, UINT Function)
 
NTSTATUS QueueUserModeIrp (PAFD_FCB FCB, PIRP Irp, UINT Function)
 
VOID OskitDumpBuffer (PCHAR Buffer, UINT Len)
 
VOID DestroySocket (PAFD_FCB FCB)
 
VOID RetryDisconnectCompletion (PAFD_FCB FCB)
 
BOOLEAN CheckUnlockExtraBuffers (PAFD_FCB FCB, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI AfdConnectedSocketReadData (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Short)
 
NTSTATUS NTAPI AfdPacketSocketReadData (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI AfdSelect (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI AfdEventSelect (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI AfdEnumEvents (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
VOID PollReeval (PAFD_DEVICE_EXTENSION DeviceObject, PFILE_OBJECT FileObject)
 
VOID KillSelectsForFCB (PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, BOOLEAN ExclusiveOnly)
 
VOID ZeroEvents (PAFD_HANDLE HandleArray, UINT HandleCount)
 
VOID SignalSocket (PAFD_ACTIVE_POLL Poll OPTIONAL, PIRP _Irp OPTIONAL, PAFD_POLL_INFO PollReq, NTSTATUS Status)
 
NTSTATUS TdiOpenAddressFile (PUNICODE_STRING DeviceName, PTRANSPORT_ADDRESS Name, ULONG ShareType, PHANDLE AddressHandle, PFILE_OBJECT *AddressObject)
 
NTSTATUS TdiAssociateAddressFile (HANDLE AddressHandle, PFILE_OBJECT ConnectionObject)
 
NTSTATUS TdiDisassociateAddressFile (PFILE_OBJECT ConnectionObject)
 
NTSTATUS TdiListen (PIRP *Irp, PFILE_OBJECT ConnectionObject, PTDI_CONNECTION_INFORMATION *RequestConnectionInfo, PTDI_CONNECTION_INFORMATION *ReturnConnectionInfo, PIO_COMPLETION_ROUTINE CompletionRoutine, PVOID CompletionContext)
 
NTSTATUS TdiReceive (PIRP *Irp, PFILE_OBJECT ConnectionObject, USHORT Flags, PCHAR Buffer, UINT BufferLength, PIO_COMPLETION_ROUTINE CompletionRoutine, PVOID CompletionContext)
 
NTSTATUS TdiSend (PIRP *Irp, PFILE_OBJECT ConnectionObject, USHORT Flags, PCHAR Buffer, UINT BufferLength, PIO_COMPLETION_ROUTINE CompletionRoutine, PVOID CompletionContext)
 
NTSTATUS TdiReceiveDatagram (PIRP *Irp, PFILE_OBJECT TransportObject, USHORT Flags, PCHAR Buffer, UINT BufferLength, PTDI_CONNECTION_INFORMATION From, PIO_COMPLETION_ROUTINE CompletionRoutine, PVOID CompletionContext)
 
NTSTATUS TdiSendDatagram (PIRP *Irp, PFILE_OBJECT TransportObject, PCHAR Buffer, UINT BufferLength, PTDI_CONNECTION_INFORMATION To, PIO_COMPLETION_ROUTINE CompletionRoutine, PVOID CompletionContext)
 
NTSTATUS TdiQueryMaxDatagramLength (PFILE_OBJECT FileObject, PUINT MaxDatagramLength)
 
NTSTATUS NTAPI AfdConnectedSocketWriteData (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Short)
 
NTSTATUS NTAPI AfdPacketSocketWriteData (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 

Variables

DRIVER_CANCEL AfdCancelHandler
 
IO_COMPLETION_ROUTINE ReceiveComplete
 
IO_COMPLETION_ROUTINE PacketSocketRecvComplete
 

Macro Definition Documentation

◆ _INC_WINDOWS

#define _INC_WINDOWS

Definition at line 20 of file afd.h.

◆ _WINBASE_

#define _WINBASE_

Definition at line 18 of file afd.h.

◆ _WINDOWS_H

#define _WINDOWS_H

Definition at line 19 of file afd.h.

◆ AFD_HANDLES

#define AFD_HANDLES (   x)    ((PAFD_HANDLE)(x)->Exclusive)

Definition at line 102 of file afd.h.

◆ DN2H

#define DN2H (   dw)
Value:
((((dw) & 0xFF000000L) >> 24) | \
(((dw) & 0x00FF0000L) >> 8) | \
(((dw) & 0x0000FF00L) << 8) | \
(((dw) & 0x000000FFL) << 24))
REFIID LPVOID DWORD dw
Definition: atlbase.h:40
static const WCHAR L[]
Definition: oid.c:1250

Definition at line 66 of file afd.h.

◆ EXTRA_LOCK_BUFFERS

#define EXTRA_LOCK_BUFFERS
Value:
2 /* Number of extra buffers needed
* for ancillary data on packet
* requests. */

Definition at line 95 of file afd.h.

◆ FUNCTION_ACCEPT

#define FUNCTION_ACCEPT   4

Definition at line 88 of file afd.h.

◆ FUNCTION_CLOSE

#define FUNCTION_CLOSE   6

Definition at line 90 of file afd.h.

◆ FUNCTION_CONNECT

#define FUNCTION_CONNECT   0

Definition at line 84 of file afd.h.

◆ FUNCTION_DISCONNECT

#define FUNCTION_DISCONNECT   5

Definition at line 89 of file afd.h.

◆ FUNCTION_PREACCEPT

#define FUNCTION_PREACCEPT   3

Definition at line 87 of file afd.h.

◆ FUNCTION_RECV

#define FUNCTION_RECV   1

Definition at line 85 of file afd.h.

◆ FUNCTION_SEND

#define FUNCTION_SEND   2

Definition at line 86 of file afd.h.

◆ IN_FLIGHT_REQUESTS

#define IN_FLIGHT_REQUESTS   5

Definition at line 93 of file afd.h.

◆ IP_MIB_ADDRTABLE_ENTRY_ID

#define IP_MIB_ADDRTABLE_ENTRY_ID   0x102

Definition at line 36 of file afd.h.

◆ IP_MIB_STATS_ID

#define IP_MIB_STATS_ID   1

Definition at line 35 of file afd.h.

◆ MAX_FUNCTIONS

#define MAX_FUNCTIONS   7

Definition at line 91 of file afd.h.

◆ MIN

#define MIN (   x,
  y 
)    (((x)<(y))?(x):(y))

Definition at line 31 of file afd.h.

◆ SET_AFD_HANDLES

#define SET_AFD_HANDLES (   x,
  y 
)    (((x)->Exclusive) = (ULONG_PTR)(y))

Definition at line 103 of file afd.h.

◆ SOCKET_STATE_BOUND

#define SOCKET_STATE_BOUND   1

Definition at line 74 of file afd.h.

◆ SOCKET_STATE_CLOSED

#define SOCKET_STATE_CLOSED   0x00000100

Definition at line 82 of file afd.h.

◆ SOCKET_STATE_CONNECTED

#define SOCKET_STATE_CONNECTED   3

Definition at line 76 of file afd.h.

◆ SOCKET_STATE_CONNECTING

#define SOCKET_STATE_CONNECTING   2

Definition at line 75 of file afd.h.

◆ SOCKET_STATE_CREATED

#define SOCKET_STATE_CREATED   0

Definition at line 73 of file afd.h.

◆ SOCKET_STATE_EOF_READ

#define SOCKET_STATE_EOF_READ   0x20000000

Definition at line 79 of file afd.h.

◆ SOCKET_STATE_INVALID_TRANSITION

#define SOCKET_STATE_INVALID_TRANSITION   ((DWORD)-1)

Definition at line 72 of file afd.h.

◆ SOCKET_STATE_LISTENING

#define SOCKET_STATE_LISTENING   4

Definition at line 77 of file afd.h.

◆ SOCKET_STATE_LOCKED

#define SOCKET_STATE_LOCKED   0x40000000

Definition at line 80 of file afd.h.

◆ SOCKET_STATE_MASK

#define SOCKET_STATE_MASK   0x0000ffff

Definition at line 78 of file afd.h.

◆ SOCKET_STATE_NEW

#define SOCKET_STATE_NEW   0x80000000

Definition at line 81 of file afd.h.

◆ TAG_AFD_ACCEPT_QUEUE

#define TAG_AFD_ACCEPT_QUEUE   'qafA'

Definition at line 46 of file afd.h.

◆ TAG_AFD_ACTIVE_POLL

#define TAG_AFD_ACTIVE_POLL   'pafA'

Definition at line 49 of file afd.h.

◆ TAG_AFD_CONNECT_DATA

#define TAG_AFD_CONNECT_DATA   'cdfA'

Definition at line 41 of file afd.h.

◆ TAG_AFD_CONNECT_OPTIONS

#define TAG_AFD_CONNECT_OPTIONS   'ocfA'

Definition at line 44 of file afd.h.

◆ TAG_AFD_DATA_BUFFER

#define TAG_AFD_DATA_BUFFER   'BdfA'

Definition at line 38 of file afd.h.

◆ TAG_AFD_DISCONNECT_DATA

#define TAG_AFD_DISCONNECT_DATA   'ddfA'

Definition at line 42 of file afd.h.

◆ TAG_AFD_DISCONNECT_OPTIONS

#define TAG_AFD_DISCONNECT_OPTIONS   'odfA'

Definition at line 45 of file afd.h.

◆ TAG_AFD_EA_INFO

#define TAG_AFD_EA_INFO   'aefA'

Definition at line 50 of file afd.h.

◆ TAG_AFD_FCB

#define TAG_AFD_FCB   'cffA'

Definition at line 48 of file afd.h.

◆ TAG_AFD_POLL_HANDLE

#define TAG_AFD_POLL_HANDLE   'hpfA'

Definition at line 47 of file afd.h.

◆ TAG_AFD_SNMP_ADDRESS_INFO

#define TAG_AFD_SNMP_ADDRESS_INFO   'asfA'

Definition at line 52 of file afd.h.

◆ TAG_AFD_SOCKET_CONTEXT

#define TAG_AFD_SOCKET_CONTEXT   'XdfA'

Definition at line 40 of file afd.h.

◆ TAG_AFD_STORED_DATAGRAM

#define TAG_AFD_STORED_DATAGRAM   'gsfA'

Definition at line 51 of file afd.h.

◆ TAG_AFD_TDI_CONNECTION_INFORMATION

#define TAG_AFD_TDI_CONNECTION_INFORMATION   'cTfA'

Definition at line 53 of file afd.h.

◆ TAG_AFD_TRANSPORT_ADDRESS

#define TAG_AFD_TRANSPORT_ADDRESS   'tdfA'

Definition at line 39 of file afd.h.

◆ TAG_AFD_WSA_BUFFER

#define TAG_AFD_WSA_BUFFER   'bWfA'

Definition at line 54 of file afd.h.

◆ TL_INSTANCE

#define TL_INSTANCE   0

Definition at line 34 of file afd.h.

Typedef Documentation

◆ AFD_ACTIVE_POLL

◆ AFD_DATA_WINDOW

◆ AFD_DEVICE_EXTENSION

◆ AFD_FCB

◆ AFD_IN_FLIGHT_REQUEST

◆ AFD_MAPBUF

◆ AFD_STORED_DATAGRAM

◆ AFD_TDI_OBJECT

◆ AFD_TDI_OBJECT_QELT

◆ IPADDR_ENTRY

◆ IRP_LIST

◆ PAFD_ACTIVE_POLL

◆ PAFD_DATA_WINDOW

◆ PAFD_DEVICE_EXTENSION

◆ PAFD_FCB

◆ PAFD_IN_FLIGHT_REQUEST

◆ PAFD_MAPBUF

◆ PAFD_STORED_DATAGRAM

◆ PAFD_TDI_OBJECT

◆ PAFD_TDI_OBJECT_QELT

◆ PIPADDR_ENTRY

◆ PIRP_LIST

Function Documentation

◆ AfdAccept()

NTSTATUS AfdAccept ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 337 of file listen.c.

338  {
341  PAFD_DEVICE_EXTENSION DeviceExt =
343  PAFD_FCB FCB = FileObject->FsContext;
344  PAFD_ACCEPT_DATA AcceptData = Irp->AssociatedIrp.SystemBuffer;
345  PLIST_ENTRY PendingConn;
346 
347  AFD_DbgPrint(MID_TRACE,("Called\n"));
348 
349  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
350 
351  FCB->EventSelectDisabled &= ~AFD_EVENT_ACCEPT;
352 
353  for( PendingConn = FCB->PendingConnections.Flink;
354  PendingConn != &FCB->PendingConnections;
355  PendingConn = PendingConn->Flink ) {
356  PAFD_TDI_OBJECT_QELT PendingConnObj =
357  CONTAINING_RECORD( PendingConn, AFD_TDI_OBJECT_QELT, ListEntry );
358 
359  AFD_DbgPrint(MID_TRACE,("Comparing Seq %u to Q %u\n",
360  AcceptData->SequenceNumber,
361  PendingConnObj->Seq));
362 
363  if( PendingConnObj->Seq == AcceptData->SequenceNumber ) {
365 
366  RemoveEntryList( PendingConn );
367 
369  ( AcceptData->ListenHandle,
371  NULL,
372  KernelMode,
373  (PVOID *)&NewFileObject,
374  NULL );
375 
376  if( !NT_SUCCESS(Status) ) return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
377 
379  ASSERT(NewFileObject->FsContext != FCB);
380 
381  /* We have a pending connection ... complete this irp right away */
382  Status = SatisfyAccept( DeviceExt, Irp, NewFileObject, PendingConnObj );
383 
385 
386  AFD_DbgPrint(MID_TRACE,("Completed a wait for accept\n"));
387 
388  ExFreePoolWithTag(PendingConnObj, TAG_AFD_ACCEPT_QUEUE);
389 
390  if( !IsListEmpty( &FCB->PendingConnections ) )
391  {
392  FCB->PollState |= AFD_EVENT_ACCEPT;
393  FCB->PollStatus[FD_ACCEPT_BIT] = STATUS_SUCCESS;
394  PollReeval( FCB->DeviceExt, FCB->FileObject );
395  } else
396  FCB->PollState &= ~AFD_EVENT_ACCEPT;
397 
399  return Status;
400  }
401  }
402 
403  AFD_DbgPrint(MIN_TRACE,("No connection waiting\n"));
404 
406 }
VOID SocketStateUnlock(PAFD_FCB FCB)
Definition: lock.c:370
#define MID_TRACE
Definition: debug.h:15
VOID PollReeval(PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
Definition: select.c:407
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
PFILE_OBJECT FileObject
Definition: ntfs.h:516
_In_ PIRP Irp
Definition: csq.h:116
Definition: cdstruc.h:908
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
_Must_inspect_result_ _In_ PFILE_OBJECT NewFileObject
Definition: fsrtlfuncs.h:1357
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define TAG_AFD_ACCEPT_QUEUE
Definition: afd.h:46
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
Definition: afd.h:161
#define AFD_EVENT_ACCEPT
Definition: shared.h:210
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
* PFILE_OBJECT
Definition: iotypes.h:1955
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
static NTSTATUS SatisfyAccept(PAFD_DEVICE_EXTENSION DeviceExt, PIRP Irp, PFILE_OBJECT NewFileObject, PAFD_TDI_OBJECT_QELT Qelt)
Definition: listen.c:13
struct _AFD_DEVICE_EXTENSION * PAFD_DEVICE_EXTENSION
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define FD_ACCEPT_BIT
Definition: winsock2.h:299
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define MIN_TRACE
Definition: debug.h:14
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by AfdDispatch().

◆ AfdBindSocket()

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

Definition at line 76 of file bind.c.

77  {
80  PAFD_FCB FCB = FileObject->FsContext;
81  PAFD_BIND_DATA BindReq;
82  HANDLE UserHandle = NULL;
83 
85 
86  AFD_DbgPrint(MID_TRACE,("Called\n"));
87 
88  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
89  if( !(BindReq = LockRequest( Irp, IrpSp, FALSE, NULL )) )
91  Irp, 0 );
92 
93  if (FCB->LocalAddress)
94  {
96  }
97 
98  FCB->LocalAddress = TaCopyTransportAddress( &BindReq->Address );
99 
100  if( FCB->LocalAddress )
101  Status = TdiBuildConnectionInfo( &FCB->AddressFrom,
102  FCB->LocalAddress );
103 
104  if( NT_SUCCESS(Status) )
105  Status = WarmSocketForBind( FCB, BindReq->ShareType );
106  AFD_DbgPrint(MID_TRACE,("FCB->Flags %x\n", FCB->Flags));
107 
108  if (NT_SUCCESS(Status))
109  {
110  Status = ObOpenObjectByPointer(FCB->AddressFile.Object,
111  0,
112  NULL,
115  Irp->RequestorMode,
116  &UserHandle);
117  if (NT_SUCCESS(Status))
118  FCB->State = SOCKET_STATE_BOUND;
119  }
120 
121  /* MSAFD relies on us returning the address file handle in the IOSB */
123  (ULONG_PTR)UserHandle);
124 }
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
#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
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
LONG NTSTATUS
Definition: precomp.h:26
#define TAG_AFD_TRANSPORT_ADDRESS
Definition: afd.h:39
NTSTATUS WarmSocketForBind(PAFD_FCB FCB, ULONG ShareType)
Definition: bind.c:13
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
NTSTATUS NTAPI ObOpenObjectByPointer(IN PVOID Object, IN ULONG HandleAttributes, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PHANDLE Handle)
Definition: obhandle.c:2739
uint32_t ULONG_PTR
Definition: typedefs.h:63
#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 NT_SUCCESS(StatCode)
Definition: apphelp.c:32
* 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
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
Status
Definition: gdiplustypes.h:24
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
ULONG ShareType
Definition: shared.h:39
#define SOCKET_STATE_BOUND
Definition: afd.h:74
PTRANSPORT_ADDRESS TaCopyTransportAddress(PTRANSPORT_ADDRESS OtherAddress)
Definition: tdiconn.c:80
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2966
TRANSPORT_ADDRESS Address
Definition: shared.h:40

Referenced by AfdDispatch().

◆ AfdConnectedSocketReadData()

NTSTATUS NTAPI AfdConnectedSocketReadData ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp,
BOOLEAN  Short 
)

Definition at line 422 of file read.c.

423  {
426  PAFD_FCB FCB = FileObject->FsContext;
427  PAFD_RECV_INFO RecvReq;
428  UINT TotalBytesCopied = 0;
429  PAFD_STORED_DATAGRAM DatagramRecv;
430  PLIST_ENTRY ListEntry;
432 
435 
436  AFD_DbgPrint(MID_TRACE,("Called on %p\n", FCB));
437 
438  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
439 
440  FCB->EventSelectDisabled &= ~AFD_EVENT_RECEIVE;
441 
443  FCB->State != SOCKET_STATE_CONNECTED &&
444  FCB->State != SOCKET_STATE_CONNECTING ) {
445  AFD_DbgPrint(MIN_TRACE,("Called recv on wrong kind of socket (s%x)\n",
446  FCB->State));
448  Irp, 0 );
449  }
450 
451  if( !(RecvReq = LockRequest( Irp, IrpSp, FALSE, &LockMode )) )
453  Irp, 0 );
454 
455  AFD_DbgPrint(MID_TRACE,("Recv flags %x\n", RecvReq->AfdFlags));
456 
457  RecvReq->BufferArray = LockBuffers( RecvReq->BufferArray,
458  RecvReq->BufferCount,
459  NULL, NULL,
460  TRUE, FALSE, LockMode );
461 
462  if( !RecvReq->BufferArray ) {
464  Irp, 0 );
465  }
466 
468  {
469  if (!IsListEmpty(&FCB->DatagramList))
470  {
471  ListEntry = RemoveHeadList(&FCB->DatagramList);
472  DatagramRecv = CONTAINING_RECORD(ListEntry, AFD_STORED_DATAGRAM, ListEntry);
473  Status = SatisfyPacketRecvRequest(FCB, Irp, DatagramRecv,
474  (PUINT)&Irp->IoStatus.Information);
475 
476  if (RecvReq->TdiFlags & TDI_RECEIVE_PEEK)
477  {
478  InsertHeadList(&FCB->DatagramList,
479  &DatagramRecv->ListEntry);
480  }
481 
482  if (!IsListEmpty(&FCB->DatagramList))
483  {
484  FCB->PollState |= AFD_EVENT_RECEIVE;
485  FCB->PollStatus[FD_READ_BIT] = STATUS_SUCCESS;
486  PollReeval( FCB->DeviceExt, FCB->FileObject );
487  }
488  else
489  FCB->PollState &= ~AFD_EVENT_RECEIVE;
490 
491  UnlockBuffers(RecvReq->BufferArray, RecvReq->BufferCount, FALSE);
492 
493  return UnlockAndMaybeComplete(FCB, Status, Irp, Irp->IoStatus.Information);
494  }
495  else if (!(RecvReq->AfdFlags & AFD_OVERLAPPED) &&
496  ((RecvReq->AfdFlags & AFD_IMMEDIATE) || (FCB->NonBlocking)))
497  {
498  AFD_DbgPrint(MID_TRACE,("Nonblocking\n"));
500  FCB->PollState &= ~AFD_EVENT_RECEIVE;
501  UnlockBuffers( RecvReq->BufferArray, RecvReq->BufferCount, FALSE );
502  return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
503  }
504  else
505  {
506  FCB->PollState &= ~AFD_EVENT_RECEIVE;
508  }
509  }
510 
511  Irp->IoStatus.Status = STATUS_PENDING;
512  Irp->IoStatus.Information = 0;
513 
514  InsertTailList( &FCB->PendingIrpList[FUNCTION_RECV],
515  &Irp->Tail.Overlay.ListEntry );
516 
517  /************ From this point, the IRP is not ours ************/
518 
520 
521  if( Status == STATUS_PENDING &&
522  !(RecvReq->AfdFlags & AFD_OVERLAPPED) &&
523  ((RecvReq->AfdFlags & AFD_IMMEDIATE) || (FCB->NonBlocking))) {
524  AFD_DbgPrint(MID_TRACE,("Nonblocking\n"));
526  TotalBytesCopied = 0;
527  RemoveEntryList( &Irp->Tail.Overlay.ListEntry );
528  UnlockBuffers( RecvReq->BufferArray, RecvReq->BufferCount, FALSE );
530  TotalBytesCopied );
531  } else if( Status == STATUS_PENDING ) {
532  AFD_DbgPrint(MID_TRACE,("Leaving read irp\n"));
535  } else {
536  AFD_DbgPrint(MID_TRACE,("Completed with status %x\n", Status));
537  }
538 
540  return Status;
541 }
VOID SocketStateUnlock(PAFD_FCB FCB)
Definition: lock.c:370
#define TRUE
Definition: types.h:120
#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_IMMEDIATE
Definition: shared.h:220
PFILE_OBJECT FileObject
Definition: ntfs.h:516
#define FUNCTION_RECV
Definition: afd.h:85
_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
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
PAFD_WSABUF LockBuffers(PAFD_WSABUF Buf, UINT Count, PVOID AddressBuf, PINT AddressLen, BOOLEAN Write, BOOLEAN LockAddress, KPROCESSOR_MODE LockMode)
Definition: lock.c:205
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
LONG NTSTATUS
Definition: precomp.h:26
ULONG AfdFlags
Definition: shared.h:87
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 InsertTailList(ListHead, Entry)
IoSetCancelRoutine(Irp, CancelRoutine)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
ULONG LockMode
Definition: env_spec_w32.cpp:8
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define AFD_ENDPOINT_CONNECTIONLESS
Definition: shared.h:153
static NTSTATUS ReceiveActivity(PAFD_FCB FCB, PIRP Irp)
Definition: read.c:151
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
smooth NULL
Definition: ftsmooth.c:416
#define AFD_EVENT_RECEIVE
Definition: shared.h:203
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
#define FD_READ_BIT
Definition: winsock2.h:293
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
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
Definition: afd.h:161
short Short
Definition: ftraster.c:311
#define AFD_OVERLAPPED
Definition: shared.h:219
NTSTATUS LeaveIrpUntilLater(PAFD_FCB FCB, PIRP Irp, UINT Function)
Definition: lock.c:433
#define STATUS_PENDING
Definition: ntstatus.h:82
#define SOCKET_STATE_CONNECTED
Definition: afd.h:76
VOID UnlockBuffers(PAFD_WSABUF Buf, UINT Count, BOOL Address)
Definition: lock.c:289
PAFD_WSABUF BufferArray
Definition: shared.h:85
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
* PFILE_OBJECT
Definition: iotypes.h:1955
ULONG Flags
Definition: ntfs.h:532
ULONG TdiFlags
Definition: shared.h:88
ULONG BufferCount
Definition: shared.h:86
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
LIST_ENTRY ListEntry
Definition: afd.h:155
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
static NTSTATUS NTAPI SatisfyPacketRecvRequest(PAFD_FCB FCB, PIRP Irp, PAFD_STORED_DATAGRAM DatagramRecv, PUINT TotalBytesCopied)
Definition: read.c:321
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
unsigned int UINT
Definition: ndis.h:50
#define TDI_RECEIVE_PEEK
Definition: tdi.h:124
#define SOCKET_STATE_CONNECTING
Definition: afd.h:75
#define MIN_TRACE
Definition: debug.h:14
return STATUS_SUCCESS
Definition: btrfs.c:2966
IoMarkIrpPending(Irp)
unsigned int * PUINT
Definition: ndis.h:50
DRIVER_CANCEL AfdCancelHandler
Definition: afd.h:304
#define STATUS_CANT_WAIT
Definition: ntstatus.h:438

Referenced by AfdDispatch().

◆ AfdConnectedSocketWriteData()

NTSTATUS NTAPI AfdConnectedSocketWriteData ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp,
BOOLEAN  Short 
)

Definition at line 329 of file write.c.

330  {
333  PAFD_FCB FCB = FileObject->FsContext;
334  PAFD_SEND_INFO SendReq;
335  UINT TotalBytesCopied = 0, i, SpaceAvail = 0, BytesCopied, SendLength;
337 
340 
341  AFD_DbgPrint(MID_TRACE,("Called on %p\n", FCB));
342 
343  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
344 
345  FCB->EventSelectDisabled &= ~AFD_EVENT_SEND;
346 
348  {
349  PAFD_SEND_INFO_UDP SendReq;
351 
352  /* Check that the socket is bound */
353  if( FCB->State != SOCKET_STATE_BOUND || !FCB->RemoteAddress )
354  {
355  AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n"));
357  0 );
358  }
359 
360  if( !(SendReq = LockRequest( Irp, IrpSp, FALSE, &LockMode )) )
362 
363  /* Must lock buffers before handing off user data */
364  SendReq->BufferArray = LockBuffers( SendReq->BufferArray,
365  SendReq->BufferCount,
366  NULL, NULL,
367  FALSE, FALSE, LockMode );
368 
369  if( !SendReq->BufferArray ) {
371  Irp, 0 );
372  }
373 
374  Status = TdiBuildConnectionInfo( &TargetAddress, FCB->RemoteAddress );
375 
376  if( NT_SUCCESS(Status) ) {
377  FCB->PollState &= ~AFD_EVENT_SEND;
378 
380  if (Status == STATUS_PENDING)
381  {
382  Status = TdiSendDatagram(&FCB->SendIrp.InFlightRequest,
383  FCB->AddressFile.Object,
384  SendReq->BufferArray[0].buf,
385  SendReq->BufferArray[0].len,
388  FCB);
389  if (Status != STATUS_PENDING)
390  {
391  NT_VERIFY(RemoveHeadList(&FCB->PendingIrpList[FUNCTION_SEND]) == &Irp->Tail.Overlay.ListEntry);
392  Irp->IoStatus.Status = Status;
393  Irp->IoStatus.Information = 0;
395  UnlockBuffers(SendReq->BufferArray, SendReq->BufferCount, FALSE);
398  }
399  }
400 
402 
404 
405  return STATUS_PENDING;
406  }
407  else
408  {
409  UnlockBuffers(SendReq->BufferArray, SendReq->BufferCount, FALSE);
410  return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
411  }
412  }
413 
414  if (FCB->PollState & AFD_EVENT_CLOSE)
415  {
416  AFD_DbgPrint(MIN_TRACE,("Connection reset by remote peer\n"));
417 
418  /* This is an unexpected remote disconnect */
419  return UnlockAndMaybeComplete(FCB, FCB->PollStatus[FD_CLOSE_BIT], Irp, 0);
420  }
421 
422  if (FCB->PollState & AFD_EVENT_ABORT)
423  {
424  AFD_DbgPrint(MIN_TRACE,("Connection aborted\n"));
425 
426  /* This is an abortive socket closure on our side */
427  return UnlockAndMaybeComplete(FCB, FCB->PollStatus[FD_CLOSE_BIT], Irp, 0);
428  }
429 
430  if (FCB->SendClosed)
431  {
432  AFD_DbgPrint(MIN_TRACE,("No more sends\n"));
433 
434  /* This is a graceful send closure */
436  }
437 
438  if( !(SendReq = LockRequest( Irp, IrpSp, FALSE, &LockMode )) )
440  ( FCB, STATUS_NO_MEMORY, Irp, 0 );
441 
442  SendReq->BufferArray = LockBuffers( SendReq->BufferArray,
443  SendReq->BufferCount,
444  NULL, NULL,
445  FALSE, FALSE, LockMode );
446 
447  if( !SendReq->BufferArray ) {
449  Irp, 0 );
450  }
451 
452  AFD_DbgPrint(MID_TRACE,("Socket state %u\n", FCB->State));
453 
454  if( FCB->State != SOCKET_STATE_CONNECTED ) {
455  AFD_DbgPrint(MID_TRACE,("Socket not connected\n"));
456  UnlockBuffers( SendReq->BufferArray, SendReq->BufferCount, FALSE );
458  }
459 
460  AFD_DbgPrint(MID_TRACE,("FCB->Send.BytesUsed = %u\n",
461  FCB->Send.BytesUsed));
462 
463  SpaceAvail = FCB->Send.Size - FCB->Send.BytesUsed;
464 
465  AFD_DbgPrint(MID_TRACE,("We can accept %u bytes\n",
466  SpaceAvail));
467 
468  /* Count the total transfer size */
469  SendLength = 0;
470  for (i = 0; i < SendReq->BufferCount; i++)
471  {
472  SendLength += SendReq->BufferArray[i].len;
473  }
474 
475  /* Make sure we've got the space */
476  if (SendLength > SpaceAvail)
477  {
478  /* Blocking sockets have to wait here */
479  if (SendLength <= FCB->Send.Size && !((SendReq->AfdFlags & AFD_IMMEDIATE) || (FCB->NonBlocking)))
480  {
481  FCB->PollState &= ~AFD_EVENT_SEND;
483  }
484 
485  /* Check if we can send anything */
486  if (SpaceAvail == 0)
487  {
488  FCB->PollState &= ~AFD_EVENT_SEND;
489 
490  /* Non-overlapped sockets will fail if we can send nothing */
491  if (!(SendReq->AfdFlags & AFD_OVERLAPPED))
492  {
493  UnlockBuffers( SendReq->BufferArray, SendReq->BufferCount, FALSE );
495  }
496  else
497  {
498  /* Overlapped sockets just pend */
500  }
501  }
502  }
503 
504  for ( i = 0; SpaceAvail > 0 && i < SendReq->BufferCount; i++ )
505  {
506  BytesCopied = MIN(SendReq->BufferArray[i].len, SpaceAvail);
507 
508  AFD_DbgPrint(MID_TRACE,("Copying Buffer %u, %p:%u to %p\n",
509  i,
510  SendReq->BufferArray[i].buf,
511  BytesCopied,
512  FCB->Send.Window + FCB->Send.BytesUsed));
513 
514  RtlCopyMemory(FCB->Send.Window + FCB->Send.BytesUsed,
515  SendReq->BufferArray[i].buf,
516  BytesCopied);
517 
518  TotalBytesCopied += BytesCopied;
519  SpaceAvail -= BytesCopied;
520  FCB->Send.BytesUsed += BytesCopied;
521  }
522 
523  Irp->IoStatus.Information = TotalBytesCopied;
524 
525  if( TotalBytesCopied == 0 ) {
526  AFD_DbgPrint(MID_TRACE,("Empty send\n"));
527  UnlockBuffers( SendReq->BufferArray, SendReq->BufferCount, FALSE );
529  ( FCB, STATUS_SUCCESS, Irp, TotalBytesCopied );
530  }
531 
532  if (SpaceAvail)
533  {
534  FCB->PollState |= AFD_EVENT_SEND;
535  FCB->PollStatus[FD_WRITE_BIT] = STATUS_SUCCESS;
536  PollReeval( FCB->DeviceExt, FCB->FileObject );
537  }
538  else
539  {
540  FCB->PollState &= ~AFD_EVENT_SEND;
541  }
542 
543  /* We use the IRP tail for some temporary storage here */
544  Irp->Tail.Overlay.DriverContext[3] = (PVOID)Irp->IoStatus.Information;
545 
547  if (Status == STATUS_PENDING && !FCB->SendIrp.InFlightRequest)
548  {
549  TdiSend(&FCB->SendIrp.InFlightRequest,
550  FCB->Connection.Object,
551  0,
552  FCB->Send.Window,
553  FCB->Send.BytesUsed,
554  SendComplete,
555  FCB);
556  }
557 
559 
560  return STATUS_PENDING;
561 }
VOID SocketStateUnlock(PAFD_FCB FCB)
Definition: lock.c:370
#define STATUS_INVALID_CONNECTION
Definition: ntstatus.h:542
UINT len
Definition: shared.h:17
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
NTSTATUS Status
Definition: write.c:2817
#define AFD_IMMEDIATE
Definition: shared.h:220
PFILE_OBJECT FileObject
Definition: ntfs.h:516
_In_ PIRP Irp
Definition: csq.h:116
PCHAR buf
Definition: shared.h:18
#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
PAFD_WSABUF LockBuffers(PAFD_WSABUF Buf, UINT Count, PVOID AddressBuf, PINT AddressLen, BOOLEAN Write, BOOLEAN LockAddress, KPROCESSOR_MODE LockMode)
Definition: lock.c:205
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
static IO_COMPLETION_ROUTINE SendComplete
Definition: write.c:13
LONG NTSTATUS
Definition: precomp.h:26
#define AFD_EVENT_ABORT
Definition: shared.h:207
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
static IO_COMPLETION_ROUTINE PacketSocketSendComplete
Definition: write.c:260
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
#define NT_VERIFY(exp)
Definition: rtlfuncs.h:3289
IoSetCancelRoutine(Irp, CancelRoutine)
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER _Outptr_ PVOID * TargetAddress
Definition: iotypes.h:998
ULONG LockMode
Definition: env_spec_w32.cpp:8
T MIN(T a, T b)
Definition: polytest.cpp:79
#define AFD_EVENT_CLOSE
Definition: shared.h:208
#define AFD_ENDPOINT_CONNECTIONLESS
Definition: shared.h:153
ULONG BufferCount
Definition: shared.h:109
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
smooth NULL
Definition: ftsmooth.c:416
_In_ UINT _In_ UINT _In_ PNDIS_PACKET _In_ UINT _Out_ PUINT BytesCopied
Definition: ndis.h:3167
#define IoCompleteRequest
Definition: irp.c:1240
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PAFD_WSABUF BufferArray
Definition: shared.h:108
void * PVOID
Definition: retypes.h:9
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
#define AFD_EVENT_SEND
Definition: shared.h:205
Definition: afd.h:161
short Short
Definition: ftraster.c:311
NTSTATUS TdiSend(PIRP *Irp, PFILE_OBJECT TransportObject, USHORT Flags, PCHAR Buffer, UINT BufferLength, PIO_COMPLETION_ROUTINE CompletionRoutine, PVOID CompletionContext)
Definition: tdi.c:898
#define AFD_OVERLAPPED
Definition: shared.h:219
#define FD_CLOSE_BIT
Definition: winsock2.h:303
NTSTATUS LeaveIrpUntilLater(PAFD_FCB FCB, PIRP Irp, UINT Function)
Definition: lock.c:433
#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
#define SOCKET_STATE_CONNECTED
Definition: afd.h:76
VOID UnlockBuffers(PAFD_WSABUF Buf, UINT Count, BOOL Address)
Definition: lock.c:289
NTSTATUS QueueUserModeIrp(PAFD_FCB FCB, PIRP Irp, UINT Function)
Definition: lock.c:397
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
* PFILE_OBJECT
Definition: iotypes.h:1955
NTSTATUS TdiSendDatagram(PIRP *Irp, PFILE_OBJECT TransportObject, PCHAR Buffer, UINT BufferLength, PTDI_CONNECTION_INFORMATION Addr, PIO_COMPLETION_ROUTINE CompletionRoutine, PVOID CompletionContext)
Definition: tdi.c:1151
NTSTATUS TdiBuildConnectionInfo(PTDI_CONNECTION_INFORMATION *ConnectionInfo, PTRANSPORT_ADDRESS Address)
Definition: tdiconn.c:237
ULONG Flags
Definition: ntfs.h:532
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
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
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 SOCKET_STATE_BOUND
Definition: afd.h:74
#define MIN_TRACE
Definition: debug.h:14
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define FD_WRITE_BIT
Definition: winsock2.h:295
#define STATUS_CANT_WAIT
Definition: ntstatus.h:438
#define STATUS_FILE_CLOSED
Definition: ntstatus.h:518

Referenced by AfdDispatch(), and StreamSocketConnectComplete().

◆ AfdEnumEvents()

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

Definition at line 328 of file select.c.

329  {
333  PAFD_FCB FCB = FileObject->FsContext;
334  PKEVENT UserEvent;
336 
338 
339  AFD_DbgPrint(MID_TRACE,("Called (FCB %p)\n", FCB));
340 
341  if( !SocketAcquireStateLock( FCB ) ) {
342  return LostSocket( Irp );
343  }
344 
345  if ( !EnumReq ) {
347  }
348 
349  /* An event may optionally be provided for us to clear */
350  if (EnumReq->Event != NULL)
351  {
355  UserMode,
356  (PVOID *)&UserEvent,
357  NULL);
358  if (!NT_SUCCESS(Status))
359  {
360  AFD_DbgPrint(MIN_TRACE,("Unable to reference event %x\n", Status));
361  return UnlockAndMaybeComplete(FCB, Status, Irp, 0);
362  }
363 
364  /* Clear the event */
365  KeClearEvent(UserEvent);
366  ObDereferenceObject(UserEvent);
367  }
368 
369  /* Copy the poll state, masking out disabled events */
370  EnumReq->PollEvents = (FCB->PollState & ~FCB->EventSelectDisabled);
371  RtlCopyMemory( EnumReq->EventStatus,
372  FCB->PollStatus,
373  sizeof(EnumReq->EventStatus) );
374 
375  /* Disable the events that triggered the select until the reenabling function is called */
376  FCB->EventSelectDisabled |= (FCB->PollState & FCB->EventSelectTriggers);
377 
379 }
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#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
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
POBJECT_TYPE ExEventObjectType
Definition: event.c:22
struct _AFD_ENUM_NETWORK_EVENTS_INFO * PAFD_ENUM_NETWORK_EVENTS_INFO
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
#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 NT_SUCCESS(StatCode)
Definition: apphelp.c:32
* PFILE_OBJECT
Definition: iotypes.h:1955
Status
Definition: gdiplustypes.h:24
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 MIN_TRACE
Definition: debug.h:14
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
return STATUS_SUCCESS
Definition: btrfs.c:2966
NTSTATUS EventStatus[AFD_MAX_EVENTS]
Definition: shared.h:132

Referenced by AfdDispatch().

◆ AfdEventSelect()

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

Definition at line 265 of file select.c.

266  {
269  PAFD_EVENT_SELECT_INFO EventSelectInfo =
271  PAFD_FCB FCB = FileObject->FsContext;
272 
274 
275  if( !SocketAcquireStateLock( FCB ) ) {
276  return LostSocket( Irp );
277  }
278 
279  if ( !EventSelectInfo ) {
281  0 );
282  }
283  AFD_DbgPrint(MID_TRACE,("Called (Event %p Triggers %u)\n",
284  EventSelectInfo->EventObject,
285  EventSelectInfo->Events));
286 
287  if( FCB->EventSelect ) ObDereferenceObject( FCB->EventSelect );
288  FCB->EventSelect = NULL;
289 
290  if( EventSelectInfo->EventObject && EventSelectInfo->Events ) {
291  Status = ObReferenceObjectByHandle( (PVOID)EventSelectInfo->
292  EventObject,
295  UserMode,
296  (PVOID *)&FCB->EventSelect,
297  NULL );
298 
299  if( !NT_SUCCESS(Status) )
300  {
301  AFD_DbgPrint(MIN_TRACE,("Failed reference event (0x%x)\n", Status));
302  FCB->EventSelect = NULL;
303  }
304  else
305  FCB->EventSelectTriggers = EventSelectInfo->Events;
306  } else {
307  FCB->EventSelect = NULL;
308  FCB->EventSelectTriggers = 0;
310  }
311 
312  if((FCB->EventSelect) &&
313  (FCB->PollState & (FCB->EventSelectTriggers & ~FCB->EventSelectDisabled)))
314  {
315  AFD_DbgPrint(MID_TRACE,("Setting event %p\n", FCB->EventSelect));
316 
317  /* Set the application's event */
318  KeSetEvent( FCB->EventSelect, IO_NETWORK_INCREMENT, FALSE );
319  }
320 
321  AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
322 
324  0 );
325 }
#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
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
POBJECT_TYPE ExEventObjectType
Definition: event.c:22
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
Definition: afd.h:161
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
* PFILE_OBJECT
Definition: iotypes.h:1955
struct _AFD_EVENT_SELECT_INFO * PAFD_EVENT_SELECT_INFO
Status
Definition: gdiplustypes.h:24
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 MIN_TRACE
Definition: debug.h:14
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by AfdDispatch().

◆ 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().

◆ AfdGetContext()

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

Definition at line 14 of file context.c.

15  {
18  PAFD_FCB FCB = FileObject->FsContext;
19  UINT ContextSize = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
20 
22 
23  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
24 
25  if( FCB->ContextSize < ContextSize ) ContextSize = FCB->ContextSize;
26 
27  if( FCB->Context ) {
28  RtlCopyMemory( Irp->UserBuffer,
29  FCB->Context,
30  ContextSize );
32  }
33 
34  AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
35 
37 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#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 STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
_Must_inspect_result_ _In_ FLT_CONTEXT_TYPE _In_ SIZE_T ContextSize
Definition: fltkernel.h:1444
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
* PFILE_OBJECT
Definition: iotypes.h:1955
Status
Definition: gdiplustypes.h:24
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
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by AfdDispatch().

◆ AfdGetContextSize()

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

Definition at line 40 of file context.c.

42 {
44  PAFD_FCB FCB = FileObject->FsContext;
45 
47 
48  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
49 
50  if (IrpSp->Parameters.DeviceIoControl.OutputBufferLength < sizeof(ULONG))
51  {
52  AFD_DbgPrint(MIN_TRACE,("Buffer too small\n"));
54  }
55 
56  RtlCopyMemory(Irp->UserBuffer,
57  &FCB->ContextSize,
58  sizeof(ULONG));
59 
61 }
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
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
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
Definition: afd.h:161
* PFILE_OBJECT
Definition: iotypes.h:1955
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 ULONG
Definition: retypes.h:1
#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().

◆ AfdGetInfo()

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

Definition at line 14 of file info.c.

15  {
17  PAFD_INFO InfoReq = LockRequest(Irp, IrpSp, TRUE, NULL);
19  PAFD_FCB FCB = FileObject->FsContext;
20  PLIST_ENTRY CurrentEntry;
21 
23 
24  AFD_DbgPrint(MID_TRACE,("Called %p %x\n", InfoReq,
25  InfoReq ? InfoReq->InformationClass : 0));
26 
27  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
28 
29  if (!InfoReq)
31 
32  _SEH2_TRY {
33  switch( InfoReq->InformationClass ) {
35  InfoReq->Information.Ulong = FCB->Recv.Size;
36  break;
37 
39  InfoReq->Information.Ulong = FCB->Send.Size;
40  AFD_DbgPrint(MID_TRACE,("Send window size %u\n", FCB->Send.Size));
41  break;
42 
44  InfoReq->Information.LargeInteger.u.HighPart = FCB->GroupType;
45  InfoReq->Information.LargeInteger.u.LowPart = FCB->GroupID;
46  AFD_DbgPrint(MID_TRACE, ("Group ID: %u Group Type: %u\n", FCB->GroupID, FCB->GroupType));
47  break;
48 
50  InfoReq->Information.Boolean = FCB->NonBlocking;
51  break;
52 
54  InfoReq->Information.Boolean = FCB->OobInline;
55  break;
56 
58  InfoReq->Information.Ulong = FCB->Recv.Content - FCB->Recv.BytesUsed;
59  break;
60 
62  InfoReq->Information.Ulong = 0;
63 
64  /* Count the queued sends */
65  CurrentEntry = FCB->PendingIrpList[FUNCTION_SEND].Flink;
66  while (CurrentEntry != &FCB->PendingIrpList[FUNCTION_SEND])
67  {
68  InfoReq->Information.Ulong++;
69  CurrentEntry = CurrentEntry->Flink;
70  }
71 
72  /* This needs to count too because when this is dispatched
73  * the user-mode IRP has already been completed and therefore
74  * will NOT be in our pending IRP list. We count this as one send
75  * outstanding although it could be multiple since we batch sends
76  * when waiting for the in flight request to return, so this number
77  * may not be accurate but it really doesn't matter that much since
78  * it's more or less a zero/non-zero comparison to determine whether
79  * we can shutdown the socket
80  */
81  if (FCB->SendIrp.InFlightRequest)
82  InfoReq->Information.Ulong++;
83  break;
84 
85  default:
86  AFD_DbgPrint(MIN_TRACE,("Unknown info id %x\n",
87  InfoReq->InformationClass));
89  break;
90  }
92  AFD_DbgPrint(MIN_TRACE,("Exception executing GetInfo\n"));
94  } _SEH2_END;
95 
96  AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
97 
98  return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
99 }
#define TRUE
Definition: types.h:120
#define MID_TRACE
Definition: debug.h:15
BOOLEAN Boolean
Definition: shared.h:33
_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
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
union _AFD_INFO::@3259 Information
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
_SEH2_TRY
Definition: create.c:4250
LARGE_INTEGER LargeInteger
Definition: shared.h:32
struct _LARGE_INTEGER::@2201 u
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define AFD_INFO_BLOCKING_MODE
Definition: shared.h:183
#define AFD_INFO_SEND_WINDOW_SIZE
Definition: shared.h:186
Definition: afd.h:161
#define AFD_INFO_RECEIVE_CONTENT_SIZE
Definition: shared.h:188
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define FUNCTION_SEND
Definition: afd.h:86
ULONG InformationClass
Definition: shared.h:29
* PFILE_OBJECT
Definition: iotypes.h:1955
#define AFD_INFO_GROUP_ID_TYPE
Definition: shared.h:187
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define AFD_INFO_SENDS_IN_PROGRESS
Definition: shared.h:184
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_SEH2_END
Definition: create.c:4424
#define AFD_INFO_INLINING_MODE
Definition: shared.h:182
#define AFD_INFO_RECEIVE_WINDOW_SIZE
Definition: shared.h:185
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 MIN_TRACE
Definition: debug.h:14
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
return STATUS_SUCCESS
Definition: btrfs.c:2966
ULONG Ulong
Definition: shared.h:31

Referenced by AfdDispatch().

◆ AfdGetPeerName()

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

Definition at line 281 of file info.c.

282  {
285  PAFD_FCB FCB = FileObject->FsContext;
286 
288 
289  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
290 
291  if (FCB->RemoteAddress == NULL) {
292  AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n"));
294  }
295 
296  if (IrpSp->Parameters.DeviceIoControl.OutputBufferLength >= TaLengthOfTransportAddress(FCB->RemoteAddress))
297  {
298  RtlCopyMemory(Irp->UserBuffer, FCB->RemoteAddress, TaLengthOfTransportAddress(FCB->RemoteAddress));
300  }
301  else
302  {
303  AFD_DbgPrint(MIN_TRACE,("Buffer too small\n"));
305  }
306 
307  return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
308 }
UINT TaLengthOfTransportAddress(PTRANSPORT_ADDRESS Addr)
Definition: tdiconn.c:46
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
LONG NTSTATUS
Definition: precomp.h:26
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
* PFILE_OBJECT
Definition: iotypes.h:1955
Status
Definition: gdiplustypes.h:24
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 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().

◆ AfdGetSockName()

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

Definition at line 232 of file info.c.

233  {
236  PAFD_FCB FCB = FileObject->FsContext;
237  PMDL Mdl = NULL;
238 
240  ASSERT(Irp->MdlAddress == NULL);
241 
242  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
243 
244  if( FCB->AddressFile.Object == NULL && FCB->Connection.Object == NULL ) {
246  }
247 
248  Mdl = IoAllocateMdl( Irp->UserBuffer,
249  IrpSp->Parameters.DeviceIoControl.OutputBufferLength,
250  FALSE,
251  FALSE,
252  NULL );
253 
254  if( Mdl != NULL ) {
255  _SEH2_TRY {
256  MmProbeAndLockPages( Mdl, Irp->RequestorMode, IoModifyAccess );
258  AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
260  } _SEH2_END;
261 
262  if( NT_SUCCESS(Status) ) {
263  Status = TdiQueryInformation( FCB->Connection.Object
264  ? FCB->Connection.Object
265  : FCB->AddressFile.Object,
267  Mdl );
268  }
269 
270  /* Check if MmProbeAndLockPages or TdiQueryInformation failed and
271  * clean up Mdl */
272  if (!NT_SUCCESS(Status) && Irp->MdlAddress != Mdl)
273  IoFreeMdl(Mdl);
274  } else
276 
277  return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
278 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_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
LONG NTSTATUS
Definition: precomp.h:26
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
NTSTATUS TdiQueryInformation(PFILE_OBJECT FileObject, LONG QueryType, PMDL MdlBuffer)
Definition: tdi.c:668
_SEH2_TRY
Definition: create.c:4250
#define TDI_QUERY_ADDRESS_INFO
Definition: tdi.h:181
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
Definition: afd.h:161
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
* PFILE_OBJECT
Definition: iotypes.h:1955
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_SEH2_END
Definition: create.c:4424
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:935
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define MIN_TRACE
Definition: debug.h:14
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by AfdDispatch().

◆ AfdListenSocket()

NTSTATUS AfdListenSocket ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 225 of file listen.c.

226  {
229  PAFD_FCB FCB = FileObject->FsContext;
230  PAFD_LISTEN_DATA ListenReq;
231 
233 
234  AFD_DbgPrint(MID_TRACE,("Called on %p\n", FCB));
235 
236  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
237 
238  if( !(ListenReq = LockRequest( Irp, IrpSp, FALSE, NULL )) )
240  0 );
241 
242  if( FCB->State != SOCKET_STATE_BOUND ) {
244  AFD_DbgPrint(MIN_TRACE,("Could not listen an unbound socket\n"));
245  return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
246  }
247 
248  FCB->DelayedAccept = ListenReq->UseDelayedAcceptance;
249 
250  AFD_DbgPrint(MID_TRACE,("ADDRESSFILE: %p\n", FCB->AddressFile.Handle));
251 
253 
254  AFD_DbgPrint(MID_TRACE,("Status from warmsocket %x\n", Status));
255 
256  if( !NT_SUCCESS(Status) ) return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
257 
259  ( &FCB->ListenIrp.ConnectionCallInfo,
260  FCB->LocalAddress->Address[0].AddressType );
261 
263 
265  ( &FCB->ListenIrp.ConnectionReturnInfo,
266  FCB->LocalAddress->Address[0].AddressType );
267 
268  if (!NT_SUCCESS(Status))
269  {
270  ExFreePoolWithTag(FCB->ListenIrp.ConnectionCallInfo,
272 
273  FCB->ListenIrp.ConnectionCallInfo = NULL;
274  return UnlockAndMaybeComplete(FCB, Status, Irp, 0);
275  }
276 
277  FCB->State = SOCKET_STATE_LISTENING;
278 
279  Status = TdiListen( &FCB->ListenIrp.InFlightRequest,
280  FCB->Connection.Object,
281  &FCB->ListenIrp.ConnectionCallInfo,
282  &FCB->ListenIrp.ConnectionReturnInfo,
284  FCB );
285 
286  if( Status == STATUS_PENDING )
288 
289  AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
290  return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
291 }
#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
BOOLEAN UseDelayedAcceptance
Definition: shared.h:46
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
LONG NTSTATUS
Definition: precomp.h:26
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
static IO_COMPLETION_ROUTINE ListenComplete
Definition: listen.c:89
#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 NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
NTSTATUS TdiListen(PIRP *Irp, PFILE_OBJECT ConnectionObject, PTDI_CONNECTION_INFORMATION *RequestConnectionInfo, PTDI_CONNECTION_INFORMATION *ReturnConnectionInfo, PIO_COMPLETION_ROUTINE CompletionRoutine, PVOID CompletionContext)
Definition: tdi.c:489
NTSTATUS WarmSocketForConnection(PAFD_FCB FCB)
Definition: connect.c:238
* PFILE_OBJECT
Definition: iotypes.h:1955
Status
Definition: gdiplustypes.h:24
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_LISTENING
Definition: afd.h:77
#define SOCKET_STATE_BOUND
Definition: afd.h:74
#define MIN_TRACE
Definition: debug.h:14
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2966
NTSTATUS TdiBuildNullConnectionInfo(PTDI_CONNECTION_INFORMATION *ConnectionInfo, ULONG Type)
Definition: tdiconn.c:171

Referenced by AfdDispatch().

◆ AfdPacketSocketReadData()

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

Definition at line 703 of file read.c.

704  {
707  PAFD_FCB FCB = FileObject->FsContext;
708  PAFD_RECV_INFO_UDP RecvReq;
709  PLIST_ENTRY ListEntry;
710  PAFD_STORED_DATAGRAM DatagramRecv;
712 
714 
715  AFD_DbgPrint(MID_TRACE,("Called on %p\n", FCB));
716 
717  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
718 
719  FCB->EventSelectDisabled &= ~AFD_EVENT_RECEIVE;
720 
721  /* Check that the socket is bound */
722  if( FCB->State != SOCKET_STATE_BOUND )
723  {
724  AFD_DbgPrint(MIN_TRACE,("Invalid socket state\n"));
726  }
727 
728  if (FCB->TdiReceiveClosed)
729  {
730  AFD_DbgPrint(MIN_TRACE,("Receive closed\n"));
732  }
733 
734  if( !(RecvReq = LockRequest( Irp, IrpSp, FALSE, &LockMode )) )
736 
737  AFD_DbgPrint(MID_TRACE,("Recv flags %x\n", RecvReq->AfdFlags));
738 
739  RecvReq->BufferArray = LockBuffers( RecvReq->BufferArray,
740  RecvReq->BufferCount,
741  RecvReq->Address,
742  RecvReq->AddressLength,
743  TRUE, TRUE, LockMode );
744 
745  if( !RecvReq->BufferArray ) { /* access violation in userspace */
747  }
748 
749  if (!IsListEmpty(&FCB->DatagramList))
750  {
751  ListEntry = RemoveHeadList(&FCB->DatagramList);
752  DatagramRecv = CONTAINING_RECORD(ListEntry, AFD_STORED_DATAGRAM, ListEntry);
753  Status = SatisfyPacketRecvRequest(FCB, Irp, DatagramRecv,
754  (PUINT)&Irp->IoStatus.Information);
755 
756  if (RecvReq->TdiFlags & TDI_RECEIVE_PEEK)
757  {
758  InsertHeadList(&FCB->DatagramList,
759  &DatagramRecv->ListEntry);
760  }
761 
762  if (!IsListEmpty(&FCB->DatagramList))
763  {
764  FCB->PollState |= AFD_EVENT_RECEIVE;
765  FCB->PollStatus[FD_READ_BIT] = STATUS_SUCCESS;
766  PollReeval( FCB->DeviceExt, FCB->FileObject );
767  }
768  else
769  FCB->PollState &= ~AFD_EVENT_RECEIVE;
770 
771  UnlockBuffers(RecvReq->BufferArray, RecvReq->BufferCount, TRUE);
772 
773  return UnlockAndMaybeComplete(FCB, Status, Irp, Irp->IoStatus.Information);
774  }
775  else if (!(RecvReq->AfdFlags & AFD_OVERLAPPED) &&
776  ((RecvReq->AfdFlags & AFD_IMMEDIATE) || (FCB->NonBlocking)))
777  {
778  AFD_DbgPrint(MID_TRACE,("Nonblocking\n"));
780  FCB->PollState &= ~AFD_EVENT_RECEIVE;
781  UnlockBuffers( RecvReq->BufferArray, RecvReq->BufferCount, TRUE );
782  return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
783  }
784  else
785  {
786  FCB->PollState &= ~AFD_EVENT_RECEIVE;
788  }
789 }
ULONG AfdFlags
Definition: shared.h:94
PINT AddressLength
Definition: shared.h:97
#define TRUE
Definition: types.h:120
#define MID_TRACE
Definition: debug.h:15
VOID PollReeval(PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
Definition: select.c:407
#define AFD_IMMEDIATE
Definition: shared.h:220
PFILE_OBJECT FileObject
Definition: ntfs.h:516
#define FUNCTION_RECV
Definition: afd.h:85
_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
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
PAFD_WSABUF LockBuffers(PAFD_WSABUF Buf, UINT Count, PVOID AddressBuf, PINT AddressLen, BOOLEAN Write, BOOLEAN LockAddress, KPROCESSOR_MODE LockMode)
Definition: lock.c:205
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
PAFD_WSABUF BufferArray
Definition: shared.h:92
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
ULONG LockMode
Definition: env_spec_w32.cpp:8
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
#define AFD_EVENT_RECEIVE
Definition: shared.h:203
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
ULONG TdiFlags
Definition: shared.h:95
#define FD_READ_BIT
Definition: winsock2.h:293
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
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
Definition: afd.h:161
#define AFD_OVERLAPPED
Definition: shared.h:219
NTSTATUS LeaveIrpUntilLater(PAFD_FCB FCB, PIRP Irp, UINT Function)
Definition: lock.c:433
VOID UnlockBuffers(PAFD_WSABUF Buf, UINT Count, BOOL Address)
Definition: lock.c:289
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
* PFILE_OBJECT
Definition: iotypes.h:1955
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
LIST_ENTRY ListEntry
Definition: afd.h:155
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
static NTSTATUS NTAPI SatisfyPacketRecvRequest(PAFD_FCB FCB, PIRP Irp, PAFD_STORED_DATAGRAM DatagramRecv, PUINT TotalBytesCopied)
Definition: read.c:321
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define TDI_RECEIVE_PEEK
Definition: tdi.h:124
ULONG BufferCount
Definition: shared.h:93
#define SOCKET_STATE_BOUND
Definition: afd.h:74
#define MIN_TRACE
Definition: debug.h:14
return STATUS_SUCCESS
Definition: btrfs.c:2966
unsigned int * PUINT
Definition: ndis.h:50
#define STATUS_CANT_WAIT
Definition: ntstatus.h:438
#define STATUS_FILE_CLOSED
Definition: ntstatus.h:518

Referenced by AfdDispatch().

◆ AfdPacketSocketWriteData()

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

Definition at line 564 of file write.c.

565  {
569  PAFD_FCB FCB = FileObject->FsContext;
570  PAFD_SEND_INFO_UDP SendReq;
572 
574 
575  AFD_DbgPrint(MID_TRACE,("Called on %p\n", FCB));
576 
577  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
578 
579  FCB->EventSelectDisabled &= ~AFD_EVENT_SEND;
580 
581  /* Check that the socket is bound */
582  if( FCB->State != SOCKET_STATE_BOUND &&
583  FCB->State != SOCKET_STATE_CREATED)
584  {
585  AFD_DbgPrint(MIN_TRACE,("Invalid socket state\n"));
587  }
588 
589  if (FCB->SendClosed)
590  {
591  AFD_DbgPrint(MIN_TRACE,("No more sends\n"));
593  }
594 
595  if( !(SendReq = LockRequest( Irp, IrpSp, FALSE, &LockMode )) )
597 
598  if (FCB->State == SOCKET_STATE_CREATED)
599  {
600  if (FCB->LocalAddress)
601  {
603  }
604 
605  FCB->LocalAddress =
607  Address[0].AddressType );
608 
609  if( FCB->LocalAddress ) {
611 
612  if( NT_SUCCESS(Status) )
613  FCB->State = SOCKET_STATE_BOUND;
614  else
615  return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
616  } else
618  ( FCB, STATUS_NO_MEMORY, Irp, 0 );
619  }
620 
621  SendReq->BufferArray = LockBuffers( SendReq->BufferArray,
622  SendReq->BufferCount,
623  NULL, NULL,
624  FALSE, FALSE, LockMode );
625 
626  if( !SendReq->BufferArray )
628  Irp, 0 );
629 
631  (MID_TRACE,("RemoteAddress #%d Type %u\n",
633  TAAddressCount,
635  Address[0].AddressType));
636 
639 
640  /* Check the size of the Address given ... */
641 
642  if( NT_SUCCESS(Status) ) {
643  FCB->PollState &= ~AFD_EVENT_SEND;
644 
646  if (Status == STATUS_PENDING)
647  {
648  Status = TdiSendDatagram(&FCB->SendIrp.InFlightRequest,
649  FCB->AddressFile.Object,
650  SendReq->BufferArray[0].buf,
651  SendReq->BufferArray[0].len,
654  FCB);
655  if (Status != STATUS_PENDING)
656  {
657  NT_VERIFY(RemoveHeadList(&FCB->PendingIrpList[FUNCTION_SEND]) == &Irp->Tail.Overlay.ListEntry);
658  Irp->IoStatus.Status = Status;
659  Irp->IoStatus.Information = 0;
661  UnlockBuffers(SendReq->BufferArray, SendReq->BufferCount, FALSE);
664  }
665  }
666 
668 
670 
671  return STATUS_PENDING;
672  }
673  else
674  {
675  UnlockBuffers(SendReq->BufferArray, SendReq->BufferCount, FALSE);
676  return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
677  }
678 }
VOID SocketStateUnlock(PAFD_FCB FCB)
Definition: lock.c:370
UINT len
Definition: shared.h:17
PTRANSPORT_ADDRESS TaBuildNullTransportAddress(UINT AddressType)
Definition: tdiconn.c:113
#define MID_TRACE
Definition: debug.h:15
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
NTSTATUS Status
Definition: write.c:2817
_In_ PIRP Irp
Definition: csq.h:116
PCHAR buf
Definition: shared.h:18
#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
TDI_CONNECTION_INFORMATION TdiConnection
Definition: shared.h:112
PAFD_WSABUF LockBuffers(PAFD_WSABUF Buf, UINT Count, PVOID AddressBuf, PINT AddressLen, BOOLEAN Write, BOOLEAN LockAddress, KPROCESSOR_MODE LockMode)
Definition: lock.c:205
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
LONG NTSTATUS
Definition: precomp.h:26
#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
static IO_COMPLETION_ROUTINE PacketSocketSendComplete
Definition: write.c:260
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
#define NT_VERIFY(exp)
Definition: rtlfuncs.h:3289
IoSetCancelRoutine(Irp, CancelRoutine)
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER _Outptr_ PVOID * TargetAddress
Definition: iotypes.h:998
ULONG LockMode
Definition: env_spec_w32.cpp:8
ULONG BufferCount
Definition: shared.h:109
#define AFD_SHARE_WILDCARD
Definition: shared.h:193
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
#define IoCompleteRequest
Definition: irp.c:1240
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PAFD_WSABUF BufferArray
Definition: shared.h:108
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
#define AFD_EVENT_SEND
Definition: shared.h:205
Definition: afd.h:161
#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
VOID UnlockBuffers(PAFD_WSABUF Buf, UINT Count, BOOL Address)
Definition: lock.c:289
NTSTATUS QueueUserModeIrp(PAFD_FCB FCB, PIRP Irp, UINT Function)
Definition: lock.c:397
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
* PFILE_OBJECT
Definition: iotypes.h:1955
NTSTATUS TdiSendDatagram(PIRP *Irp, PFILE_OBJECT TransportObject, PCHAR Buffer, UINT BufferLength, PTDI_CONNECTION_INFORMATION Addr, PIO_COMPLETION_ROUTINE CompletionRoutine, PVOID CompletionContext)
Definition: tdi.c:1151
NTSTATUS TdiBuildConnectionInfo(PTDI_CONNECTION_INFORMATION *ConnectionInfo, PTRANSPORT_ADDRESS Address)
Definition: tdiconn.c:237
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
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
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 MIN_TRACE
Definition: debug.h:14
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define STATUS_FILE_CLOSED
Definition: ntstatus.h:518

Referenced by AfdDispatch().

◆ AfdSelect()

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

Definition at line 165 of file select.c.

166  {
168  PAFD_FCB FCB;
170  PAFD_POLL_INFO PollReq = Irp->AssociatedIrp.SystemBuffer;
172  KIRQL OldIrql;
173  UINT i, Signalled = 0;
174  ULONG Exclusive = PollReq->Exclusive;
175 
177 
178  AFD_DbgPrint(MID_TRACE,("Called (HandleCount %u Timeout %d)\n",
179  PollReq->HandleCount,
180  (INT)(PollReq->Timeout.QuadPart)));
181 
182  SET_AFD_HANDLES(PollReq,
183  LockHandles( PollReq->Handles, PollReq->HandleCount ));
184 
185  if( !AFD_HANDLES(PollReq) ) {
186  Irp->IoStatus.Status = STATUS_NO_MEMORY;
187  Irp->IoStatus.Information = 0;
189  return STATUS_NO_MEMORY;
190  }
191 
192  if( Exclusive ) {
193  for( i = 0; i < PollReq->HandleCount; i++ ) {
194  if( !AFD_HANDLES(PollReq)[i].Handle ) continue;
195 
196  KillSelectsForFCB( DeviceExt,
197  (PFILE_OBJECT)AFD_HANDLES(PollReq)[i].Handle,
198  TRUE );
199  }
200  }
201 
202  KeAcquireSpinLock( &DeviceExt->Lock, &OldIrql );
203 
204  for( i = 0; i < PollReq->HandleCount; i++ ) {
205  if( !AFD_HANDLES(PollReq)[i].Handle ) continue;
206 
207  FileObject = (PFILE_OBJECT)AFD_HANDLES(PollReq)[i].Handle;
208  FCB = FileObject->FsContext;
209 
210  AFD_DbgPrint(MID_TRACE, ("AFD: Select Events: "));
211  PrintEvents( PollReq->Handles[i].Events );
212  AFD_DbgPrint(MID_TRACE,("\n"));
213 
214  PollReq->Handles[i].Status =
215  PollReq->Handles[i].Events & FCB->PollState;
216  if( PollReq->Handles[i].Status ) {
217  AFD_DbgPrint(MID_TRACE,("Signalling %p with %x\n",
218  FCB, FCB->PollState));
219  Signalled++;
220  }
221  }
222 
223  if( Signalled ) {
225  Irp->IoStatus.Status = Status;
226  SignalSocket( NULL, Irp, PollReq, Status );
227  } else {
228 
229  PAFD_ACTIVE_POLL Poll = NULL;
230 
232  sizeof(AFD_ACTIVE_POLL),
234 
235  if (Poll){
236  Poll->Irp = Irp;
237  Poll->DeviceExt = DeviceExt;
238  Poll->Exclusive = Exclusive;
239 
241 
243 
244  InsertTailList( &DeviceExt->Polls, &Poll->ListEntry );
245 
246  KeSetTimer( &Poll->Timer, PollReq->Timeout, &Poll->TimeoutDpc );
247 
251  } else {
252  AFD_DbgPrint(MAX_TRACE, ("FIXME: do something with the IRP!\n"));
254  }
255  }
256 
257  KeReleaseSpinLock( &DeviceExt->Lock, OldIrql );
258 
259  AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
260 
261  return Status;
262 }
NTSTATUS Status
Definition: shared.h:52
#define TRUE
Definition: types.h:120
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
#define MID_TRACE
Definition: debug.h:15
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
Definition: cdstruc.h:908
LONG NTSTATUS
Definition: precomp.h:26
LARGE_INTEGER Timeout
Definition: shared.h:56
#define InsertTailList(ListHead, Entry)
IoSetCancelRoutine(Irp, CancelRoutine)
VOID KillSelectsForFCB(PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, BOOLEAN OnlyExclusive)
Definition: select.c:125
int32_t INT
Definition: typedefs.h:56
KSPIN_LOCK Lock
Definition: afd.h:113
UCHAR KIRQL
Definition: env_spec_w32.h:591
VOID SignalSocket(PAFD_ACTIVE_POLL Poll OPTIONAL, PIRP _Irp OPTIONAL, PAFD_POLL_INFO PollReq, NTSTATUS Status)
Definition: select.c:56
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define SET_AFD_HANDLES(x, y)
Definition: afd.h:103
ULONG Events
Definition: shared.h:51
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
PVOID DeviceExtension
Definition: env_spec_w32.h:418
struct _FCB FCB
smooth NULL
Definition: ftsmooth.c:416
#define TAG_AFD_ACTIVE_POLL
Definition: afd.h:49
#define IoCompleteRequest
Definition: irp.c:1240
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
Definition: afd.h:161
LIST_ENTRY Polls
Definition: afd.h:112
_In_ HANDLE Handle
Definition: extypes.h:390
#define AFD_HANDLES(x)
Definition: afd.h:102
#define STATUS_PENDING
Definition: ntstatus.h:82
KDPC TimeoutDpc
Definition: afd.h:120
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
* PFILE_OBJECT
Definition: iotypes.h:1955
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: ketypes.h:687
ULONG_PTR Exclusive
Definition: shared.h:58
KTIMER Timer
Definition: afd.h:121
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define MAX_TRACE
Definition: debug.h:16
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
ULONG HandleCount
Definition: shared.h:57
AFD_HANDLE Handles[1]
Definition: shared.h:59
unsigned int UINT
Definition: ndis.h:50
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
PAFD_DEVICE_EXTENSION DeviceExt
Definition: afd.h:119
unsigned int ULONG
Definition: retypes.h:1
BOOLEAN Exclusive
Definition: afd.h:123
static VOID PrintEvents(ULONG Events)
Definition: select.c:13
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:711
return STATUS_SUCCESS
Definition: btrfs.c:2966
IoMarkIrpPending(Irp)
static KDEFERRED_ROUTINE SelectTimeout
Definition: select.c:95
VOID NTAPI KeInitializeTimerEx(OUT PKTIMER Timer, IN TIMER_TYPE Type)
Definition: timerobj.c:244
PIRP Irp
Definition: afd.h:118
LONGLONG QuadPart
Definition: typedefs.h:112
DRIVER_CANCEL AfdCancelHandler
Definition: afd.h:304
LIST_ENTRY ListEntry
Definition: afd.h:117
PAFD_HANDLE LockHandles(PAFD_HANDLE HandleArray, UINT HandleCount)
Definition: lock.c:310

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().

◆ AfdSetContext()

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

Definition at line 64 of file context.c.

65  {
67  PAFD_FCB FCB = FileObject->FsContext;
69 
71 
72  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
73 
74  if (!Context)
76 
77  if( FCB->Context ) {
79  FCB->ContextSize = 0;
80  }
81 
83  IrpSp->Parameters.DeviceIoControl.InputBufferLength,
85 
86  if( !FCB->Context ) return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY, Irp, 0 );
87 
88  FCB->ContextSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
89 
90  RtlCopyMemory( FCB->Context,
91  Context,
92  FCB->ContextSize );
93 
95 }
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
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
#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
#define TAG_AFD_SOCKET_CONTEXT
Definition: afd.h:40

Referenced by AfdDispatch().

◆ AfdSetInfo()

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

Definition at line 102 of file info.c.

103  {
105  PAFD_INFO InfoReq = LockRequest(Irp, IrpSp, FALSE, NULL);
107  PAFD_FCB FCB = FileObject->FsContext;
108  PCHAR NewBuffer;
109 
111 
112  if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp);
113 
114  if (!InfoReq)
116 
117  _SEH2_TRY {
118  switch (InfoReq->InformationClass) {
120  AFD_DbgPrint(MID_TRACE,("Blocking mode set to %u\n", InfoReq->Information.Boolean));
121  FCB->NonBlocking = InfoReq->Information.Boolean;
122  break;
124  FCB->OobInline = InfoReq->Information.Boolean;
125  break;
127  if (FCB->State == SOCKET_STATE_CONNECTED ||
129  {
130  /* FIXME: likely not right, check tcpip.sys for TDI_QUERY_MAX_DATAGRAM_INFO */
131  if (InfoReq->Information.Ulong > 0 && InfoReq->Information.Ulong < 0xFFFF &&
132  InfoReq->Information.Ulong != FCB->Recv.Size)
133  {
134  NewBuffer = ExAllocatePoolWithTag(PagedPool,
135  InfoReq->Information.Ulong,
137 
138  if (NewBuffer)
139  {
140  if (FCB->Recv.Content > InfoReq->Information.Ulong)
141  FCB->Recv.Content = InfoReq->Information.Ulong;
142 
143  if (FCB->Recv.Window)
144  {
145  RtlCopyMemory(NewBuffer,
146  FCB->Recv.Window,
147  FCB->Recv.Content);
148 
150  }
151 
152  FCB->Recv.Size = InfoReq->Information.Ulong;
153  FCB->Recv.Window = NewBuffer;
154 
156  }
157  else
158  {
160  }
161  }
162  else
163  {
165  }
166  }
167  else
168  {
170  }
171  break;
173  if (FCB->State == SOCKET_STATE_CONNECTED ||
175  {
176  if (InfoReq->Information.Ulong > 0 && InfoReq->Information.Ulong < 0xFFFF &&
177  InfoReq->Information.Ulong != FCB->Send.Size)
178  {
179  NewBuffer = ExAllocatePoolWithTag(PagedPool,
180  InfoReq->Information.Ulong,
182 
183  if (NewBuffer)
184  {
185  if (FCB->Send.BytesUsed > InfoReq->Information.Ulong)
186  FCB->Send.BytesUsed = InfoReq->Information.Ulong;
187 
188  if (FCB->Send.Window)
189  {
190  RtlCopyMemory(NewBuffer,
191  FCB->Send.Window,
192  FCB->Send.BytesUsed);
193 
195  }
196 
197  FCB->Send.Size = InfoReq->Information.Ulong;
198  FCB->Send.Window = NewBuffer;
199 
201  }
202  else
203  {
205  }
206  }
207  else
208  {
210  }
211  }
212  else
213  {
215  }
216  break;
217  default:
218  AFD_DbgPrint(MIN_TRACE,("Unknown request %u\n", InfoReq->InformationClass));
219  break;
220  }
222  AFD_DbgPrint(MIN_TRACE,("Exception executing SetInfo\n"));
224  } _SEH2_END;
225 
226  AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
227 
228  return UnlockAndMaybeComplete(FCB, Status, Irp, 0);
229 }
signed char * PCHAR
Definition: retypes.h:7
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define MID_TRACE
Definition: debug.h:15
BOOLEAN Boolean
Definition: shared.h:33
_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
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
union _AFD_INFO::@3259 Information
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
_SEH2_TRY
Definition: create.c:4250
#define AFD_ENDPOINT_CONNECTIONLESS
Definition: shared.h:153
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define AFD_INFO_BLOCKING_MODE
Definition: shared.h:183
#define TAG_AFD_DATA_BUFFER
Definition: afd.h:38
#define AFD_INFO_SEND_WINDOW_SIZE
Definition: shared.h:186
Definition: afd.h:161
ULONG InformationClass
Definition: shared.h:29
#define SOCKET_STATE_CONNECTED
Definition: afd.h:76
* PFILE_OBJECT
Definition: iotypes.h:1955
ULONG Flags
Definition: ntfs.h:532
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_SEH2_END
Definition: create.c:4424
#define AFD_INFO_INLINING_MODE
Definition: shared.h:182
#define AFD_INFO_RECEIVE_WINDOW_SIZE
Definition: shared.h:185
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 MIN_TRACE
Definition: debug.h:14
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2966
ULONG Ulong
Definition: shared.h:31

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().

◆ AfdWaitForListen()

NTSTATUS AfdWaitForListen ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 293 of file listen.c.

294  {
296  PAFD_FCB FCB = FileObject->FsContext;
298 
300 
301  AFD_DbgPrint(MID_TRACE,("Called\n"));
302 
303  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
304 
305  if( !IsListEmpty( &FCB->PendingConnections ) ) {
306  PLIST_ENTRY PendingConn = FCB->PendingConnections.Flink;
307 
308  /* We have a pending connection ... complete this irp right away */
310  ( Irp,
312  ( PendingConn, AFD_TDI_OBJECT_QELT, ListEntry ) );
313 
314  AFD_DbgPrint(MID_TRACE,("Completed a wait for accept\n"));
315 
316  if ( !IsListEmpty( &FCB->PendingConnections ) )
317  {
318  FCB->PollState |= AFD_EVENT_ACCEPT;
319  FCB->PollStatus[FD_ACCEPT_BIT] = STATUS_SUCCESS;
320  PollReeval( FCB->DeviceExt, FCB->FileObject );
321  } else
322  FCB->PollState &= ~AFD_EVENT_ACCEPT;
323 
325  return Status;
326  } else if (FCB->NonBlocking) {
327  AFD_DbgPrint(MIN_TRACE,("No connection ready on a non-blocking socket\n"));
328 
330  } else {
331  AFD_DbgPrint(MID_TRACE,("Holding\n"));
332 
334  }
335 }
VOID SocketStateUnlock(PAFD_FCB FCB)
Definition: lock.c:370
static NTSTATUS SatisfyPreAccept(PIRP Irp, PAFD_TDI_OBJECT_QELT Qelt)
Definition: listen.c:52
#define MID_TRACE
Definition: debug.h:15
VOID PollReeval(PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
Definition: select.c:407
PFILE_OBJECT FileObject
Definition: ntfs.h:516
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
Definition: cdstruc.h:908
LONG NTSTATUS
Definition: precomp.h:26
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
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define FUNCTION_PREACCEPT
Definition: afd.h:87
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
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
Definition: afd.h:161
#define AFD_EVENT_ACCEPT
Definition: shared.h:210
NTSTATUS LeaveIrpUntilLater(PAFD_FCB FCB, PIRP Irp, UINT Function)
Definition: lock.c:433
* PFILE_OBJECT
Definition: iotypes.h:1955
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define FD_ACCEPT_BIT
Definition: winsock2.h:299
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define MIN_TRACE
Definition: debug.h:14
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define STATUS_CANT_WAIT
Definition: ntstatus.h:438

Referenced by AfdDispatch().

◆ CheckUnlockExtraBuffers()

BOOLEAN CheckUnlockExtraBuffers ( PAFD_FCB  FCB,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 1092 of file main.c.

1093 {
1095  {
1097  {
1098  /* read()/write() call - no extra buffers */
1099  return FALSE;
1100  }
1102  {
1103  if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_RECV_DATAGRAM)
1104  {
1105  /* recvfrom() call - extra buffers */
1106  return TRUE;
1107  }
1108  else if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_RECV)
1109  {
1110  /* recv() call - no extra buffers */
1111  return FALSE;
1112  }
1113  else if (