ReactOS  0.4.13-dev-66-gc714b7f
main.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS kernel
4  * FILE: drivers/net/afd/afd/main.c
5  * PURPOSE: Ancillary functions driver
6  * PROGRAMMER: Art Yerkes (ayerkes@speakeasy.net)
7  * UPDATE HISTORY:
8  * 20040630 Created
9  *
10  * Suggestions: Uniform naming (AfdXxx)
11  */
12 
13 /* INCLUDES */
14 
15 #include "afd.h"
16 
17 #if DBG
18 
19 /* See debug.h for debug/trace constants */
20 //DWORD DebugTraceLevel = DEBUG_ULTRA;
22 
23 #endif /* DBG */
24 
25 /* FIXME: should depend on SystemSize */
28 
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 }
39 
40 /* FUNCTIONS */
41 
44 
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,
69  BufferSize);
70 
72 }
73 
75 NTAPI
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 }
114 
115 NTSTATUS
116 NTAPI
119 {
121  PAFD_FCB FCB = FileObject->FsContext;
122  PUINT DisconnectOptionsSize = LockRequest(Irp, IrpSp, FALSE, NULL);
123  UINT BufferSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
124 
126 
127  if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp);
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  {
140  ExFreePoolWithTag(FCB->DisconnectOptions, TAG_AFD_DISCONNECT_OPTIONS);
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 }
155 
159 {
161  PAFD_FCB FCB = FileObject->FsContext;
162  UINT BufferSize = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
163 
165 
166  if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp);
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 }
185 
186 NTSTATUS
187 NTAPI
190 {
192  PAFD_FCB FCB = FileObject->FsContext;
193  PVOID DisconnectData = LockRequest(Irp, IrpSp, FALSE, NULL);
194  UINT DisconnectDataSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
195 
197 
198  if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp);
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 }
226 
227 NTSTATUS
228 NTAPI
231 {
233  PAFD_FCB FCB = FileObject->FsContext;
234  PUINT DisconnectDataSize = LockRequest(Irp, IrpSp, FALSE, NULL);
235  UINT BufferSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
236 
238 
239  if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp);
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 }
268 
269 static NTSTATUS NTAPI
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 
280  if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp);
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 }
300 
301 static NTSTATUS NTAPI
304  PAFD_FCB FCB;
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 }
424 
425 static NTSTATUS NTAPI
428 {
430  PAFD_FCB FCB = FileObject->FsContext;
431  PLIST_ENTRY CurrentEntry, NextEntry;
432  UINT Function;
433  PIRP CurrentIrp;
434 
436 
437  if( !SocketAcquireStateLock( FCB ) ) return LostSocket(Irp);
438 
439  for (Function = 0; Function < MAX_FUNCTIONS; Function++)
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 }
458 
459 static NTSTATUS NTAPI
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)
547  ExFreePoolWithTag(FCB->DisconnectOptions, TAG_AFD_DISCONNECT_OPTIONS);
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 }
595 
596 static IO_COMPLETION_ROUTINE DisconnectComplete;
597 static
598 NTSTATUS
599 NTAPI
601  PIRP Irp,
602  PVOID Context)
603 {
604  PAFD_FCB FCB = Context;
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 }
665 
666 static
667 NTSTATUS
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 }
701 
702 VOID
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 */
710  DoDisconnect(FCB);
711  }
712 }
713 
714 static NTSTATUS NTAPI
718  PAFD_FCB FCB = FileObject->FsContext;
719  PAFD_DISCONNECT_INFO DisReq;
721  USHORT Flags;
722  PLIST_ENTRY CurrentEntry;
723  PIRP CurrentIrp;
724 
726 
727  if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp);
728 
729  if (!(DisReq = LockRequest(Irp, IrpSp, FALSE, NULL)))
731  Irp, 0 );
732 
733  /* Send direction only */
734  if ((DisReq->DisconnectType & AFD_DISCONNECT_SEND) &&
735  !(DisReq->DisconnectType & AFD_DISCONNECT_RECV))
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  /* Mark us as overread to complete future reads with an error */
755  FCB->Overread = TRUE;
756 
757  /* Set a successful receive status to indicate a shutdown on overread */
758  FCB->LastReceiveStatus = STATUS_SUCCESS;
759 
760  /* Clear the receive event */
761  FCB->PollState &= ~AFD_EVENT_RECEIVE;
762 
763  /* Receive direction only */
764  if ((DisReq->DisconnectType & AFD_DISCONNECT_RECV) &&
765  !(DisReq->DisconnectType & AFD_DISCONNECT_SEND))
766  {
767  /* No need to tell the transport driver for receive direction only */
769  }
770  else
771  {
772  /* Perform an abortive disconnect */
774  }
775  }
776 
778  {
779  if (!FCB->ConnectCallInfo)
780  {
781  AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n"));
783  Irp, 0 );
784  }
785 
786  if (FCB->DisconnectPending)
787  {
788  if (FCB->DisconnectIrp.InFlightRequest)
789  {
790  IoCancelIrp(FCB->DisconnectIrp.InFlightRequest);
791  ASSERT(!FCB->DisconnectIrp.InFlightRequest);
792  }
793  else
794  {
795  while (!IsListEmpty(&FCB->PendingIrpList[FUNCTION_DISCONNECT]))
796  {
797  CurrentEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_DISCONNECT]);
798  CurrentIrp = CONTAINING_RECORD(CurrentEntry, IRP, Tail.Overlay.ListEntry);
799  CurrentIrp->IoStatus.Status = STATUS_CANCELLED;
800  CurrentIrp->IoStatus.Information = 0;
801  UnlockRequest(CurrentIrp, IoGetCurrentIrpStackLocation(CurrentIrp));
802  (void)IoSetCancelRoutine(CurrentIrp, NULL);
804  }
805  }
806  }
807 
808  FCB->DisconnectFlags = Flags;
809  FCB->DisconnectTimeout = DisReq->Timeout;
810  FCB->DisconnectPending = TRUE;
811  FCB->SendClosed = TRUE;
812  FCB->PollState &= ~AFD_EVENT_SEND;
813 
815  if (Status == STATUS_PENDING)
816  {
817  if ((IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]) && !FCB->SendIrp.InFlightRequest) ||
818  (FCB->DisconnectFlags & TDI_DISCONNECT_ABORT))
819  {
820  /* Go ahead and execute the disconnect because we're ready for it */
822  }
823 
824  if (Status != STATUS_PENDING)
825  RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
826  }
827 
828  if (Status == STATUS_PENDING)
829  {
831 
832  return Status;
833  }
834  }
835  else
836  {
837  if (!(Flags & TDI_DISCONNECT_RELEASE))
838  {
839  if (!FCB->RemoteAddress)
840  {
841  AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n"));
843  }
844 
846 
847  FCB->RemoteAddress = NULL;
848  }
849 
850  FCB->PollState &= ~AFD_EVENT_SEND;
851  FCB->SendClosed = TRUE;
852  }
853 
854  return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
855 }
856 
857 NTSTATUS
859 {
860  if (*Length >= sizeof(FILE_FS_DEVICE_INFORMATION))
861  {
862  Buffer->Characteristics = 0;
863  Buffer->DeviceType = FILE_DEVICE_NAMED_PIPE;
864 
866 
867  return STATUS_SUCCESS;
868  }
869  else
870  {
873  }
874 }
875 
876 static NTSTATUS NTAPI
878 {
879  FS_INFORMATION_CLASS InfoClass;
880  PVOID Buffer;
881  ULONG Length;
883 
884  Buffer = Irp->AssociatedIrp.SystemBuffer;
885  Length = IrpSp->Parameters.QueryVolume.Length;
886  InfoClass = IrpSp->Parameters.QueryVolume.FsInformationClass;
887 
888  switch (InfoClass)
889  {
892  break;
893  default:
894  break;
895  }
896 
897  Irp->IoStatus.Status = Status;
898  Irp->IoStatus.Information = IrpSp->Parameters.QueryVolume.Length - Length;
900 
901  return Status;
902 }
903 
905 static NTSTATUS NTAPI
907 {
910 #if DBG
912 #endif
913 
914  AFD_DbgPrint(MID_TRACE,("AfdDispatch: %u\n", IrpSp->MajorFunction));
916  AFD_DbgPrint(MID_TRACE,("FO %p, IrpSp->FO %p\n",
919  }
920 
921  Irp->IoStatus.Information = 0;
922 
923  switch(IrpSp->MajorFunction)
924  {
925  /* opening and closing handles to the device */
926  case IRP_MJ_CREATE:
927  /* Mostly borrowed from the named pipe file system */
929 
930  case IRP_MJ_CLOSE:
931  /* Ditto the borrowing */
933 
934  case IRP_MJ_CLEANUP:
936 
937  /* write data */
938  case IRP_MJ_WRITE:
940 
941  /* read data */
942  case IRP_MJ_READ:
944 
945  /* query volume info */
948 
950  {
951  switch( IrpSp->Parameters.DeviceIoControl.IoControlCode ) {
952  case IOCTL_AFD_BIND:
953  return AfdBindSocket( DeviceObject, Irp, IrpSp );
954 
955  case IOCTL_AFD_CONNECT:
957 
960 
961  case IOCTL_AFD_RECV:
963  FALSE );
964 
965  case IOCTL_AFD_SELECT:
966  return AfdSelect( DeviceObject, Irp, IrpSp );
967 
969  return AfdEventSelect( DeviceObject, Irp, IrpSp );
970 
972  return AfdEnumEvents( DeviceObject, Irp, IrpSp );
973 
976 
977  case IOCTL_AFD_SEND:
979  FALSE );
980 
983 
984  case IOCTL_AFD_GET_INFO:
985  return AfdGetInfo( DeviceObject, Irp, IrpSp );
986 
987  case IOCTL_AFD_SET_INFO:
988  return AfdSetInfo( DeviceObject, Irp, IrpSp );
989 
992 
994  return AfdGetContext( DeviceObject, Irp, IrpSp );
995 
997  return AfdSetContext( DeviceObject, Irp, IrpSp );
998 
1000  return AfdWaitForListen( DeviceObject, Irp, IrpSp );
1001 
1002  case IOCTL_AFD_ACCEPT:
1003  return AfdAccept( DeviceObject, Irp, IrpSp );
1004 
1005  case IOCTL_AFD_DISCONNECT:
1006  return AfdDisconnect( DeviceObject, Irp, IrpSp );
1007 
1009  return AfdGetSockName( DeviceObject, Irp, IrpSp );
1010 
1012  return AfdGetPeerName( DeviceObject, Irp, IrpSp );
1013 
1016 
1019 
1022 
1025 
1028 
1031 
1034 
1037 
1040 
1043 
1046 
1049 
1052 
1054  DbgPrint("IOCTL_AFD_DEFER_ACCEPT is UNIMPLEMENTED!\n");
1055  break;
1056 
1058  DbgPrint("IOCTL_AFD_GET_PENDING_CONNECT_DATA is UNIMPLEMENTED!\n");
1059  break;
1060 
1062  DbgPrint("IOCTL_AFD_VALIDATE_GROUP is UNIMPLEMENTED!\n");
1063  break;
1064 
1065  default:
1067  DbgPrint("Unknown IOCTL (0x%x)\n",
1068  IrpSp->Parameters.DeviceIoControl.IoControlCode);
1069  break;
1070  }
1071  break;
1072  }
1073 
1074 /* unsupported operations */
1075  default:
1076  {
1079  ("Irp: Unknown Major code was %x\n",
1080  IrpSp->MajorFunction));
1081  break;
1082  }
1083  }
1084 
1085  AFD_DbgPrint(MID_TRACE, ("Returning %x\n", Status));
1086  Irp->IoStatus.Status = Status;
1088 
1089  return Status;
1090 }
1091 
1093 {
1095  {
1097  {
1098  /* read()/write() call - no extra buffers */
1099  return FALSE;
1100  }
1102  {
1103  if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_RECV_DATAGRAM)
1104  {
1105  /* recvfrom() call - extra buffers */
1106  return TRUE;
1107  }
1108  else if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_RECV)
1109  {
1110  /* recv() call - no extra buffers */
1111  return FALSE;
1112  }
1113  else if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_SEND ||
1114  IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_SEND_DATAGRAM)
1115  {
1116  /* send()/sendto() call - no extra buffers */
1117  return FALSE;
1118  }
1119  else
1120  {
1121  /* Unknown IOCTL */
1122  ASSERT(FALSE);
1123  return FALSE;
1124  }
1125  }
1126  else
1127  {
1128  /* Unknown IRP_MJ code */
1129  ASSERT(FALSE);
1130  return FALSE;
1131  }
1132  }
1133  else
1134  {
1135  /* Connection-oriented never has extra buffers */
1136  return FALSE;
1137  }
1138 }
1139 
1140 VOID
1142 {
1143  PAFD_RECV_INFO RecvReq;
1144  PAFD_SEND_INFO SendReq;
1145  PAFD_POLL_INFO PollReq;
1146 
1148  {
1149  RecvReq = GetLockedData(Irp, IrpSp);
1151  }
1152  else if (IrpSp->MajorFunction == IRP_MJ_WRITE)
1153  {
1154  SendReq = GetLockedData(Irp, IrpSp);
1156  }
1157  else
1158  {
1160 
1161  if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_RECV)
1162  {
1163  RecvReq = GetLockedData(Irp, IrpSp);
1165  }
1166  else if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_SEND)
1167  {
1168  SendReq = GetLockedData(Irp, IrpSp);
1170  }
1171  else if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_SELECT)
1172  {
1173  ASSERT(Poll);
1174 
1175  PollReq = Irp->AssociatedIrp.SystemBuffer;
1176  ZeroEvents(PollReq->Handles, PollReq->HandleCount);
1177  SignalSocket(Poll, NULL, PollReq, STATUS_CANCELLED);
1178  }
1179  }
1180 }
1181 
1182 VOID
1183 NTAPI
1185  PIRP Irp)
1186 {
1189  PAFD_FCB FCB = FileObject->FsContext;
1190  ULONG Function, IoctlCode;
1191  PIRP CurrentIrp;
1192  PLIST_ENTRY CurrentEntry;
1194  KIRQL OldIrql;
1195  PAFD_ACTIVE_POLL Poll;
1196 
1197  IoReleaseCancelSpinLock(Irp->CancelIrql);
1198 
1200  return;
1201 
1202  switch (IrpSp->MajorFunction)
1203  {
1204  case IRP_MJ_DEVICE_CONTROL:
1205  IoctlCode = IrpSp->Parameters.DeviceIoControl.IoControlCode;
1206  break;
1207 
1208  case IRP_MJ_READ:
1209  IoctlCode = IOCTL_AFD_RECV;
1210  break;
1211 
1212  case IRP_MJ_WRITE:
1213  IoctlCode = IOCTL_AFD_SEND;
1214  break;
1215 
1216  default:
1217  ASSERT(FALSE);
1219  return;
1220  }
1221 
1222  switch (IoctlCode)
1223  {
1224  case IOCTL_AFD_RECV:
1227  break;
1228 
1229  case IOCTL_AFD_SEND:
1232  break;
1233 
1234  case IOCTL_AFD_CONNECT:
1236  break;
1237 
1240  break;
1241 
1242  case IOCTL_AFD_SELECT:
1243  KeAcquireSpinLock(&DeviceExt->Lock, &OldIrql);
1244 
1245  CurrentEntry = DeviceExt->Polls.Flink;
1246  while (CurrentEntry != &DeviceExt->Polls)
1247  {
1248  Poll = CONTAINING_RECORD(CurrentEntry, AFD_ACTIVE_POLL, ListEntry);
1249 
1250  if (Irp == Poll->Irp)
1251  {
1252  CleanupPendingIrp(FCB, Irp, IrpSp, Poll);
1253  KeReleaseSpinLock(&DeviceExt->Lock, OldIrql);
1255  return;
1256  }
1257  else
1258  {
1259  CurrentEntry = CurrentEntry->Flink;
1260  }
1261  }
1262 
1263  KeReleaseSpinLock(&DeviceExt->Lock, OldIrql);
1264 
1266 
1267  DbgPrint("WARNING!!! IRP cancellation race could lead to a process hang! (IOCTL_AFD_SELECT)\n");
1268  return;
1269 
1270  case IOCTL_AFD_DISCONNECT:
1272  break;
1273 
1274  default:
1275  ASSERT(FALSE);
1277  return;
1278  }
1279 
1280  CurrentEntry = FCB->PendingIrpList[Function].Flink;
1281  while (CurrentEntry != &FCB->PendingIrpList[Function])
1282  {
1283  CurrentIrp = CONTAINING_RECORD(CurrentEntry, IRP, Tail.Overlay.ListEntry);
1284 
1285  if (CurrentIrp == Irp)
1286  {
1287  RemoveEntryList(CurrentEntry);
1290  return;
1291  }
1292  else
1293  {
1294  CurrentEntry = CurrentEntry->Flink;
1295  }
1296  }
1297 
1299 
1300  DbgPrint("WARNING!!! IRP cancellation race could lead to a process hang! (Function: %u)\n", Function);
1301 }
1302 
1303 static DRIVER_UNLOAD AfdUnload;
1304 static VOID NTAPI
1306 {
1308 }
1309 
1312 {
1314  UNICODE_STRING wstrDeviceName = RTL_CONSTANT_STRING(L"\\Device\\Afd");
1315  PAFD_DEVICE_EXTENSION DeviceExt;
1316  NTSTATUS Status;
1317 
1319  /* register driver routines */
1328 
1330  sizeof(AFD_DEVICE_EXTENSION),
1331  &wstrDeviceName,
1333  0,
1334  FALSE,
1335  &DeviceObject);
1336 
1337  /* failure */
1338  if (!NT_SUCCESS(Status))
1339  {
1340  return Status;
1341  }
1342 
1343  DeviceExt = DeviceObject->DeviceExtension;
1344  KeInitializeSpinLock( &DeviceExt->Lock );
1345  InitializeListHead( &DeviceExt->Polls );
1346 
1347  AFD_DbgPrint(MID_TRACE,("Device created: object %p ext %p\n",
1348  DeviceObject, DeviceExt));
1349 
1350  return Status;
1351 }
1352 
1353 /* EOF */
#define TDI_DISCONNECT_RELEASE
Definition: tdi.h:144
VOID SocketStateUnlock(PAFD_FCB FCB)
Definition: lock.c:370
VOID RetryDisconnectCompletion(PAFD_FCB FCB)
Definition: main.c:703
signed char * PCHAR
Definition: retypes.h:7
void OskitDumpBuffer(PCHAR Data, UINT Len)
Definition: main.c:29
NTSTATUS NTAPI AfdSetConnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: connect.c:45
HANDLE Handle
Definition: afd.h:133
NTSTATUS TdiDisassociateAddressFile(PFILE_OBJECT ConnectionObject)
Definition: tdi.c:442
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define TAG_AFD_CONNECT_DATA
Definition: afd.h:41
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define IOCTL_AFD_BIND
Definition: shared.h:267
#define MID_TRACE
Definition: debug.h:15
VOID PollReeval(PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
Definition: select.c:407
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define DbgPrint
Definition: loader.c:25
PFILE_OBJECT FileObject
Definition: ntfs.h:504
#define FUNCTION_RECV
Definition: afd.h:85
#define IN_FLIGHT_REQUESTS
Definition: afd.h:93
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS NTAPI AfdPacketSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: read.c:703
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
Definition: cdstruc.h:908
#define TAG_AFD_TDI_CONNECTION_INFORMATION
Definition: afd.h:53
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
HANDLE TdiConnectionHandle
Definition: shared.h:149
#define FILE_DEVICE_NAMED_PIPE
Definition: winioctl.h:122
NTSTATUS NTAPI AfdSetDisconnectDataSize(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:229
AFD_TDI_OBJECT Object
Definition: afd.h:140
LONG NTSTATUS
Definition: precomp.h:26
#define FUNCTION_CONNECT
Definition: afd.h:84
#define IOCTL_AFD_SET_DISCONNECT_DATA_SIZE
Definition: shared.h:323
#define AFD_EVENT_ABORT
Definition: shared.h:207
#define IOCTL_AFD_GET_TDI_HANDLES
Definition: shared.h:293
static NTSTATUS DoDisconnect(PAFD_FCB FCB)
Definition: main.c:668
#define TAG_AFD_TRANSPORT_ADDRESS
Definition: afd.h:39
#define MAX_FUNCTIONS
Definition: afd.h:91
#define SOCKET_STATE_CREATED
Definition: afd.h:73
ULONG AfdSendWindowSize
Definition: main.c:27
#define TAG_AFD_DISCONNECT_DATA
Definition: afd.h:42
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define IOCTL_AFD_SET_DISCONNECT_DATA
Definition: shared.h:307
NTSTATUS NTAPI AfdGetConnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: connect.c:127
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
#define IOCTL_AFD_START_LISTEN
Definition: shared.h:271
NTSTATUS NTAPI AfdGetConnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: connect.c:15
#define IOCTL_AFD_GET_PENDING_CONNECT_DATA
Definition: shared.h:333
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define IOCTL_AFD_RECV_DATAGRAM
Definition: shared.h:279
IRP
Definition: iotypes.h:2462
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
uint16_t * PWCHAR
Definition: typedefs.h:54
#define IOCTL_AFD_VALIDATE_GROUP
Definition: shared.h:337
NTSTATUS NTAPI AfdSetInfo(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: info.c:102
IoSetCancelRoutine(Irp, CancelRoutine)
#define IOCTL_AFD_WAIT_FOR_LISTEN
Definition: shared.h:273
VOID KillSelectsForFCB(PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, BOOLEAN OnlyExclusive)
Definition: select.c:125
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define FUNCTION_DISCONNECT
Definition: afd.h:89
VOID ZeroEvents(PAFD_HANDLE HandleArray, UINT HandleCount)
Definition: select.c:44
#define IOCTL_AFD_SET_CONNECT_OPTIONS
Definition: shared.h:305
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
NTSTATUS NTAPI AfdGetDisconnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:46
NTSTATUS NTAPI AfdEnumEvents(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: select.c:328
VOID NTAPI AfdCancelHandler(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: main.c:1184
T MIN(T a, T b)
Definition: polytest.cpp:79
#define IOCTL_AFD_DISCONNECT
Definition: shared.h:287
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
KSPIN_LOCK Lock
Definition: afd.h:113
#define IOCTL_AFD_GET_CONTEXT_SIZE
Definition: shared.h:297
UCHAR KIRQL
Definition: env_spec_w32.h:591
NTSTATUS NTAPI AfdSetContext(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: context.c:64
#define AFD_ENDPOINT_CONNECTIONLESS
Definition: shared.h:153
static NTSTATUS NTAPI AfdCloseSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:460
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
VOID SignalSocket(PAFD_ACTIVE_POLL Poll OPTIONAL, PIRP _Irp OPTIONAL, PAFD_POLL_INFO PollReq, NTSTATUS Status)
Definition: select.c:56
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
static LPOVERLAPPED_COMPLETION_ROUTINE Function
Definition: sync.c:684
ULONG AfdReceiveWindowSize
Definition: main.c:26
NTSTATUS NTAPI AfdSetConnectDataSize(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: connect.c:197
HANDLE TdiAddressHandle
Definition: shared.h:148
DWORD EndpointFlags
Definition: shared.h:22
#define FUNCTION_PREACCEPT
Definition: afd.h:87
#define AFD_CONNECTION_HANDLE
Definition: shared.h:162
#define IOCTL_AFD_SET_CONNECT_DATA_SIZE
Definition: shared.h:319
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
#define FO_NAMED_PIPE
Definition: iotypes.h:1738
#define IOCTL_AFD_SELECT
Definition: shared.h:285
#define IOCTL_AFD_GET_DISCONNECT_OPTIONS
Definition: shared.h:317
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
static IO_COMPLETION_ROUTINE DisconnectComplete
Definition: main.c:596
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
struct _FCB FCB
smooth NULL
Definition: ftsmooth.c:416
LARGE_INTEGER Timeout
Definition: shared.h:137
#define IOCTL_AFD_SEND_DATAGRAM
Definition: shared.h:283
#define TAG_AFD_FCB
Definition: afd.h:48
#define AFD_EVENT_RECEIVE
Definition: shared.h:203
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IoCompleteRequest
Definition: irp.c:1240
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
DWORD SizeOfTransportName
Definition: shared.h:24
#define IOCTL_AFD_SET_CONNECT_DATA
Definition: shared.h:303
Definition: bufpool.h:45
VOID CleanupPendingIrp(PAFD_FCB FCB, PIRP Irp, PIO_STACK_LOCATION IrpSp, PAFD_ACTIVE_POLL Poll)
Definition: main.c:1141
NTSTATUS AfdWaitForListen(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: listen.c:293
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
NTSTATUS NTAPI AfdSelect(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: select.c:165
#define IOCTL_AFD_ENUM_NETWORK_EVENTS
Definition: shared.h:335
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define TAG_AFD_ACCEPT_QUEUE
Definition: afd.h:46
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
#define TAG_AFD_CONNECT_OPTIONS
Definition: afd.h:44
enum _FSINFOCLASS FS_INFORMATION_CLASS
#define AFD_DISCONNECT_SEND
Definition: shared.h:197
NTSTATUS NTAPI AfdSetDisconnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:76
#define IOCTL_AFD_SET_CONNECT_OPTIONS_SIZE
Definition: shared.h:321
#define TAG_AFD_DATA_BUFFER
Definition: afd.h:38
#define AFD_EVENT_SEND
Definition: shared.h:205
Definition: afd.h:161
ULONG DebugTraceLevel
Definition: ndis.c:13
NTSTATUS NTAPI AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Short)
Definition: write.c:329
ULONG BufferCount
Definition: shared.h:102
LIST_ENTRY Polls
Definition: afd.h:112
NTSTATUS NTAPI AfdSetConnectOptionsSize(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: connect.c:86
#define AFD_ADDRESS_HANDLE
Definition: shared.h:161
#define IOCTL_AFD_CONNECT
Definition: shared.h:269
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define IOCTL_AFD_SET_INFO
Definition: shared.h:295
#define FD_CLOSE_BIT
Definition: winsock2.h:303
#define IOCTL_AFD_DEFER_ACCEPT
Definition: shared.h:331
#define FUNCTION_SEND
Definition: afd.h:86
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
VOID UnlockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lock.c:180
#define IOCTL_AFD_GET_PEER_NAME
Definition: shared.h:291
#define IOCTL_AFD_GET_SOCK_NAME
Definition: shared.h:289
static NTSTATUS NTAPI AfdCreateSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:302
static NTSTATUS NTAPI AfdQueryVolumeInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:877
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
VOID UnlockBuffers(PAFD_WSABUF Buf, UINT Count, BOOL Address)
Definition: lock.c:289
#define BufferSize
Definition: classpnp.h:419
NTSTATUS NTAPI AfdStreamSocketConnect(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: connect.c:431
NTSTATUS AfdQueryFsDeviceInfo(PDEVICE_OBJECT DeviceObject, PFILE_FS_DEVICE_INFORMATION Buffer, PULONG Length)
Definition: main.c:858
unsigned long DWORD
Definition: ntddk_ex.h:95
NTSTATUS QueueUserModeIrp(PAFD_FCB FCB, PIRP Irp, UINT Function)
Definition: lock.c:397
#define Len
Definition: deflate.h:82
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
PAFD_WSABUF BufferArray
Definition: shared.h:85
* PFILE_OBJECT
Definition: iotypes.h:1954
PVOID GetLockedData(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lock.c:13
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
ULONG Flags
Definition: ntfs.h:520
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static NTSTATUS NTAPI AfdGetTdiHandles(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:270
#define IOCTL_AFD_GET_DISCONNECT_DATA
Definition: shared.h:315
NTSTATUS NTAPI AfdGetSockName(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: info.c:232
VOID NTAPI KeInitializeMutex(IN PKMUTEX Mutex, IN ULONG Level)
Definition: mutex.c:67
ULONG BufferCount
Definition: shared.h:86
static DRIVER_UNLOAD AfdUnload
Definition: main.c:1303
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IOCTL_AFD_ACCEPT
Definition: shared.h:275
#define STATUS_INVALID_INFO_CLASS
Definition: ntstatus.h:226
static const WCHAR L[]
Definition: oid.c:1250
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2179
#define TAG_AFD_DISCONNECT_OPTIONS
Definition: afd.h:45
struct _FILE_FS_DEVICE_INFORMATION FILE_FS_DEVICE_INFORMATION
#define IOCTL_AFD_SEND
Definition: shared.h:281
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
Definition: typedefs.h:117
NTSTATUS AfdListenSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: listen.c:225
#define IOCTL_AFD_RECV
Definition: shared.h:277
DRIVER_DISPATCH(nfs41_FsdDispatch)
PAFD_WSABUF BufferArray
Definition: shared.h:101
NTSTATUS NTAPI AfdSetDisconnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:188
NTSTATUS NTAPI AfdSetDisconnectOptionsSize(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:117
NTSTATUS NTAPI AfdGetDisconnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:157
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
Status
Definition: gdiplustypes.h:24
#define IOCTL_AFD_GET_INFO
Definition: shared.h:327
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
NTSTATUS NTAPI AfdGetContext(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: context.c:14
static DRIVER_DISPATCH AfdDispatch
Definition: main.c:904
unsigned short USHORT
Definition: pedump.c:61
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
NTSTATUS NTAPI DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
Definition: main.c:690
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
NTSTATUS NTAPI AfdPacketSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: write.c:564
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
ULONG HandleCount
Definition: shared.h:57
struct _AFD_CREATE_PACKET * PAFD_CREATE_PACKET
unsigned int * PULONG
Definition: retypes.h:1
AFD_HANDLE Handles[1]
Definition: shared.h:59
unsigned int UINT
Definition: ndis.h:50
NTSTATUS NTAPI AfdGetContextSize(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: context.c:40
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
ULONG DisconnectType
Definition: shared.h:136
#define IOCTL_AFD_GET_CONNECT_DATA
Definition: shared.h:311
#define IRP_MJ_READ
Definition: rdpdr.c:46
WCHAR TransportName[1]
Definition: shared.h:25
BOOLEAN NTAPI IoCancelIrp(IN PIRP Irp)
Definition: irp.c:1101
PFILE_OBJECT Object
Definition: afd.h:132
#define IRP_MJ_CLEANUP
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2180
#define IOCTL_AFD_SET_DISCONNECT_OPTIONS
Definition: shared.h:309
struct tagContext Context
Definition: acpixf.h:1012
#define SOCKET_STATE_CLOSED
Definition: afd.h:82
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:565
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 RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define MIN_TRACE
Definition: debug.h:14
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
#define IOCTL_AFD_SET_DISCONNECT_OPTIONS_SIZE
Definition: shared.h:325
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
NTSTATUS AfdAccept(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: listen.c:337
#define IOCTL_AFD_EVENT_SELECT
Definition: shared.h:329
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define AFD_DISCONNECT_RECV
Definition: shared.h:198
static NTSTATUS NTAPI AfdCleanupSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:426
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2725
static NTSTATUS NTAPI AfdDisconnect(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:715
BOOLEAN CheckUnlockExtraBuffers(PAFD_FCB FCB, PIO_STACK_LOCATION IrpSp)
Definition: main.c:1092
#define IOCTL_AFD_GET_CONNECT_OPTIONS
Definition: shared.h:313
NTSTATUS NTAPI AfdGetInfo(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: info.c:14
#define TAG_AFD_SOCKET_CONTEXT
Definition: afd.h:40
NTSTATUS NTAPI AfdBindSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: bind.c:76
#define TDI_DISCONNECT_ABORT
Definition: tdi.h:143
unsigned int * PUINT
Definition: ndis.h:50
#define FD_WRITE_BIT
Definition: winsock2.h:295
NTSTATUS NTAPI AfdSetConnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: connect.c:157
NTSTATUS NTAPI AfdEventSelect(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: select.c:265
PIRP Irp
Definition: afd.h:118
#define IOCTL_AFD_SET_CONTEXT
Definition: shared.h:301
NTSTATUS NTAPI AfdConnectedSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Short)
Definition: read.c:422
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IOCTL_AFD_GET_CONTEXT
Definition: shared.h:299
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
NTSTATUS NTAPI AfdGetPeerName(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: info.c:281
#define STATUS_FILE_CLOSED
Definition: ntstatus.h:518