Repository navigation
Expand file tree
/
Copy pathmisc.c
More file actions
4795 lines (3405 loc) · 108 KB
/
Copy pathmisc.c
File metadata and controls
4795 lines (3405 loc) · 108 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*++
Copyright (c) 1989 Microsoft Corporation
Module Name:
misc.c
Abstract:
This module contains the miscellaneous AFD routines.
Author:
David Treadwell (davidtr) 13-Nov-1992
Revision History:
--*/
#include "afdp.h"
#define TL_INSTANCE 0
#include <ipexport.h>
#include <tdiinfo.h>
#include <tcpinfo.h>
#include <ntddtcp.h>
VOID
AfdDoWork (
IN PVOID Context
);
NTSTATUS
AfdRestartDeviceControl (
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN PVOID Context
);
VOID
AfdUnlockDriver (
IN PVOID Context
);
#ifdef NT351
typedef struct _AFD_APC {
KAPC Apc;
} AFD_APC, *PAFD_APC;
VOID
AfdSpecialApc (
struct _KAPC *Apc,
PKNORMAL_ROUTINE *NormalRoutine,
PVOID *NormalContext,
PVOID *SystemArgument1,
PVOID *SystemArgument2
);
VOID
AfdSpecialApcRundown (
struct _KAPC *Apc
);
#endif // NT351
BOOLEAN
AfdCompareAddresses(
IN PTRANSPORT_ADDRESS Address1,
IN ULONG Address1Length,
IN PTRANSPORT_ADDRESS Address2,
IN ULONG Address2Length
);
PAFD_CONNECTION
AfdFindReturnedConnection(
IN PAFD_ENDPOINT Endpoint,
IN ULONG Sequence
);
#ifdef ALLOC_PRAGMA
#pragma alloc_text( PAGE, AfdCalcBufferArrayByteLengthRead )
#pragma alloc_text( PAGE, AfdCalcBufferArrayByteLengthWrite )
#pragma alloc_text( PAGE, AfdCopyBufferArrayToBuffer )
#pragma alloc_text( PAGE, AfdCopyBufferToBufferArray )
#pragma alloc_text( PAGEAFD, AfdAdvanceMdlChain )
#pragma alloc_text( PAGEAFD, AfdAllocateMdlChain )
#pragma alloc_text( PAGE, AfdQueryHandles )
#pragma alloc_text( PAGE, AfdGetInformation )
#pragma alloc_text( PAGE, AfdSetInformation )
#pragma alloc_text( PAGE, AfdSetInLineMode )
#pragma alloc_text( PAGE, AfdGetContext )
#pragma alloc_text( PAGE, AfdGetContextLength )
#pragma alloc_text( PAGE, AfdSetContext )
#pragma alloc_text( PAGE, AfdIssueDeviceControl )
#pragma alloc_text( PAGE, AfdSetEventHandler )
#pragma alloc_text( PAGE, AfdInsertNewEndpointInList )
#pragma alloc_text( PAGE, AfdRemoveEndpointFromList )
#pragma alloc_text( PAGEAFD, AfdCompleteIrpList )
#pragma alloc_text( PAGEAFD, AfdErrorEventHandler )
//#pragma alloc_text( PAGEAFD, AfdRestartDeviceControl ) // can't ever be paged!
#pragma alloc_text( PAGEAFD, AfdGetConnectData )
#pragma alloc_text( PAGEAFD, AfdSetConnectData )
#pragma alloc_text( PAGEAFD, AfdFreeConnectDataBuffers )
#pragma alloc_text( PAGEAFD, AfdSaveReceivedConnectData )
//#pragma alloc_text( PAGEAFD, AfdDoWork )
#pragma alloc_text( PAGEAFD, AfdAllocateWorkItem )
#pragma alloc_text( PAGEAFD, AfdQueueWorkItem )
#pragma alloc_text( PAGEAFD, AfdFreeWorkItem )
#if DBG
#pragma alloc_text( PAGEAFD, AfdIoCallDriverDebug )
#pragma alloc_text( PAGEAFD, AfdAllocateWorkItemPool )
#pragma alloc_text( PAGEAFD, AfdFreeWorkItemPool )
#else
#pragma alloc_text( PAGEAFD, AfdIoCallDriverFree )
#endif
#ifdef NT351
#pragma alloc_text( PAGE, AfdReferenceEventObjectByHandle )
#pragma alloc_text( PAGE, AfdQueueUserApc )
#pragma alloc_text( PAGE, AfdSpecialApc )
#pragma alloc_text( PAGE, AfdSpecialApcRundown )
#endif
#pragma alloc_text( PAGE, AfdSetQos )
#pragma alloc_text( PAGE, AfdGetQos )
#pragma alloc_text( PAGE, AfdNoOperation )
#pragma alloc_text( PAGE, AfdValidateGroup )
#pragma alloc_text( PAGE, AfdCompareAddresses )
#pragma alloc_text( PAGE, AfdGetUnacceptedConnectData )
#pragma alloc_text( PAGE, AfdFindReturnedConnection )
#endif
VOID
AfdCompleteIrpList (
IN PLIST_ENTRY IrpListHead,
IN PKSPIN_LOCK SpinLock,
IN NTSTATUS Status,
IN PAFD_IRP_CLEANUP_ROUTINE CleanupRoutine OPTIONAL
)
/*++
Routine Description:
Completes a list of IRPs with the specified status.
Arguments:
IrpListHead - the head of the list of IRPs to complete.
SpinLock - a lock which protects the list of IRPs.
Status - the status to use for completing the IRPs.
CleanupRoutine - a pointer to an optional IRP cleanup routine called
before the IRP is completed.
Return Value:
None.
--*/
{
PLIST_ENTRY listEntry;
PIRP irp;
KIRQL oldIrql;
KIRQL cancelIrql;
IoAcquireCancelSpinLock( &cancelIrql );
AfdAcquireSpinLock( SpinLock, &oldIrql );
while ( !IsListEmpty( IrpListHead ) ) {
//
// Remove the first IRP from the list, get a pointer to
// the IRP and reset the cancel routine in the IRP. The
// IRP is no longer cancellable.
//
listEntry = RemoveHeadList( IrpListHead );
irp = CONTAINING_RECORD( listEntry, IRP, Tail.Overlay.ListEntry );
IoSetCancelRoutine( irp, NULL );
//
// If we have a cleanup routine, call it.
//
if( CleanupRoutine != NULL ) {
(CleanupRoutine)( irp );
}
//
// We must release the locks in order to actually
// complete the IRP. It is OK to release these locks
// because we don't maintain any absolute pointer into
// the list; the loop termination condition is just
// whether the list is completely empty.
//
AfdReleaseSpinLock( SpinLock, oldIrql );
IoReleaseCancelSpinLock( cancelIrql );
//
// Complete the IRP.
//
irp->IoStatus.Status = Status;
irp->IoStatus.Information = 0;
IoCompleteRequest( irp, AfdPriorityBoost );
//
// Reacquire the locks and continue completing IRPs.
//
IoAcquireCancelSpinLock( &cancelIrql );
AfdAcquireSpinLock( SpinLock, &oldIrql );
}
AfdReleaseSpinLock( SpinLock, oldIrql );
IoReleaseCancelSpinLock( cancelIrql );
return;
} // AfdCompleteIrpList
NTSTATUS
AfdErrorEventHandler (
IN PVOID TdiEventContext,
IN NTSTATUS Status
)
{
IF_DEBUG(CONNECT) {
KdPrint(( "AfdErrorEventHandler called for endpoint %lx\n",
TdiEventContext ));
}
return STATUS_SUCCESS;
} // AfdErrorEventHandler
VOID
AfdInsertNewEndpointInList (
IN PAFD_ENDPOINT Endpoint
)
/*++
Routine Description:
Inserts a new endpoint in the global list of AFD endpoints. If this
is the first endpoint, then this routine does various allocations to
prepare AFD for usage.
Arguments:
Endpoint - the endpoint being added.
Return Value:
None.
--*/
{
PAGED_CODE( );
//
// Acquire a lock which prevents other threads from performing this operation.
//
ExAcquireResourceExclusiveLite( AfdResource, TRUE );
InterlockedIncrement( &AfdEndpointsOpened );
//
// If the list of endpoints is empty, do some allocations.
//
if ( IsListEmpty( &AfdEndpointListHead ) )
{
//
// Tell MM to revert to normal paging semantics.
//
MmResetDriverPaging( DriverEntry );
//
// Lock down the AFD section that cannot be pagable if any sockets are open.
//
ASSERT( AfdDiscardableCodeHandle == NULL );
AfdDiscardableCodeHandle = MmLockPagableCodeSection( AfdGetBuffer );
ASSERT( AfdDiscardableCodeHandle != NULL );
AfdLoaded = TRUE;
}
//
// Add the endpoint to the list(s).
//
ExInterlockedInsertHeadList(
&AfdEndpointListHead,
&Endpoint->GlobalEndpointListEntry,
&AfdSpinLock
);
if( Endpoint->GroupType == GroupTypeConstrained )
{
ExInterlockedInsertHeadList(
&AfdConstrainedEndpointListHead,
&Endpoint->ConstrainedEndpointListEntry,
&AfdSpinLock
);
}
//
// Release the lock and return.
//
ExReleaseResourceLite( AfdResource );
return;
} // AfdInsertNewEndpointInList
VOID
AfdRemoveEndpointFromList (
IN PAFD_ENDPOINT Endpoint
)
/*++
Routine Description:
Removes a new endpoint from the global list of AFD endpoints. If
this is the last endpoint in the list, then this routine does
various deallocations to save resource utilization.
Arguments:
Endpoint - the endpoint being removed.
Return Value:
None.
--*/
{
PAGED_CODE( );
//
// Acquire a lock which prevents other threads from performing this
// operation.
//
ExAcquireResourceExclusiveLite( AfdResource, TRUE );
InterlockedIncrement(
&AfdEndpointsClosed
);
//
// Remove the endpoint from the list(s).
//
AfdInterlockedRemoveEntryList(
&Endpoint->GlobalEndpointListEntry,
&AfdSpinLock
);
if( Endpoint->GroupType == GroupTypeConstrained ) {
AfdInterlockedRemoveEntryList(
&Endpoint->ConstrainedEndpointListEntry,
&AfdSpinLock
);
}
//
// If the list of endpoints is now empty, do some deallocations.
//
if ( IsListEmpty( &AfdEndpointListHead ) ) {
PAFD_WORK_ITEM afdWorkItem;
//
// Unlock the AFD section that can be pagable when no sockets
// are open.
//
ASSERT( IsListEmpty( &AfdConstrainedEndpointListHead ) );
ASSERT( AfdDiscardableCodeHandle != NULL );
MmUnlockPagableImageSection( AfdDiscardableCodeHandle );
AfdDiscardableCodeHandle = NULL;
//
// Queue off an executive worker thread to unlock AFD. We do
// this using special hacks in the AFD worker thread code so
// that we don't need to acuire a spin lock after the unlock.
//
afdWorkItem = AfdAllocateWorkItem();
ASSERT( afdWorkItem != NULL );
AfdQueueWorkItem( AfdUnlockDriver, afdWorkItem );
}
//
// Release the lock and return.
//
ExReleaseResourceLite( AfdResource );
return;
} // AfdRemoveEndpointFromList
VOID
AfdUnlockDriver (
IN PVOID Context
)
{
//
// Free the work item allocated in AdfRemoveEndpointFromList().
//
AfdFreeWorkItem( (PAFD_WORK_ITEM)Context );
//
// Acquire a lock which prevents other threads from performing this
// operation.
//
ExAcquireResourceExclusiveLite( AfdResource, TRUE );
//
// Test whether the endpoint list remains empty. If it is still
// empty, we can proceed with unlocking the driver. If a new
// endpoint has been placed on the list, then do not make AFD
// pagable.
//
if ( IsListEmpty( &AfdEndpointListHead ) ) {
//
// Tell MM that it can page all of AFD as it desires.
//
AfdLoaded = FALSE;
MmPageEntireDriver( DriverEntry );
}
ExReleaseResourceLite( AfdResource );
} // AfdUnlockDriver
VOID
AfdInterlockedRemoveEntryList (
IN PLIST_ENTRY ListEntry,
IN PKSPIN_LOCK SpinLock
)
{
KIRQL oldIrql;
//
// Our own routine since EX doesn't have a version of this....
//
AfdAcquireSpinLock( SpinLock, &oldIrql );
RemoveEntryList( ListEntry );
AfdReleaseSpinLock( SpinLock, oldIrql );
} // AfdInterlockedRemoveEntryList
NTSTATUS
AfdQueryHandles (
IN PIRP Irp,
IN PIO_STACK_LOCATION IrpSp
)
/*++
Routine Description:
Returns information about the TDI handles corresponding to an AFD
endpoint. NULL is returned for either the connection handle or the
address handle (or both) if the endpoint does not have that particular
object.
Arguments:
Irp - Pointer to I/O request packet.
IrpSp - pointer to the IO stack location to use for this request.
Return Value:
NTSTATUS -- Indicates whether the request was successfully queued.
--*/
{
PAFD_ENDPOINT endpoint;
PAFD_HANDLE_INFO handleInfo;
ULONG getHandleInfo;
NTSTATUS status;
PAGED_CODE( );
//
// Set up local pointers.
//
endpoint = IrpSp->FileObject->FsContext;
ASSERT( IS_AFD_ENDPOINT_TYPE( endpoint ) );
handleInfo = Irp->AssociatedIrp.SystemBuffer;
//
// Make sure that the input and output buffers are large enough.
//
if ( IrpSp->Parameters.DeviceIoControl.InputBufferLength <
sizeof(getHandleInfo) ||
IrpSp->Parameters.DeviceIoControl.OutputBufferLength <
sizeof(*handleInfo) ) {
return STATUS_BUFFER_TOO_SMALL;
}
//
// Determine which handles we need to get.
//
getHandleInfo = *(PULONG)Irp->AssociatedIrp.SystemBuffer;
//
// If no handle information or invalid handle information was
// requested, fail.
//
if ( (getHandleInfo &
~(AFD_QUERY_ADDRESS_HANDLE | AFD_QUERY_CONNECTION_HANDLE)) != 0 ||
getHandleInfo == 0 ) {
return STATUS_INVALID_PARAMETER;
}
//
// Initialize the output buffer.
//
handleInfo->TdiAddressHandle = NULL;
handleInfo->TdiConnectionHandle = NULL;
//
// If the caller requested a TDI address handle and we have an
// address handle for this endpoint, dupe the address handle to the
// user process.
//
if ( (getHandleInfo & AFD_QUERY_ADDRESS_HANDLE) != 0 &&
endpoint->State != AfdEndpointStateOpen &&
endpoint->AddressHandle != NULL ) {
ASSERT( endpoint->AddressFileObject != NULL );
status = ObOpenObjectByPointer(
endpoint->AddressFileObject,
OBJ_CASE_INSENSITIVE,
NULL,
GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE,
*IoFileObjectType,
KernelMode,
&handleInfo->TdiAddressHandle
);
if ( !NT_SUCCESS(status) ) {
return status;
}
}
//
// If the caller requested a TDI connection handle and we have a
// connection handle for this endpoint, dupe the connection handle
// to the user process.
//
if ( (getHandleInfo & AFD_QUERY_CONNECTION_HANDLE) != 0 &&
endpoint->Type == AfdBlockTypeVcConnecting &&
endpoint->Common.VcConnecting.Connection != NULL &&
endpoint->Common.VcConnecting.Connection->Handle != NULL ) {
ASSERT( endpoint->Common.VcConnecting.Connection->Type == AfdBlockTypeConnection );
ASSERT( endpoint->Common.VcConnecting.Connection->FileObject != NULL );
status = ObOpenObjectByPointer(
endpoint->Common.VcConnecting.Connection->FileObject,
OBJ_CASE_INSENSITIVE,
NULL,
GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE,
*IoFileObjectType,
KernelMode,
&handleInfo->TdiConnectionHandle
);
if ( !NT_SUCCESS(status) ) {
if ( handleInfo->TdiAddressHandle != NULL ) {
ZwClose( handleInfo->TdiAddressHandle );
}
return status;
}
}
Irp->IoStatus.Information = sizeof(*handleInfo);
return STATUS_SUCCESS;
} // AfdQueryHandles
NTSTATUS
AfdGetInformation (
IN PIRP Irp,
IN PIO_STACK_LOCATION IrpSp
)
/*++
Routine Description:
Gets information in the endpoint.
Arguments:
Irp - Pointer to I/O request packet.
IrpSp - pointer to the IO stack location to use for this request.
Return Value:
NTSTATUS -- Indicates whether the request was successfully queued.
--*/
{
PAFD_ENDPOINT endpoint;
PAFD_CONNECTION connection;
PAFD_INFORMATION afdInfo;
PVOID additionalInfo;
ULONG additionalInfoLength;
TDI_REQUEST_KERNEL_QUERY_INFORMATION kernelQueryInfo;
TDI_CONNECTION_INFORMATION connectionInfo;
NTSTATUS status;
LONGLONG currentTime;
LONGLONG connectTime;
PAGED_CODE( );
//
// Set up local pointers.
//
endpoint = IrpSp->FileObject->FsContext;
ASSERT( IS_AFD_ENDPOINT_TYPE( endpoint ) );
afdInfo = Irp->AssociatedIrp.SystemBuffer;
//
// Make sure that the input and output buffers are large enough.
//
if ( IrpSp->Parameters.DeviceIoControl.InputBufferLength <
sizeof(*afdInfo) ||
IrpSp->Parameters.DeviceIoControl.OutputBufferLength <
sizeof(*afdInfo) ) {
return STATUS_BUFFER_TOO_SMALL;
}
//
// Figure out the additional information, if any.
//
additionalInfo = afdInfo + 1;
additionalInfoLength =
IrpSp->Parameters.DeviceIoControl.InputBufferLength - sizeof(*afdInfo);
//
// Set up appropriate information in the endpoint.
//
switch ( afdInfo->InformationType ) {
case AFD_MAX_PATH_SEND_SIZE:
//
// Set up a query to the TDI provider to obtain the largest
// datagram that can be sent to a particular address.
//
kernelQueryInfo.QueryType = TDI_QUERY_MAX_DATAGRAM_INFO;
kernelQueryInfo.RequestConnectionInformation = &connectionInfo;
connectionInfo.UserDataLength = 0;
connectionInfo.UserData = NULL;
connectionInfo.OptionsLength = 0;
connectionInfo.Options = NULL;
connectionInfo.RemoteAddressLength = additionalInfoLength;
connectionInfo.RemoteAddress = additionalInfo;
//
// Ask the TDI provider for the information.
//
status = AfdIssueDeviceControl(
NULL,
endpoint->AddressFileObject,
&kernelQueryInfo,
sizeof(kernelQueryInfo),
&afdInfo->Information.Ulong,
sizeof(afdInfo->Information.Ulong),
TDI_QUERY_INFORMATION
);
//
// If the request succeeds, use this information. Otherwise,
// fall through and use the transport's global information.
// This is done because not all transports support this
// particular TDI request, and for those which do not the
// global information is a reasonable approximation.
//
if ( NT_SUCCESS(status) ) {
break;
}
case AFD_MAX_SEND_SIZE:
//
// Return the MaxSendSize or MaxDatagramSendSize from the
// TDI_PROVIDER_INFO based on whether or not this is a datagram
// endpoint.
//
if ( IS_DGRAM_ENDPOINT(endpoint) ) {
afdInfo->Information.Ulong =
endpoint->TransportInfo->ProviderInfo.MaxDatagramSize;
} else {
afdInfo->Information.Ulong =
endpoint->TransportInfo->ProviderInfo.MaxSendSize;
}
break;
case AFD_SENDS_PENDING:
//
// If this is an endpoint on a bufferring transport, no sends
// are pending in AFD. If it is on a nonbufferring transport,
// return the count of sends pended in AFD.
//
if ( endpoint->TdiBufferring || endpoint->Type != AfdBlockTypeVcConnecting ) {
afdInfo->Information.Ulong = 0;
} else {
afdInfo->Information.Ulong =
endpoint->Common.VcConnecting.Connection->VcBufferredSendCount;
}
break;
case AFD_RECEIVE_WINDOW_SIZE:
//
// Return the default receive window.
//
afdInfo->Information.Ulong = AfdReceiveWindowSize;
break;
case AFD_SEND_WINDOW_SIZE:
//
// Return the default send window.
//
afdInfo->Information.Ulong = AfdSendWindowSize;
break;
case AFD_CONNECT_TIME:
//
// If the endpoint is not yet connected, return -1. Otherwise,
// calculate the number of seconds that the connection has been
// active.
//
if ( endpoint->State != AfdEndpointStateConnected ||
endpoint->EndpointType == AfdEndpointTypeDatagram ) {
afdInfo->Information.Ulong = 0xFFFFFFFF;
} else {
connection = AFD_CONNECTION_FROM_ENDPOINT( endpoint );
ASSERT( connection != NULL );
ASSERT( connection->Type == AfdBlockTypeConnection );
//
// Calculate how long the connection has been active by
// subtracting the time at which the connection started from
// the current time. Note that we convert the units of the
// time value from 100s of nanoseconds to seconds.
//
KeQuerySystemTime( (PLARGE_INTEGER)¤tTime );
connectTime = (currentTime - connection->ConnectTime);
connectTime /= 10*1000*1000;
//
// We can safely convert this to a ULONG because it takes
// 127 years to overflow a ULONG counting seconds. The
// bizarre conversion to a LARGE_INTEGER is required to
// prevent the compiler from optimizing out the full 64-bit
// division above. Without this, the compiler would do only
// a 32-bit division and lose some information.
//
//afdInfo->Information.Ulong = (ULONG)connectTime;
afdInfo->Information.Ulong = ((PLARGE_INTEGER)&connectTime)->LowPart;
}
break;
case AFD_GROUP_ID_AND_TYPE : {
PAFD_GROUP_INFO groupInfo;
groupInfo = (PAFD_GROUP_INFO)&afdInfo->Information.LargeInteger;
//
// Return the endpoint's group ID and group type.
//
groupInfo->GroupID = endpoint->GroupID;
groupInfo->GroupType = endpoint->GroupType;
}
break;
default:
return STATUS_INVALID_PARAMETER;
}
Irp->IoStatus.Information = sizeof(*afdInfo);
Irp->IoStatus.Status = STATUS_SUCCESS;
return STATUS_SUCCESS;
} // AfdGetInformation
NTSTATUS
AfdSetInformation (
IN PIRP Irp,
IN PIO_STACK_LOCATION IrpSp
)
/*++
Routine Description:
Sets information in the endpoint.
Arguments:
Irp - Pointer to I/O request packet.
IrpSp - pointer to the IO stack location to use for this request.
Return Value:
NTSTATUS -- Indicates whether the request was successfully queued.
--*/
{
PAFD_ENDPOINT endpoint;
PAFD_CONNECTION connection;
PAFD_INFORMATION afdInfo;
NTSTATUS status;
PAGED_CODE( );
//
// Set up local pointers.
//
endpoint = IrpSp->FileObject->FsContext;
ASSERT( IS_AFD_ENDPOINT_TYPE( endpoint ) );
afdInfo = Irp->AssociatedIrp.SystemBuffer;
//
// Make sure that the input buffer is large enough.
//
if ( IrpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(*afdInfo) ) {
return STATUS_BUFFER_TOO_SMALL;
}
//
// Set up appropriate information in the endpoint.
//
switch ( afdInfo->InformationType ) {
case AFD_NONBLOCKING_MODE:
//
// Set the blocking mode of the endpoint. If TRUE, send and receive
// calls on the endpoint will fail if they cannot be completed
// immediately.
//
endpoint->NonBlocking = afdInfo->Information.Boolean;
break;
case AFD_CIRCULAR_QUEUEING:
//
// Enables circular queuing on the endpoint.
//
if( !IS_DGRAM_ENDPOINT( endpoint ) ) {
return STATUS_INVALID_PARAMETER;
}
endpoint->Common.Datagram.CircularQueueing = afdInfo->Information.Boolean;
break;
case AFD_INLINE_MODE:
//
// Set the inline mode of the endpoint. If TRUE, a receive for
// normal data will be completed with either normal data or
// expedited data. If the endpoint is connected, we need to
// tell the TDI provider that the endpoint is inline so that it
// delivers data to us in order. If the endpoint is not yet
// connected, then we will set the inline mode when we create
// the TDI connection object.
//
if ( endpoint->Type == AfdBlockTypeVcConnecting ) {
status = AfdSetInLineMode(
AFD_CONNECTION_FROM_ENDPOINT( endpoint ),
afdInfo->Information.Boolean
);
if ( !NT_SUCCESS(status) ) {
return status;
}
}
endpoint->InLine = afdInfo->Information.Boolean;
break;
case AFD_RECEIVE_WINDOW_SIZE:
case AFD_SEND_WINDOW_SIZE: {
LONG newBytes;
PCLONG maxBytes;
CLONG requestedCount;
PCSHORT maxCount;
#ifdef AFDDBG_QUOTA
PVOID chargeBlock;
PSZ chargeType;
#endif
//
// First determine where the appropriate limits are stored in the
// connection or endpoint. We do this so that we can use common
// code to charge quota and set the new counters.
//
if ( endpoint->Type == AfdBlockTypeVcConnecting ) {
connection = endpoint->Common.VcConnecting.Connection;
if ( afdInfo->InformationType == AFD_SEND_WINDOW_SIZE ) {
maxBytes = &connection->MaxBufferredSendBytes;
maxCount = &connection->MaxBufferredSendCount;
} else {
maxBytes = &connection->MaxBufferredReceiveBytes;