ReactOS 0.4.16-dev-297-gc569aee
main.c File Reference
#include "afd.h"
Include dependency graph for main.c:

Go to the source code of this file.

Functions

void OskitDumpBuffer (PCHAR Data, UINT Len)
 
NTSTATUS NTAPI DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
 
NTSTATUS NTAPI AfdGetDisconnectOptions (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI AfdSetDisconnectOptions (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI AfdSetDisconnectOptionsSize (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI AfdGetDisconnectData (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI AfdSetDisconnectData (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI AfdSetDisconnectDataSize (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
static NTSTATUS NTAPI AfdGetTdiHandles (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
static NTSTATUS NTAPI AfdCreateSocket (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
static NTSTATUS NTAPI AfdCleanupSocket (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
static NTSTATUS NTAPI AfdCloseSocket (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
static NTSTATUS NTAPI DisconnectComplete (PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
 
static NTSTATUS DoDisconnect (PAFD_FCB FCB)
 
VOID RetryDisconnectCompletion (PAFD_FCB FCB)
 
static NTSTATUS NTAPI AfdDisconnect (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS AfdQueryFsDeviceInfo (PDEVICE_OBJECT DeviceObject, PFILE_FS_DEVICE_INFORMATION Buffer, PULONG Length)
 
static NTSTATUS NTAPI AfdQueryVolumeInformation (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
static NTSTATUS NTAPI AfdDispatch (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
BOOLEAN CheckUnlockExtraBuffers (PAFD_FCB FCB, PIO_STACK_LOCATION IrpSp)
 
VOID CleanupPendingIrp (PAFD_FCB FCB, PIRP Irp, PIO_STACK_LOCATION IrpSp, PAFD_ACTIVE_POLL Poll)
 
VOID NTAPI AfdCancelHandler (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
static VOID NTAPI AfdUnload (PDRIVER_OBJECT DriverObject)
 

Variables

ULONG AfdReceiveWindowSize = 0x2000
 
ULONG AfdSendWindowSize = 0x2000
 
static IO_COMPLETION_ROUTINE DisconnectComplete
 
static DRIVER_DISPATCH AfdDispatch
 
static DRIVER_UNLOAD AfdUnload
 

Function Documentation

◆ AfdCancelHandler()

VOID NTAPI AfdCancelHandler ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 1181 of file main.c.

1183{
1186 PAFD_FCB FCB = FileObject->FsContext;
1188 PIRP CurrentIrp;
1189 PLIST_ENTRY CurrentEntry;
1190 PAFD_DEVICE_EXTENSION DeviceExt = DeviceObject->DeviceExtension;
1191 KIRQL OldIrql;
1192 PAFD_ACTIVE_POLL Poll;
1193
1194 IoReleaseCancelSpinLock(Irp->CancelIrql);
1195
1197 return;
1198
1199 switch (IrpSp->MajorFunction)
1200 {
1202 IoctlCode = IrpSp->Parameters.DeviceIoControl.IoControlCode;
1203 break;
1204
1205 case IRP_MJ_READ:
1207 break;
1208
1209 case IRP_MJ_WRITE:
1211 break;
1212
1213 default:
1214 ASSERT(FALSE);
1216 return;
1217 }
1218
1219 switch (IoctlCode)
1220 {
1221 case IOCTL_AFD_RECV:
1224 break;
1225
1226 case IOCTL_AFD_SEND:
1229 break;
1230
1231 case IOCTL_AFD_CONNECT:
1233 break;
1234
1237 break;
1238
1239 case IOCTL_AFD_SELECT:
1240 KeAcquireSpinLock(&DeviceExt->Lock, &OldIrql);
1241
1242 CurrentEntry = DeviceExt->Polls.Flink;
1243 while (CurrentEntry != &DeviceExt->Polls)
1244 {
1245 Poll = CONTAINING_RECORD(CurrentEntry, AFD_ACTIVE_POLL, ListEntry);
1246
1247 if (Irp == Poll->Irp)
1248 {
1249 CleanupPendingIrp(FCB, Irp, IrpSp, Poll);
1250 KeReleaseSpinLock(&DeviceExt->Lock, OldIrql);
1252 return;
1253 }
1254 else
1255 {
1256 CurrentEntry = CurrentEntry->Flink;
1257 }
1258 }
1259
1260 KeReleaseSpinLock(&DeviceExt->Lock, OldIrql);
1261
1263
1264 DbgPrint("WARNING!!! IRP cancellation race could lead to a process hang! (IOCTL_AFD_SELECT)\n");
1265 return;
1266
1269 break;
1270
1271 default:
1272 ASSERT(FALSE);
1274 return;
1275 }
1276
1277 CurrentEntry = FCB->PendingIrpList[Function].Flink;
1278 while (CurrentEntry != &FCB->PendingIrpList[Function])
1279 {
1280 CurrentIrp = CONTAINING_RECORD(CurrentEntry, IRP, Tail.Overlay.ListEntry);
1281
1282 if (CurrentIrp == Irp)
1283 {
1284 RemoveEntryList(CurrentEntry);
1287 return;
1288 }
1289 else
1290 {
1291 CurrentEntry = CurrentEntry->Flink;
1292 }
1293 }
1294
1296
1297 DbgPrint("WARNING!!! IRP cancellation race could lead to a process hang! (Function: %u)\n", Function);
1298}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define FUNCTION_CONNECT
Definition: afd.h:84
#define FUNCTION_RECV
Definition: afd.h:85
#define FUNCTION_PREACCEPT
Definition: afd.h:87
#define FUNCTION_DISCONNECT
Definition: afd.h:89
#define FUNCTION_SEND
Definition: afd.h:86
_In_ CDROM_SCAN_FOR_SPECIAL_INFO _In_ PCDROM_SCAN_FOR_SPECIAL_HANDLER Function
Definition: cdrom.h:1156
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
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 CleanupPendingIrp(PAFD_FCB FCB, PIRP Irp, PIO_STACK_LOCATION IrpSp, PAFD_ACTIVE_POLL Poll)
Definition: main.c:1138
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
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 DbgPrint
Definition: hal.h:12
#define ASSERT(a)
Definition: mode.c:44
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
#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_WAIT_FOR_LISTEN
Definition: shared.h:273
#define IOCTL_AFD_SELECT
Definition: shared.h:285
#define IOCTL_AFD_RECV
Definition: shared.h:277
#define IOCTL_AFD_CONNECT
Definition: shared.h:269
#define IOCTL_AFD_DISCONNECT
Definition: shared.h:287
#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
PIRP Irp
Definition: afd.h:116
LIST_ENTRY Polls
Definition: afd.h:110
KSPIN_LOCK Lock
Definition: afd.h:111
Definition: afd.h:159
Definition: cdstruc.h:902
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
struct _IO_STACK_LOCATION::@1579::@1580 DeviceIoControl
union _IO_STACK_LOCATION::@1579 Parameters
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_ ULONG IoctlCode
Definition: wdfiotarget.h:1043
* PFILE_OBJECT
Definition: iotypes.h:1998
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

◆ AfdCleanupSocket()

static NTSTATUS NTAPI AfdCleanupSocket ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)
static

Definition at line 426 of file main.c.

428{
430 PAFD_FCB FCB = FileObject->FsContext;
431 PLIST_ENTRY CurrentEntry, NextEntry;
433 PIRP CurrentIrp;
434
436
437 if( !SocketAcquireStateLock( FCB ) ) return LostSocket(Irp);
438
440 {
441 CurrentEntry = FCB->PendingIrpList[Function].Flink;
442 while (CurrentEntry != &FCB->PendingIrpList[Function])
443 {
444 NextEntry = CurrentEntry->Flink;
445 CurrentIrp = CONTAINING_RECORD(CurrentEntry, IRP, Tail.Overlay.ListEntry);
446
447 /* The cancel routine will remove the IRP from the list */
448 IoCancelIrp(CurrentIrp);
449
450 CurrentEntry = NextEntry;
451 }
452 }
453
454 KillSelectsForFCB( FCB->DeviceExt, FileObject, FALSE );
455
457}
#define MAX_FUNCTIONS
Definition: afd.h:91
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
VOID KillSelectsForFCB(PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, BOOLEAN OnlyExclusive)
Definition: select.c:125
unsigned int UINT
Definition: ndis.h:50
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
BOOLEAN NTAPI IoCancelIrp(IN PIRP Irp)
Definition: irp.c:1101
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by AfdDispatch().

◆ AfdCloseSocket()

static NTSTATUS NTAPI AfdCloseSocket ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)
static

Definition at line 460 of file main.c.

462{
464 PAFD_FCB FCB = FileObject->FsContext;
465 UINT i;
468 PLIST_ENTRY QeltEntry;
469
470
471 AFD_DbgPrint(MID_TRACE,("AfdClose(DeviceObject %p Irp %p)\n",
472 DeviceObject, Irp));
473
475
476 FCB->State = SOCKET_STATE_CLOSED;
477
478 InFlightRequest[0] = &FCB->ListenIrp;
479 InFlightRequest[1] = &FCB->ReceiveIrp;
480 InFlightRequest[2] = &FCB->SendIrp;
481 InFlightRequest[3] = &FCB->ConnectIrp;
482 InFlightRequest[4] = &FCB->DisconnectIrp;
483
484 /* Cancel our pending requests */
485 for( i = 0; i < IN_FLIGHT_REQUESTS; i++ ) {
486 if( InFlightRequest[i]->InFlightRequest ) {
487 AFD_DbgPrint(MID_TRACE,("Cancelling in flight irp %u (%p)\n",
488 i, InFlightRequest[i]->InFlightRequest));
489 IoCancelIrp(InFlightRequest[i]->InFlightRequest);
490 }
491 }
492
493 KillSelectsForFCB( FCB->DeviceExt, FileObject, FALSE );
494
495 ASSERT(IsListEmpty(&FCB->PendingIrpList[FUNCTION_CONNECT]));
496 ASSERT(IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]));
497 ASSERT(IsListEmpty(&FCB->PendingIrpList[FUNCTION_RECV]));
498 ASSERT(IsListEmpty(&FCB->PendingIrpList[FUNCTION_PREACCEPT]));
499 ASSERT(IsListEmpty(&FCB->PendingIrpList[FUNCTION_DISCONNECT]));
500
501 while (!IsListEmpty(&FCB->PendingConnections))
502 {
503 QeltEntry = RemoveHeadList(&FCB->PendingConnections);
504 Qelt = CONTAINING_RECORD(QeltEntry, AFD_TDI_OBJECT_QELT, ListEntry);
505
506 /* We have to close all pending connections or the listen won't get closed */
509 ZwClose(Qelt->Object.Handle);
510
512 }
513
515
516 if( FCB->EventSelect )
517 ObDereferenceObject( FCB->EventSelect );
518
519 if (FCB->Context)
521
522 if (FCB->Recv.Window)
524
525 if (FCB->Send.Window)
527
528 if (FCB->AddressFrom)
530
531 if (FCB->ConnectCallInfo)
533
534 if (FCB->ConnectReturnInfo)
536
537 if (FCB->ConnectData)
539
540 if (FCB->DisconnectData)
542
543 if (FCB->ConnectOptions)
545
546 if (FCB->DisconnectOptions)
548
549 if (FCB->LocalAddress)
551
552 if (FCB->RemoteAddress)
554
555 if( FCB->Connection.Object )
556 {
557 TdiDisassociateAddressFile(FCB->Connection.Object);
558 ObDereferenceObject(FCB->Connection.Object);
559 }
560
561 if( FCB->AddressFile.Object )
562 ObDereferenceObject(FCB->AddressFile.Object);
563
564 if( FCB->AddressFile.Handle != INVALID_HANDLE_VALUE )
565 {
566 if (ZwClose(FCB->AddressFile.Handle) == STATUS_INVALID_HANDLE)
567 {
568 DbgPrint("INVALID ADDRESS FILE HANDLE VALUE: %p %p\n", FCB->AddressFile.Handle, FCB->AddressFile.Object);
569 }
570 }
571
572 if( FCB->Connection.Handle != INVALID_HANDLE_VALUE )
573 {
574 if (ZwClose(FCB->Connection.Handle) == STATUS_INVALID_HANDLE)
575 {
576 DbgPrint("INVALID CONNECTION HANDLE VALUE: %p %p\n", FCB->Connection.Handle, FCB->Connection.Object);
577 }
578 }
579
580 if (FCB->TdiDeviceName.Buffer)
581 {
582 ExFreePoolWithTag(FCB->TdiDeviceName.Buffer, TAG_AFD_TRANSPORT_ADDRESS);
583 }
584
586
587 Irp->IoStatus.Status = STATUS_SUCCESS;
588 Irp->IoStatus.Information = 0;
590
591 AFD_DbgPrint(MID_TRACE, ("Returning success.\n"));
592
593 return STATUS_SUCCESS;
594}
#define SOCKET_STATE_CLOSED
Definition: afd.h:82
#define IN_FLIGHT_REQUESTS
Definition: afd.h:93
#define TAG_AFD_DISCONNECT_DATA
Definition: afd.h:42
#define TAG_AFD_TDI_CONNECTION_INFORMATION
Definition: afd.h:53
#define TAG_AFD_DISCONNECT_OPTIONS
Definition: afd.h:45
#define TAG_AFD_ACCEPT_QUEUE
Definition: afd.h:46
#define TAG_AFD_CONNECT_OPTIONS
Definition: afd.h:44
#define TAG_AFD_SOCKET_CONTEXT
Definition: afd.h:40
#define TAG_AFD_FCB
Definition: afd.h:48
#define TAG_AFD_CONNECT_DATA
Definition: afd.h:41
#define TAG_AFD_DATA_BUFFER
Definition: afd.h:38
#define TAG_AFD_TRANSPORT_ADDRESS
Definition: afd.h:39
#define MID_TRACE
Definition: debug.h:15
#define STATUS_INVALID_HANDLE
Definition: d3dkmdt.h:40
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
NTSTATUS TdiDisassociateAddressFile(PFILE_OBJECT ConnectionObject)
Definition: tdi.c:442
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_FILE_CLOSED
Definition: ntstatus.h:532
AFD_TDI_OBJECT Object
Definition: afd.h:138
HANDLE Handle
Definition: afd.h:131
PFILE_OBJECT Object
Definition: afd.h:130
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by AfdDispatch().

◆ AfdCreateSocket()

static NTSTATUS NTAPI AfdCreateSocket ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)
static

Definition at line 302 of file main.c.

303 {
306 PAFD_DEVICE_EXTENSION DeviceExt;
308 PAFD_CREATE_PACKET ConnectInfo = NULL;
309 //ULONG EaLength;
310 PWCHAR EaInfoValue = NULL;
311 //UINT Disposition;
312 UINT i;
314
315 AFD_DbgPrint(MID_TRACE,("AfdCreate(DeviceObject %p Irp %p)\n",
316 DeviceObject, Irp));
317
318 DeviceExt = DeviceObject->DeviceExtension;
320 FileObject->Flags |= FO_NAMED_PIPE;
321 //Disposition = (IrpSp->Parameters.Create.Options >> 24) & 0xff;
322
323 Irp->IoStatus.Information = 0;
324
325 EaInfo = Irp->AssociatedIrp.SystemBuffer;
326
327 if( EaInfo ) {
328 ConnectInfo = (PAFD_CREATE_PACKET)(EaInfo->EaName + EaInfo->EaNameLength + 1);
329 EaInfoValue = (PWCHAR)(((PCHAR)ConnectInfo) + sizeof(AFD_CREATE_PACKET));
330
331 //EaLength = sizeof(FILE_FULL_EA_INFORMATION) + EaInfo->EaNameLength + EaInfo->EaValueLength;
332
333 AFD_DbgPrint(MID_TRACE,("EaInfo: %p, EaInfoValue: %p\n",
334 EaInfo, EaInfoValue));
335 }
336
337 AFD_DbgPrint(MID_TRACE,("About to allocate the new FCB\n"));
338
340 if( FCB == NULL ) {
341 Irp->IoStatus.Status = STATUS_NO_MEMORY;
343 return STATUS_NO_MEMORY;
344 }
345
346 AFD_DbgPrint(MID_TRACE,("Initializing the new FCB @ %p (FileObject %p Flags %x)\n",
347 FCB, FileObject, ConnectInfo ? ConnectInfo->EndpointFlags : 0));
348
349 RtlZeroMemory( FCB, sizeof( *FCB ) );
350
351 FCB->Flags = ConnectInfo ? ConnectInfo->EndpointFlags : 0;
352 FCB->GroupID = ConnectInfo ? ConnectInfo->GroupID : 0;
353 FCB->GroupType = 0; /* FIXME */
354 FCB->State = SOCKET_STATE_CREATED;
356 FCB->DeviceExt = DeviceExt;
357 FCB->AddressFile.Handle = INVALID_HANDLE_VALUE;
358 FCB->Connection.Handle = INVALID_HANDLE_VALUE;
359 FCB->Recv.Size = AfdReceiveWindowSize;
360 FCB->Send.Size = AfdSendWindowSize;
361
362 KeInitializeMutex( &FCB->Mutex, 0 );
363
364 for( i = 0; i < MAX_FUNCTIONS; i++ ) {
365 InitializeListHead( &FCB->PendingIrpList[i] );
366 }
367
368 InitializeListHead( &FCB->DatagramList );
369 InitializeListHead( &FCB->PendingConnections );
370
371 AFD_DbgPrint(MID_TRACE,("%p: Checking command channel\n", FCB));
372
373 if( ConnectInfo ) {
374 FCB->TdiDeviceName.Length = ConnectInfo->SizeOfTransportName;
375 FCB->TdiDeviceName.MaximumLength = FCB->TdiDeviceName.Length;
376 FCB->TdiDeviceName.Buffer = ExAllocatePoolWithTag(NonPagedPool,
377 FCB->TdiDeviceName.Length,
379
380 if( !FCB->TdiDeviceName.Buffer ) {
382 AFD_DbgPrint(MID_TRACE,("Could not copy target string\n"));
383 Irp->IoStatus.Status = STATUS_NO_MEMORY;
385 return STATUS_NO_MEMORY;
386 }
387
388 RtlCopyMemory( FCB->TdiDeviceName.Buffer,
389 ConnectInfo->TransportName,
390 FCB->TdiDeviceName.Length );
391
392 AFD_DbgPrint(MID_TRACE,("Success: %s %wZ\n",
393 EaInfo->EaName, &FCB->TdiDeviceName));
394 } else {
395 AFD_DbgPrint(MID_TRACE,("Success: Control connection\n"));
396 }
397
398 FileObject->FsContext = FCB;
399
400 /* It seems that UDP sockets are writable from inception */
402 AFD_DbgPrint(MID_TRACE,("Packet oriented socket\n"));
403
404 /* A datagram socket is always sendable */
405 FCB->PollState |= AFD_EVENT_SEND;
406 FCB->PollStatus[FD_WRITE_BIT] = STATUS_SUCCESS;
407 PollReeval( FCB->DeviceExt, FCB->FileObject );
408 }
409
410 if( !NT_SUCCESS(Status) ) {
411 if (FCB->TdiDeviceName.Buffer)
412 {
413 ExFreePoolWithTag(FCB->TdiDeviceName.Buffer, TAG_AFD_TRANSPORT_ADDRESS);
414 }
416 FileObject->FsContext = NULL;
417 }
418
419 Irp->IoStatus.Status = Status;
421
422 return Status;
423}
#define SOCKET_STATE_CREATED
Definition: afd.h:73
LONG NTSTATUS
Definition: precomp.h:26
struct _FCB FCB
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
ULONG AfdSendWindowSize
Definition: main.c:27
ULONG AfdReceiveWindowSize
Definition: main.c:26
VOID PollReeval(PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
Definition: select.c:407
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
Status
Definition: gdiplustypes.h:25
VOID NTAPI KeInitializeMutex(IN PKMUTEX Mutex, IN ULONG Level)
Definition: mutex.c:67
struct _AFD_CREATE_PACKET * PAFD_CREATE_PACKET
#define AFD_EVENT_SEND
Definition: shared.h:205
#define AFD_ENDPOINT_CONNECTIONLESS
Definition: shared.h:153
DWORD EndpointFlags
Definition: shared.h:22
WCHAR TransportName[1]
Definition: shared.h:25
DWORD SizeOfTransportName
Definition: shared.h:24
ULONG Flags
Definition: ntfs.h:536
PFILE_OBJECT FileObject
Definition: ntfs.h:520
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint16_t * PWCHAR
Definition: typedefs.h:56
char * PCHAR
Definition: typedefs.h:51
#define FD_WRITE_BIT
Definition: winsock2.h:295
#define FO_NAMED_PIPE
Definition: iotypes.h:1782
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by AfdDispatch(), TestSend(), TestSendTo(), TestTcp(), and TestUdp().

◆ AfdDisconnect()

static NTSTATUS NTAPI AfdDisconnect ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)
static

Definition at line 715 of file main.c.

716 {
718 PAFD_FCB FCB = FileObject->FsContext;
722 PLIST_ENTRY CurrentEntry;
723 PIRP CurrentIrp;
724
726
728
729 if (!(DisReq = LockRequest(Irp, IrpSp, FALSE, NULL)))
731 Irp, 0 );
732
733 /* Send direction only */
734 if ((DisReq->DisconnectType & AFD_DISCONNECT_SEND) &&
736 {
737 /* Perform a controlled disconnect */
739 }
740 /* Receive direction or both */
741 else
742 {
743 /* Mark that we can't issue another receive request */
744 FCB->TdiReceiveClosed = TRUE;
745
746 /* Try to cancel a pending TDI receive IRP if there was one in progress */
747 if (FCB->ReceiveIrp.InFlightRequest)
748 IoCancelIrp(FCB->ReceiveIrp.InFlightRequest);
749
750 /* Discard any pending data */
751 FCB->Recv.Content = 0;
752 FCB->Recv.BytesUsed = 0;
753
754 /* Set a successful receive status to indicate a shutdown on overread */
755 FCB->LastReceiveStatus = STATUS_SUCCESS;
756
757 /* Clear the receive event */
758 FCB->PollState &= ~AFD_EVENT_RECEIVE;
759
760 /* Receive direction only */
761 if ((DisReq->DisconnectType & AFD_DISCONNECT_RECV) &&
763 {
764 /* No need to tell the transport driver for receive direction only */
766 }
767 else
768 {
769 /* Perform an abortive disconnect */
771 }
772 }
773
775 {
776 if (!FCB->ConnectCallInfo)
777 {
778 AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n"));
780 Irp, 0 );
781 }
782
783 if (FCB->DisconnectPending)
784 {
785 if (FCB->DisconnectIrp.InFlightRequest)
786 {
787 IoCancelIrp(FCB->DisconnectIrp.InFlightRequest);
788 ASSERT(!FCB->DisconnectIrp.InFlightRequest);
789 }
790 else
791 {
792 while (!IsListEmpty(&FCB->PendingIrpList[FUNCTION_DISCONNECT]))
793 {
794 CurrentEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_DISCONNECT]);
795 CurrentIrp = CONTAINING_RECORD(CurrentEntry, IRP, Tail.Overlay.ListEntry);
796 CurrentIrp->IoStatus.Status = STATUS_CANCELLED;
797 CurrentIrp->IoStatus.Information = 0;
798 UnlockRequest(CurrentIrp, IoGetCurrentIrpStackLocation(CurrentIrp));
799 (void)IoSetCancelRoutine(CurrentIrp, NULL);
801 }
802 }
803 }
804
805 FCB->DisconnectFlags = Flags;
806 FCB->DisconnectTimeout = DisReq->Timeout;
807 FCB->DisconnectPending = TRUE;
808 FCB->SendClosed = TRUE;
809 FCB->PollState &= ~AFD_EVENT_SEND;
810
812 if (Status == STATUS_PENDING)
813 {
814 if ((IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]) && !FCB->SendIrp.InFlightRequest) ||
815 (FCB->DisconnectFlags & TDI_DISCONNECT_ABORT))
816 {
817 /* Go ahead and execute the disconnect because we're ready for it */
819 }
820
821 if (Status != STATUS_PENDING)
822 RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
823 }
824
825 if (Status == STATUS_PENDING)
826 {
828
829 return Status;
830 }
831 }
832 else
833 {
835 {
836 if (!FCB->RemoteAddress)
837 {
838 AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n"));
840 }
841
843
844 FCB->RemoteAddress = NULL;
845 }
846
847 FCB->PollState &= ~AFD_EVENT_SEND;
848 FCB->SendClosed = TRUE;
849 }
850
851 return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
852}
#define MIN_TRACE
Definition: debug.h:14
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define TRUE
Definition: types.h:120
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
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
static NTSTATUS DoDisconnect(PAFD_FCB FCB)
Definition: main.c:668
IoSetCancelRoutine(Irp, CancelRoutine)
unsigned short USHORT
Definition: pedump.c:61
#define AFD_DISCONNECT_RECV
Definition: shared.h:198
#define AFD_DISCONNECT_SEND
Definition: shared.h:197
LARGE_INTEGER Timeout
Definition: shared.h:137
ULONG DisconnectType
Definition: shared.h:136
IO_STATUS_BLOCK IoStatus
#define TDI_DISCONNECT_RELEASE
Definition: tdi.h:144
#define TDI_DISCONNECT_ABORT
Definition: tdi.h:143
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by AfdDispatch().

◆ AfdDispatch()

static NTSTATUS NTAPI AfdDispatch ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)
static

Definition at line 903 of file main.c.

904{
907#if DBG
909#endif
910
911 AFD_DbgPrint(MID_TRACE,("AfdDispatch: %u\n", IrpSp->MajorFunction));
913 AFD_DbgPrint(MID_TRACE,("FO %p, IrpSp->FO %p\n",
916 }
917
918 Irp->IoStatus.Information = 0;
919
920 switch(IrpSp->MajorFunction)
921 {
922 /* opening and closing handles to the device */
923 case IRP_MJ_CREATE:
924 /* Mostly borrowed from the named pipe file system */
926
927 case IRP_MJ_CLOSE:
928 /* Ditto the borrowing */
930
931 case IRP_MJ_CLEANUP:
933
934 /* write data */
935 case IRP_MJ_WRITE:
937
938 /* read data */
939 case IRP_MJ_READ:
941
942 /* query volume info */
945
947 {
948 switch( IrpSp->Parameters.DeviceIoControl.IoControlCode ) {
949 case IOCTL_AFD_BIND:
951
954
957
958 case IOCTL_AFD_RECV:
960 FALSE );
961
962 case IOCTL_AFD_SELECT:
963 return AfdSelect( DeviceObject, Irp, IrpSp );
964
967
970
973
974 case IOCTL_AFD_SEND:
976 FALSE );
977
980
982 return AfdGetInfo( DeviceObject, Irp, IrpSp );
983
985 return AfdSetInfo( DeviceObject, Irp, IrpSp );
986
989
992
995
998
999 case IOCTL_AFD_ACCEPT:
1000 return AfdAccept( DeviceObject, Irp, IrpSp );
1001
1003 return AfdDisconnect( DeviceObject, Irp, IrpSp );
1004
1007
1010
1013
1016
1019
1022
1025
1028
1031
1034
1037
1040
1043
1046
1049
1051 DbgPrint("IOCTL_AFD_DEFER_ACCEPT is UNIMPLEMENTED!\n");
1052 break;
1053
1055 DbgPrint("IOCTL_AFD_GET_PENDING_CONNECT_DATA is UNIMPLEMENTED!\n");
1056 break;
1057
1059 DbgPrint("IOCTL_AFD_VALIDATE_GROUP is UNIMPLEMENTED!\n");
1060 break;
1061
1062 default:
1064 DbgPrint("Unknown IOCTL (0x%x)\n",
1065 IrpSp->Parameters.DeviceIoControl.IoControlCode);
1066 break;
1067 }
1068 break;
1069 }
1070
1071/* unsupported operations */
1072 default:
1073 {
1076 ("Irp: Unknown Major code was %x\n",
1078 break;
1079 }
1080 }
1081
1082 AFD_DbgPrint(MID_TRACE, ("Returning %x\n", Status));
1083 Irp->IoStatus.Status = Status;
1085
1086 return Status;
1087}
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
NTSTATUS NTAPI AfdBindSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: bind.c:76
NTSTATUS NTAPI AfdSetConnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: connect.c:157
NTSTATUS NTAPI AfdSetConnectDataSize(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: connect.c:197
NTSTATUS NTAPI AfdStreamSocketConnect(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: connect.c:431
NTSTATUS NTAPI AfdGetConnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: connect.c:15
NTSTATUS NTAPI AfdGetConnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: connect.c:127
NTSTATUS NTAPI AfdSetConnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: connect.c:45
NTSTATUS NTAPI AfdSetConnectOptionsSize(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: connect.c:86
NTSTATUS NTAPI AfdSetContext(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: context.c:64
NTSTATUS NTAPI AfdGetContextSize(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: context.c:40
NTSTATUS NTAPI AfdGetContext(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: context.c:14
NTSTATUS NTAPI AfdSetInfo(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: info.c:102
NTSTATUS NTAPI AfdGetSockName(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: info.c:232
NTSTATUS NTAPI AfdGetInfo(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: info.c:14
NTSTATUS NTAPI AfdGetPeerName(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: info.c:281
NTSTATUS AfdAccept(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: listen.c:337
NTSTATUS AfdListenSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: listen.c:225
NTSTATUS AfdWaitForListen(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: listen.c:293
NTSTATUS NTAPI AfdSetDisconnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:188
static NTSTATUS NTAPI AfdQueryVolumeInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:874
NTSTATUS NTAPI AfdSetDisconnectDataSize(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:229
static NTSTATUS NTAPI AfdGetTdiHandles(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:270
static NTSTATUS NTAPI AfdCreateSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:302
static NTSTATUS NTAPI AfdCleanupSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:426
NTSTATUS NTAPI AfdSetDisconnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:76
static NTSTATUS NTAPI AfdDisconnect(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:715
NTSTATUS NTAPI AfdSetDisconnectOptionsSize(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:117
static NTSTATUS NTAPI AfdCloseSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:460
NTSTATUS NTAPI AfdGetDisconnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:46
NTSTATUS NTAPI AfdGetDisconnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:157
NTSTATUS NTAPI AfdEnumEvents(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: select.c:328
NTSTATUS NTAPI AfdSelect(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: select.c:165
NTSTATUS NTAPI AfdEventSelect(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: select.c:265
NTSTATUS NTAPI AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Short)
Definition: write.c:329
NTSTATUS NTAPI AfdPacketSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: write.c:564
NTSTATUS NTAPI AfdConnectedSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Short)
Definition: read.c:415
NTSTATUS NTAPI AfdPacketSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: read.c:696
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define IOCTL_AFD_EVENT_SELECT
Definition: shared.h:329
#define IOCTL_AFD_GET_TDI_HANDLES
Definition: shared.h:293
#define IOCTL_AFD_SET_INFO
Definition: shared.h:295
#define IOCTL_AFD_SET_DISCONNECT_OPTIONS
Definition: shared.h:309
#define IOCTL_AFD_SET_CONNECT_OPTIONS_SIZE
Definition: shared.h:321
#define IOCTL_AFD_GET_SOCK_NAME
Definition: shared.h:289
#define IOCTL_AFD_DEFER_ACCEPT
Definition: shared.h:331
#define IOCTL_AFD_START_LISTEN
Definition: shared.h:271
#define IOCTL_AFD_SET_CONNECT_OPTIONS
Definition: shared.h:305
#define IOCTL_AFD_GET_DISCONNECT_DATA
Definition: shared.h:315
#define IOCTL_AFD_GET_CONTEXT
Definition: shared.h:299
#define IOCTL_AFD_SET_DISCONNECT_DATA_SIZE
Definition: shared.h:323
#define IOCTL_AFD_GET_DISCONNECT_OPTIONS
Definition: shared.h:317
#define IOCTL_AFD_GET_INFO
Definition: shared.h:327
#define IOCTL_AFD_GET_CONTEXT_SIZE
Definition: shared.h:297
#define IOCTL_AFD_GET_CONNECT_OPTIONS
Definition: shared.h:313
#define IOCTL_AFD_SET_CONNECT_DATA
Definition: shared.h:303
#define IOCTL_AFD_ACCEPT
Definition: shared.h:275
#define IOCTL_AFD_BIND
Definition: shared.h:267
#define IOCTL_AFD_VALIDATE_GROUP
Definition: shared.h:337
#define IOCTL_AFD_SET_DISCONNECT_OPTIONS_SIZE
Definition: shared.h:325
#define IOCTL_AFD_ENUM_NETWORK_EVENTS
Definition: shared.h:335
#define IOCTL_AFD_SET_DISCONNECT_DATA
Definition: shared.h:307
#define IOCTL_AFD_GET_PENDING_CONNECT_DATA
Definition: shared.h:333
#define IOCTL_AFD_SET_CONNECT_DATA_SIZE
Definition: shared.h:319
#define IOCTL_AFD_GET_PEER_NAME
Definition: shared.h:291
#define IOCTL_AFD_SET_CONTEXT
Definition: shared.h:301
#define IOCTL_AFD_GET_CONNECT_DATA
Definition: shared.h:311
#define IRP_MJ_CLEANUP

◆ AfdGetDisconnectData()

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

Definition at line 157 of file main.c.

159{
161 PAFD_FCB FCB = FileObject->FsContext;
162 UINT BufferSize = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
163
165
167
168 if (FCB->DisconnectDataSize == 0)
169 {
170 AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n"));
172 }
173
174 ASSERT(FCB->DisconnectData);
175
176 if (FCB->FilledDisconnectData < BufferSize)
177 BufferSize = FCB->FilledDisconnectData;
178
179 RtlCopyMemory(Irp->UserBuffer,
180 FCB->DisconnectData,
181 BufferSize);
182
184}
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Referenced by AfdDispatch().

◆ AfdGetDisconnectOptions()

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

Definition at line 46 of file main.c.

48{
50 PAFD_FCB FCB = FileObject->FsContext;
51 UINT BufferSize = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
52
54
56
57 if (FCB->DisconnectOptionsSize == 0)
58 {
59 AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n"));
61 }
62
63 ASSERT(FCB->DisconnectOptions);
64
65 if (FCB->FilledDisconnectOptions < BufferSize) BufferSize = FCB->FilledDisconnectOptions;
66
67 RtlCopyMemory(Irp->UserBuffer,
68 FCB->DisconnectOptions,
70
72}

Referenced by AfdDispatch().

◆ AfdGetTdiHandles()

static NTSTATUS NTAPI AfdGetTdiHandles ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)
static

Definition at line 270 of file main.c.

272{
274 PAFD_FCB FCB = FileObject->FsContext;
275 PULONG HandleFlags = LockRequest(Irp, IrpSp, TRUE, NULL);
276 PAFD_TDI_HANDLE_DATA HandleData = Irp->UserBuffer;
277
279
281
282 if (!HandleFlags)
284
285 if (IrpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(ULONG) ||
286 IrpSp->Parameters.DeviceIoControl.OutputBufferLength < sizeof(*HandleData))
287 {
288 AFD_DbgPrint(MIN_TRACE,("Buffer too small\n"));
290 }
291
292 if ((*HandleFlags) & AFD_ADDRESS_HANDLE)
293 HandleData->TdiAddressHandle = FCB->AddressFile.Handle;
294
295 if ((*HandleFlags) & AFD_CONNECTION_HANDLE)
296 HandleData->TdiConnectionHandle = FCB->Connection.Handle;
297
299}
#define AFD_CONNECTION_HANDLE
Definition: shared.h:162
#define AFD_ADDRESS_HANDLE
Definition: shared.h:161
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
HANDLE TdiConnectionHandle
Definition: shared.h:149
HANDLE TdiAddressHandle
Definition: shared.h:148
uint32_t * PULONG
Definition: typedefs.h:59

Referenced by AfdDispatch().

◆ AfdQueryFsDeviceInfo()

NTSTATUS AfdQueryFsDeviceInfo ( PDEVICE_OBJECT  DeviceObject,
PFILE_FS_DEVICE_INFORMATION  Buffer,
PULONG  Length 
)

Definition at line 855 of file main.c.

856{
857 if (*Length >= sizeof(FILE_FS_DEVICE_INFORMATION))
858 {
859 Buffer->Characteristics = 0;
860 Buffer->DeviceType = FILE_DEVICE_NAMED_PIPE;
861
863
864 return STATUS_SUCCESS;
865 }
866 else
867 {
870 }
871}
Definition: bufpool.h:45
struct _FILE_FS_DEVICE_INFORMATION FILE_FS_DEVICE_INFORMATION
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define FILE_DEVICE_NAMED_PIPE
Definition: winioctl.h:62
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133

Referenced by AfdQueryVolumeInformation().

◆ AfdQueryVolumeInformation()

static NTSTATUS NTAPI AfdQueryVolumeInformation ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)
static

Definition at line 874 of file main.c.

875{
876 FS_INFORMATION_CLASS InfoClass;
880
881 Buffer = Irp->AssociatedIrp.SystemBuffer;
883 InfoClass = IrpSp->Parameters.QueryVolume.FsInformationClass;
884
885 switch (InfoClass)
886 {
889 break;
890 default:
891 break;
892 }
893
894 Irp->IoStatus.Status = Status;
895 Irp->IoStatus.Information = IrpSp->Parameters.QueryVolume.Length - Length;
897
898 return Status;
899}
NTSTATUS AfdQueryFsDeviceInfo(PDEVICE_OBJECT DeviceObject, PFILE_FS_DEVICE_INFORMATION Buffer, PULONG Length)
Definition: main.c:855
@ FileFsDeviceInformation
Definition: from_kernel.h:222
enum _FSINFOCLASS FS_INFORMATION_CLASS
#define STATUS_INVALID_INFO_CLASS
Definition: ntstatus.h:240
struct _IO_STACK_LOCATION::@3978::@3991 QueryVolume

Referenced by AfdDispatch().

◆ AfdSetDisconnectData()

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

Definition at line 188 of file main.c.

190{
192 PAFD_FCB FCB = FileObject->FsContext;
193 PVOID DisconnectData = LockRequest(Irp, IrpSp, FALSE, NULL);
194 UINT DisconnectDataSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
195
197
199
200 if (!DisconnectData)
202
203 if (FCB->DisconnectData)
204 {
206 FCB->DisconnectData = NULL;
207 FCB->DisconnectDataSize = 0;
208 FCB->FilledDisconnectData = 0;
209 }
210
211 FCB->DisconnectData = ExAllocatePoolWithTag(PagedPool,
212 DisconnectDataSize,
214
215 if (!FCB->DisconnectData)
217
218 RtlCopyMemory(FCB->DisconnectData,
219 DisconnectData,
220 DisconnectDataSize);
221
222 FCB->DisconnectDataSize = DisconnectDataSize;
223
225}
#define PagedPool
Definition: env_spec_w32.h:308

Referenced by AfdDispatch().

◆ AfdSetDisconnectDataSize()

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

Definition at line 229 of file main.c.

231{
233 PAFD_FCB FCB = FileObject->FsContext;
234 PUINT DisconnectDataSize = LockRequest(Irp, IrpSp, FALSE, NULL);
235 UINT BufferSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
236
238
240
241 if (!DisconnectDataSize)
243
244 if (BufferSize < sizeof(UINT))
245 {
246 AFD_DbgPrint(MIN_TRACE,("Buffer too small\n"));
248 }
249
250 if (FCB->DisconnectData)
251 {
253 FCB->DisconnectDataSize = 0;
254 FCB->FilledDisconnectData = 0;
255 }
256
257 FCB->DisconnectData = ExAllocatePoolWithTag(PagedPool,
258 *DisconnectDataSize,
260
261 if (!FCB->DisconnectData)
263
264 FCB->DisconnectDataSize = *DisconnectDataSize;
265
267}
unsigned int * PUINT
Definition: ndis.h:50

Referenced by AfdDispatch().

◆ AfdSetDisconnectOptions()

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

Definition at line 76 of file main.c.

78{
80 PAFD_FCB FCB = FileObject->FsContext;
81 PVOID DisconnectOptions = LockRequest(Irp, IrpSp, FALSE, NULL);
82 UINT DisconnectOptionsSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
83
85
87
88 if (!DisconnectOptions)
90
91 if (FCB->DisconnectOptions)
92 {
94 FCB->DisconnectOptions = NULL;
95 FCB->DisconnectOptionsSize = 0;
96 FCB->FilledDisconnectOptions = 0;
97 }
98
99 FCB->DisconnectOptions = ExAllocatePoolWithTag(PagedPool,
100 DisconnectOptionsSize,
102
103 if (!FCB->DisconnectOptions)
105
106 RtlCopyMemory(FCB->DisconnectOptions,
107 DisconnectOptions,
108 DisconnectOptionsSize);
109
110 FCB->DisconnectOptionsSize = DisconnectOptionsSize;
111
113}

Referenced by AfdDispatch().

◆ AfdSetDisconnectOptionsSize()

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

Definition at line 117 of file main.c.

119{
121 PAFD_FCB FCB = FileObject->FsContext;
122 PUINT DisconnectOptionsSize = LockRequest(Irp, IrpSp, FALSE, NULL);
123 UINT BufferSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
124
126
128
129 if (!DisconnectOptionsSize)
131
132 if (BufferSize < sizeof(UINT))
133 {
134 AFD_DbgPrint(MIN_TRACE,("Buffer too small\n"));
136 }
137
138 if (FCB->DisconnectOptions)
139 {
141 FCB->DisconnectOptionsSize = 0;
142 FCB->FilledDisconnectOptions = 0;
143 }
144
145 FCB->DisconnectOptions = ExAllocatePoolWithTag(PagedPool,
146 *DisconnectOptionsSize,
148
149 if (!FCB->DisconnectOptions) return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
150
151 FCB->DisconnectOptionsSize = *DisconnectOptionsSize;
152
154}

Referenced by AfdDispatch().

◆ AfdUnload()

static VOID NTAPI AfdUnload ( PDRIVER_OBJECT  DriverObject)
static

Definition at line 1302 of file main.c.

1303{
1305}
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213

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

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

◆ CleanupPendingIrp()

VOID CleanupPendingIrp ( PAFD_FCB  FCB,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp,
PAFD_ACTIVE_POLL  Poll 
)

Definition at line 1138 of file main.c.

1139{
1140 PAFD_RECV_INFO RecvReq;
1141 PAFD_SEND_INFO SendReq;
1142 PAFD_POLL_INFO PollReq;
1143
1145 {
1146 RecvReq = GetLockedData(Irp, IrpSp);
1148 }
1149 else if (IrpSp->MajorFunction == IRP_MJ_WRITE)
1150 {
1151 SendReq = GetLockedData(Irp, IrpSp);
1153 }
1154 else
1155 {
1157
1158 if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_RECV)
1159 {
1160 RecvReq = GetLockedData(Irp, IrpSp);
1162 }
1163 else if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_SEND)
1164 {
1165 SendReq = GetLockedData(Irp, IrpSp);
1167 }
1168 else if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_SELECT)
1169 {
1170 ASSERT(Poll);
1171
1172 PollReq = Irp->AssociatedIrp.SystemBuffer;
1173 ZeroEvents(PollReq->Handles, PollReq->HandleCount);
1174 SignalSocket(Poll, NULL, PollReq, STATUS_CANCELLED);
1175 }
1176 }
1177}
VOID UnlockBuffers(PAFD_WSABUF Buf, UINT Count, BOOL Address)
Definition: lock.c:289
PVOID GetLockedData(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lock.c:13
BOOLEAN CheckUnlockExtraBuffers(PAFD_FCB FCB, PIO_STACK_LOCATION IrpSp)
Definition: main.c:1089
VOID ZeroEvents(PAFD_HANDLE HandleArray, UINT HandleCount)
Definition: select.c:44
VOID SignalSocket(PAFD_ACTIVE_POLL Poll OPTIONAL, PIRP _Irp OPTIONAL, PAFD_POLL_INFO PollReq, NTSTATUS Status)
Definition: select.c:56
ULONG HandleCount
Definition: shared.h:57
AFD_HANDLE Handles[1]
Definition: shared.h:59
ULONG BufferCount
Definition: shared.h:86
PAFD_WSABUF BufferArray
Definition: shared.h:85
ULONG BufferCount
Definition: shared.h:102
PAFD_WSABUF BufferArray
Definition: shared.h:101

Referenced by AfdCancelHandler().

◆ DisconnectComplete()

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

Definition at line 600 of file main.c.

603{
605 PIRP CurrentIrp;
606 PLIST_ENTRY CurrentEntry;
607
609
611 return STATUS_FILE_CLOSED;
612
613 ASSERT(FCB->DisconnectIrp.InFlightRequest == Irp);
614 FCB->DisconnectIrp.InFlightRequest = NULL;
615
616 ASSERT(FCB->DisconnectPending);
617 ASSERT((IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]) && !FCB->SendIrp.InFlightRequest) ||
618 (FCB->DisconnectFlags & TDI_DISCONNECT_ABORT));
619
620 if (NT_SUCCESS(Irp->IoStatus.Status) && (FCB->DisconnectFlags & TDI_DISCONNECT_RELEASE))
621 {
622 FCB->FilledDisconnectData = MIN(FCB->DisconnectDataSize, FCB->ConnectReturnInfo->UserDataLength);
623 if (FCB->FilledDisconnectData)
624 {
625 RtlCopyMemory(FCB->DisconnectData,
626 FCB->ConnectReturnInfo->UserData,
627 FCB->FilledDisconnectData);
628 }
629
630 FCB->FilledDisconnectOptions = MIN(FCB->DisconnectOptionsSize, FCB->ConnectReturnInfo->OptionsLength);
631 if (FCB->FilledDisconnectOptions)
632 {
633 RtlCopyMemory(FCB->DisconnectOptions,
634 FCB->ConnectReturnInfo->Options,
635 FCB->FilledDisconnectOptions);
636 }
637 }
638
639 FCB->DisconnectPending = FALSE;
640
641 while (!IsListEmpty(&FCB->PendingIrpList[FUNCTION_DISCONNECT]))
642 {
643 CurrentEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_DISCONNECT]);
644 CurrentIrp = CONTAINING_RECORD(CurrentEntry, IRP, Tail.Overlay.ListEntry);
645 CurrentIrp->IoStatus.Status = Irp->IoStatus.Status;
646 CurrentIrp->IoStatus.Information = 0;
647 UnlockRequest(CurrentIrp, IoGetCurrentIrpStackLocation(CurrentIrp));
648 (void)IoSetCancelRoutine(CurrentIrp, NULL);
650 }
651
652 if (!(FCB->DisconnectFlags & TDI_DISCONNECT_RELEASE))
653 {
654 /* Signal complete connection closure immediately */
655 FCB->PollState |= AFD_EVENT_ABORT;
656 FCB->PollStatus[FD_CLOSE_BIT] = Irp->IoStatus.Status;
657 FCB->LastReceiveStatus = STATUS_FILE_CLOSED;
658 PollReeval(FCB->DeviceExt, FCB->FileObject);
659 }
660
662
663 return Irp->IoStatus.Status;
664}
#define MIN(x, y)
Definition: rdesktop.h:171
#define AFD_EVENT_ABORT
Definition: shared.h:207
#define FD_CLOSE_BIT
Definition: winsock2.h:303

◆ DoDisconnect()

static NTSTATUS DoDisconnect ( PAFD_FCB  FCB)
static

Definition at line 668 of file main.c.

669{
671
672 ASSERT(FCB->DisconnectPending);
673 ASSERT((IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]) && !FCB->SendIrp.InFlightRequest) ||
674 (FCB->DisconnectFlags & TDI_DISCONNECT_ABORT));
675
676 if (FCB->DisconnectIrp.InFlightRequest)
677 {
678 return STATUS_PENDING;
679 }
680
681 FCB->ConnectCallInfo->UserData = FCB->DisconnectData;
682 FCB->ConnectCallInfo->UserDataLength = FCB->DisconnectDataSize;
683 FCB->ConnectCallInfo->Options = FCB->DisconnectOptions;
684 FCB->ConnectCallInfo->OptionsLength = FCB->DisconnectOptionsSize;
685
686 Status = TdiDisconnect(&FCB->DisconnectIrp.InFlightRequest,
687 FCB->Connection.Object,
688 &FCB->DisconnectTimeout,
689 FCB->DisconnectFlags,
691 FCB,
692 FCB->ConnectCallInfo,
693 FCB->ConnectReturnInfo);
694 if (Status != STATUS_PENDING)
695 {
696 FCB->DisconnectPending = FALSE;
697 }
698
699 return Status;
700}
static IO_COMPLETION_ROUTINE DisconnectComplete
Definition: main.c:596
NTSTATUS TdiDisconnect(PIRP *Irp, PFILE_OBJECT TransportObject, PLARGE_INTEGER Time, USHORT Flags, PIO_COMPLETION_ROUTINE CompletionRoutine, PVOID CompletionContext, PTDI_CONNECTION_INFORMATION RequestConnectionInfo, PTDI_CONNECTION_INFORMATION ReturnConnectionInfo)
Definition: tdi.c:1249

Referenced by AfdDisconnect(), and RetryDisconnectCompletion().

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( PDRIVER_OBJECT  DriverObject,
PUNICODE_STRING  RegistryPath 
)

Definition at line 1308 of file main.c.

1309{
1311 UNICODE_STRING wstrDeviceName = RTL_CONSTANT_STRING(L"\\Device\\Afd");
1312 PAFD_DEVICE_EXTENSION DeviceExt;
1314
1316 /* register driver routines */
1317 DriverObject->MajorFunction[IRP_MJ_CLOSE] = AfdDispatch;
1318 DriverObject->MajorFunction[IRP_MJ_CREATE] = AfdDispatch;
1319 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = AfdDispatch;
1320 DriverObject->MajorFunction[IRP_MJ_WRITE] = AfdDispatch;
1321 DriverObject->MajorFunction[IRP_MJ_READ] = AfdDispatch;
1324 DriverObject->DriverUnload = AfdUnload;
1325
1327 sizeof(AFD_DEVICE_EXTENSION),
1328 &wstrDeviceName,
1330 0,
1331 FALSE,
1332 &DeviceObject);
1333
1334 /* failure */
1335 if (!NT_SUCCESS(Status))
1336 {
1337 return Status;
1338 }
1339
1340 DeviceExt = DeviceObject->DeviceExtension;
1341 KeInitializeSpinLock( &DeviceExt->Lock );
1342 InitializeListHead( &DeviceExt->Polls );
1343
1344 AFD_DbgPrint(MID_TRACE,("Device created: object %p ext %p\n",
1345 DeviceObject, DeviceExt));
1346
1347 return Status;
1348}
static DRIVER_UNLOAD AfdUnload
Definition: main.c:1300
static DRIVER_DISPATCH AfdDispatch
Definition: main.c:901
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define L(x)
Definition: ntvdm.h:50
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215

◆ OskitDumpBuffer()

void OskitDumpBuffer ( PCHAR  Data,
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

Referenced by AfdStreamSocketConnect().

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

Referenced by SendComplete().

Variable Documentation

◆ AfdDispatch

DRIVER_DISPATCH AfdDispatch
static

Definition at line 901 of file main.c.

Referenced by DriverEntry().

◆ AfdReceiveWindowSize

ULONG AfdReceiveWindowSize = 0x2000

Definition at line 26 of file main.c.

Referenced by AfdCreateSocket().

◆ AfdSendWindowSize

ULONG AfdSendWindowSize = 0x2000

Definition at line 27 of file main.c.

Referenced by AfdCreateSocket().

◆ AfdUnload

DRIVER_UNLOAD AfdUnload
static

Definition at line 1300 of file main.c.

Referenced by DriverEntry().

◆ DisconnectComplete

IO_COMPLETION_ROUTINE DisconnectComplete
static

Definition at line 596 of file main.c.

Referenced by DoDisconnect().