ReactOS 0.4.17-dev-966-gf06eace
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#include "wdm.h"
17
18#if DBG
19
20/* See debug.h for debug/trace constants */
21//DWORD DebugTraceLevel = DEBUG_ULTRA;
23
24#endif /* DBG */
25
26/* FIXME: should depend on SystemSize */
29
31 unsigned int i;
32
33 for( i = 0; i < Len; i++ ) {
34 if( i && !(i & 0xf) ) DbgPrint( "\n" );
35 if( !(i & 0xf) ) DbgPrint( "%p: ", (Data + i) );
36 DbgPrint( " %02x", Data[i] & 0xff );
37 }
38 DbgPrint("\n");
39}
40
41/* FUNCTIONS */
42
45
49{
51 PAFD_FCB FCB = FileObject->FsContext;
52 UINT BufferSize = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
53
55
57
58 if (FCB->DisconnectOptionsSize == 0)
59 {
60 AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n"));
62 }
63
64 ASSERT(FCB->DisconnectOptions);
65
66 if (FCB->FilledDisconnectOptions < BufferSize) BufferSize = FCB->FilledDisconnectOptions;
67
68 RtlCopyMemory(Irp->UserBuffer,
69 FCB->DisconnectOptions,
71
73}
74
79{
81 PAFD_FCB FCB = FileObject->FsContext;
82 PVOID DisconnectOptions = LockRequest(Irp, IrpSp, FALSE, NULL);
83 UINT DisconnectOptionsSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
84
86
88
89 if (!DisconnectOptions)
91
92 if (FCB->DisconnectOptions)
93 {
95 FCB->DisconnectOptions = NULL;
96 FCB->DisconnectOptionsSize = 0;
97 FCB->FilledDisconnectOptions = 0;
98 }
99
100 FCB->DisconnectOptions = ExAllocatePoolWithTag(PagedPool,
101 DisconnectOptionsSize,
103
104 if (!FCB->DisconnectOptions)
106
107 RtlCopyMemory(FCB->DisconnectOptions,
108 DisconnectOptions,
109 DisconnectOptionsSize);
110
111 FCB->DisconnectOptionsSize = DisconnectOptionsSize;
112
114}
115
117NTAPI
120{
122 PAFD_FCB FCB = FileObject->FsContext;
123 PUINT DisconnectOptionsSize = LockRequest(Irp, IrpSp, FALSE, NULL);
124 UINT BufferSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
125
127
129
130 if (!DisconnectOptionsSize)
132
133 if (BufferSize < sizeof(UINT))
134 {
135 AFD_DbgPrint(MIN_TRACE,("Buffer too small\n"));
137 }
138
139 if (FCB->DisconnectOptions)
140 {
142 FCB->DisconnectOptionsSize = 0;
143 FCB->FilledDisconnectOptions = 0;
144 }
145
146 FCB->DisconnectOptions = ExAllocatePoolWithTag(PagedPool,
147 *DisconnectOptionsSize,
149
150 if (!FCB->DisconnectOptions) return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
151
152 FCB->DisconnectOptionsSize = *DisconnectOptionsSize;
153
155}
156
160{
162 PAFD_FCB FCB = FileObject->FsContext;
163 UINT BufferSize = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
164
166
168
169 if (FCB->DisconnectDataSize == 0)
170 {
171 AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n"));
173 }
174
175 ASSERT(FCB->DisconnectData);
176
177 if (FCB->FilledDisconnectData < BufferSize)
178 BufferSize = FCB->FilledDisconnectData;
179
180 RtlCopyMemory(Irp->UserBuffer,
181 FCB->DisconnectData,
182 BufferSize);
183
185}
186
188NTAPI
191{
193 PAFD_FCB FCB = FileObject->FsContext;
194 PVOID DisconnectData = LockRequest(Irp, IrpSp, FALSE, NULL);
195 UINT DisconnectDataSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
196
198
200
201 if (!DisconnectData)
203
204 if (FCB->DisconnectData)
205 {
207 FCB->DisconnectData = NULL;
208 FCB->DisconnectDataSize = 0;
209 FCB->FilledDisconnectData = 0;
210 }
211
212 FCB->DisconnectData = ExAllocatePoolWithTag(PagedPool,
213 DisconnectDataSize,
215
216 if (!FCB->DisconnectData)
218
219 RtlCopyMemory(FCB->DisconnectData,
220 DisconnectData,
221 DisconnectDataSize);
222
223 FCB->DisconnectDataSize = DisconnectDataSize;
224
226}
227
229NTAPI
232{
234 PAFD_FCB FCB = FileObject->FsContext;
235 PUINT DisconnectDataSize = LockRequest(Irp, IrpSp, FALSE, NULL);
236 UINT BufferSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
237
239
241
242 if (!DisconnectDataSize)
244
245 if (BufferSize < sizeof(UINT))
246 {
247 AFD_DbgPrint(MIN_TRACE,("Buffer too small\n"));
249 }
250
251 if (FCB->DisconnectData)
252 {
254 FCB->DisconnectDataSize = 0;
255 FCB->FilledDisconnectData = 0;
256 }
257
258 FCB->DisconnectData = ExAllocatePoolWithTag(PagedPool,
259 *DisconnectDataSize,
261
262 if (!FCB->DisconnectData)
264
265 FCB->DisconnectDataSize = *DisconnectDataSize;
266
268}
269
270static NTSTATUS NTAPI
273{
275 PAFD_FCB FCB = FileObject->FsContext;
276 PULONG HandleFlags = LockRequest(Irp, IrpSp, TRUE, NULL);
277 PAFD_TDI_HANDLE_DATA HandleData = Irp->UserBuffer;
278
280
282
283 if (!HandleFlags)
285
286 if (IrpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(ULONG) ||
287 IrpSp->Parameters.DeviceIoControl.OutputBufferLength < sizeof(*HandleData))
288 {
289 AFD_DbgPrint(MIN_TRACE,("Buffer too small\n"));
291 }
292
293 if ((*HandleFlags) & AFD_ADDRESS_HANDLE)
294 HandleData->TdiAddressHandle = FCB->AddressFile.Handle;
295
296 if ((*HandleFlags) & AFD_CONNECTION_HANDLE)
297 HandleData->TdiConnectionHandle = FCB->Connection.Handle;
298
300}
301
302static NTSTATUS NTAPI
307 PAFD_DEVICE_EXTENSION DeviceExt;
309 PAFD_CREATE_PACKET ConnectInfo = NULL;
310 //ULONG EaLength;
311 PWCHAR EaInfoValue = NULL;
312 //UINT Disposition;
313 UINT i;
315
316 AFD_DbgPrint(MID_TRACE,("AfdCreate(DeviceObject %p Irp %p)\n",
317 DeviceObject, Irp));
318
319 DeviceExt = DeviceObject->DeviceExtension;
321 FileObject->Flags |= FO_NAMED_PIPE;
322 //Disposition = (IrpSp->Parameters.Create.Options >> 24) & 0xff;
323
324 Irp->IoStatus.Information = 0;
325
326 EaInfo = Irp->AssociatedIrp.SystemBuffer;
327
328 if( EaInfo ) {
329 ConnectInfo = (PAFD_CREATE_PACKET)(EaInfo->EaName + EaInfo->EaNameLength + 1);
330 EaInfoValue = (PWCHAR)(((PCHAR)ConnectInfo) + sizeof(AFD_CREATE_PACKET));
331
332 //EaLength = sizeof(FILE_FULL_EA_INFORMATION) + EaInfo->EaNameLength + EaInfo->EaValueLength;
333
334 AFD_DbgPrint(MID_TRACE,("EaInfo: %p, EaInfoValue: %p\n",
335 EaInfo, EaInfoValue));
336 }
337
338 AFD_DbgPrint(MID_TRACE,("About to allocate the new FCB\n"));
339
341 if( FCB == NULL ) {
342 Irp->IoStatus.Status = STATUS_NO_MEMORY;
344 return STATUS_NO_MEMORY;
345 }
346
347 AFD_DbgPrint(MID_TRACE,("Initializing the new FCB @ %p (FileObject %p Flags %x)\n",
348 FCB, FileObject, ConnectInfo ? ConnectInfo->EndpointFlags : 0));
349
350 RtlZeroMemory( FCB, sizeof( *FCB ) );
351
352 FCB->Flags = ConnectInfo ? ConnectInfo->EndpointFlags : 0;
353 FCB->GroupID = ConnectInfo ? ConnectInfo->GroupID : 0;
354 FCB->GroupType = 0; /* FIXME */
355 FCB->SharedData.State = SOCKET_STATE_CREATED;
357 FCB->DeviceExt = DeviceExt;
358 FCB->AddressFile.Handle = INVALID_HANDLE_VALUE;
359 FCB->Connection.Handle = INVALID_HANDLE_VALUE;
360 FCB->Recv.Size = AfdReceiveWindowSize;
361 FCB->Send.Size = AfdSendWindowSize;
362
363 KeInitializeMutex( &FCB->Mutex, 0 );
364
365 for( i = 0; i < MAX_FUNCTIONS; i++ ) {
366 InitializeListHead( &FCB->PendingIrpList[i] );
367 }
368
369 InitializeListHead( &FCB->DatagramList );
370 InitializeListHead( &FCB->PendingConnections );
371
372 AFD_DbgPrint(MID_TRACE,("%p: Checking command channel\n", FCB));
373
374 if( ConnectInfo ) {
375 FCB->TdiDeviceName.Length = ConnectInfo->SizeOfTransportName;
376 FCB->TdiDeviceName.MaximumLength = FCB->TdiDeviceName.Length;
377 FCB->TdiDeviceName.Buffer = ExAllocatePoolWithTag(NonPagedPool,
378 FCB->TdiDeviceName.Length,
380
381 if( !FCB->TdiDeviceName.Buffer ) {
383 AFD_DbgPrint(MID_TRACE,("Could not copy target string\n"));
384 Irp->IoStatus.Status = STATUS_NO_MEMORY;
386 return STATUS_NO_MEMORY;
387 }
388
389 RtlCopyMemory( FCB->TdiDeviceName.Buffer,
390 ConnectInfo->TransportName,
391 FCB->TdiDeviceName.Length );
392
393 AFD_DbgPrint(MID_TRACE,("Success: %s %wZ\n",
394 EaInfo->EaName, &FCB->TdiDeviceName));
395 } else {
396 AFD_DbgPrint(MID_TRACE,("Success: Control connection\n"));
397 }
398
399 FileObject->FsContext = FCB;
400
401 /* It seems that UDP sockets are writable from inception */
403 AFD_DbgPrint(MID_TRACE,("Packet oriented socket\n"));
404
405 /* A datagram socket is always sendable */
406 FCB->PollState |= AFD_EVENT_SEND;
407 FCB->PollStatus[FD_WRITE_BIT] = STATUS_SUCCESS;
408 PollReeval( FCB->DeviceExt, FCB->FileObject );
409 }
410
411 if( !NT_SUCCESS(Status) ) {
412 if (FCB->TdiDeviceName.Buffer)
413 {
414 ExFreePoolWithTag(FCB->TdiDeviceName.Buffer, TAG_AFD_TRANSPORT_ADDRESS);
415 }
417 FileObject->FsContext = NULL;
418 }
419
420 Irp->IoStatus.Status = Status;
422
423 return Status;
424}
425
426static NTSTATUS NTAPI
429{
431 PAFD_FCB FCB = FileObject->FsContext;
432 PLIST_ENTRY CurrentEntry, NextEntry;
434 PIRP CurrentIrp;
435
437
438 if( !SocketAcquireStateLock( FCB ) ) return LostSocket(Irp);
439
441 {
442 CurrentEntry = FCB->PendingIrpList[Function].Flink;
443 while (CurrentEntry != &FCB->PendingIrpList[Function])
444 {
445 NextEntry = CurrentEntry->Flink;
446 CurrentIrp = CONTAINING_RECORD(CurrentEntry, IRP, Tail.Overlay.ListEntry);
447
448 /* The cancel routine will remove the IRP from the list */
449 IoCancelIrp(CurrentIrp);
450
451 CurrentEntry = NextEntry;
452 }
453 }
454
455 KillSelectsForFCB( FCB->DeviceExt, FileObject, FALSE );
456
458}
459
460static NTSTATUS NTAPI
463{
465 PAFD_FCB FCB = FileObject->FsContext;
466 UINT i;
469 PLIST_ENTRY QeltEntry;
470
471
472 AFD_DbgPrint(MID_TRACE,("AfdClose(DeviceObject %p Irp %p)\n",
473 DeviceObject, Irp));
474
476
477 FCB->SharedData.State = SOCKET_STATE_CLOSED;
478
479 InFlightRequest[0] = &FCB->ListenIrp;
480 InFlightRequest[1] = &FCB->ReceiveIrp;
481 InFlightRequest[2] = &FCB->SendIrp;
482 InFlightRequest[3] = &FCB->ConnectIrp;
483 InFlightRequest[4] = &FCB->DisconnectIrp;
484
485 /* Cancel our pending requests */
486 for( i = 0; i < IN_FLIGHT_REQUESTS; i++ ) {
487 if( InFlightRequest[i]->InFlightRequest ) {
488 AFD_DbgPrint(MID_TRACE,("Cancelling in flight irp %u (%p)\n",
489 i, InFlightRequest[i]->InFlightRequest));
490 IoCancelIrp(InFlightRequest[i]->InFlightRequest);
491 }
492 }
493
494 KillSelectsForFCB( FCB->DeviceExt, FileObject, FALSE );
495
496 ASSERT(IsListEmpty(&FCB->PendingIrpList[FUNCTION_CONNECT]));
497 ASSERT(IsListEmpty(&FCB->PendingIrpList[FUNCTION_CONNECTEX]));
498 ASSERT(IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]));
499 ASSERT(IsListEmpty(&FCB->PendingIrpList[FUNCTION_RECV]));
500 ASSERT(IsListEmpty(&FCB->PendingIrpList[FUNCTION_PREACCEPT]));
501 ASSERT(IsListEmpty(&FCB->PendingIrpList[FUNCTION_DISCONNECT]));
502
503 while (!IsListEmpty(&FCB->PendingConnections))
504 {
505 QeltEntry = RemoveHeadList(&FCB->PendingConnections);
506 Qelt = CONTAINING_RECORD(QeltEntry, AFD_TDI_OBJECT_QELT, ListEntry);
507
508 /* We have to close all pending connections or the listen won't get closed */
511 ZwClose(Qelt->Object.Handle);
512
514 }
515
517
518 if( FCB->EventSelect )
519 ObDereferenceObject( FCB->EventSelect );
520
521 if (FCB->Context)
523
524 if (FCB->Recv.Window)
526
527 if (FCB->Send.Window)
529
530 if (FCB->AddressFrom)
532
533 if (FCB->ConnectCallInfo)
535
536 if (FCB->ConnectReturnInfo)
538
539 if (FCB->ConnectData)
541
542 if (FCB->DisconnectData)
544
545 if (FCB->ConnectOptions)
547
548 if (FCB->DisconnectOptions)
550
551 if (FCB->LocalAddress)
553
554 if (FCB->RemoteAddress)
556
557 if (FCB->OnConnectSendBuffer)
559
560 if( FCB->Connection.Object )
561 {
562 TdiDisassociateAddressFile(FCB->Connection.Object);
563 ObDereferenceObject(FCB->Connection.Object);
564 }
565
566 if( FCB->AddressFile.Object )
567 ObDereferenceObject(FCB->AddressFile.Object);
568
569 if( FCB->AddressFile.Handle != INVALID_HANDLE_VALUE )
570 {
571 if (ZwClose(FCB->AddressFile.Handle) == STATUS_INVALID_HANDLE)
572 {
573 DbgPrint("INVALID ADDRESS FILE HANDLE VALUE: %p %p\n", FCB->AddressFile.Handle, FCB->AddressFile.Object);
574 }
575 }
576
577 if( FCB->Connection.Handle != INVALID_HANDLE_VALUE )
578 {
579 if (ZwClose(FCB->Connection.Handle) == STATUS_INVALID_HANDLE)
580 {
581 DbgPrint("INVALID CONNECTION HANDLE VALUE: %p %p\n", FCB->Connection.Handle, FCB->Connection.Object);
582 }
583 }
584
585 if (FCB->TdiDeviceName.Buffer)
586 {
587 ExFreePoolWithTag(FCB->TdiDeviceName.Buffer, TAG_AFD_TRANSPORT_ADDRESS);
588 }
589
591
592 Irp->IoStatus.Status = STATUS_SUCCESS;
593 Irp->IoStatus.Information = 0;
595
596 AFD_DbgPrint(MID_TRACE, ("Returning success.\n"));
597
598 return STATUS_SUCCESS;
599}
600
601static IO_COMPLETION_ROUTINE DisconnectComplete;
602static
604NTAPI
606 PIRP Irp,
608{
610 PIRP CurrentIrp;
611 PLIST_ENTRY CurrentEntry;
612
614
616 return STATUS_FILE_CLOSED;
617
618 ASSERT(FCB->DisconnectIrp.InFlightRequest == Irp);
619 FCB->DisconnectIrp.InFlightRequest = NULL;
620
621 ASSERT(FCB->DisconnectPending);
622 ASSERT((IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]) && !FCB->SendIrp.InFlightRequest) ||
623 (FCB->DisconnectFlags & TDI_DISCONNECT_ABORT));
624
625 if (NT_SUCCESS(Irp->IoStatus.Status) && (FCB->DisconnectFlags & TDI_DISCONNECT_RELEASE))
626 {
627 FCB->FilledDisconnectData = MIN(FCB->DisconnectDataSize, FCB->ConnectReturnInfo->UserDataLength);
628 if (FCB->FilledDisconnectData)
629 {
630 RtlCopyMemory(FCB->DisconnectData,
631 FCB->ConnectReturnInfo->UserData,
632 FCB->FilledDisconnectData);
633 }
634
635 FCB->FilledDisconnectOptions = MIN(FCB->DisconnectOptionsSize, FCB->ConnectReturnInfo->OptionsLength);
636 if (FCB->FilledDisconnectOptions)
637 {
638 RtlCopyMemory(FCB->DisconnectOptions,
639 FCB->ConnectReturnInfo->Options,
640 FCB->FilledDisconnectOptions);
641 }
642 }
643
644 FCB->DisconnectPending = FALSE;
645
646 while (!IsListEmpty(&FCB->PendingIrpList[FUNCTION_DISCONNECT]))
647 {
648 CurrentEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_DISCONNECT]);
649 CurrentIrp = CONTAINING_RECORD(CurrentEntry, IRP, Tail.Overlay.ListEntry);
650 CurrentIrp->IoStatus.Status = Irp->IoStatus.Status;
651 CurrentIrp->IoStatus.Information = 0;
652 UnlockRequest(CurrentIrp, IoGetCurrentIrpStackLocation(CurrentIrp));
653 (void)IoSetCancelRoutine(CurrentIrp, NULL);
655 }
656
657 if (!(FCB->DisconnectFlags & TDI_DISCONNECT_RELEASE))
658 {
659 /* Signal complete connection closure immediately */
660 FCB->PollState |= AFD_EVENT_ABORT;
661 FCB->PollStatus[FD_CLOSE_BIT] = Irp->IoStatus.Status;
662 FCB->LastReceiveStatus = STATUS_FILE_CLOSED;
663 PollReeval(FCB->DeviceExt, FCB->FileObject);
664 }
665
667
668 return Irp->IoStatus.Status;
669}
670
671static
674{
676
677 ASSERT(FCB->DisconnectPending);
678 ASSERT((IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]) && !FCB->SendIrp.InFlightRequest) ||
679 (FCB->DisconnectFlags & TDI_DISCONNECT_ABORT));
680
681 if (FCB->DisconnectIrp.InFlightRequest)
682 {
683 return STATUS_PENDING;
684 }
685
686 FCB->ConnectCallInfo->UserData = FCB->DisconnectData;
687 FCB->ConnectCallInfo->UserDataLength = FCB->DisconnectDataSize;
688 FCB->ConnectCallInfo->Options = FCB->DisconnectOptions;
689 FCB->ConnectCallInfo->OptionsLength = FCB->DisconnectOptionsSize;
690
691 Status = TdiDisconnect(&FCB->DisconnectIrp.InFlightRequest,
692 FCB->Connection.Object,
693 &FCB->DisconnectTimeout,
694 FCB->DisconnectFlags,
696 FCB,
697 FCB->ConnectCallInfo,
698 FCB->ConnectReturnInfo);
699 if (Status != STATUS_PENDING)
700 {
701 FCB->DisconnectPending = FALSE;
702 }
703
704 return Status;
705}
706
707VOID
709{
710 ASSERT(FCB->RemoteAddress);
711
712 if (IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]) && !FCB->SendIrp.InFlightRequest && FCB->DisconnectPending)
713 {
714 /* Sends are done; fire off a TDI_DISCONNECT request */
716 }
717}
718
719static NTSTATUS NTAPI
723 PAFD_FCB FCB = FileObject->FsContext;
727 PLIST_ENTRY CurrentEntry;
728 PIRP CurrentIrp;
729
731
733
734 if (!(DisReq = LockRequest(Irp, IrpSp, FALSE, NULL)))
736 Irp, 0 );
737
738 /* Send direction only */
739 if ((DisReq->DisconnectType & AFD_DISCONNECT_SEND) &&
741 {
742 /* Perform a controlled disconnect */
744 }
745 /* Receive direction or both */
746 else
747 {
748 /* Mark that we can't issue another receive request */
749 FCB->TdiReceiveClosed = TRUE;
750
751 /* Try to cancel a pending TDI receive IRP if there was one in progress */
752 if (FCB->ReceiveIrp.InFlightRequest)
753 IoCancelIrp(FCB->ReceiveIrp.InFlightRequest);
754
755 /* Discard any pending data */
756 FCB->Recv.Content = 0;
757 FCB->Recv.BytesUsed = 0;
758
759 /* Set a successful receive status to indicate a shutdown on overread */
760 FCB->LastReceiveStatus = STATUS_SUCCESS;
761
762 /* Clear the receive event */
763 FCB->PollState &= ~AFD_EVENT_RECEIVE;
764
765 /* Receive direction only */
766 if ((DisReq->DisconnectType & AFD_DISCONNECT_RECV) &&
768 {
769 /* No need to tell the transport driver for receive direction only */
771 }
772 else
773 {
774 /* Perform an abortive disconnect */
776 }
777 }
778
780 {
781 if (!FCB->ConnectCallInfo)
782 {
783 AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n"));
785 Irp, 0 );
786 }
787
788 if (FCB->DisconnectPending)
789 {
790 if (FCB->DisconnectIrp.InFlightRequest)
791 {
792 IoCancelIrp(FCB->DisconnectIrp.InFlightRequest);
793 ASSERT(!FCB->DisconnectIrp.InFlightRequest);
794 }
795 else
796 {
797 while (!IsListEmpty(&FCB->PendingIrpList[FUNCTION_DISCONNECT]))
798 {
799 CurrentEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_DISCONNECT]);
800 CurrentIrp = CONTAINING_RECORD(CurrentEntry, IRP, Tail.Overlay.ListEntry);
801 CurrentIrp->IoStatus.Status = STATUS_CANCELLED;
802 CurrentIrp->IoStatus.Information = 0;
803 UnlockRequest(CurrentIrp, IoGetCurrentIrpStackLocation(CurrentIrp));
804 (void)IoSetCancelRoutine(CurrentIrp, NULL);
806 }
807 }
808 }
809
810 FCB->DisconnectFlags = Flags;
811 FCB->DisconnectTimeout = DisReq->Timeout;
812 FCB->DisconnectPending = TRUE;
813 FCB->SendClosed = TRUE;
814 FCB->PollState &= ~AFD_EVENT_SEND;
815
817 if (Status == STATUS_PENDING)
818 {
819 if ((IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]) && !FCB->SendIrp.InFlightRequest) ||
820 (FCB->DisconnectFlags & TDI_DISCONNECT_ABORT))
821 {
822 /* Go ahead and execute the disconnect because we're ready for it */
824 }
825
826 if (Status != STATUS_PENDING)
827 RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
828 }
829
830 if (Status == STATUS_PENDING)
831 {
833
834 return Status;
835 }
836 }
837 else
838 {
840 {
841 if (!FCB->RemoteAddress)
842 {
843 AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n"));
845 }
846
848
849 FCB->RemoteAddress = NULL;
850 }
851
852 FCB->PollState &= ~AFD_EVENT_SEND;
853 FCB->SendClosed = TRUE;
854 }
855
856 return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
857}
858
861{
862 if (*Length >= sizeof(FILE_FS_DEVICE_INFORMATION))
863 {
864 Buffer->Characteristics = 0;
865 Buffer->DeviceType = FILE_DEVICE_NAMED_PIPE;
866
868
869 return STATUS_SUCCESS;
870 }
871 else
872 {
875 }
876}
877
878static NTSTATUS NTAPI
880{
881 FS_INFORMATION_CLASS InfoClass;
885
886 Buffer = Irp->AssociatedIrp.SystemBuffer;
888 InfoClass = IrpSp->Parameters.QueryVolume.FsInformationClass;
889
890 switch (InfoClass)
891 {
894 break;
895 default:
896 break;
897 }
898
899 Irp->IoStatus.Status = Status;
900 Irp->IoStatus.Information = IrpSp->Parameters.QueryVolume.Length - Length;
902
903 return Status;
904}
905
907static NTSTATUS NTAPI
909{
912#if DBG
914#endif
915
916 AFD_DbgPrint(MID_TRACE,("AfdDispatch: %u\n", IrpSp->MajorFunction));
918 AFD_DbgPrint(MID_TRACE,("FO %p, IrpSp->FO %p\n",
921 }
922
923 Irp->IoStatus.Information = 0;
924
925 switch(IrpSp->MajorFunction)
926 {
927 /* opening and closing handles to the device */
928 case IRP_MJ_CREATE:
929 /* Mostly borrowed from the named pipe file system */
931
932 case IRP_MJ_CLOSE:
933 /* Ditto the borrowing */
935
936 case IRP_MJ_CLEANUP:
938
939 /* write data */
940 case IRP_MJ_WRITE:
942
943 /* read data */
944 case IRP_MJ_READ:
946
947 /* query volume info */
950
952 {
953 switch( IrpSp->Parameters.DeviceIoControl.IoControlCode ) {
954 case IOCTL_AFD_BIND:
956
959
962
965
966 case IOCTL_AFD_RECV:
968 FALSE );
969
970 case IOCTL_AFD_SELECT:
971 return AfdSelect( DeviceObject, Irp, IrpSp );
972
975
978
981
982 case IOCTL_AFD_SEND:
984 FALSE );
985
988
990 return AfdGetInfo( DeviceObject, Irp, IrpSp );
991
993 return AfdSetInfo( DeviceObject, Irp, IrpSp );
994
997
1000
1002 return AfdSetContext( DeviceObject, Irp, IrpSp );
1003
1006
1007 case IOCTL_AFD_ACCEPT:
1008 return AfdAccept( DeviceObject, Irp, IrpSp );
1009
1012
1014 return AfdDisconnect( DeviceObject, Irp, IrpSp );
1015
1018
1021
1024
1027
1030
1033
1036
1039
1042
1045
1048
1051
1054
1057
1060
1062 DbgPrint("IOCTL_AFD_DEFER_ACCEPT is UNIMPLEMENTED!\n");
1063 break;
1064
1066 DbgPrint("IOCTL_AFD_GET_PENDING_CONNECT_DATA is UNIMPLEMENTED!\n");
1067 break;
1068
1070 DbgPrint("IOCTL_AFD_VALIDATE_GROUP is UNIMPLEMENTED!\n");
1071 break;
1072
1073 default:
1075 DbgPrint("Unknown IOCTL (0x%x)\n",
1076 IrpSp->Parameters.DeviceIoControl.IoControlCode);
1077 break;
1078 }
1079 break;
1080 }
1081
1082/* unsupported operations */
1083 default:
1084 {
1087 ("Irp: Unknown Major code was %x\n",
1089 break;
1090 }
1091 }
1092
1093 AFD_DbgPrint(MID_TRACE, ("Returning %x\n", Status));
1094 Irp->IoStatus.Status = Status;
1096
1097 return Status;
1098}
1099
1101{
1103 {
1105 {
1106 /* read()/write() call - no extra buffers */
1107 return FALSE;
1108 }
1110 {
1112 {
1113 /* recvfrom() call - extra buffers */
1114 return TRUE;
1115 }
1116 else if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_RECV)
1117 {
1118 /* recv() call - no extra buffers */
1119 return FALSE;
1120 }
1121 else if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_SEND ||
1123 {
1124 /* send()/sendto() call - no extra buffers */
1125 return FALSE;
1126 }
1127 else
1128 {
1129 /* Unknown IOCTL */
1130 ASSERT(FALSE);
1131 return FALSE;
1132 }
1133 }
1134 else
1135 {
1136 /* Unknown IRP_MJ code */
1137 ASSERT(FALSE);
1138 return FALSE;
1139 }
1140 }
1141 else
1142 {
1143 /* Connection-oriented never has extra buffers */
1144 return FALSE;
1145 }
1146}
1147
1148VOID
1150{
1151 PAFD_RECV_INFO RecvReq;
1152 PAFD_SEND_INFO SendReq;
1153 PAFD_POLL_INFO PollReq;
1154
1156 {
1157 RecvReq = GetLockedData(Irp, IrpSp);
1159 }
1160 else if (IrpSp->MajorFunction == IRP_MJ_WRITE)
1161 {
1162 SendReq = GetLockedData(Irp, IrpSp);
1164 }
1165 else
1166 {
1168
1169 if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_RECV)
1170 {
1171 RecvReq = GetLockedData(Irp, IrpSp);
1173 }
1174 else if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_SEND)
1175 {
1176 SendReq = GetLockedData(Irp, IrpSp);
1178 }
1179 else if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_SELECT)
1180 {
1181 ASSERT(Poll);
1182
1183 PollReq = Irp->AssociatedIrp.SystemBuffer;
1184 ZeroEvents(PollReq->Handles, PollReq->HandleCount);
1185 SignalSocket(Poll, NULL, PollReq, STATUS_CANCELLED);
1186 }
1187 }
1188}
1189
1190VOID
1191NTAPI
1193 PIRP Irp)
1194{
1197 PAFD_FCB FCB = FileObject->FsContext;
1199 PIRP CurrentIrp;
1200 PLIST_ENTRY CurrentEntry;
1201 PAFD_DEVICE_EXTENSION DeviceExt = DeviceObject->DeviceExtension;
1202 KIRQL OldIrql;
1203 PAFD_ACTIVE_POLL Poll;
1204
1205 IoReleaseCancelSpinLock(Irp->CancelIrql);
1206
1208 return;
1209
1210 switch (IrpSp->MajorFunction)
1211 {
1213 IoctlCode = IrpSp->Parameters.DeviceIoControl.IoControlCode;
1214 break;
1215
1216 case IRP_MJ_READ:
1218 break;
1219
1220 case IRP_MJ_WRITE:
1222 break;
1223
1224 default:
1225 ASSERT(FALSE);
1227 return;
1228 }
1229
1230 switch (IoctlCode)
1231 {
1232 case IOCTL_AFD_RECV:
1235 break;
1236
1237 case IOCTL_AFD_SEND:
1240 break;
1241
1242 case IOCTL_AFD_CONNECT:
1244 break;
1245
1248 break;
1249
1252 break;
1253
1256 break;
1257
1258 case IOCTL_AFD_SELECT:
1259 KeAcquireSpinLock(&DeviceExt->Lock, &OldIrql);
1260
1261 CurrentEntry = DeviceExt->Polls.Flink;
1262 while (CurrentEntry != &DeviceExt->Polls)
1263 {
1264 Poll = CONTAINING_RECORD(CurrentEntry, AFD_ACTIVE_POLL, ListEntry);
1265
1266 if (Irp == Poll->Irp)
1267 {
1268 CleanupPendingIrp(FCB, Irp, IrpSp, Poll);
1269 KeReleaseSpinLock(&DeviceExt->Lock, OldIrql);
1271 return;
1272 }
1273 else
1274 {
1275 CurrentEntry = CurrentEntry->Flink;
1276 }
1277 }
1278
1279 KeReleaseSpinLock(&DeviceExt->Lock, OldIrql);
1280
1282
1283 DbgPrint("WARNING!!! IRP cancellation race could lead to a process hang! (IOCTL_AFD_SELECT)\n");
1284 return;
1285
1288 break;
1289
1290 default:
1291 ASSERT(FALSE);
1293 return;
1294 }
1295
1296 CurrentEntry = FCB->PendingIrpList[Function].Flink;
1297 while (CurrentEntry != &FCB->PendingIrpList[Function])
1298 {
1299 CurrentIrp = CONTAINING_RECORD(CurrentEntry, IRP, Tail.Overlay.ListEntry);
1300
1301 if (CurrentIrp == Irp)
1302 {
1303 RemoveEntryList(CurrentEntry);
1306 {
1307 /* Unlock the acceptor socket so that it can be reused */
1308 PFILE_OBJECT NewFileObject = (PFILE_OBJECT)Irp->Tail.Overlay.DriverContext[2];
1310 {
1311 PAFD_FCB FCB2 = NewFileObject->FsContext;
1313
1315 Irp->Tail.Overlay.DriverContext[2] = NULL;
1316 }
1317
1318 if (Irp->Tail.Overlay.DriverContext[3])
1319 {
1320 MmUnlockPages((PMDL)Irp->Tail.Overlay.DriverContext[3]);
1321 IoFreeMdl((PMDL)Irp->Tail.Overlay.DriverContext[3]);
1322 Irp->Tail.Overlay.DriverContext[3] = NULL;
1323 }
1324 }
1326 return;
1327 }
1328 else
1329 {
1330 CurrentEntry = CurrentEntry->Flink;
1331 }
1332 }
1333
1335
1336 DbgPrint("WARNING!!! IRP cancellation race could lead to a process hang! (Function: %u)\n", Function);
1337}
1338
1339static DRIVER_UNLOAD AfdUnload;
1340static VOID NTAPI
1342{
1344}
1345
1348{
1350 UNICODE_STRING wstrDeviceName = RTL_CONSTANT_STRING(L"\\Device\\Afd");
1351 PAFD_DEVICE_EXTENSION DeviceExt;
1353
1355 /* register driver routines */
1356 DriverObject->MajorFunction[IRP_MJ_CLOSE] = AfdDispatch;
1357 DriverObject->MajorFunction[IRP_MJ_CREATE] = AfdDispatch;
1358 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = AfdDispatch;
1359 DriverObject->MajorFunction[IRP_MJ_WRITE] = AfdDispatch;
1360 DriverObject->MajorFunction[IRP_MJ_READ] = AfdDispatch;
1363 DriverObject->DriverUnload = AfdUnload;
1364
1366 sizeof(AFD_DEVICE_EXTENSION),
1367 &wstrDeviceName,
1369 0,
1370 FALSE,
1371 &DeviceObject);
1372
1373 /* failure */
1374 if (!NT_SUCCESS(Status))
1375 {
1376 return Status;
1377 }
1378
1379 DeviceExt = DeviceObject->DeviceExtension;
1380 KeInitializeSpinLock( &DeviceExt->Lock );
1381 InitializeListHead( &DeviceExt->Polls );
1382
1383 AFD_DbgPrint(MID_TRACE,("Device created: object %p ext %p\n",
1384 DeviceObject, DeviceExt));
1385
1386 return Status;
1387}
1388
1389/* EOF */
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
unsigned char BOOLEAN
Definition: actypes.h:127
#define FUNCTION_CONNECT
Definition: afd.h:85
#define SOCKET_STATE_CLOSED
Definition: afd.h:83
#define IN_FLIGHT_REQUESTS
Definition: afd.h:95
#define SOCKET_STATE_CREATED
Definition: afd.h:74
#define TAG_AFD_DISCONNECT_DATA
Definition: afd.h:42
#define TAG_AFD_TDI_CONNECTION_INFORMATION
Definition: afd.h:54
#define TAG_AFD_SUPER_CONNECT_BUFFER
Definition: afd.h:46
#define FUNCTION_RECV
Definition: afd.h:86
#define TAG_AFD_DISCONNECT_OPTIONS
Definition: afd.h:45
#define FUNCTION_PREACCEPT
Definition: afd.h:88
#define TAG_AFD_ACCEPT_QUEUE
Definition: afd.h:47
#define TAG_AFD_CONNECT_OPTIONS
Definition: afd.h:44
#define TAG_AFD_SOCKET_CONTEXT
Definition: afd.h:40
DRIVER_CANCEL AfdCancelHandler
Definition: afd.h:313
#define TAG_AFD_FCB
Definition: afd.h:49
#define TAG_AFD_CONNECT_DATA
Definition: afd.h:41
#define FUNCTION_CONNECTEX
Definition: afd.h:92
#define MAX_FUNCTIONS
Definition: afd.h:93
#define TAG_AFD_DATA_BUFFER
Definition: afd.h:38
#define TAG_AFD_TRANSPORT_ADDRESS
Definition: afd.h:39
#define FUNCTION_DISCONNECT
Definition: afd.h:90
#define FUNCTION_SEND
Definition: afd.h:87
LONG NTSTATUS
Definition: precomp.h:26
#define MIN(x, y)
Definition: rdesktop.h:171
#define MIN_TRACE
Definition: debug.h:14
#define MID_TRACE
Definition: debug.h:15
_In_ CDROM_SCAN_FOR_SPECIAL_INFO _In_ PCDROM_SCAN_FOR_SPECIAL_HANDLER Function
Definition: cdrom.h:1156
struct _FCB FCB
Definition: bufpool.h:45
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_HANDLE
Definition: d3dkmdt.h:40
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
#define Len
Definition: deflate.h:82
_In_ ULONG BufferSize
Definition: dispmprt.h:490
_In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ ULONG _In_ ULONG Flags
Definition: dispmprt.h:245
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define RTL_CONSTANT_STRING(s)
Definition: combase.c:35
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
DRIVER_INITIALIZE DriverEntry
Definition: main.c:9
#define L(x)
Definition: resources.c:13
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4138
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:523
NTSTATUS NTAPI AfdStreamSocketSuperConnect(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: connect.c:676
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:71
NTSTATUS NTAPI AfdGetContextSize(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: context.c:47
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:470
NTSTATUS AfdSuperAccept(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: listen.c:541
NTSTATUS AfdListenSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: listen.c:358
NTSTATUS AfdWaitForListen(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: listen.c:426
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
VOID UnlockBuffers(PAFD_WSABUF Buf, UINT Count, BOOL Address)
Definition: lock.c:289
VOID UnlockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lock.c:180
NTSTATUS QueueUserModeIrp(PAFD_FCB FCB, PIRP Irp, UINT Function)
Definition: lock.c:397
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
VOID SocketStateUnlock(PAFD_FCB FCB)
Definition: lock.c:370
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
PVOID GetLockedData(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lock.c:13
VOID RetryDisconnectCompletion(PAFD_FCB FCB)
Definition: main.c:708
NTSTATUS NTAPI AfdSetDisconnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:189
static DRIVER_UNLOAD AfdUnload
Definition: main.c:1339
static NTSTATUS NTAPI AfdQueryVolumeInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:879
BOOLEAN CheckUnlockExtraBuffers(PAFD_FCB FCB, PIO_STACK_LOCATION IrpSp)
Definition: main.c:1100
NTSTATUS NTAPI AfdSetDisconnectDataSize(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:230
static NTSTATUS NTAPI AfdGetTdiHandles(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:271
ULONG AfdSendWindowSize
Definition: main.c:28
static NTSTATUS NTAPI AfdCreateSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:303
static NTSTATUS NTAPI AfdCleanupSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:427
NTSTATUS AfdQueryFsDeviceInfo(PDEVICE_OBJECT DeviceObject, PFILE_FS_DEVICE_INFORMATION Buffer, PULONG Length)
Definition: main.c:860
void OskitDumpBuffer(PCHAR Data, UINT Len)
Definition: main.c:30
NTSTATUS NTAPI AfdSetDisconnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:77
static NTSTATUS NTAPI AfdDisconnect(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:720
VOID CleanupPendingIrp(PAFD_FCB FCB, PIRP Irp, PIO_STACK_LOCATION IrpSp, PAFD_ACTIVE_POLL Poll)
Definition: main.c:1149
static DRIVER_DISPATCH AfdDispatch
Definition: main.c:906
static IO_COMPLETION_ROUTINE DisconnectComplete
Definition: main.c:601
NTSTATUS NTAPI AfdSetDisconnectOptionsSize(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:118
static NTSTATUS NTAPI AfdCloseSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:461
ULONG AfdReceiveWindowSize
Definition: main.c:27
NTSTATUS NTAPI AfdGetDisconnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:47
NTSTATUS NTAPI AfdGetDisconnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:158
static NTSTATUS DoDisconnect(PAFD_FCB FCB)
Definition: main.c:673
NTSTATUS NTAPI AfdEnumEvents(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: select.c:328
VOID KillSelectsForFCB(PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, BOOLEAN OnlyExclusive)
Definition: select.c:125
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
VOID ZeroEvents(PAFD_HANDLE HandleArray, UINT HandleCount)
Definition: select.c:44
VOID PollReeval(PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
Definition: select.c:407
VOID SignalSocket(PAFD_ACTIVE_POLL Poll OPTIONAL, PIRP _Irp OPTIONAL, PAFD_POLL_INFO PollReq, NTSTATUS Status)
Definition: select.c:56
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:568
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
ULONG DebugTraceLevel
Definition: ndis.c:13
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
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 RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
#define PagedPool
Definition: env_spec_w32.h:308
unsigned long DWORD
Definition: ntddk_ex.h:95
@ FileFsDeviceInformation
Definition: from_kernel.h:222
enum _FSINFOCLASS FS_INFORMATION_CLASS
_Must_inspect_result_ _In_ PFILE_OBJECT NewFileObject
Definition: fsrtlfuncs.h:1357
#define IoFreeMdl
Definition: fxmdl.h:89
Status
Definition: gdiplustypes.h:24
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 DbgPrint
Definition: hal.h:12
unsigned int UINT
Definition: sysinfo.c:13
IoSetCancelRoutine(Irp, CancelRoutine)
if(dx< 0)
Definition: linetemp.h:194
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
Definition: mdlsup.c:1435
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
unsigned int * PUINT
Definition: ndis.h:50
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSTATUS NTAPI AfdConnectedSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Short)
Definition: read.c:446
NTSTATUS NTAPI AfdPacketSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: read.c:727
DRIVER_DISPATCH(nfs41_FsdDispatch)
struct _FILE_FS_DEVICE_INFORMATION FILE_FS_DEVICE_INFORMATION
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
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:1036
#define IoCompleteRequest
Definition: irp.c:1272
BOOLEAN NTAPI IoCancelIrp(IN PIRP Irp)
Definition: irp.c:1133
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
VOID NTAPI KeInitializeMutex(IN PKMUTEX Mutex, IN ULONG Level)
Definition: mutex.c:67
#define STATUS_FILE_CLOSED
Definition: ntstatus.h:626
#define STATUS_INVALID_INFO_CLASS
Definition: ntstatus.h:333
LONG_PTR FASTCALL ObfDereferenceObject(IN PVOID Object)
Definition: obref.c:317
unsigned short USHORT
Definition: pedump.c:61
#define FILE_DEVICE_NAMED_PIPE
Definition: winioctl.h:62
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define IOCTL_AFD_EVENT_SELECT
Definition: shared.h:349
#define IOCTL_AFD_GET_TDI_HANDLES
Definition: shared.h:311
#define AFD_DISCONNECT_RECV
Definition: shared.h:214
struct _AFD_CREATE_PACKET * PAFD_CREATE_PACKET
#define IOCTL_AFD_SET_INFO
Definition: shared.h:313
#define IOCTL_AFD_SET_DISCONNECT_OPTIONS
Definition: shared.h:327
#define AFD_EVENT_SEND
Definition: shared.h:221
#define IOCTL_AFD_WAIT_FOR_LISTEN
Definition: shared.h:291
#define IOCTL_AFD_SET_CONNECT_OPTIONS_SIZE
Definition: shared.h:339
#define IOCTL_AFD_GET_SOCK_NAME
Definition: shared.h:307
#define IOCTL_AFD_DEFER_ACCEPT
Definition: shared.h:351
#define IOCTL_AFD_START_LISTEN
Definition: shared.h:289
#define IOCTL_AFD_SET_CONNECT_OPTIONS
Definition: shared.h:323
#define IOCTL_AFD_GET_DISCONNECT_DATA
Definition: shared.h:333
#define IOCTL_AFD_SUPER_ACCEPT
Definition: shared.h:347
#define IOCTL_AFD_GET_CONTEXT
Definition: shared.h:317
#define IOCTL_AFD_SET_DISCONNECT_DATA_SIZE
Definition: shared.h:341
#define IOCTL_AFD_SELECT
Definition: shared.h:303
#define IOCTL_AFD_GET_DISCONNECT_OPTIONS
Definition: shared.h:335
#define IOCTL_AFD_RECV
Definition: shared.h:295
#define IOCTL_AFD_GET_INFO
Definition: shared.h:345
#define IOCTL_AFD_GET_CONTEXT_SIZE
Definition: shared.h:315
#define IOCTL_AFD_GET_CONNECT_OPTIONS
Definition: shared.h:331
#define IOCTL_AFD_SET_CONNECT_DATA
Definition: shared.h:321
#define AFD_CONNECTION_HANDLE
Definition: shared.h:178
#define IOCTL_AFD_CONNECT
Definition: shared.h:287
#define IOCTL_AFD_ACCEPT
Definition: shared.h:293
#define IOCTL_AFD_BIND
Definition: shared.h:285
#define IOCTL_AFD_DISCONNECT
Definition: shared.h:305
#define IOCTL_AFD_SEND_DATAGRAM
Definition: shared.h:301
#define AFD_EVENT_ABORT
Definition: shared.h:223
#define AFD_ADDRESS_HANDLE
Definition: shared.h:177
#define IOCTL_AFD_VALIDATE_GROUP
Definition: shared.h:357
#define IOCTL_AFD_SET_DISCONNECT_OPTIONS_SIZE
Definition: shared.h:343
#define IOCTL_AFD_SUPER_CONNECT
Definition: shared.h:359
#define IOCTL_AFD_RECV_DATAGRAM
Definition: shared.h:297
#define IOCTL_AFD_ENUM_NETWORK_EVENTS
Definition: shared.h:355
#define IOCTL_AFD_SET_DISCONNECT_DATA
Definition: shared.h:325
#define IOCTL_AFD_SEND
Definition: shared.h:299
#define AFD_ENDPOINT_CONNECTIONLESS
Definition: shared.h:169
#define IOCTL_AFD_GET_PENDING_CONNECT_DATA
Definition: shared.h:353
#define IOCTL_AFD_SET_CONNECT_DATA_SIZE
Definition: shared.h:337
#define IOCTL_AFD_GET_PEER_NAME
Definition: shared.h:309
#define IOCTL_AFD_SET_CONTEXT
Definition: shared.h:319
#define IOCTL_AFD_GET_CONNECT_DATA
Definition: shared.h:329
#define AFD_DISCONNECT_SEND
Definition: shared.h:213
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_In_ PVOID Context
Definition: storport.h:2269
PIRP Irp
Definition: afd.h:118
DWORD EndpointFlags
Definition: shared.h:22
WCHAR TransportName[1]
Definition: shared.h:25
DWORD SizeOfTransportName
Definition: shared.h:24
LIST_ENTRY Polls
Definition: afd.h:112
KSPIN_LOCK Lock
Definition: afd.h:113
LARGE_INTEGER Timeout
Definition: shared.h:153
ULONG DisconnectType
Definition: shared.h:152
Definition: afd.h:161
SOCK_SHARED_INFO SharedData
Definition: afd.h:162
ULONG HandleCount
Definition: shared.h:57
AFD_HANDLE Handles[1]
Definition: shared.h:59
ULONG BufferCount
Definition: shared.h:96
PAFD_WSABUF BufferArray
Definition: shared.h:95
ULONG BufferCount
Definition: shared.h:112
PAFD_WSABUF BufferArray
Definition: shared.h:111
HANDLE TdiConnectionHandle
Definition: shared.h:165
HANDLE TdiAddressHandle
Definition: shared.h:164
AFD_TDI_OBJECT Object
Definition: afd.h:140
HANDLE Handle
Definition: afd.h:133
PFILE_OBJECT Object
Definition: afd.h:132
Definition: cdstruc.h:902
ULONG Flags
Definition: ntfs.h:536
PFILE_OBJECT FileObject
Definition: ntfs.h:520
PFILE_OBJECT FileObject
Definition: iotypes.h:3171
struct _IO_STACK_LOCATION::@4925::@4938 QueryVolume
union _IO_STACK_LOCATION::@1803 Parameters
struct _IO_STACK_LOCATION::@1803::@1804 DeviceIoControl
IO_STATUS_BLOCK IoStatus
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
SOCKET_STATE State
Definition: shared.h:383
#define TDI_DISCONNECT_RELEASE
Definition: tdi.h:144
#define TDI_DISCONNECT_ABORT
Definition: tdi.h:143
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:1260
NTSTATUS TdiDisassociateAddressFile(PFILE_OBJECT ConnectionObject)
Disassociates a connection endpoint from an address file object.
Definition: tdi.c:414
#define STATUS_PENDING
Definition: telnetd.h:14
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint16_t * PWCHAR
Definition: typedefs.h:56
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_ ULONG IoctlCode
Definition: wdfiotarget.h:1043
#define FD_CLOSE_BIT
Definition: winsock2.h:297
#define FD_WRITE_BIT
Definition: winsock2.h:289
#define FO_NAMED_PIPE
Definition: iotypes.h:1782
#define IO_NO_INCREMENT
Definition: iotypes.h:598
* PFILE_OBJECT
Definition: iotypes.h:1998
#define IRP_MJ_CLEANUP
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778
#define ObDereferenceObject
Definition: obfuncs.h:203