summaryrefslogtreecommitdiffstats
path: root/private/ntos/ndis/testprot/tpdrvr/tputils.c
blob: b16105ccf15c0338713149ebb1e8438f2d2ffa7b (plain) (blame)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
// *******************************
// 
// Copyright (c) 1990  Microsoft Corporation
// 
// Module Name:
// 
//     tputils.c
// 
// Abstract:
// 
//     This module implements the utility functions for the NDIS 3.0
//     Test Protocol Tester.
// 
// Author:
// 
//     Tom Adams (tomad) 14-Jul-1990
// 
// Environment:
// 
//     Kernel mode
// 
// Revision History:
// 
//     Tom Adams (tomad) 15-Dec-1990
//     seperate from testprot.c and add test control and statistics fcns.
// 
//     Tom Adams (tomad) 14-March-1991
//     add support for calling TpStress from command line with arguments.
// 
//     Tim Wynsma (timothyw) 5-18-94
//     Fixed warnings, some general cleanup
//
// ****************************

#include <ndis.h>
#include <stdlib.h>
#include <string.h>

#include "tpdefs.h"
#include "media.h"
#include "tpprocs.h"


PUCHAR
TpGetStatus(
    NDIS_STATUS GeneralStatus
    )
{
    static NDIS_STATUS Status[] = {
        NDIS_STATUS_SUCCESS,
        NDIS_STATUS_PENDING,
        NDIS_STATUS_NOT_RECOGNIZED,
        NDIS_STATUS_NOT_COPIED,
        NDIS_STATUS_ONLINE,
        NDIS_STATUS_RESET_START,
        NDIS_STATUS_RESET_END,
        NDIS_STATUS_RING_STATUS,
        NDIS_STATUS_CLOSED,

        NDIS_STATUS_WAN_LINE_UP,
        NDIS_STATUS_WAN_LINE_DOWN,
        NDIS_STATUS_WAN_FRAGMENT,

        NDIS_STATUS_NOT_RESETTABLE,
        NDIS_STATUS_SOFT_ERRORS,
        NDIS_STATUS_HARD_ERRORS,
        NDIS_STATUS_FAILURE,
        NDIS_STATUS_RESOURCES,
        NDIS_STATUS_CLOSING,
        NDIS_STATUS_BAD_VERSION,
        NDIS_STATUS_BAD_CHARACTERISTICS,
        NDIS_STATUS_ADAPTER_NOT_FOUND,
        NDIS_STATUS_OPEN_FAILED,
        NDIS_STATUS_DEVICE_FAILED,
        NDIS_STATUS_MULTICAST_FULL,
        NDIS_STATUS_MULTICAST_EXISTS,
        NDIS_STATUS_MULTICAST_NOT_FOUND,
        NDIS_STATUS_REQUEST_ABORTED,
        NDIS_STATUS_RESET_IN_PROGRESS,
        NDIS_STATUS_CLOSING_INDICATING,
        NDIS_STATUS_NOT_SUPPORTED,
        NDIS_STATUS_INVALID_PACKET,
        NDIS_STATUS_OPEN_LIST_FULL,
        NDIS_STATUS_ADAPTER_NOT_READY,
        NDIS_STATUS_ADAPTER_NOT_OPEN,
        NDIS_STATUS_NOT_INDICATING,
        NDIS_STATUS_INVALID_LENGTH,
        NDIS_STATUS_INVALID_DATA,
        NDIS_STATUS_BUFFER_TOO_SHORT,
        NDIS_STATUS_INVALID_OID,
        NDIS_STATUS_ADAPTER_REMOVED,
        NDIS_STATUS_UNSUPPORTED_MEDIA,
        NDIS_STATUS_GROUP_ADDRESS_IN_USE,
        NDIS_STATUS_FILE_NOT_FOUND,
        NDIS_STATUS_ERROR_READING_FILE,
        NDIS_STATUS_ALREADY_MAPPED,
        NDIS_STATUS_RESOURCE_CONFLICT,
        NDIS_STATUS_TOKEN_RING_OPEN_ERROR,
        TP_STATUS_NO_SERVERS,
        TP_STATUS_NO_EVENTS
    };

    static PUCHAR String[] = {
        "NDIS_STATUS_SUCCESS",
        "NDIS_STATUS_PENDING",
        "NDIS_STATUS_NOT_RECOGNIZED",
        "NDIS_STATUS_NOT_COPIED",
        "NDIS_STATUS_ONLINE",
        "NDIS_STATUS_RESET_START",
        "NDIS_STATUS_RESET_END",
        "NDIS_STATUS_RING_STATUS",
        "NDIS_STATUS_CLOSED",
        "NDIS_STATUS_WAN_LINE_UP",
        "NDIS_STATUS_WAN_LINE_DOWN",
        "NDIS_STATUS_WAN_FRAGMENT",
        "NDIS_STATUS_NOT_RESETTABLE",
        "NDIS_STATUS_SOFT_ERRORS",
        "NDIS_STATUS_HARD_ERRORS",
        "NDIS_STATUS_FAILURE",
        "NDIS_STATUS_RESOURCES",
        "NDIS_STATUS_CLOSING",
        "NDIS_STATUS_BAD_VERSION",
        "NDIS_STATUS_BAD_CHARACTERISTICS",
        "NDIS_STATUS_ADAPTER_NOT_FOUND",
        "NDIS_STATUS_OPEN_FAILED",
        "NDIS_STATUS_DEVICE_FAILED",
        "NDIS_STATUS_MULTICAST_FULL",
        "NDIS_STATUS_MULTICAST_EXISTS",
        "NDIS_STATUS_MULTICAST_NOT_FOUND",
        "NDIS_STATUS_REQUEST_ABORTED",
        "NDIS_STATUS_RESET_IN_PROGRESS",
        "NDIS_STATUS_CLOSING_INDICATING",
        "NDIS_STATUS_NOT_SUPPORTED",
        "NDIS_STATUS_INVALID_PACKET",
        "NDIS_STATUS_OPEN_LIST_FULL",
        "NDIS_STATUS_ADAPTER_NOT_READY",
        "NDIS_STATUS_ADAPTER_NOT_OPEN",
        "NDIS_STATUS_NOT_INDICATING",
        "NDIS_STATUS_INVALID_LENGTH",
        "NDIS_STATUS_INVALID_DATA",
        "NDIS_STATUS_BUFFER_TOO_SHORT",
        "NDIS_STATUS_INVALID_OID",
        "NDIS_STATUS_ADAPTER_REMOVED",
        "NDIS_STATUS_UNSUPPORTED_MEDIA",
        "NDIS_STATUS_GROUP_ADDRESS_IN_USE",
        "NDIS_STATUS_FILE_NOT_FOUND",
        "NDIS_STATUS_ERROR_READING_FILE",
        "NDIS_STATUS_ALREADY_MAPPED",
        "NDIS_STATUS_RESOURCE_CONFLICT",
        "NDIS_STATUS_TOKEN_RING_OPEN_ERROR",
        "TP_STATUS_NO_SERVERS",
        "TP_STATUS_NO_EVENTS"
    };

    static UCHAR BadStatus[] = "UNDEFINED";

#define StatusCount (sizeof(Status)/sizeof(NDIS_STATUS))

    INT i;

    for (i=0; i<StatusCount; i++)
    { 
        if (GeneralStatus == Status[i])
        {
            return String[i];
        }
    }
    return BadStatus;

#undef StatusCount
}



NDIS_STATUS
TpInitStressArguments(
    PSTRESS_ARGUMENTS *StressArguments,
    PCMD_ARGS CmdArgs
    )

// --------
// 
// Routine Description:
// 
// Arguments:
// 
//     The arguments for the test to be run.
// 
// Return Value:
// 
//  ------

{
    NDIS_STATUS Status;

    Status = NdisAllocateMemory((PVOID *)StressArguments,
                                sizeof( STRESS_ARGUMENTS ),
                                0,
                                HighestAddress );

    if ( Status != NDIS_STATUS_SUCCESS ) 
    {
        IF_TPDBG (TP_DEBUG_RESOURCES) 
        {
            TpPrint0("TpInitStressArguments: unable to allocate Argument buffer.\n");
        }
        return NDIS_STATUS_RESOURCES;
    } 
    else 
    {
        NdisZeroMemory( *StressArguments,sizeof( STRESS_ARGUMENTS ));
    }


    (*StressArguments)->MemberType = CmdArgs->ARGS.TPSTRESS.MemberType;
    (*StressArguments)->PacketType = CmdArgs->ARGS.TPSTRESS.PacketType;
    (*StressArguments)->PacketSize = CmdArgs->ARGS.TPSTRESS.PacketSize;
    (*StressArguments)->PacketMakeUp = CmdArgs->ARGS.TPSTRESS.PacketMakeUp;
    (*StressArguments)->ResponseType = CmdArgs->ARGS.TPSTRESS.ResponseType;
    (*StressArguments)->Iterations = 0;
    (*StressArguments)->TotalIterations = CmdArgs->ARGS.TPSTRESS.TotalIterations;
    (*StressArguments)->TotalPackets = CmdArgs->ARGS.TPSTRESS.TotalPackets;
    (*StressArguments)->AllPacketsSent = FALSE;
    (*StressArguments)->DelayType  = CmdArgs->ARGS.TPSTRESS.DelayType;
    (*StressArguments)->DelayLength = CmdArgs->ARGS.TPSTRESS.DelayLength;
    (*StressArguments)->WindowEnabled = (UCHAR)CmdArgs->ARGS.TPSTRESS.WindowEnabled;
    (*StressArguments)->DataChecking = (UCHAR)CmdArgs->ARGS.TPSTRESS.DataChecking;
    (*StressArguments)->PacketsFromPool = (UCHAR)CmdArgs->ARGS.TPSTRESS.PacketsFromPool;
    (*StressArguments)->BeginReceives = FALSE;
    (*StressArguments)->ServerContinue = TRUE;

    return NDIS_STATUS_SUCCESS;
}



NDIS_STATUS
TpInitServerArguments(
    PSTRESS_ARGUMENTS *StressArguments
    )

// -----------
// 
// Routine Description:
// 
// Arguments:
// 
//     The arguments for the test to be run.
// 
// Return Value:
// 
//  ----------------

{
    NDIS_STATUS Status;

    Status = NdisAllocateMemory((PVOID *)StressArguments,
                                sizeof( STRESS_ARGUMENTS ),
                                0,
                                HighestAddress );

    if ( Status != NDIS_STATUS_SUCCESS ) 
    {
        IF_TPDBG (TP_DEBUG_RESOURCES) 
        {
            TpPrint0("TpInitServerArguments: unable to allocate Argument buffer.\n");
        }
        return NDIS_STATUS_RESOURCES;
    } 
    else 
    {
        NdisZeroMemory( *StressArguments,sizeof( STRESS_ARGUMENTS ));
    }

    (*StressArguments)->MemberType = TP_SERVER;
    (*StressArguments)->PacketType = 0;
    (*StressArguments)->PacketSize = 100;
    (*StressArguments)->PacketMakeUp = RAND;
    (*StressArguments)->ResponseType = ACK_EVERY;
    (*StressArguments)->Iterations = 0;
    (*StressArguments)->TotalIterations = 0;
    (*StressArguments)->TotalPackets = 0;
    (*StressArguments)->AllPacketsSent = FALSE;
    (*StressArguments)->DelayType  = 0;
    (*StressArguments)->DelayLength = FIXEDDELAY;
    (*StressArguments)->WindowEnabled = TRUE;
    (*StressArguments)->DataChecking = FALSE;
    (*StressArguments)->PacketsFromPool = TRUE;
    (*StressArguments)->BeginReceives = FALSE;
    (*StressArguments)->ServerContinue = TRUE;

    return NDIS_STATUS_SUCCESS;
}



VOID
TpStressWriteResults(
    IN POPEN_BLOCK OpenP
    )

// ---------
// 
// Routine Description:
// 
// Arguments:
// 
// Return Value:
// 
//     None.
// 
// ---------

{
    PSTRESS_RESULTS OutputBuffer;

    NdisAcquireSpinLock( &OpenP->SpinLock );

    OutputBuffer = MmGetSystemAddressForMdl( OpenP->Stress->StressIrp->MdlAddress );

    RtlMoveMemory(  OutputBuffer,
                    OpenP->Stress->Results,
                    sizeof( STRESS_RESULTS ) );

    NdisReleaseSpinLock( &OpenP->SpinLock );
}



VOID
TpCopyClientStatistics(
    IN POPEN_BLOCK OpenP
    )

// --------
// 
// Routine Description:
// 
// Arguments:
// 
// Return Value:
// 
//     None.
// 
// ---------

{
    PSTRESS_RESULTS res;
    PGLOBAL_COUNTERS gc;
    PINSTANCE_COUNTERS ic;
    PINSTANCE_COUNTERS lc;
    PUCHAR p, q;
    USHORT i;

    p = OpenP->Stress->Results->Address;
    q = OpenP->StationAddress;

    for ( i=0;i<OpenP->Media->AddressLen;i++ ) 
    {
        *p++ = *q++;
    }

    res = OpenP->Stress->Results;
    gc = OpenP->GlobalCounters;

    res->OpenInstance = OpenP->OpenInstance;
    res->NumServers = OpenP->Stress->Client->NumServers;

    res->Global.Sends = gc->Sends;
    res->Global.SendComps = gc->SendComps;
    res->Global.Receives = gc->Receives;
    res->Global.ReceiveComps = gc->ReceiveComps;
    res->Global.CorruptRecs = gc->CorruptRecs;
    res->Global.InvalidPacketRecs = gc->InvalidPacketRecs;

    //
    // Now calculate the Packets Per Second value.
    //

    // first find the total number of test packets sent.

    gc->Sends = 0;
    gc->Receives = 0;

    for ( i = 0 ; i < OpenP->Stress->Client->NumServers ; i++ ) 
    {
        ic = OpenP->Stress->Client->Servers[i].Counters;
        gc->Sends += ic->Sends;
        gc->Receives += ic->Receives;
    }

    // find the total test time in Nanoseconds

    OpenP->Stress->EndTime = RtlLargeIntegerSubtract(   OpenP->Stress->EndTime,
                                                        OpenP->Stress->StartTime );
    // convert it to seconds.

    OpenP->Stress->EndTime = RtlExtendedLargeIntegerDivide( OpenP->Stress->EndTime,
                                                            10000000,
                                                            NULL );

    // then determine the packets per second value.
    // NOTE: we are assuming that the high part of time is now 0.

    res->PacketsPerSecond = OpenP->Stress->PacketsPerSecond =
        (( gc->Sends + gc->Receives ) / OpenP->Stress->EndTime.LowPart );

    //
    // Now copy the Server stats into the buffer.
    //

    for( i=0;i<OpenP->Stress->Client->NumServers;i++ ) 
    {
        ic = OpenP->Stress->Client->Servers[i].Counters;
        lc = &res->Servers[i].Instance;

        lc->Sends = ic->Sends;
        lc->SendPends = ic->SendPends;
        lc->SendComps = ic->SendComps;
        lc->SendFails = ic->SendFails;
        lc->Receives = ic->Receives;
        ic->ReceiveComps = ic->ReceiveComps;
        lc->CorruptRecs = ic->CorruptRecs;
    }
}



VOID
TpCopyServerStatistics(
    IN POPEN_BLOCK OpenP,
    IN PVOID Buffer,
    IN INT ServerReference
    )

// -----------
// 
// Routine Description:
// 
// Arguments:
// 
// Return Value:
// 
//     None.
// 
// -------------

{
    PSERVER_RESULTS res;
    PINSTANCE_COUNTERS ic;
    PGLOBAL_COUNTERS gc;
    PUCHAR p, q;
    USHORT i;

    res = &OpenP->Stress->Results->Servers[ServerReference];

    ic = (PINSTANCE_COUNTERS)((PUCHAR)Buffer +
                              (ULONG)sizeof( PACKET_INFO ) +
                              (ULONG)sizeof( STRESS_CONTROL ));

    gc = (PGLOBAL_COUNTERS)((PUCHAR)Buffer +
                            (ULONG)( sizeof( PACKET_INFO ) +
                                     sizeof( STRESS_CONTROL ) +
                                     sizeof( INSTANCE_COUNTERS )));

    res->OpenInstance = OpenP->Stress->Client->Servers[ServerReference].ServerInstance;

    res->StatsRcvd = TRUE;

    // p = res->Address;
    p = OpenP->Stress->Results->Servers[ServerReference].Address;
    q = OpenP->Stress->Client->Servers[ServerReference].Address;

    for ( i=0;i<OpenP->Media->AddressLen;i++ ) 
    {
        *p++ = *q++;
    }

    //
    // Now copy the servers instance counters into the results buffer array.
    //

    res->S_Instance.Sends = ic->Sends;
    res->S_Instance.SendPends = ic->SendPends;
    res->S_Instance.SendComps = ic->SendComps;
    res->S_Instance.SendFails = ic->SendFails;

    res->S_Instance.Receives = ic->Receives;
    res->S_Instance.ReceiveComps = ic->ReceiveComps;
    res->S_Instance.CorruptRecs = ic->CorruptRecs;

    res->S_Instance.XferData = ic->XferData;
    res->S_Instance.XferDataPends = ic->XferDataPends;
    res->S_Instance.XferDataComps = ic->XferDataComps;
    res->S_Instance.XferDataFails = ic->XferDataFails;

    //
    // and the servers global counters.
    //

    res->S_Global.Sends = gc->Sends;
    res->S_Global.SendComps = gc->SendComps;
    res->S_Global.Receives = gc->Receives;
    res->S_Global.ReceiveComps = gc->ReceiveComps;

    res->S_Global.CorruptRecs = gc->CorruptRecs;
    res->S_Global.InvalidPacketRecs = gc->InvalidPacketRecs;
}



VOID
TpWriteServerStatistics(
    IN POPEN_BLOCK OpenP,
    IN OUT PNDIS_PACKET Packet,
    IN PCLIENT_INFO Client
    )

// -----------------
// 
// Routine Description:
// 
// 
//     NOTE: This routine requires a packet with one single contiguous
//           buffer, it does not attempt to write to any other buffers.
// 
// Arguments:
// 
//     OpenP - A pointer to the OPEN_BLOCK describing the Server.
// 
// Return Value:
// 
//     None.
// 
// -----------------

{
    PNDIS_BUFFER Buffer;
    PUCHAR Memory;
    UINT BufLen;


    NdisQueryPacket(Packet,NULL,NULL,&Buffer,NULL);

    NdisQueryBuffer( Buffer,(PVOID *)&Memory,&BufLen );

    RtlMoveMemory(  Memory + sizeof( STRESS_PACKET ),
                    (PVOID)Client->Counters,
                    sizeof( INSTANCE_COUNTERS ) );

    RtlMoveMemory(  Memory + (ULONG) ( sizeof( STRESS_PACKET ) +
                                       sizeof( INSTANCE_COUNTERS )),
                    (PVOID)OpenP->GlobalCounters,
                    sizeof( GLOBAL_COUNTERS ) );
}



VOID
TpPrintClientStatistics(
    POPEN_BLOCK OpenP
    )

// --------------
// 
// Routine Description:
// 
//     This routine dumps the interesting statistics held in the Client's
//     Test Protocol data structures at the end of the test.
// 
// Arguments:
// 
//     OpenP - A pointer to the OPEN_BLOCK describing the Client.
// 
// Return Value:
// 
//     None.
// 
// --------------

{
    PGLOBAL_COUNTERS GCounters;
    PINSTANCE_COUNTERS ICounters;
    PSERVER_INFO Server;
    USHORT i;

    //
    // Print out the Client Network Address and Test Counters.
    //

    IF_TPDBG ( TP_DEBUG_STATISTICS ) 
    {
        TpPrint0("\n\t****** CLIENT STATISTICS ******\n\n");
        if ( OpenP->Media->MediumType == NdisMediumArcnet878_2 ) 
        {
            TpPrint1("\tLocal Address %x\t", OpenP->StationAddress[0]);
        } 
        else 
        {
            TpPrint6("\tLocal Address %x-%x-%x-%x-%x-%x\t",
                OpenP->StationAddress[0],OpenP->StationAddress[1],
                OpenP->StationAddress[2],OpenP->StationAddress[3],
                OpenP->StationAddress[4],OpenP->StationAddress[5]);
        }
        TpPrint1("OpenInstance %d\n",OpenP->OpenInstance);

        TpPrint0("\n\t****** Global Statistics ******\n\n");

        GCounters = OpenP->GlobalCounters;

        GCounters->Sends = 0;
        GCounters->Receives = 0;

        for (i=0;i<OpenP->Stress->Client->NumServers;i++) 
        {
            ICounters = OpenP->Stress->Client->Servers[i].Counters;
            GCounters->Sends += ICounters->Sends;
            GCounters->Receives += ICounters->Receives;
        }

        TpPrint1("\tTotal Packets Sent:\t\t%8lu\n",GCounters->Sends);
        TpPrint1("\tTotal Packets Received:\t\t%8lu\n",GCounters->Receives);
        TpPrint1("\tTotal Packets Lost:\t\t%8lu\n\n", GCounters->Sends-GCounters->Receives);

        TpPrint1("\tTotal Packet Sends Completed:\t%8lu\n", GCounters->SendComps);
        TpPrint1("\tTotal Packet Receives Completed:%8lu\n\n", GCounters->ReceiveComps);

        TpPrint1("\tCorrupted Packet Receives:\t%8lu\n", GCounters->CorruptRecs);
        TpPrint1("\tInvalid Packet Receives:\t%8lu\n", GCounters->InvalidPacketRecs);

        //
        // And then print out the information about each of the Servers
        // involved in the test.
        //

        TpPrint0("\n\t***** Remote Server Statistics ******\n\n");

        TpPrint1("\tClient at this address has %d Server(s) as follows:\n",
            OpenP->Stress->Client->NumServers);

        for (i=0;i<OpenP->Stress->Client->NumServers;i++) 
        {
            Server = &OpenP->Stress->Client->Servers[i];

            if ( OpenP->Media->MediumType == NdisMediumArcnet878_2 ) 
            {
                TpPrint1("\n\tRemote Server Address %x, ", Server->Address[0]);
            } 
            else 
            {
                TpPrint6("\n\tRemote Server Address %x-%x-%x-%x-%x-%x, ",
                    Server->Address[0],Server->Address[1],Server->Address[2],
                    Server->Address[3],Server->Address[4],Server->Address[5]);
            }

            TpPrint1("OpenInstance %d\n\n",Server->ServerInstance);

            ICounters = Server->Counters;

            TpPrint1("\tTotal Packets Sent To:\t\t%8lu\n", ICounters->Sends);
            TpPrint1("\tTotal Packets Received From:\t%8lu\n", ICounters->Receives);
            TpPrint1("\tTotal Packets Lost:\t\t%8lu\n\n", ICounters->Sends-ICounters->Receives);

            TpPrint1("\tPacket Sends Failed:\t\t%8lu\n", ICounters->SendFails);
            TpPrint1("\tPacket Sends Pended:\t\t%8lu\n", ICounters->SendPends);
            TpPrint1("\tPacket Sends Completed:\t\t%8lu\n\n", ICounters->SendComps);
        }
    }
}



VOID
TpPrintServerStatistics(
    POPEN_BLOCK OpenP,
    PCLIENT_INFO Client
    )

// --------------
// 
// Routine Description:
// 
//     This routine dumps the interesting statistics held in the Server's
//     Test Protocol data structures at the end of the test, and information
//     about the Client that the Server was cooperating with.
// 
// Arguments:
// 
//     OpenP - A pointer to the OPEN_BLOCK describing the Server.
// 
//     Client - A pointer to the CLIENT_INFO structure describing the
//              Client this Server was responding to.
// 
// Return Value:
// 
//     None.
// 
// ----------------

{
    PINSTANCE_COUNTERS ICounters;

    //
    // Print out the Server's Network Address and Test Counters.
    //
    IF_TPDBG ( TP_DEBUG_STATISTICS ) 
    {
        TpPrint0("\t****** SERVER STATISTICS ******\n\n");

        if ( OpenP->Media->MediumType == NdisMediumArcnet878_2 ) 
        {
            TpPrint1("\tLocal Address %x\t", OpenP->StationAddress[0]);
        } 
        else 
        {
            TpPrint6("\tLocal Address %x-%x-%x-%x-%x-%x\t",
                OpenP->StationAddress[0],OpenP->StationAddress[1],
                OpenP->StationAddress[2],OpenP->StationAddress[3],
                OpenP->StationAddress[4],OpenP->StationAddress[5]);
        }

        TpPrint1("OpenInstance %d\n",OpenP->OpenInstance);

        TpPrint0("\n\t****** Client Instance Statistics ******\n");

        if ( OpenP->Media->MediumType == NdisMediumArcnet878_2 ) 
        {
            TpPrint1("\n\tRemote Client Address %x, ", Client->Address[0]);
        } 
        else 
        {
            TpPrint6("\n\tRemote Client Address %x-%x-%x-%x-%x-%x, ",
                Client->Address[0],Client->Address[1],Client->Address[2],
                Client->Address[3],Client->Address[4],Client->Address[5]);
        }
        TpPrint1("OpenInstance %d\n\n",Client->ClientInstance);

        //
        // And then print out the information about the Client involved
        // in the test.
        //

        ICounters = Client->Counters;

        TpPrint1("\tPackets Received:\t\t%8lu\n",ICounters->Receives);
        TpPrint1("\tPackets Sent:\t\t\t%8lu\n",ICounters->Sends);
        TpPrint1("\tPackets Not Responded To:\t%8lu\n\n", ICounters->Receives-ICounters->Sends);

        TpPrint1("\tPacket Sends Failed:\t\t%8lu\n",ICounters->SendFails);
        TpPrint1("\tPacket Sends Pended:\t\t%8lu\n",ICounters->SendPends);
        TpPrint1("\tPacket Sends Completed:\t\t%8lu\n", ICounters->SendComps);
        TpPrint1("\tPacket Receives Completed:\t%8lu\n\n", ICounters->ReceiveComps);
    }
}



VOID
TpWriteSendReceiveResults(
    PINSTANCE_COUNTERS Counters,
    PIRP Irp
    )

// ------------
// 
// Routine Description:
// 
//     Write the SEND test statistics into the Output buffer passed
//     in by the IOCTL call.  The buffer is in the Irp->MdlAddress.
//     NOTE: The OpenP->SpinLock must be held when making this call.
// 
// Arguments:
// 
//     OpenP - The location of the Irp to find the Output buffer on.
// 
//     Counters - The counters to write into the Output buffer into.
// 
// Return Value:
// 
//     None.
// 
// -------------

{
    PSEND_RECEIVE_RESULTS OutputBuffer;

    //
    // Get the output buffer out of the MDL stored in the IRP, and map
    // it so we may write the statistics to it.
    //

    OutputBuffer = MmGetSystemAddressForMdl( Irp->MdlAddress );

    //
    // Write the statistics to the outbuffer
    //

    OutputBuffer->Signature    = SENDREC_RESULTS_SIGNATURE;
    OutputBuffer->ResultsExist = TRUE;

    OutputBuffer->Counters.Sends     = Counters->Sends;
    OutputBuffer->Counters.SendPends = Counters->SendPends;
    OutputBuffer->Counters.SendComps = Counters->SendComps;
    OutputBuffer->Counters.SendFails = Counters->SendFails;

    OutputBuffer->Counters.Receives     = Counters->Receives;
    OutputBuffer->Counters.ReceiveComps = Counters->ReceiveComps;
    OutputBuffer->Counters.CorruptRecs  = Counters->CorruptRecs;

    OutputBuffer->Counters.XferData      = Counters->XferData;
    OutputBuffer->Counters.XferDataPends = Counters->XferDataPends;
    OutputBuffer->Counters.XferDataComps = Counters->XferDataComps;
    OutputBuffer->Counters.XferDataFails = Counters->XferDataFails;
}



VOID
TpInitializePending(
    PPENDING Pend
    )

// ----------
// 
// Routine Description:
// 
//     This routine zeroes the counters in a PENDING_WATCH structure, and
//     sets up the storage area for pending packets.
// 
// Arguments:
// 
//     Pend - A pointer to the Pend Structure to be zeroed.
// 
// Return Value:
// 
//     None.
// 
// ----------

{
    INT i;

    //
    // set up the pending packet storage and counters.
    //

    Pend->PendingPackets = 0;
    Pend->PendingRequests = 0;
    Pend->PacketPendNumber = 0;
    Pend->PacketCompleteNumber = 0;

    for ( i=0 ; i<NUM_PACKET_PENDS ; i++ ) 
    {
        Pend->Packets[i] = NULL;
    }
}



VOID
TpInitializeStressResults(
    PSTRESS_RESULTS Results
    )

// ---------
// 
// Routine Description:
// 
// Arguments:
// 
// Return Value:
// 
//     None.
// 
// ---------

{
    INT i;

    NdisZeroMemory((PVOID)Results,sizeof( STRESS_RESULTS ));

    Results->Signature = STRESS_RESULTS_SIGNATURE;

    for ( i=0;i<MAX_SERVERS;i++ ) 
    {
        Results->Servers[i].Signature = STRESS_RESULTS_SIGNATURE;
    }
}


#if 0

//   do it on a per open basis.


VOID
TpDumpInfo(
    VOID
    )

// --------------
// 
// Routine Description:
// 
//     TpDumpInfo is a debugging routine that may be called from the kernel
//     debugger by resetting EIP to the entry of TpDumpInfo to dump the state
//     for the Test Protocol at any given time.
// 
//     NOTE: This routine does not reset the stack so care must be used if
//           one wishes to continue running the Test Protocol after this
//           procedure has executed.  This routine was designed to dump
//           the state of the Protocol after a system crash.
// 
// Arguments:
// 
//     None.
// 
// Return Value:
// 
//     None.
// 
// --------------

{
    static POPEN_BLOCK OpenP;
    static PSTRESS_ARGUMENTS Args;
    static PCLIENT_STORAGE Client;
    static PSERVER_STORAGE Server;
    static PGLOBAL_COUNTERS GCounters
    static PINSTANCE_COUNTERS ICounters;
    static INT i;

    OpenP = OpenList;

    TpPrint0("****** Open Block Structure ******\n\n");

    TpPrint1("Ndis Handle\t\t%10lX\n",OpenP->NdisBindingHandle);
    TpPrint1("Next Open Block\t\t%10lX\n",OpenP->Next);
    TpPrint1("Open Instance\t\t%10ld\n",OpenP->OpenInstance);

    if ( OpenP->Media->NdisMedium == NdisMediumArcnet878_2 ) 
    {
        TpPrint1("Machine Address  \t%x\n\n", OpenP->StationAddress[0] );
    } 
    else 
    {
        TpPrint6("Machine Address  \t%x-%x-%x-%x-%x-%x\n\n",
            OpenP->StationAddress[0],OpenP->StationAddress[1],
            OpenP->StationAddress[2],OpenP->StationAddress[3],
            OpenP->StationAddress[4],OpenP->StationAddress[5]);
    }

    TpPrint0("****** Test Arguments Structure ******\n\n");

    Args = OpenP->Arguments;

    TpPrint1("MemberType\t\t%10d\n",Args->MemberType);
    TpPrint1"PACKET_TYPE\t\t%10d\n",Args->PacketType);
    TpPrint1("Packet Size Value\t%10d\n",Args->PacketSize);
    TpPrint1("PACKET_MAKEUP\t\t%10d\n",Args->PacketMakeUp);
    TpPrint1("RESPONSE_TYPE\t\t%10d\n",Args->ResponseType);
    TpPrint1("Iterations So Far\t%10lu\n",Args->Iterations);
    TpPrint1("Total Iterations\t%10lu\n",Args->TotalIterations);
    TpPrint1("Total Packets\t\t%10lu\n",Args->TotalPackets);
    TpPrint1("Interpacket Delay\t%10lu\n",Args->DelayLength);
    TpPrint1("All Packets Sent?\t\t%s\n",(Args->AllPacketsSent) ? "TRUE" : "FALSE");
    TpPrint1("Window Enabled?\t\t\t%s\n",(Args->WindowEnabled) ? "TRUE" : "FALSE");
    TpPrint1("Data Checking?\t\t\t%s\n",(Args->DataChecking) ? "TRUE" : "FALSE");
    TpPrint1("Packets From Pool?\t\t%s\n",(Args->PacketsFromPool) ? "TRUE" : "FALSE");
    TpPrint1("Begin Receives?\t\t\t%s\n",(Args->BeginReceives) ? "TRUE" : "FALSE");
    TpPrint1("Server Continue?\t\t\t%s\n\n",(Args->ServerContinue) ? "TRUE" : "FALSE");

    TpPrint0("****** Global Counters Structure ******\n\n");

    GCounters = OpenP->GlobalCounters;

    TpPrint1("Packet Sends\t\t\t%10lu\n",GCounters->Sends);
    TpPrint1("Packet Receives\t\t%10lu\n",GCounters->Receives);
    TpPrint1("Corrupted Packet Receives\t%10lu\n",GCounters->CorruptRecs);
    TpPrint1("Invalid Protocol Receives\t%10lu\n",GCounters->InvalidPacketRecs);

    if (OpenP->Stress->Client != NULL) 
    {
        TpPrint0("****** Client Storage Structure ******\n\n");

        Client = OpenP->Stress->Client;

        TpPrint1("Number of Servers\t\t%10ld\n",Client->NumServers);
        TpPrint1("Packet Pool\t\t\t%10lX\n",Client->PacketPool);
        TpPrint1("Transmit Pool\t\t\t%10lX\n",Client->TransmitPool);

        TpPrint0("\n****** Servers with this Client ******\n\n");

        for (i=0;i<Client->NumServers;i++) 
        {
            TpPrint1("****** Server Number %d ******\n\n",i+1);
            TpPrint1("Server Instance\t\t\t%10ld\n",Client->Servers[i].ServerInstance);
            TpPrint1("Client Reference\t\t%10ld\n",Client->Servers[i].ClientReference);
            TpPrint1("Server Reference\t\t\t%10ld\n",Client->Servers[i].ServerReference);

            if ( OpenP->Media->NdisMedium == NdisMediumArcnet878_2 ) 
            {
                TpPrint1("Server[%d] Address\t%x\n",i, Client->Servers[i].Address[0]);
            } 
            else 
            {
                TpPrint6("Server[%d] Address\t%x-%x-%x-%x-%x-%x\n",i,
                    Client->Servers[i].Address[0],Client->Servers[i].Address[1],
                    Client->Servers[i].Address[2],Client->Servers[i].Address[3],
                    Client->Servers[i].Address[4],Client->Servers[i].Address[5]);
            }

            TpPrint1("Sequence Number\t\t\t%10lu\n",Client->Servers[i].SequenceNumber);
            TpPrint1("Max Sequence Number\t\t%10lu\n",Client->Servers[i].MaxSequenceNumber);
            TpPrint1("Packet Delay\t\t\t%10lu\n\n", Client->Servers[i].PacketDelay);

            ICounters = Client->Servers[i].Counters;

            TpPrint1("****** Server Number %d's Counters ******\n\n",i+1);
            TpPrint1("Packet Sends\t\t\t%10lu\n",ICounters->Sends);
            TpPrint1("Packet Send Pends\t\t%10lu\n",ICounters->SendPends);
            TpPrint1("Packet Send Completes\t\t%10lu\n",ICounters->SendComps);
            TpPrint1("Packet Send Fails\t\t%10lu\n",ICounters->SendFails);
            TpPrint1("Packet Receives\t\t\t%10lu\n",ICounters->Receives);
            TpPrint1("Corrupted Packet Receives\t%10lu\n",ICounters->CorruptRecs);
        }
    }

    if (OpenP->Stress->Server != NULL) 
    {
        TpPrint0("****** Server Storage Structure ******\n\n");

        Server = OpenP->Stress->Server;

        TpPrint1("Number of Clients\t%10ld\n",Server->NumClients);
        TpPrint1("Number of Active Clients%10ld\n",Server->ActiveClients);
        TpPrint1("Packet Pool\t\t%10lX\n",Server->PacketPool);
        TpPrint1("Transmit Pool\t\t%10lX\n\n",Server->TransmitPool);

        TpPrint0("******Clients with this Server******\n\n");

        for (i=0;i<Server->NumClients;i++) 
        {
            TpPrint1("****** Client Number %d ******\n\n",i+1);
            TpPrint1("Client Instance\t\t%10ld\n",Server->Clients[i].ClientInstance);
            TpPrint1("Client Reference\t%10ld\n",Server->Clients[i].ClientReference);
            TpPrint1("Data Checking\t\t\t%s\n",
                (Server->Clients[i].DataChecking) ? "TRUE" : "FALSE");

            if ( OpenP->Media->NdisMedium == NdisMediumArcnet878_2 ) 
            {
                TpPrint1("Client[%d] Address\t%x\n\n",i, Server->Clients[i].Address[0]);
            } 
            else 
            {
                TpPrint6("Client[%d] Address\t%x-%x-%x-%x-%x-%x\n\n",i,
                    Server->Clients[i].Address[0],Server->Clients[i].Address[1],
                    Server->Clients[i].Address[2],Server->Clients[i].Address[3],
                    Server->Clients[i].Address[4],Server->Clients[i].Address[5]);
            }

            ICounters = Server->Clients[i].Counters;

            TpPrint1("****** Client Number %d's ICountersers ******\n\n",i);
            TpPrint1("Packet Sends\t\t\t%10lu\n",ICounters->Sends);
            TpPrint1("Packet Send Pends\t\t%10lu\n",ICounters->SendPends);
            TpPrint1("Packet Send Completes\t\t%10lu\n",ICounters->SendComps);
            TpPrint1("Packet Send Fails\t\t%10lu\n",ICounters->SendFails);
            TpPrint1("Packet Receives\t\t\t%10lu\n",ICounters->Receives);
            TpPrint1("Corrupted Packet Receives\t%10lu\n",ICounters->CorruptRecs);
        }
    }

    TpPrint0("\n\n\n");

    ASSERT( FALSE );
}

#endif