ReactOS 0.4.16-dev-297-gc569aee
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 100 of file afd.h.

◆ DN2H

#define DN2H (   dw)
Value:
((((dw) & 0xFF000000L) >> 24) | \
(((dw) & 0x00FF0000L) >> 8) | \
(((dw) & 0x0000FF00L) << 8) | \
(((dw) & 0x000000FFL) << 24))
REFIID LPVOID DWORD_PTR dw
Definition: atlbase.h:40

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 101 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 =
342 (PAFD_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
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,
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
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}
#define TAG_AFD_ACCEPT_QUEUE
Definition: afd.h:46
struct _AFD_DEVICE_EXTENSION * PAFD_DEVICE_EXTENSION
LONG NTSTATUS
Definition: precomp.h:26
#define MIN_TRACE
Definition: debug.h:14
#define MID_TRACE
Definition: debug.h:15
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
static NTSTATUS SatisfyAccept(PAFD_DEVICE_EXTENSION DeviceExt, PIRP Irp, PFILE_OBJECT NewFileObject, PAFD_TDI_OBJECT_QELT Qelt)
Definition: listen.c:13
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
VOID SocketStateUnlock(PAFD_FCB FCB)
Definition: lock.c:370
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
VOID PollReeval(PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
Definition: select.c:407
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
_Must_inspect_result_ _In_ PFILE_OBJECT NewFileObject
Definition: fsrtlfuncs.h:1357
Status
Definition: gdiplustypes.h:25
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define KernelMode
Definition: asm.h:34
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
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:494
#define AFD_EVENT_ACCEPT
Definition: shared.h:210
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: afd.h:159
Definition: cdstruc.h:902
PFILE_OBJECT FileObject
Definition: ntfs.h:520
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
Definition: typedefs.h:120
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
#define FD_ACCEPT_BIT
Definition: winsock2.h:299
* PFILE_OBJECT
Definition: iotypes.h:1998
#define ObDereferenceObject
Definition: obfuncs.h:203

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 SOCKET_STATE_BOUND
Definition: afd.h:74
#define TAG_AFD_TRANSPORT_ADDRESS
Definition: afd.h:39
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define FALSE
Definition: types.h:117
NTSTATUS WarmSocketForBind(PAFD_FCB FCB, ULONG ShareType)
Definition: bind.c:13
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
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:2742
ULONG ShareType
Definition: shared.h:39
TRANSPORT_ADDRESS Address
Definition: shared.h:40
ULONG Flags
Definition: ntfs.h:536
NTSTATUS TdiBuildConnectionInfo(PTDI_CONNECTION_INFORMATION *ConnectionInfo, PTRANSPORT_ADDRESS Address)
Definition: tdiconn.c:237
PTRANSPORT_ADDRESS TaCopyTransportAddress(PTRANSPORT_ADDRESS OtherAddress)
Definition: tdiconn.c:80
uint32_t ULONG_PTR
Definition: typedefs.h:65

Referenced by AfdDispatch().

◆ AfdConnectedSocketReadData()

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

Definition at line 415 of file read.c.

416 {
419 PAFD_FCB FCB = FileObject->FsContext;
420 PAFD_RECV_INFO RecvReq;
421 UINT TotalBytesCopied = 0;
422 PAFD_STORED_DATAGRAM DatagramRecv;
423 PLIST_ENTRY ListEntry;
425
428
429 AFD_DbgPrint(MID_TRACE,("Called on %p\n", FCB));
430
431 if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
432
433 FCB->EventSelectDisabled &= ~AFD_EVENT_RECEIVE;
434
436 FCB->State != SOCKET_STATE_CONNECTED &&
437 FCB->State != SOCKET_STATE_CONNECTING ) {
438 AFD_DbgPrint(MIN_TRACE,("Called recv on wrong kind of socket (s%x)\n",
439 FCB->State));
441 Irp, 0 );
442 }
443
444 if( !(RecvReq = LockRequest( Irp, IrpSp, FALSE, &LockMode )) )
446 Irp, 0 );
447
448 AFD_DbgPrint(MID_TRACE,("Recv flags %x\n", RecvReq->AfdFlags));
449
450 RecvReq->BufferArray = LockBuffers( RecvReq->BufferArray,
451 RecvReq->BufferCount,
452 NULL, NULL,
453 TRUE, FALSE, LockMode );
454
455 if( !RecvReq->BufferArray ) {
457 Irp, 0 );
458 }
459
461 {
462 if (!IsListEmpty(&FCB->DatagramList))
463 {
464 ListEntry = RemoveHeadList(&FCB->DatagramList);
465 DatagramRecv = CONTAINING_RECORD(ListEntry, AFD_STORED_DATAGRAM, ListEntry);
466 Status = SatisfyPacketRecvRequest(FCB, Irp, DatagramRecv,
467 (PUINT)&Irp->IoStatus.Information);
468
469 if (RecvReq->TdiFlags & TDI_RECEIVE_PEEK)
470 {
471 InsertHeadList(&FCB->DatagramList,
472 &DatagramRecv->ListEntry);
473 }
474
475 if (!IsListEmpty(&FCB->DatagramList))
476 {
477 FCB->PollState |= AFD_EVENT_RECEIVE;
478 FCB->PollStatus[FD_READ_BIT] = STATUS_SUCCESS;
479 PollReeval( FCB->DeviceExt, FCB->FileObject );
480 }
481 else
482 FCB->PollState &= ~AFD_EVENT_RECEIVE;
483
484 UnlockBuffers(RecvReq->BufferArray, RecvReq->BufferCount, FALSE);
485
486 return UnlockAndMaybeComplete(FCB, Status, Irp, Irp->IoStatus.Information);
487 }
488 else if (!(RecvReq->AfdFlags & AFD_OVERLAPPED) &&
489 ((RecvReq->AfdFlags & AFD_IMMEDIATE) || (FCB->NonBlocking)))
490 {
491 AFD_DbgPrint(MID_TRACE,("Nonblocking\n"));
493 FCB->PollState &= ~AFD_EVENT_RECEIVE;
494 UnlockBuffers( RecvReq->BufferArray, RecvReq->BufferCount, FALSE );
495 return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
496 }
497 else
498 {
499 FCB->PollState &= ~AFD_EVENT_RECEIVE;
501 }
502 }
503
504 Irp->IoStatus.Status = STATUS_PENDING;
505 Irp->IoStatus.Information = 0;
506
507 InsertTailList( &FCB->PendingIrpList[FUNCTION_RECV],
508 &Irp->Tail.Overlay.ListEntry );
509
510 /************ From this point, the IRP is not ours ************/
511
513
514 if( Status == STATUS_PENDING &&
515 !(RecvReq->AfdFlags & AFD_OVERLAPPED) &&
516 ((RecvReq->AfdFlags & AFD_IMMEDIATE) || (FCB->NonBlocking))) {
517 AFD_DbgPrint(MID_TRACE,("Nonblocking\n"));
519 TotalBytesCopied = 0;
520 RemoveEntryList( &Irp->Tail.Overlay.ListEntry );
521 UnlockBuffers( RecvReq->BufferArray, RecvReq->BufferCount, FALSE );
523 TotalBytesCopied );
524 } else if( Status == STATUS_PENDING ) {
525 AFD_DbgPrint(MID_TRACE,("Leaving read irp\n"));
528 } else {
529 AFD_DbgPrint(MID_TRACE,("Completed with status %x\n", Status));
530 }
531
533 return Status;
534}
#define SOCKET_STATE_CONNECTED
Definition: afd.h:76
#define FUNCTION_RECV
Definition: afd.h:85
DRIVER_CANCEL AfdCancelHandler
Definition: afd.h:302
#define SOCKET_STATE_CONNECTING
Definition: afd.h:75
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define TRUE
Definition: types.h:120
VOID UnlockBuffers(PAFD_WSABUF Buf, UINT Count, BOOL Address)
Definition: lock.c:289
PAFD_WSABUF LockBuffers(PAFD_WSABUF Buf, UINT Count, PVOID AddressBuf, PINT AddressLen, BOOLEAN Write, BOOLEAN LockAddress, KPROCESSOR_MODE LockMode)
Definition: lock.c:205
NTSTATUS LeaveIrpUntilLater(PAFD_FCB FCB, PIRP Irp, UINT Function)
Definition: lock.c:433
ULONG LockMode
Definition: env_spec_w32.cpp:8
#define InsertTailList(ListHead, Entry)
#define InsertHeadList(ListHead, Entry)
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
short Short
Definition: ftraster.c:311
IoMarkIrpPending(Irp)
IoSetCancelRoutine(Irp, CancelRoutine)
unsigned int * PUINT
Definition: ndis.h:50
unsigned int UINT
Definition: ndis.h:50
static NTSTATUS NTAPI SatisfyPacketRecvRequest(PAFD_FCB FCB, PIRP Irp, PAFD_STORED_DATAGRAM DatagramRecv, PUINT TotalBytesCopied)
Definition: read.c:314
static NTSTATUS ReceiveActivity(PAFD_FCB FCB, PIRP Irp)
Definition: read.c:151
#define STATUS_CANT_WAIT
Definition: ntstatus.h:452
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define AFD_IMMEDIATE
Definition: shared.h:220
#define AFD_OVERLAPPED
Definition: shared.h:219
#define AFD_EVENT_RECEIVE
Definition: shared.h:203
#define AFD_ENDPOINT_CONNECTIONLESS
Definition: shared.h:153
ULONG BufferCount
Definition: shared.h:86
ULONG TdiFlags
Definition: shared.h:88
ULONG AfdFlags
Definition: shared.h:87
PAFD_WSABUF BufferArray
Definition: shared.h:85
LIST_ENTRY ListEntry
Definition: afd.h:153
#define TDI_RECEIVE_PEEK
Definition: tdi.h:124
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define FD_READ_BIT
Definition: winsock2.h:293
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7

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,
512 FCB->Send.Window + FCB->Send.BytesUsed));
513
514 RtlCopyMemory(FCB->Send.Window + FCB->Send.BytesUsed,
515 SendReq->BufferArray[i].buf,
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,
555 FCB);
556 }
557
559
560 return STATUS_PENDING;
561}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define TAG_AFD_TDI_CONNECTION_INFORMATION
Definition: afd.h:53
#define FUNCTION_SEND
Definition: afd.h:86
#define MIN(x, y)
Definition: rdesktop.h:171
VOID UnlockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lock.c:180
NTSTATUS QueueUserModeIrp(PAFD_FCB FCB, PIRP Irp, UINT Function)
Definition: lock.c:397
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 TdiSend(PIRP *Irp, PFILE_OBJECT TransportObject, USHORT Flags, PCHAR Buffer, UINT BufferLength, PIO_COMPLETION_ROUTINE CompletionRoutine, PVOID CompletionContext)
Definition: tdi.c:898
static IO_COMPLETION_ROUTINE SendComplete
Definition: write.c:13
static IO_COMPLETION_ROUTINE PacketSocketSendComplete
Definition: write.c:260
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
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
_In_ UINT _In_ UINT _In_ PNDIS_PACKET _In_ UINT _Out_ PUINT BytesCopied
Definition: ndis.h:3171
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_FILE_CLOSED
Definition: ntstatus.h:532
#define STATUS_INVALID_CONNECTION
Definition: ntstatus.h:556
#define AFD_EVENT_SEND
Definition: shared.h:205
#define AFD_EVENT_ABORT
Definition: shared.h:207
#define AFD_EVENT_CLOSE
Definition: shared.h:208
ULONG BufferCount
Definition: shared.h:109
PAFD_WSABUF BufferArray
Definition: shared.h:108
PCHAR buf
Definition: shared.h:18
UINT len
Definition: shared.h:17
void * PVOID
Definition: typedefs.h:50
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define FD_CLOSE_BIT
Definition: winsock2.h:303
#define FD_WRITE_BIT
Definition: winsock2.h:295
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER _Outptr_ PVOID * TargetAddress
Definition: iotypes.h:1037
#define NT_VERIFY(exp)
Definition: rtlfuncs.h:3304

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));
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}
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
#define UserMode
Definition: asm.h:35
POBJECT_TYPE ExEventObjectType
Definition: event.c:18
struct _AFD_ENUM_NETWORK_EVENTS_INFO * PAFD_ENUM_NETWORK_EVENTS_INFO
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 KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
struct _AFD_EVENT_SELECT_INFO * PAFD_EVENT_SELECT_INFO

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
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}
struct _IO_STACK_LOCATION::@1579::@1580 DeviceIoControl
union _IO_STACK_LOCATION::@1579 Parameters
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

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,
39
41}

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,
32 }
33
34 AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
35
37}
_Must_inspect_result_ _In_ FLT_CONTEXT_TYPE _In_ SIZE_T ContextSize
Definition: fltkernel.h:1444

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}
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
uint32_t ULONG
Definition: typedefs.h:59

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 EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define _SEH2_END
Definition: pseh2_64.h:155
#define _SEH2_TRY
Definition: pseh2_64.h:55
#define AFD_INFO_SEND_WINDOW_SIZE
Definition: shared.h:186
#define AFD_INFO_RECEIVE_WINDOW_SIZE
Definition: shared.h:185
#define AFD_INFO_RECEIVE_CONTENT_SIZE
Definition: shared.h:188
#define AFD_INFO_BLOCKING_MODE
Definition: shared.h:183
#define AFD_INFO_SENDS_IN_PROGRESS
Definition: shared.h:184
#define AFD_INFO_INLINING_MODE
Definition: shared.h:182
#define AFD_INFO_GROUP_ID_TYPE
Definition: shared.h:187
ULONG InformationClass
Definition: shared.h:29
ULONG Ulong
Definition: shared.h:31
union _AFD_INFO::@3383 Information
BOOLEAN Boolean
Definition: shared.h:33
LARGE_INTEGER LargeInteger
Definition: shared.h:32
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
struct _LARGE_INTEGER::@2302 u

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

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}
NTSTATUS TdiQueryInformation(PFILE_OBJECT FileObject, LONG QueryType, PMDL MdlBuffer)
Definition: tdi.c:668
#define IoFreeMdl
Definition: fxmdl.h:89
#define IoAllocateMdl
Definition: fxmdl.h:88
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:931
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define TDI_QUERY_ADDRESS_INFO
Definition: tdi.h:181
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
@ IoModifyAccess
Definition: ketypes.h:865

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;
275 }
276
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 SOCKET_STATE_LISTENING
Definition: afd.h:77
NTSTATUS WarmSocketForConnection(PAFD_FCB FCB)
Definition: connect.c:238
static IO_COMPLETION_ROUTINE ListenComplete
Definition: listen.c:89
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
BOOLEAN UseDelayedAcceptance
Definition: shared.h:46
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 696 of file read.c.

697 {
700 PAFD_FCB FCB = FileObject->FsContext;
701 PAFD_RECV_INFO_UDP RecvReq;
702 PLIST_ENTRY ListEntry;
703 PAFD_STORED_DATAGRAM DatagramRecv;
705
707
708 AFD_DbgPrint(MID_TRACE,("Called on %p\n", FCB));
709
710 if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
711
712 FCB->EventSelectDisabled &= ~AFD_EVENT_RECEIVE;
713
714 /* Check that the socket is bound */
715 if( FCB->State != SOCKET_STATE_BOUND )
716 {
717 AFD_DbgPrint(MIN_TRACE,("Invalid socket state\n"));
719 }
720
721 if (FCB->TdiReceiveClosed)
722 {
723 AFD_DbgPrint(MIN_TRACE,("Receive closed\n"));
725 }
726
727 if( !(RecvReq = LockRequest( Irp, IrpSp, FALSE, &LockMode )) )
729
730 AFD_DbgPrint(MID_TRACE,("Recv flags %x\n", RecvReq->AfdFlags));
731
732 RecvReq->BufferArray = LockBuffers( RecvReq->BufferArray,
733 RecvReq->BufferCount,
734 RecvReq->Address,
735 RecvReq->AddressLength,
736 TRUE, TRUE, LockMode );
737
738 if( !RecvReq->BufferArray ) { /* access violation in userspace */
740 }
741
742 if (!IsListEmpty(&FCB->DatagramList))
743 {
744 ListEntry = RemoveHeadList(&FCB->DatagramList);
745 DatagramRecv = CONTAINING_RECORD(ListEntry, AFD_STORED_DATAGRAM, ListEntry);
746 Status = SatisfyPacketRecvRequest(FCB, Irp, DatagramRecv,
747 (PUINT)&Irp->IoStatus.Information);
748
749 if (RecvReq->TdiFlags & TDI_RECEIVE_PEEK)
750 {
751 InsertHeadList(&FCB->DatagramList,
752 &DatagramRecv->ListEntry);
753 }
754
755 if (!IsListEmpty(&FCB->DatagramList))
756 {
757 FCB->PollState |= AFD_EVENT_RECEIVE;
758 FCB->PollStatus[FD_READ_BIT] = STATUS_SUCCESS;
759 PollReeval( FCB->DeviceExt, FCB->FileObject );
760 }
761 else
762 FCB->PollState &= ~AFD_EVENT_RECEIVE;
763
764 UnlockBuffers(RecvReq->BufferArray, RecvReq->BufferCount, TRUE);
765
766 return UnlockAndMaybeComplete(FCB, Status, Irp, Irp->IoStatus.Information);
767 }
768 else if (!(RecvReq->AfdFlags & AFD_OVERLAPPED) &&
769 ((RecvReq->AfdFlags & AFD_IMMEDIATE) || (FCB->NonBlocking)))
770 {
771 AFD_DbgPrint(MID_TRACE,("Nonblocking\n"));
773 FCB->PollState &= ~AFD_EVENT_RECEIVE;
774 UnlockBuffers( RecvReq->BufferArray, RecvReq->BufferCount, TRUE );
775 return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
776 }
777 else
778 {
779 FCB->PollState &= ~AFD_EVENT_RECEIVE;
781 }
782}
ULONG AfdFlags
Definition: shared.h:94
PINT AddressLength
Definition: shared.h:97
ULONG BufferCount
Definition: shared.h:93
ULONG TdiFlags
Definition: shared.h:95
PAFD_WSABUF BufferArray
Definition: shared.h:92

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}
#define SOCKET_STATE_CREATED
Definition: afd.h:73
static WCHAR Address[46]
Definition: ping.c:68
#define AFD_SHARE_WILDCARD
Definition: shared.h:193
TDI_CONNECTION_INFORMATION TdiConnection
Definition: shared.h:112
PTRANSPORT_ADDRESS TaBuildNullTransportAddress(UINT AddressType)
Definition: tdiconn.c:113

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 {
170 PAFD_POLL_INFO PollReq = Irp->AssociatedIrp.SystemBuffer;
171 PAFD_DEVICE_EXTENSION DeviceExt = DeviceObject->DeviceExtension;
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}
#define SET_AFD_HANDLES(x, y)
Definition: afd.h:101
#define AFD_HANDLES(x)
Definition: afd.h:100
#define TAG_AFD_ACTIVE_POLL
Definition: afd.h:49
#define MAX_TRACE
Definition: debug.h:16
struct _FCB FCB
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
PAFD_HANDLE LockHandles(PAFD_HANDLE HandleArray, UINT HandleCount)
Definition: lock.c:310
VOID KillSelectsForFCB(PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, BOOLEAN OnlyExclusive)
Definition: select.c:125
static KDEFERRED_ROUTINE SelectTimeout
Definition: select.c:95
VOID SignalSocket(PAFD_ACTIVE_POLL Poll OPTIONAL, PIRP _Irp OPTIONAL, PAFD_POLL_INFO PollReq, NTSTATUS Status)
Definition: select.c:56
static VOID PrintEvents(ULONG Events)
Definition: select.c:13
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define NonPagedPool
Definition: env_spec_w32.h:307
__in PWDFDEVICE_INIT __in BOOLEAN Exclusive
ULONG Handle
Definition: gdb_input.c:15
@ NotificationTimer
PIRP Irp
Definition: afd.h:116
KDPC TimeoutDpc
Definition: afd.h:118
LIST_ENTRY ListEntry
Definition: afd.h:115
KTIMER Timer
Definition: afd.h:119
PAFD_DEVICE_EXTENSION DeviceExt
Definition: afd.h:117
BOOLEAN Exclusive
Definition: afd.h:121
LIST_ENTRY Polls
Definition: afd.h:110
KSPIN_LOCK Lock
Definition: afd.h:111
ULONG Events
Definition: shared.h:51
NTSTATUS Status
Definition: shared.h:52
LARGE_INTEGER Timeout
Definition: shared.h:56
ULONG HandleCount
Definition: shared.h:57
AFD_HANDLE Handles[1]
Definition: shared.h:59
ULONG_PTR Exclusive
Definition: shared.h:58
Definition: ketypes.h:699
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
VOID NTAPI KeInitializeTimerEx(OUT PKTIMER Timer, IN TIMER_TYPE Type)
Definition: timerobj.c:244
int32_t INT
Definition: typedefs.h:58
LONGLONG QuadPart
Definition: typedefs.h:114
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

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
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}
#define TAG_AFD_CONNECT_DATA
Definition: afd.h:41
#define PagedPool
Definition: env_spec_w32.h:308

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
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}

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}
#define TAG_AFD_CONNECT_OPTIONS
Definition: afd.h:44

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}

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}
#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
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 {
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 {
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
229}
#define TAG_AFD_DATA_BUFFER
Definition: afd.h:38
char * PCHAR
Definition: typedefs.h:51

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 =
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
502 if (FCB->RemoteAddress)
503 {
505 }
506
507 FCB->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
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}
#define FUNCTION_CONNECT
Definition: afd.h:84
static IO_COMPLETION_ROUTINE StreamSocketConnectComplete
Definition: connect.c:320
void OskitDumpBuffer(PCHAR Data, UINT Len)
Definition: main.c:29
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
TRANSPORT_ADDRESS RemoteAddress
Definition: shared.h:121
USHORT AddressType
Definition: tdi.h:339
TA_ADDRESS Address[1]
Definition: tdi.h:377

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}
#define FUNCTION_PREACCEPT
Definition: afd.h:87
static NTSTATUS SatisfyPreAccept(PIRP Irp, PAFD_TDI_OBJECT_QELT Qelt)
Definition: listen.c:52

Referenced by AfdDispatch().

◆ CheckUnlockExtraBuffers()

BOOLEAN CheckUnlockExtraBuffers ( PAFD_FCB  FCB,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 1089 of file main.c.

1090{
1092 {
1094 {
1095 /* read()/write() call - no extra buffers */
1096 return FALSE;
1097 }
1099 {
1101 {
1102 /* recvfrom() call - extra buffers */
1103 return TRUE;
1104 }
1105 else if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_RECV)
1106 {
1107 /* recv() call - no extra buffers */
1108 return FALSE;
1109 }
1110 else if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_SEND ||
1112 {
1113 /* send()/sendto() call - no extra buffers */
1114 return FALSE;
1115 }
1116 else
1117 {
1118 /* Unknown IOCTL */
1119 ASSERT(FALSE);
1120 return FALSE;
1121 }
1122 }
1123 else
1124 {
1125 /* Unknown IRP_MJ code */
1126 ASSERT(FALSE);
1127 return FALSE;
1128 }
1129 }
1130 else
1131 {
1132 /* Connection-oriented never has extra buffers */
1133 return FALSE;
1134 }
1135}
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IOCTL_AFD_RECV
Definition: shared.h:277
#define IOCTL_AFD_SEND_DATAGRAM
Definition: shared.h:283
#define IOCTL_AFD_RECV_DATAGRAM
Definition: shared.h:279
#define IOCTL_AFD_SEND
Definition: shared.h:281

Referenced by CleanupPendingIrp(), PacketSocketRecvComplete(), and SatisfyPacketRecvRequest().

◆ DestroySocket()

VOID DestroySocket ( PAFD_FCB  FCB)

◆ GetLockedData()

PVOID GetLockedData ( PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 13 of file lock.c.

14{
15 ASSERT(Irp->MdlAddress);
16 ASSERT(Irp->Tail.Overlay.DriverContext[0]);
17
19
20 return Irp->Tail.Overlay.DriverContext[0];
21}

Referenced by CleanupPendingIrp(), LockRequest(), PacketSocketRecvComplete(), PacketSocketSendComplete(), ReceiveActivity(), ReceiveComplete(), SatisfyPacketRecvRequest(), and SendComplete().

◆ KillSelectsForFCB()

VOID KillSelectsForFCB ( PAFD_DEVICE_EXTENSION  DeviceExt,
PFILE_OBJECT  FileObject,
BOOLEAN  ExclusiveOnly 
)

Definition at line 125 of file select.c.

127 {
129 PLIST_ENTRY ListEntry;
130 PAFD_ACTIVE_POLL Poll;
131 PIRP Irp;
132 PAFD_POLL_INFO PollReq;
133 PAFD_HANDLE HandleArray;
134 UINT i;
135
136 AFD_DbgPrint(MID_TRACE,("Killing selects that refer to %p\n", FileObject));
137
138 KeAcquireSpinLock( &DeviceExt->Lock, &OldIrql );
139
140 ListEntry = DeviceExt->Polls.Flink;
141 while ( ListEntry != &DeviceExt->Polls ) {
142 Poll = CONTAINING_RECORD(ListEntry, AFD_ACTIVE_POLL, ListEntry);
143 ListEntry = ListEntry->Flink;
144 Irp = Poll->Irp;
145 PollReq = Irp->AssociatedIrp.SystemBuffer;
146 HandleArray = AFD_HANDLES(PollReq);
147
148 for( i = 0; i < PollReq->HandleCount; i++ ) {
149 AFD_DbgPrint(MAX_TRACE,("Req: %u, This %p\n",
150 HandleArray[i].Handle, FileObject));
151 if( (PVOID)HandleArray[i].Handle == FileObject &&
152 (!OnlyExclusive || (OnlyExclusive && Poll->Exclusive)) ) {
153 ZeroEvents( PollReq->Handles, PollReq->HandleCount );
154 SignalSocket( Poll, NULL, PollReq, STATUS_CANCELLED );
155 }
156 }
157 }
158
159 KeReleaseSpinLock( &DeviceExt->Lock, OldIrql );
160
161 AFD_DbgPrint(MID_TRACE,("Done\n"));
162}
VOID ZeroEvents(PAFD_HANDLE HandleArray, UINT HandleCount)
Definition: select.c:44
#define STATUS_CANCELLED
Definition: udferr_usr.h:170

Referenced by AfdCleanupSocket(), AfdCloseSocket(), and AfdSelect().

◆ LeaveIrpUntilLater()

NTSTATUS LeaveIrpUntilLater ( PAFD_FCB  FCB,
PIRP  Irp,
UINT  Function 
)

Definition at line 433 of file lock.c.

433 {
435
437
439
440 return Status;
441}
_In_ CDROM_SCAN_FOR_SPECIAL_INFO _In_ PCDROM_SCAN_FOR_SPECIAL_HANDLER Function
Definition: cdrom.h:1156

Referenced by AfdConnectedSocketReadData(), AfdConnectedSocketWriteData(), AfdPacketSocketReadData(), AfdStreamSocketConnect(), and AfdWaitForListen().

◆ LockBuffers()

PAFD_WSABUF LockBuffers ( PAFD_WSABUF  Buf,
UINT  Count,
PVOID  AddressBuf,
PINT  AddressLen,
BOOLEAN  Write,
BOOLEAN  LockAddress,
KPROCESSOR_MODE  LockMode 
)

Definition at line 205 of file lock.c.

208 {
209 UINT i;
210 /* Copy the buffer array so we don't lose it */
211 UINT Lock = LockAddress ? 2 : 0;
212 UINT Size = (sizeof(AFD_WSABUF) + sizeof(AFD_MAPBUF)) * (Count + Lock);
214 BOOLEAN LockFailed = FALSE;
215 PAFD_MAPBUF MapBuf;
216
217 AFD_DbgPrint(MID_TRACE,("Called(%p)\n", NewBuf));
218
219 if( NewBuf ) {
220 RtlZeroMemory(NewBuf, Size);
221
222 MapBuf = (PAFD_MAPBUF)(NewBuf + Count + Lock);
223
224 _SEH2_TRY {
225 RtlCopyMemory( NewBuf, Buf, sizeof(AFD_WSABUF) * Count );
226 if( LockAddress ) {
227 if (AddressBuf && AddressLen) {
228 NewBuf[Count].buf = AddressBuf;
229 NewBuf[Count].len = *AddressLen;
230 NewBuf[Count + 1].buf = (PVOID)AddressLen;
231 NewBuf[Count + 1].len = sizeof(*AddressLen);
232 }
233 Count += 2;
234 }
236 AFD_DbgPrint(MIN_TRACE,("Access violation copying buffer info "
237 "from userland (%p %p)\n",
238 Buf, AddressLen));
240 _SEH2_YIELD(return NULL);
241 } _SEH2_END;
242
243 for( i = 0; i < Count; i++ ) {
244 AFD_DbgPrint(MID_TRACE,("Locking buffer %u (%p:%u)\n",
245 i, NewBuf[i].buf, NewBuf[i].len));
246
247 if( NewBuf[i].buf && NewBuf[i].len ) {
248 MapBuf[i].Mdl = IoAllocateMdl( NewBuf[i].buf,
249 NewBuf[i].len,
250 FALSE,
251 FALSE,
252 NULL );
253 } else {
254 MapBuf[i].Mdl = NULL;
255 continue;
256 }
257
258 AFD_DbgPrint(MID_TRACE,("NewMdl @ %p\n", MapBuf[i].Mdl));
259
260 if( MapBuf[i].Mdl ) {
261 AFD_DbgPrint(MID_TRACE,("Probe and lock pages\n"));
262 _SEH2_TRY {
266 LockFailed = TRUE;
267 } _SEH2_END;
268 AFD_DbgPrint(MID_TRACE,("MmProbeAndLock finished\n"));
269
270 if( LockFailed ) {
271 AFD_DbgPrint(MIN_TRACE,("Failed to lock pages\n"));
272 IoFreeMdl( MapBuf[i].Mdl );
273 MapBuf[i].Mdl = NULL;
275 return NULL;
276 }
277 } else {
279 return NULL;
280 }
281 }
282 }
283
284 AFD_DbgPrint(MID_TRACE,("Leaving %p\n", NewBuf));
285
286 return NewBuf;
287}
unsigned char BOOLEAN
struct _AFD_MAPBUF * PAFD_MAPBUF
#define TAG_AFD_WSA_BUFFER
Definition: afd.h:54
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
int Count
Definition: noreturn.cpp:7
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
struct _AFD_WSABUF AFD_WSABUF
PMDL Mdl
Definition: afd.h:105
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
static BOOL Write(PBYTE Address, PBYTE Data, SIZE_T Size)
Definition: vmhorizon.c:15
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:127
@ IoReadAccess
Definition: ketypes.h:863

Referenced by AfdConnectedSocketReadData(), AfdConnectedSocketWriteData(), AfdPacketSocketReadData(), and AfdPacketSocketWriteData().

◆ LockHandles()

PAFD_HANDLE LockHandles ( PAFD_HANDLE  HandleArray,
UINT  HandleCount 
)

Definition at line 310 of file lock.c.

310 {
311 UINT i;
313
315 HandleCount * sizeof(AFD_HANDLE),
317
318 for( i = 0; FileObjects && i < HandleCount; i++ ) {
319 FileObjects[i].Status = 0;
320 FileObjects[i].Events = HandleArray[i].Events;
321 FileObjects[i].Handle = 0;
322 if( !HandleArray[i].Handle ) continue;
323 if( NT_SUCCESS(Status) ) {
325 ( (PVOID)HandleArray[i].Handle,
327 NULL,
329 (PVOID*)&FileObjects[i].Handle,
330 NULL );
331 }
332
333 if( !NT_SUCCESS(Status) )
334 {
335 AFD_DbgPrint(MIN_TRACE,("Failed to reference handles (0x%x)\n", Status));
336 FileObjects[i].Handle = 0;
337 }
338 }
339
340 if( !NT_SUCCESS(Status) ) {
341 UnlockHandles( FileObjects, HandleCount );
342 return NULL;
343 }
344
345 return FileObjects;
346}
#define TAG_AFD_POLL_HANDLE
Definition: afd.h:47
VOID UnlockHandles(PAFD_HANDLE HandleArray, UINT HandleCount)
Definition: lock.c:348
SOCKET Handle
Definition: shared.h:50

Referenced by AfdSelect().

◆ LockRequest()

PVOID LockRequest ( PIRP  Irp,
PIO_STACK_LOCATION  IrpSp,
BOOLEAN  Output,
KPROCESSOR_MODE LockMode 
)

Definition at line 24 of file lock.c.

27 {
28 BOOLEAN LockFailed = FALSE;
29
30 ASSERT(!Irp->MdlAddress);
31
32 switch (IrpSp->MajorFunction)
33 {
36 ASSERT(IrpSp->Parameters.DeviceIoControl.Type3InputBuffer);
37 ASSERT(IrpSp->Parameters.DeviceIoControl.InputBufferLength);
38
39
40 Irp->MdlAddress =
42 IrpSp->Parameters.DeviceIoControl.InputBufferLength,
43 FALSE,
44 FALSE,
45 NULL );
46 if( Irp->MdlAddress ) {
47 _SEH2_TRY {
48 MmProbeAndLockPages( Irp->MdlAddress, Irp->RequestorMode, IoModifyAccess );
50 LockFailed = TRUE;
51 } _SEH2_END;
52
53 if( LockFailed ) {
54 AFD_DbgPrint(MIN_TRACE,("Failed to lock pages\n"));
55 IoFreeMdl( Irp->MdlAddress );
56 Irp->MdlAddress = NULL;
57 return NULL;
58 }
59
60 /* The mapped address goes in index 1 */
61 Irp->Tail.Overlay.DriverContext[1] = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
62 if (!Irp->Tail.Overlay.DriverContext[1])
63 {
64 AFD_DbgPrint(MIN_TRACE,("Failed to get mapped address\n"));
65 MmUnlockPages(Irp->MdlAddress);
66 IoFreeMdl( Irp->MdlAddress );
67 Irp->MdlAddress = NULL;
68 return NULL;
69 }
70
71 /* The allocated address goes in index 0 */
72 Irp->Tail.Overlay.DriverContext[0] = ExAllocatePoolWithTag(NonPagedPool,
73 MmGetMdlByteCount(Irp->MdlAddress),
75
76 if (!Irp->Tail.Overlay.DriverContext[0])
77 {
78 AFD_DbgPrint(MIN_TRACE,("Failed to allocate memory\n"));
79 MmUnlockPages(Irp->MdlAddress);
80 IoFreeMdl( Irp->MdlAddress );
81 Irp->MdlAddress = NULL;
82 return NULL;
83 }
84
85 RtlCopyMemory(Irp->Tail.Overlay.DriverContext[0],
86 Irp->Tail.Overlay.DriverContext[1],
87 MmGetMdlByteCount(Irp->MdlAddress));
88
89 /* If we don't want a copy back, we zero the mapped address pointer */
90 if (!Output)
91 {
92 Irp->Tail.Overlay.DriverContext[1] = NULL;
93 }
94
95 /* We're using a user-mode buffer directly */
96 if (LockMode != NULL)
97 {
99 }
100 }
101 else return NULL;
102 break;
103
104 case IRP_MJ_READ:
105 case IRP_MJ_WRITE:
106 ASSERT(Irp->UserBuffer);
107
108 Irp->MdlAddress =
109 IoAllocateMdl(Irp->UserBuffer,
111 IrpSp->Parameters.Read.Length : IrpSp->Parameters.Write.Length,
112 FALSE,
113 FALSE,
114 NULL );
115 if( Irp->MdlAddress ) {
116 PAFD_RECV_INFO AfdInfo;
117
118 _SEH2_TRY {
119 MmProbeAndLockPages( Irp->MdlAddress, Irp->RequestorMode, IoModifyAccess );
121 LockFailed = TRUE;
122 } _SEH2_END;
123
124 if( LockFailed ) {
125 AFD_DbgPrint(MIN_TRACE,("Failed to lock pages\n"));
126 IoFreeMdl( Irp->MdlAddress );
127 Irp->MdlAddress = NULL;
128 return NULL;
129 }
130
131 /* We need to create the info struct that AFD expects for all send/recv requests */
133 sizeof(AFD_RECV_INFO) + sizeof(AFD_WSABUF),
135
136 if (!AfdInfo)
137 {
138 AFD_DbgPrint(MIN_TRACE,("Failed to allocate memory\n"));
139 MmUnlockPages(Irp->MdlAddress);
140 IoFreeMdl( Irp->MdlAddress );
141 Irp->MdlAddress = NULL;
142 return NULL;
143 }
144
145 /* We'll append the buffer array to this struct */
146 AfdInfo->BufferArray = (PAFD_WSABUF)(AfdInfo + 1);
147 AfdInfo->BufferCount = 1;
148
149 /* Setup the default flags values */
150 AfdInfo->AfdFlags = 0;
151 AfdInfo->TdiFlags = 0;
152
153 /* Now build the buffer array */
154 AfdInfo->BufferArray[0].buf = MmGetSystemAddressForMdl(Irp->MdlAddress);
155 AfdInfo->BufferArray[0].len = MmGetMdlByteCount(Irp->MdlAddress);
156
157 /* Store the struct where AFD expects */
158 Irp->Tail.Overlay.DriverContext[0] = AfdInfo;
159
160 /* Don't copy anything out */
161 Irp->Tail.Overlay.DriverContext[1] = NULL;
162
163 /* We're using a placeholder buffer that we allocated */
164 if (LockMode != NULL)
165 {
167 }
168 }
169 else return NULL;
170 break;
171
172 default:
173 ASSERT(FALSE);
174 return NULL;
175 }
176
177 return GetLockedData(Irp, IrpSp);
178}
PVOID GetLockedData(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lock.c:13
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
Definition: mdlsup.c:1435
@ NormalPagePriority
Definition: imports.h:54
@ Output
Definition: arc.h:85
struct _AFD_WSABUF * PAFD_WSABUF
struct _IO_STACK_LOCATION::@3978::@3983 Write
struct _IO_STACK_LOCATION::@3978::@3982 Read
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define MmGetMdlByteCount(_Mdl)
#define MmGetSystemAddressForMdl(Mdl)
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)

Referenced by AfdBindSocket(), AfdConnectedSocketReadData(), AfdConnectedSocketWriteData(), AfdDisconnect(), AfdEnumEvents(), AfdEventSelect(), AfdGetInfo(), AfdGetTdiHandles(), AfdListenSocket(), AfdPacketSocketReadData(), AfdPacketSocketWriteData(), AfdSetConnectData(), AfdSetConnectDataSize(), AfdSetConnectOptions(), AfdSetConnectOptionsSize(), AfdSetContext(), AfdSetDisconnectData(), AfdSetDisconnectDataSize(), AfdSetDisconnectOptions(), AfdSetDisconnectOptionsSize(), AfdSetInfo(), AfdStreamSocketConnect(), MimeProtocol_LockRequest(), PersistMoniker_Load(), Protocol_Continue(), Protocol_LockRequest(), Protocol_Start(), ProtocolEmul_LockRequest(), test_binding(), test_BindToStorage(), test_download(), test_submit(), and thread_proc().

◆ LostSocket()

◆ MakeSocketIntoConnection()

NTSTATUS MakeSocketIntoConnection ( PAFD_FCB  FCB)

Definition at line 259 of file connect.c.

259 {
261
262 ASSERT(!FCB->Recv.Window);
263 ASSERT(!FCB->Send.Window);
264
265 if (!FCB->Recv.Size)
266 {
267 Status = TdiQueryMaxDatagramLength(FCB->Connection.Object,
268 &FCB->Recv.Size);
269 if (!NT_SUCCESS(Status))
270 return Status;
271 }
272
273 if (!FCB->Send.Size)
274 {
275 Status = TdiQueryMaxDatagramLength(FCB->Connection.Object,
276 &FCB->Send.Size);
277 if (!NT_SUCCESS(Status))
278 return Status;
279 }
280
281 /* Allocate the receive area and start receiving */
282 if (!FCB->Recv.Window)
283 {
284 FCB->Recv.Window = ExAllocatePoolWithTag(PagedPool,
285 FCB->Recv.Size,
287
288 if( !FCB->Recv.Window ) return STATUS_NO_MEMORY;
289 }
290
291 if (!FCB->Send.Window)
292 {
293 FCB->Send.Window = ExAllocatePoolWithTag(PagedPool,
294 FCB->Send.Size,
296
297 if( !FCB->Send.Window ) return STATUS_NO_MEMORY;
298 }
299
301
302 Status = TdiReceive( &FCB->ReceiveIrp.InFlightRequest,
303 FCB->Connection.Object,
305 FCB->Recv.Window,
306 FCB->Recv.Size,
308 FCB );
309
311
312 FCB->PollState |= AFD_EVENT_CONNECT | AFD_EVENT_SEND;
313 FCB->PollStatus[FD_CONNECT_BIT] = STATUS_SUCCESS;
314 FCB->PollStatus[FD_WRITE_BIT] = STATUS_SUCCESS;
315 PollReeval( FCB->DeviceExt, FCB->FileObject );
316
317 return Status;
318}
IO_COMPLETION_ROUTINE ReceiveComplete
Definition: afd.h:308
NTSTATUS TdiQueryMaxDatagramLength(PFILE_OBJECT FileObject, PUINT MaxDatagramLength)
Definition: tdi.c:226
NTSTATUS TdiReceive(PIRP *Irp, PFILE_OBJECT TransportObject, USHORT Flags, PCHAR Buffer, UINT BufferLength, PIO_COMPLETION_ROUTINE CompletionRoutine, PVOID CompletionContext)
Definition: tdi.c:976
#define AFD_EVENT_CONNECT
Definition: shared.h:209
#define TDI_RECEIVE_NORMAL
Definition: tdi.h:122
#define FD_CONNECT_BIT
Definition: winsock2.h:301

Referenced by SatisfyAccept(), and StreamSocketConnectComplete().

◆ OskitDumpBuffer()

VOID OskitDumpBuffer ( PCHAR  Buffer,
UINT  Len 
)

Definition at line 29 of file main.c.

29 {
30 unsigned int i;
31
32 for( i = 0; i < Len; i++ ) {
33 if( i && !(i & 0xf) ) DbgPrint( "\n" );
34 if( !(i & 0xf) ) DbgPrint( "%p: ", (Data + i) );
35 DbgPrint( " %02x", Data[i] & 0xff );
36 }
37 DbgPrint("\n");
38}
#define Len
Definition: deflate.h:82
#define DbgPrint
Definition: hal.h:12

Referenced by AfdStreamSocketConnect().

◆ PollReeval()

VOID PollReeval ( PAFD_DEVICE_EXTENSION  DeviceObject,
PFILE_OBJECT  FileObject 
)

Definition at line 407 of file select.c.

407 {
408 PAFD_ACTIVE_POLL Poll = NULL;
409 PLIST_ENTRY ThePollEnt = NULL;
412 PAFD_POLL_INFO PollReq;
413
414 AFD_DbgPrint(MID_TRACE,("Called: DeviceExt %p FileObject %p\n",
415 DeviceExt, FileObject));
416
417 KeAcquireSpinLock( &DeviceExt->Lock, &OldIrql );
418
419 /* Take care of any event select signalling */
420 FCB = (PAFD_FCB)FileObject->FsContext;
421
422 if( !FCB ) {
423 KeReleaseSpinLock( &DeviceExt->Lock, OldIrql );
424 return;
425 }
426
427 /* Now signal normal select irps */
428 ThePollEnt = DeviceExt->Polls.Flink;
429
430 while( ThePollEnt != &DeviceExt->Polls ) {
431 Poll = CONTAINING_RECORD( ThePollEnt, AFD_ACTIVE_POLL, ListEntry );
432 PollReq = Poll->Irp->AssociatedIrp.SystemBuffer;
433 AFD_DbgPrint(MID_TRACE,("Checking poll %p\n", Poll));
434
435 if( UpdatePollWithFCB( Poll, FileObject ) ) {
436 ThePollEnt = ThePollEnt->Flink;
437 AFD_DbgPrint(MID_TRACE,("Signalling socket\n"));
438 SignalSocket( Poll, NULL, PollReq, STATUS_SUCCESS );
439 } else
440 ThePollEnt = ThePollEnt->Flink;
441 }
442
443 KeReleaseSpinLock( &DeviceExt->Lock, OldIrql );
444
445 if((FCB->EventSelect) &&
446 (FCB->PollState & (FCB->EventSelectTriggers & ~FCB->EventSelectDisabled)))
447 {
448 AFD_DbgPrint(MID_TRACE,("Setting event %p\n", FCB->EventSelect));
449
450 /* Set the application's event */
451 KeSetEvent( FCB->EventSelect, IO_NETWORK_INCREMENT, FALSE );
452 }
453
454 AFD_DbgPrint(MID_TRACE,("Leaving\n"));
455}
struct _AFD_FCB * PAFD_FCB
static BOOLEAN UpdatePollWithFCB(PAFD_ACTIVE_POLL Poll, PFILE_OBJECT FileObject)
Definition: select.c:382
PVOID SystemBuffer
union _IRP::@1581 AssociatedIrp

Referenced by AfdAccept(), AfdConnectedSocketReadData(), AfdConnectedSocketWriteData(), AfdCreateSocket(), AfdPacketSocketReadData(), AfdWaitForListen(), DisconnectComplete(), ListenComplete(), MakeSocketIntoConnection(), PacketSocketRecvComplete(), PacketSocketSendComplete(), ReceiveActivity(), SendComplete(), and StreamSocketConnectComplete().

◆ QueueUserModeIrp()

NTSTATUS QueueUserModeIrp ( PAFD_FCB  FCB,
PIRP  Irp,
UINT  Function 
)

Definition at line 397 of file lock.c.

398{
400
401 /* Add the IRP to the queue in all cases (so AfdCancelHandler will work properly) */
402 InsertTailList( &FCB->PendingIrpList[Function],
403 &Irp->Tail.Overlay.ListEntry );
404
405 /* Acquire the cancel spin lock and check the cancel bit */
406 IoAcquireCancelSpinLock(&Irp->CancelIrql);
407 if (!Irp->Cancel)
408 {
409 /* We are not cancelled; we're good to go so
410 * set the cancel routine, release the cancel spin lock,
411 * mark the IRP as pending, and
412 * return STATUS_PENDING to the caller
413 */
415 IoReleaseCancelSpinLock(Irp->CancelIrql);
418 }
419 else
420 {
421 /* We were already cancelled before we were able to register our cancel routine
422 * so we are to call the cancel routine ourselves right here to cancel the IRP
423 * (which handles all the stuff we do above) and return STATUS_CANCELLED to the caller
424 */
426 Irp);
428 }
429
430 return Status;
431}
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56

Referenced by AfdConnectedSocketWriteData(), AfdDisconnect(), AfdPacketSocketWriteData(), AfdStreamSocketConnect(), and LeaveIrpUntilLater().

◆ RetryDisconnectCompletion()

VOID RetryDisconnectCompletion ( PAFD_FCB  FCB)

Definition at line 703 of file main.c.

704{
705 ASSERT(FCB->RemoteAddress);
706
707 if (IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]) && !FCB->SendIrp.InFlightRequest && FCB->DisconnectPending)
708 {
709 /* Sends are done; fire off a TDI_DISCONNECT request */
711 }
712}
static NTSTATUS DoDisconnect(PAFD_FCB FCB)
Definition: main.c:668

Referenced by SendComplete().

◆ SignalSocket()

VOID SignalSocket ( PAFD_ACTIVE_POLL Poll  OPTIONAL,
PIRP _Irp  OPTIONAL,
PAFD_POLL_INFO  PollReq,
NTSTATUS  Status 
)

Definition at line 56 of file select.c.

62{
63 UINT i;
64 PIRP Irp = _Irp ? _Irp : Poll->Irp;
65 AFD_DbgPrint(MID_TRACE,("Called (Status %x)\n", Status));
66
67 if (Poll)
68 {
69 KeCancelTimer( &Poll->Timer );
70 RemoveEntryList( &Poll->ListEntry );
72 }
73
74 Irp->IoStatus.Status = Status;
75 Irp->IoStatus.Information =
76 FIELD_OFFSET(AFD_POLL_INFO, Handles) + sizeof(AFD_HANDLE) * PollReq->HandleCount;
77 CopyBackStatus( PollReq->Handles,
78 PollReq->HandleCount );
79 for( i = 0; i < PollReq->HandleCount; i++ ) {
81 (MAX_TRACE,
82 ("Handle(%x): Got %x,%x\n",
83 PollReq->Handles[i].Handle,
84 PollReq->Handles[i].Events,
85 PollReq->Handles[i].Status));
86 }
87 UnlockHandles( AFD_HANDLES(PollReq), PollReq->HandleCount );
88 if( Irp->MdlAddress ) UnlockRequest( Irp, IoGetCurrentIrpStackLocation( Irp ) );
89 AFD_DbgPrint(MID_TRACE,("Completing\n"));
92 AFD_DbgPrint(MID_TRACE,("Done\n"));
93}
static VOID CopyBackStatus(PAFD_HANDLE HandleArray, UINT HandleCount)
Definition: select.c:34
struct _AFD_HANDLE_ AFD_HANDLE
BOOLEAN NTAPI KeCancelTimer(IN OUT PKTIMER Timer)
Definition: timerobj.c:206
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255

Referenced by AfdSelect(), CleanupPendingIrp(), KillSelectsForFCB(), PollReeval(), and SelectTimeout().

◆ SocketAcquireStateLock()

◆ SocketStateUnlock()

◆ TdiAssociateAddressFile()

NTSTATUS TdiAssociateAddressFile ( HANDLE  AddressHandle,
PFILE_OBJECT  ConnectionObject 
)

Definition at line 391 of file tdi.c.

402{
406 PIRP Irp;
407
408 AFD_DbgPrint(MAX_TRACE, ("Called. AddressHandle (%p) ConnectionObject (%p)\n",
409 AddressHandle, ConnectionObject));
410
411 if (!ConnectionObject) {
412 AFD_DbgPrint(MIN_TRACE, ("Bad connection object.\n"));
414 }
415
416 DeviceObject = IoGetRelatedDeviceObject(ConnectionObject);
417 if (!DeviceObject) {
418 AFD_DbgPrint(MIN_TRACE, ("Bad device object.\n"));
420 }
421
423
425 DeviceObject, /* Device object */
426 ConnectionObject, /* File object */
427 &Event, /* Event */
428 &Iosb); /* Status */
429 if (!Irp)
431
434 ConnectionObject,
435 NULL,
436 NULL,
437 AddressHandle);
438
439 return TdiCall(Irp, DeviceObject, &Event, &Iosb);
440}
return Iosb
Definition: create.c:4402
static NTSTATUS TdiCall(PIRP Irp, PDEVICE_OBJECT DeviceObject, PKEVENT Event, PIO_STATUS_BLOCK Iosb)
Definition: tdi.c:46
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
@ NotificationEvent
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
#define TdiBuildAssociateAddress( Irp, DevObj, FileObj, CompRoutine, Contxt, AddrHandle)
Definition: tdikrnl.h:467
#define TdiBuildInternalDeviceControlIrp(IrpSubFunction, DeviceObject, FileObject, Event, IoStatusBlock)
Definition: tdikrnl.h:573
#define TDI_ASSOCIATE_ADDRESS
Definition: tdikrnl.h:47

Referenced by WarmSocketForConnection().

◆ TdiDisassociateAddressFile()

NTSTATUS TdiDisassociateAddressFile ( PFILE_OBJECT  ConnectionObject)

Definition at line 442 of file tdi.c.

451{
455 PIRP Irp;
456
457 AFD_DbgPrint(MAX_TRACE, ("Called. ConnectionObject (%p)\n", ConnectionObject));
458
459 if (!ConnectionObject) {
460 AFD_DbgPrint(MIN_TRACE, ("Bad connection object.\n"));
462 }
463
464 DeviceObject = IoGetRelatedDeviceObject(ConnectionObject);
465 if (!DeviceObject) {
466 AFD_DbgPrint(MIN_TRACE, ("Bad device object.\n"));
468 }
469
471
473 DeviceObject, /* Device object */
474 ConnectionObject, /* File object */
475 &Event, /* Event */
476 &Iosb); /* Status */
477 if (!Irp)
479
482 ConnectionObject,
483 NULL,
484 NULL);
485
486 return TdiCall(Irp, DeviceObject, &Event, &Iosb);
487}
#define TdiBuildDisassociateAddress( Irp, DevObj, FileObj, CompRoutine, Contxt)
Definition: tdikrnl.h:521
#define TDI_DISASSOCIATE_ADDRESS
Definition: tdikrnl.h:48

Referenced by AfdCloseSocket().

◆ TdiListen()

NTSTATUS TdiListen ( PIRP Irp,
PFILE_OBJECT  ConnectionObject,
PTDI_CONNECTION_INFORMATION RequestConnectionInfo,
PTDI_CONNECTION_INFORMATION ReturnConnectionInfo,
PIO_COMPLETION_ROUTINE  CompletionRoutine,
PVOID  CompletionContext 
)

Definition at line 489 of file tdi.c.

505{
507
508 AFD_DbgPrint(MAX_TRACE, ("Called\n"));
509
510 ASSERT(*Irp == NULL);
511
512 if (!ConnectionObject) {
513 AFD_DbgPrint(MIN_TRACE, ("Bad connection object.\n"));
515 }
516
517 DeviceObject = IoGetRelatedDeviceObject(ConnectionObject);
518 if (!DeviceObject) {
519 AFD_DbgPrint(MIN_TRACE, ("Bad device object.\n"));
521 }
522
523 *Irp = TdiBuildInternalDeviceControlIrp(TDI_LISTEN, /* Sub function */
524 DeviceObject, /* Device object */
525 ConnectionObject, /* File object */
526 NULL, /* Event */
527 NULL); /* Status */
528 if (*Irp == NULL)
530
531 TdiBuildListen(*Irp, /* IRP */
532 DeviceObject, /* Device object */
533 ConnectionObject, /* File object */
534 CompletionRoutine, /* Completion routine */
535 CompletionContext, /* Completion routine context */
536 0, /* Flags */
537 *RequestConnectionInfo, /* Request connection information */
538 *ReturnConnectionInfo); /* Return connection information */
539
540 TdiCall(*Irp, DeviceObject, NULL /* Don't wait for completion */, NULL);
541
542 return STATUS_PENDING;
543}
#define TdiBuildListen( Irp, DevObj, FileObj, CompRoutine, Contxt, Flags, RequestConnectionInfo, ReturnConnectionInfo)
Definition: tdikrnl.h:593
#define TDI_LISTEN
Definition: tdikrnl.h:50
_In_ WDFREQUEST _In_opt_ PFN_WDF_REQUEST_COMPLETION_ROUTINE _In_opt_ __drv_aliasesMem WDFCONTEXT CompletionContext
Definition: wdfrequest.h:898
_In_ WDFREQUEST _In_opt_ PFN_WDF_REQUEST_COMPLETION_ROUTINE CompletionRoutine
Definition: wdfrequest.h:895

Referenced by AfdListenSocket(), and ListenComplete().

◆ TdiOpenAddressFile()

NTSTATUS TdiOpenAddressFile ( PUNICODE_STRING  DeviceName,
PTRANSPORT_ADDRESS  Name,
ULONG  ShareType,
PHANDLE  AddressHandle,
PFILE_OBJECT AddressObject 
)

Definition at line 170 of file tdi.c.

186{
191
192 AFD_DbgPrint(MAX_TRACE, ("Called. DeviceName (%wZ) Name (%p)\n",
193 DeviceName, Name));
194
195 /* EaName must be 0-terminated, even though TDI_TRANSPORT_ADDRESS_LENGTH does *not* include the 0 */
200 EaLength,
202 if (!EaInfo)
204
205 RtlZeroMemory(EaInfo, EaLength);
207 /* Don't copy the terminating 0; we have already zeroed it */
208 RtlCopyMemory(EaInfo->EaName,
211 EaInfo->EaValueLength = sizeof(TA_IP_ADDRESS);
212 Address =
213 (PTRANSPORT_ADDRESS)(EaInfo->EaName + TDI_TRANSPORT_ADDRESS_LENGTH + 1); /* 0-terminated */
215
217 EaLength,
218 EaInfo,
219 ShareType,
220 AddressHandle,
221 AddressObject);
223 return Status;
224}
#define TAG_AFD_EA_INFO
Definition: afd.h:50
static NTSTATUS TdiOpenDevice(PUNICODE_STRING DeviceName, ULONG EaLength, PFILE_FULL_EA_INFORMATION EaInfo, ULONG ShareType, PHANDLE Handle, PFILE_OBJECT *Object)
Definition: tdi.c:88
IN PVCB IN PDIRENT OUT PULONG EaLength
Definition: fatprocs.h:879
struct _FILE_FULL_EA_INFORMATION * PFILE_FULL_EA_INFORMATION
struct _FILE_FULL_EA_INFORMATION FILE_FULL_EA_INFORMATION
struct _TA_ADDRESS_IP TA_IP_ADDRESS
struct _TRANSPORT_ADDRESS * PTRANSPORT_ADDRESS
#define TDI_TRANSPORT_ADDRESS_LENGTH
Definition: tdi.h:372
#define TdiTransportAddress
Definition: tdi.h:370
VOID TaCopyTransportAddressInPlace(PTRANSPORT_ADDRESS Target, PTRANSPORT_ADDRESS Source)
Definition: tdiconn.c:74
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275

Referenced by WarmSocketForBind().

◆ TdiQueryMaxDatagramLength()

NTSTATUS TdiQueryMaxDatagramLength ( PFILE_OBJECT  FileObject,
PUINT  MaxDatagramLength 
)

Definition at line 226 of file tdi.c.

229{
230 PMDL Mdl;
233
235 sizeof(TDI_MAX_DATAGRAM_INFO),
237
238 if (!Buffer) return STATUS_NO_MEMORY;
239
241 if (!Mdl)
242 {
244 return STATUS_NO_MEMORY;
245 }
246
248 {
250 }
252 {
254 }
255 _SEH2_END;
256
257 if (!NT_SUCCESS(Status))
258 {
259 AFD_DbgPrint(MIN_TRACE,("Failed to lock pages\n"));
260 IoFreeMdl(Mdl);
262 return Status;
263 }
264
267 Mdl);
268 if (!NT_SUCCESS(Status))
269 {
271 return Status;
272 }
273
274 *MaxDatagramLength = Buffer->MaxDatagramSize;
275
277
278 return STATUS_SUCCESS;
279}
Definition: bufpool.h:45
#define TDI_QUERY_MAX_DATAGRAM_INFO
Definition: tdi.h:187

Referenced by MakeSocketIntoConnection(), and WarmSocketForBind().

◆ TdiReceive()

NTSTATUS TdiReceive ( PIRP Irp,
PFILE_OBJECT  ConnectionObject,
USHORT  Flags,
PCHAR  Buffer,
UINT  BufferLength,
PIO_COMPLETION_ROUTINE  CompletionRoutine,
PVOID  CompletionContext 
)

Definition at line 976 of file tdi.c.

984{
986 PMDL Mdl;
987
988 ASSERT(*Irp == NULL);
989
990 if (!TransportObject) {
991 AFD_DbgPrint(MIN_TRACE, ("Bad transport object.\n"));
993 }
994
995 DeviceObject = IoGetRelatedDeviceObject(TransportObject);
996 if (!DeviceObject) {
997 AFD_DbgPrint(MIN_TRACE, ("Bad device object.\n"));
999 }
1000
1001 *Irp = TdiBuildInternalDeviceControlIrp(TDI_RECEIVE, /* Sub function */
1002 DeviceObject, /* Device object */
1003 TransportObject, /* File object */
1004 NULL, /* Event */
1005 NULL); /* Status */
1006
1007 if (!*Irp) {
1008 AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
1010 }
1011
1012 AFD_DbgPrint(MID_TRACE, ("Allocating irp for %p:%u\n", Buffer,BufferLength));
1013
1014 Mdl = IoAllocateMdl(Buffer, /* Virtual address */
1015 BufferLength, /* Length of buffer */
1016 FALSE, /* Not secondary */
1017 FALSE, /* Don't charge quota */
1018 NULL); /* Don't use IRP */
1019 if (!Mdl) {
1020 AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
1022 *Irp = NULL;
1024 }
1025
1026 _SEH2_TRY {
1027 AFD_DbgPrint(MID_TRACE, ("probe and lock\n"));
1028 MmProbeAndLockPages(Mdl, (*Irp)->RequestorMode, IoModifyAccess);
1029 AFD_DbgPrint(MID_TRACE, ("probe and lock done\n"));
1031 AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
1032 IoFreeMdl(Mdl);
1034 *Irp = NULL;
1036 } _SEH2_END;
1037
1038 AFD_DbgPrint(MID_TRACE,("AFD>>> Got an MDL: %p\n", Mdl));
1039
1040 TdiBuildReceive(*Irp, /* I/O Request Packet */
1041 DeviceObject, /* Device object */
1042 TransportObject, /* File object */
1043 CompletionRoutine, /* Completion routine */
1044 CompletionContext, /* Completion context */
1045 Mdl, /* Data buffer */
1046 Flags, /* Flags */
1047 BufferLength); /* Length of data */
1048
1049
1051 /* Does not block... The MDL is deleted in the receive completion
1052 routine. */
1053
1054 return STATUS_PENDING;
1055}
#define TdiBuildReceive( Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr, InFlags, ReceiveLen)
Definition: tdikrnl.h:667
#define TDI_RECEIVE
Definition: tdikrnl.h:54
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by MakeSocketIntoConnection(), and RefillSocketBuffer().

◆ TdiReceiveDatagram()

NTSTATUS TdiReceiveDatagram ( PIRP Irp,
PFILE_OBJECT  TransportObject,
USHORT  Flags,
PCHAR  Buffer,
UINT  BufferLength,
PTDI_CONNECTION_INFORMATION  From,
PIO_COMPLETION_ROUTINE  CompletionRoutine,
PVOID  CompletionContext 
)

Definition at line 1058 of file tdi.c.

1078{
1080 PMDL Mdl;
1081
1082 ASSERT(*Irp == NULL);
1083
1084 if (!TransportObject) {
1085 AFD_DbgPrint(MIN_TRACE, ("Bad tranport object.\n"));
1087 }
1088
1089 DeviceObject = IoGetRelatedDeviceObject(TransportObject);
1090 if (!DeviceObject) {
1091 AFD_DbgPrint(MIN_TRACE, ("Bad device object.\n"));
1093 }
1094
1096 DeviceObject, /* Device object */
1097 TransportObject, /* File object */
1098 NULL, /* Event */
1099 NULL); /* Status */
1100
1101 if (!*Irp) {
1102 AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
1104 }
1105
1106 AFD_DbgPrint(MID_TRACE, ("Allocating irp for %p:%u\n", Buffer,BufferLength));
1107
1108 Mdl = IoAllocateMdl(Buffer, /* Virtual address */
1109 BufferLength, /* Length of buffer */
1110 FALSE, /* Not secondary */
1111 FALSE, /* Don't charge quota */
1112 NULL); /* Don't use IRP */
1113 if (!Mdl) {
1114 AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
1116 *Irp = NULL;
1118 }
1119
1120 _SEH2_TRY {
1121 MmProbeAndLockPages(Mdl, (*Irp)->RequestorMode, IoModifyAccess);
1123 AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
1124 IoFreeMdl(Mdl);
1126 *Irp = NULL;
1128 } _SEH2_END;
1129
1130 AFD_DbgPrint(MID_TRACE,("AFD>>> Got an MDL: %p\n", Mdl));
1131
1132 TdiBuildReceiveDatagram(*Irp, /* I/O Request Packet */
1133 DeviceObject, /* Device object */
1134 TransportObject, /* File object */
1135 CompletionRoutine, /* Completion routine */
1136 CompletionContext, /* Completion context */
1137 Mdl, /* Data buffer */
1139 Addr,
1140 Addr,
1141 Flags); /* Length of data */
1142
1144 /* Does not block... The MDL is deleted in the receive completion
1145 routine. */
1146
1147 return STATUS_PENDING;
1148}
#define TDI_RECEIVE_DATAGRAM
Definition: tdikrnl.h:56
#define TdiBuildReceiveDatagram( Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr, ReceiveLen, ReceiveDatagramInfo, ReturnInfo, InFlags)
Definition: tdikrnl.h:699

Referenced by PacketSocketRecvComplete(), and WarmSocketForBind().

◆ TdiSend()

NTSTATUS TdiSend ( PIRP Irp,
PFILE_OBJECT  ConnectionObject,
USHORT  Flags,
PCHAR  Buffer,
UINT  BufferLength,
PIO_COMPLETION_ROUTINE  CompletionRoutine,
PVOID  CompletionContext 
)

Definition at line 898 of file tdi.c.

906{
908 PMDL Mdl;
909
910 ASSERT(*Irp == NULL);
911
912 if (!TransportObject) {
913 AFD_DbgPrint(MIN_TRACE, ("Bad transport object.\n"));
915 }
916
917 DeviceObject = IoGetRelatedDeviceObject(TransportObject);
918 if (!DeviceObject) {
919 AFD_DbgPrint(MIN_TRACE, ("Bad device object.\n"));
921 }
922
923 *Irp = TdiBuildInternalDeviceControlIrp(TDI_SEND, /* Sub function */
924 DeviceObject, /* Device object */
925 TransportObject, /* File object */
926 NULL, /* Event */
927 NULL); /* Status */
928
929 if (!*Irp) {
930 AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
932 }
933
934 AFD_DbgPrint(MID_TRACE, ("Allocating irp for %p:%u\n", Buffer,BufferLength));
935
936 Mdl = IoAllocateMdl(Buffer, /* Virtual address */
937 BufferLength, /* Length of buffer */
938 FALSE, /* Not secondary */
939 FALSE, /* Don't charge quota */
940 NULL); /* Don't use IRP */
941 if (!Mdl) {
942 AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
944 *Irp = NULL;
946 }
947
948 _SEH2_TRY {
949 MmProbeAndLockPages(Mdl, (*Irp)->RequestorMode, IoReadAccess);
951 AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
952 IoFreeMdl(Mdl);
954 *Irp = NULL;
956 } _SEH2_END;
957
958 AFD_DbgPrint(MID_TRACE,("AFD>>> Got an MDL: %p\n", Mdl));
959
960 TdiBuildSend(*Irp, /* I/O Request Packet */
961 DeviceObject, /* Device object */
962 TransportObject, /* File object */
963 CompletionRoutine, /* Completion routine */
964 CompletionContext, /* Completion context */
965 Mdl, /* Data buffer */
966 Flags, /* Flags */
967 BufferLength); /* Length of data */
968
970 /* Does not block... The MDL is deleted in the receive completion
971 routine. */
972
973 return STATUS_PENDING;
974}
#define TDI_SEND
Definition: tdikrnl.h:53
#define TdiBuildSend( Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr, InFlags, SendLen)
Definition: tdikrnl.h:731

Referenced by AfdConnectedSocketWriteData(), and SendComplete().

◆ TdiSendDatagram()

NTSTATUS TdiSendDatagram ( PIRP Irp,
PFILE_OBJECT  TransportObject,
PCHAR  Buffer,
UINT  BufferLength,
PTDI_CONNECTION_INFORMATION  To,
PIO_COMPLETION_ROUTINE  CompletionRoutine,
PVOID  CompletionContext 
)

Definition at line 1151 of file tdi.c.

1170{
1172 PMDL Mdl;
1173
1174 ASSERT(*Irp == NULL);
1175
1176 if (!TransportObject) {
1177 AFD_DbgPrint(MIN_TRACE, ("Bad transport object.\n"));
1179 }
1180
1181 AFD_DbgPrint(MID_TRACE,("Called(TransportObject %p)\n", TransportObject));
1182
1183 DeviceObject = IoGetRelatedDeviceObject(TransportObject);
1184 if (!DeviceObject) {
1185 AFD_DbgPrint(MIN_TRACE, ("Bad device object.\n"));
1187 }
1188
1189 if (BufferLength == 0)
1190 {
1191 AFD_DbgPrint(MID_TRACE, ("Succeeding send with length 0.\n"));
1192 return STATUS_SUCCESS;
1193 }
1194
1196 DeviceObject, /* Device object */
1197 TransportObject, /* File object */
1198 NULL, /* Event */
1199 NULL); /* Status */
1200
1201 if (!*Irp) {
1202 AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
1204 }
1205
1206 AFD_DbgPrint(MID_TRACE, ("Allocating irp for %p:%u\n", Buffer,BufferLength));
1207
1208 Mdl = IoAllocateMdl(Buffer, /* Virtual address */
1209 BufferLength, /* Length of buffer */
1210 FALSE, /* Not secondary */
1211 FALSE, /* Don't charge quota */
1212 NULL); /* Don't use IRP */
1213
1214 if (!Mdl) {
1215 AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
1217 *Irp = NULL;
1219 }
1220
1221 _SEH2_TRY {
1222 MmProbeAndLockPages(Mdl, (*Irp)->RequestorMode, IoReadAccess);
1224 AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
1225 IoFreeMdl(Mdl);
1227 *Irp = NULL;
1229 } _SEH2_END;
1230
1231 AFD_DbgPrint(MID_TRACE,("AFD>>> Got an MDL: %p\n", Mdl));
1232
1233 TdiBuildSendDatagram(*Irp, /* I/O Request Packet */
1234 DeviceObject, /* Device object */
1235 TransportObject, /* File object */
1236 CompletionRoutine, /* Completion routine */
1237 CompletionContext, /* Completion context */
1238 Mdl, /* Data buffer */
1239 BufferLength, /* Bytes to send */
1240 Addr); /* Address */
1241
1243 /* Does not block... The MDL is deleted in the send completion
1244 routine. */
1245
1246 return STATUS_PENDING;
1247}
#define TDI_SEND_DATAGRAM
Definition: tdikrnl.h:55
#define TdiBuildSendDatagram( Irp, DevObj, FileObj, CompRoutine, Contxt, MdlAddr, SendLen, SendDatagramInfo)
Definition: tdikrnl.h:761

Referenced by AfdConnectedSocketWriteData(), and AfdPacketSocketWriteData().

◆ UnlockAndMaybeComplete()

◆ UnlockBuffers()

VOID UnlockBuffers ( PAFD_WSABUF  Buf,
UINT  Count,
BOOL  Address 
)

Definition at line 289 of file lock.c.

289 {
290 UINT Lock = Address ? 2 : 0;
291 PAFD_MAPBUF Map = (PAFD_MAPBUF)(Buf + Count + Lock);
292 UINT i;
293
294 if( !Buf ) return;
295
296 for( i = 0; i < Count + Lock; i++ ) {
297 if( Map[i].Mdl ) {
298 MmUnlockPages( Map[i].Mdl );
299 IoFreeMdl( Map[i].Mdl );
300 Map[i].Mdl = NULL;
301 }
302 }
303
305 Buf = NULL;
306}

Referenced by AfdConnectedSocketReadData(), AfdConnectedSocketWriteData(), AfdPacketSocketReadData(), AfdPacketSocketWriteData(), CleanupPendingIrp(), PacketSocketRecvComplete(), PacketSocketSendComplete(), ReceiveActivity(), ReceiveComplete(), and SendComplete().

◆ UnlockHandles()

VOID UnlockHandles ( PAFD_HANDLE  HandleArray,
UINT  HandleCount 
)

Definition at line 348 of file lock.c.

348 {
349 UINT i;
350
351 for( i = 0; i < HandleCount; i++ ) {
352 if( HandleArray[i].Handle )
353 ObDereferenceObject( (PVOID)HandleArray[i].Handle );
354 }
355
357 HandleArray = NULL;
358}

Referenced by LockHandles(), and SignalSocket().

◆ UnlockRequest()

VOID UnlockRequest ( PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 180 of file lock.c.

181{
182 ASSERT(Irp->MdlAddress);
183 ASSERT(Irp->Tail.Overlay.DriverContext[0]);
184
186
187 /* Check if we need to copy stuff back */
188 if (Irp->Tail.Overlay.DriverContext[1] != NULL)
189 {
190 RtlCopyMemory(Irp->Tail.Overlay.DriverContext[1],
191 Irp->Tail.Overlay.DriverContext[0],
192 MmGetMdlByteCount(Irp->MdlAddress));
193 }
194
195 ExFreePoolWithTag(Irp->Tail.Overlay.DriverContext[0], TAG_AFD_DATA_BUFFER);
196 MmUnlockPages( Irp->MdlAddress );
197 IoFreeMdl( Irp->MdlAddress );
198 Irp->MdlAddress = NULL;
199}

Referenced by AfdConnectedSocketWriteData(), AfdDisconnect(), AfdPacketSocketWriteData(), DisconnectComplete(), ListenComplete(), LostSocket(), MimeProtocol_UnlockRequest(), PacketSocketRecvComplete(), PacketSocketSendComplete(), Protocol_UnlockRequest(), ProtocolEmul_UnlockRequest(), ReceiveActivity(), ReceiveComplete(), SatisfyPreAccept(), SendComplete(), SignalSocket(), StreamSocketConnectComplete(), test_binding(), test_BindToObject(), test_BindToStorage(), test_download(), test_submit(), test_URLDownloadToFile(), and UnlockAndMaybeComplete().

◆ WarmSocketForBind()

NTSTATUS WarmSocketForBind ( PAFD_FCB  FCB,
ULONG  ShareType 
)

Definition at line 13 of file bind.c.

13 {
15
16 AFD_DbgPrint(MID_TRACE,("Called (AF %u)\n",
17 FCB->LocalAddress->Address[0].AddressType));
18
19 if( !FCB->TdiDeviceName.Length || !FCB->TdiDeviceName.Buffer ) {
20 AFD_DbgPrint(MIN_TRACE,("Null Device\n"));
22 }
23 if( !FCB->LocalAddress ) {
24 AFD_DbgPrint(MIN_TRACE,("No local address\n"));
26 }
27
28 Status = TdiOpenAddressFile(&FCB->TdiDeviceName,
29 FCB->LocalAddress,
30 ShareType,
31 &FCB->AddressFile.Handle,
32 &FCB->AddressFile.Object );
33 if (!NT_SUCCESS(Status))
34 return Status;
35
37 {
38 if (!FCB->Recv.Size)
39 {
40 Status = TdiQueryMaxDatagramLength(FCB->AddressFile.Object,
41 &FCB->Recv.Size);
42 }
43
44 if (NT_SUCCESS(Status) && !FCB->Recv.Window)
45 {
46 FCB->Recv.Window = ExAllocatePoolWithTag(PagedPool,
47 FCB->Recv.Size,
49
50 if (!FCB->Recv.Window)
52 }
53
54 if (NT_SUCCESS(Status) && FCB->Recv.Content < FCB->Recv.Size)
55 {
56 Status = TdiReceiveDatagram(&FCB->ReceiveIrp.InFlightRequest,
57 FCB->AddressFile.Object,
58 0,
59 FCB->Recv.Window,
60 FCB->Recv.Size,
61 FCB->AddressFrom,
63 FCB);
64
65 /* We don't want to wait for this read to complete. */
67 }
68 }
69
70 AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
71
72 return Status;
73}
IO_COMPLETION_ROUTINE PacketSocketRecvComplete
Definition: afd.h:310
NTSTATUS TdiReceiveDatagram(PIRP *Irp, PFILE_OBJECT TransportObject, USHORT Flags, PCHAR Buffer, UINT BufferLength, PTDI_CONNECTION_INFORMATION Addr, PIO_COMPLETION_ROUTINE CompletionRoutine, PVOID CompletionContext)
Definition: tdi.c:1058
NTSTATUS TdiOpenAddressFile(PUNICODE_STRING DeviceName, PTRANSPORT_ADDRESS Name, ULONG ShareType, PHANDLE AddressHandle, PFILE_OBJECT *AddressObject)
Definition: tdi.c:170
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136

Referenced by AfdBindSocket(), AfdPacketSocketWriteData(), and AfdStreamSocketConnect().

◆ WarmSocketForConnection()

NTSTATUS WarmSocketForConnection ( PAFD_FCB  FCB)

Definition at line 238 of file connect.c.

238 {
240
241 if( !FCB->TdiDeviceName.Length || !FCB->TdiDeviceName.Buffer ) {
242 AFD_DbgPrint(MIN_TRACE,("Null Device\n"));
244 }
245
246 Status = TdiOpenConnectionEndpointFile(&FCB->TdiDeviceName,
247 &FCB->Connection.Handle,
248 &FCB->Connection.Object );
249
250 if( NT_SUCCESS(Status) ) {
251 Status = TdiAssociateAddressFile( FCB->AddressFile.Handle,
252 FCB->Connection.Object );
253 }
254
255 return Status;
256}
NTSTATUS TdiAssociateAddressFile(HANDLE AddressHandle, PFILE_OBJECT ConnectionObject)
Definition: tdi.c:391
NTSTATUS TdiOpenConnectionEndpointFile(PUNICODE_STRING DeviceName, PHANDLE ConnectionHandle, PFILE_OBJECT *ConnectionObject)
Definition: tdi.c:281

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

◆ ZeroEvents()

VOID ZeroEvents ( PAFD_HANDLE  HandleArray,
UINT  HandleCount 
)

Definition at line 44 of file select.c.

45 {
46 UINT i;
47
48 for( i = 0; i < HandleCount; i++ ) {
49 HandleArray[i].Status = 0;
50 HandleArray[i].Events = 0;
51 }
52}

Referenced by CleanupPendingIrp(), KillSelectsForFCB(), and SelectTimeout().

Variable Documentation

◆ AfdCancelHandler

DRIVER_CANCEL AfdCancelHandler

Definition at line 302 of file afd.h.

Referenced by AfdConnectedSocketReadData(), AfdSelect(), and QueueUserModeIrp().

◆ PacketSocketRecvComplete

IO_COMPLETION_ROUTINE PacketSocketRecvComplete

Definition at line 310 of file afd.h.

Referenced by PacketSocketRecvComplete(), and WarmSocketForBind().

◆ ReceiveComplete

IO_COMPLETION_ROUTINE ReceiveComplete

Definition at line 308 of file afd.h.

Referenced by MakeSocketIntoConnection(), and RefillSocketBuffer().