summaryrefslogblamecommitdiffstats
path: root/private/ntos/ndis/madge/driver/request.c
blob: 21172e71b503ad7371905251511d7a0325ccc336 (plain) (tree)
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
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158





































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                             
/***************************************************************************
*
* REQUEST.C
*
* FastMAC Plus based NDIS3 miniport driver routines for handling SRB 
* requests and ODI_ requsts.
*
* Copyright (c) Madge Networks Ltd 1994                                     
*
* COMPANY CONFIDENTIAL
*
* Created: PBA 21/06/1994
*                                                                          
****************************************************************************/

#include <ndis.h>

#include "ftk_defs.h"
#include "ftk_extr.h"

#include "mdgmport.upd"
#include "ndismod.h"


/*---------------------------------------------------------------------------
|
| Global OIDs that we will support queries on.
|
---------------------------------------------------------------------------*/

NDIS_OID MadgeGlobalSupportedOids[] = 
{
    //
    // General, Operational, Mandatory.
    //

    OID_GEN_SUPPORTED_LIST,
    OID_GEN_HARDWARE_STATUS,
    OID_GEN_MEDIA_SUPPORTED,
    OID_GEN_MEDIA_IN_USE,
    OID_GEN_MAXIMUM_LOOKAHEAD,
    OID_GEN_MAXIMUM_FRAME_SIZE,
    OID_GEN_LINK_SPEED,
    OID_GEN_TRANSMIT_BUFFER_SPACE,
    OID_GEN_RECEIVE_BUFFER_SPACE,
    OID_GEN_TRANSMIT_BLOCK_SIZE,
    OID_GEN_RECEIVE_BLOCK_SIZE,
    OID_GEN_VENDOR_ID,
    OID_GEN_VENDOR_DESCRIPTION,
    OID_GEN_CURRENT_PACKET_FILTER,
    OID_GEN_CURRENT_LOOKAHEAD,
    OID_GEN_DRIVER_VERSION,
    OID_GEN_MAXIMUM_TOTAL_SIZE,
    OID_GEN_PROTOCOL_OPTIONS,
    OID_GEN_MAC_OPTIONS,

    //
    // General, Statistical, Mandatory.
    //

    OID_GEN_XMIT_OK,
    OID_GEN_RCV_OK,
    OID_GEN_XMIT_ERROR,
    OID_GEN_RCV_ERROR,
    OID_GEN_RCV_NO_BUFFER,

    //
    // Token Ring, Operational, Mandatory.
    //

    OID_802_5_PERMANENT_ADDRESS,
    OID_802_5_CURRENT_ADDRESS,
    OID_802_5_CURRENT_FUNCTIONAL,
    OID_802_5_CURRENT_GROUP,
    OID_802_5_LAST_OPEN_STATUS,
    OID_802_5_CURRENT_RING_STATUS,
    OID_802_5_CURRENT_RING_STATE,

    //
    // Token Ring, Statistical, Mandatory.
    //

    OID_802_5_LINE_ERRORS,
    OID_802_5_LOST_FRAMES,

    //
    // Token Ring Statistical, Optional.
    //

    OID_802_5_BURST_ERRORS,
    OID_802_5_AC_ERRORS,
    OID_802_5_FRAME_COPIED_ERRORS,
    OID_802_5_TOKEN_ERRORS

    //
    // There are three more Token Ring error stat's but TI MAC code does not
    // support them, so we go without! (ABORT_DELIMITERS, FREQUENCY_ERRORS,
    // and INTERNAL_ERRORS).
    //
};


/**************************************************************************
*
* Function    - MadgeCompletePendingRequest
*
* Parameters  - ndisAdap -> Pointer NDIS3 level adapter structure.
*
* Purpose     - Complete a pending request on the adapter specified.
*
* Returns     - Nothing.
*
***************************************************************************/

VOID
MadgeCompletePendingRequest(PMADGE_ADAPTER ndisAdap)
{
    BOOLEAN   success;
    ADAPTER * ftkAdapter;
    ULONG   * infoBuffer;

//    MadgePrint1("MadgeCompletePendingRequest started\n");

    success = ndisAdap->SrbRequestStatus;

    switch(ndisAdap->RequestType)
    {
        case NdisRequestQueryInformation:

            infoBuffer = (ULONG *) ndisAdap->InformationBuffer;

            if (success)
            {
                ftkAdapter = adapter_record[ndisAdap->FtkAdapterHandle];

                ndisAdap->ReceiveCongestionCount += 
                    ftkAdapter->status_info->error_log.congestion_errors;
                ndisAdap->LineErrors             += 
                    ftkAdapter->status_info->error_log.line_errors;
                ndisAdap->BurstErrors            += 
                    ftkAdapter->status_info->error_log.burst_errors;
                ndisAdap->AcErrors               += 
                    ftkAdapter->status_info->error_log.ari_fci_errors;
                ndisAdap->TokenErrors            += 
                    ftkAdapter->status_info->error_log.token_errors;

                switch(ndisAdap->RequestOid)
                {
                    case OID_GEN_RCV_NO_BUFFER:
                
                        *infoBuffer = ndisAdap->ReceiveCongestionCount;
                        break;

                    case OID_802_5_LINE_ERRORS:

                        *infoBuffer = ndisAdap->LineErrors;
                        break;

                    case OID_802_5_BURST_ERRORS:

                        *infoBuffer = ndisAdap->BurstErrors;
                        break;

                    case OID_802_5_AC_ERRORS:

                        *infoBuffer = ndisAdap->AcErrors;
                        break;

                    case OID_802_5_TOKEN_ERRORS:

                        *infoBuffer = ndisAdap->TokenErrors;
                        break;
                }

                ndisAdap->JustReadErrorLog = ndisAdap->RequestOid;
            }

            //
            // And complete the request.
            //

            NdisMQueryInformationComplete(
                ndisAdap->UsedInISR.MiniportHandle,
                (success) ? NDIS_STATUS_SUCCESS : NDIS_STATUS_FAILURE
                );

            break;

        case NdisRequestSetInformation:

            //
            // All we need to do is complete the request.
            //

            NdisMSetInformationComplete(
                ndisAdap->UsedInISR.MiniportHandle,
                (success) ? NDIS_STATUS_SUCCESS : NDIS_STATUS_FAILURE
                );

            break;
    }

//    MadgePrint1("MadgeCompletePendingRequest finished\n");
}


/***************************************************************************
*
* Function    - MadgeQueryInformation
*
* Parameters  - adapterContext -> Pointer NDIS3 level adapter structure.
*               oid            -> The OID.
*               infoBuffer     -> Pointer to the information buffer.
*               infoLength     -> Length of the information buffer.
*               bytesWritten   -> Pointer to a holder for the number of
*                                 bytes we've written.
*               bytesNeeded    -> Pointer to a holder for the number of
*                                 bytes we need.
*
* Purpose     - Set adapter information.
*
* Returns     - An NDIS3 status code.
*
***************************************************************************/

NDIS_STATUS
MadgeQueryInformation(
    NDIS_HANDLE adapterContext,
    NDIS_OID    oid,
    PVOID       infoBuffer,
    ULONG       infoLength,
    PULONG      bytesWritten,
    PULONG      bytesNeeded
    )
{
    PMADGE_ADAPTER   ndisAdap;
    UINT             supportedOids;
    UINT             i;
    ULONG            genericULong;
    USHORT           genericUShort;
    UCHAR            genericArray[6];
    PVOID            sourceBuffer;
    ULONG            sourceLength;
    UCHAR          * vendorID;


    static UCHAR VendorDescription[] = DRIVER_VERSION;

//    MadgePrint2("MadgeQueryInformation Oid = %08x\n", (UINT) oid);

    //
    // Do some pre-calculation.
    //

    ndisAdap      = PMADGE_ADAPTER_FROM_CONTEXT(adapterContext);
    sourceBuffer  = (PVOID) &genericULong;
    sourceLength  = (ULONG) sizeof(ULONG);
    vendorID      = (UCHAR *) &genericULong;
    supportedOids = sizeof(MadgeGlobalSupportedOids) / sizeof(NDIS_OID);

    //
    // Check that we recognise the OID.
    //

#ifdef OID_MADGE_MONITOR

    if (oid == OID_MADGE_MONITOR)
    {
        if (sizeof(MADGE_MONITOR) > infoLength)
        {
            *bytesNeeded = sizeof(MADGE_MONITOR);
            return NDIS_STATUS_BUFFER_TOO_SHORT;
        }

        MADGE_MOVE_MEMORY(
            infoBuffer,
            &(ndisAdap->MonitorInfo),
            sizeof(MADGE_MONITOR)
            );

        *bytesWritten = sizeof(MADGE_MONITOR);

        // Clear out the Monitor Structure
        for (i = 0; i < sizeof(MADGE_MONITOR); i++)
        {
            ((UCHAR *) &(ndisAdap->MonitorInfo))[i] = (UCHAR) 0;
        }

        return NDIS_STATUS_SUCCESS;
    }

#endif

    for (i = 0; i < supportedOids; i++) 
    {
        if (oid == MadgeGlobalSupportedOids[i])
        {
            break;
        }
    }

    if (i == supportedOids) 
    {
	*bytesWritten = 0;
        MadgePrint1("OID not supported\n");
	return NDIS_STATUS_INVALID_OID;
    }

    //
    // Now decode the OID based on the component bytes - this should make
    // the switch statement slightly quicker than a simple linear list.
    //
    // The OIDs are classed by category (General or Media Specific) and type
    // (Operational or Statistical), so we'll deal with them thus :
    //     General Operational 
    //     General Statistical 
    //     Media Specific Operational
    //     Media Specific Statistical
    //

    switch (oid & OID_TYPE_MASK) 
    {
        /*-----------------------------------------------------------------*/

        case OID_TYPE_GENERAL_OPERATIONAL:

            switch (oid)
            {
                case OID_GEN_SUPPORTED_LIST:

                    sourceBuffer = MadgeGlobalSupportedOids;
                    sourceLength = sizeof(MadgeGlobalSupportedOids);
                    break;

                case OID_GEN_HARDWARE_STATUS:

                    genericULong = ndisAdap->HardwareStatus;
                    break;

                case OID_GEN_MEDIA_SUPPORTED:

                    genericULong = NdisMedium802_5;
                    break;

                case OID_GEN_MEDIA_IN_USE:

                    genericULong = NdisMedium802_5;
                    break;

                case OID_GEN_MAXIMUM_LOOKAHEAD:

                    //
                    // The maximum lookahead size is the size of the whole
                    // frame, less the MAC header. It is NOT the maximum
                    // frame size according to the ring speed.
                    //

                    genericULong = ndisAdap->MaxFrameSize - FRAME_HEADER_SIZE;

                    //
                    // WARNING: What about Source Routing in the header? 
                    //

//                    MadgePrint2("OID_GEN_MAXIMUM_LOOKAHEAD = %ld\n",
//                        genericULong);

                    break;

                case OID_GEN_MAXIMUM_FRAME_SIZE:
                case OID_GEN_MAXIMUM_TOTAL_SIZE:

                    //
                    // Note that the MAXIMUM_FRAME_SIZE is the largest frame 
                    // supported, not including any MAC header, while the
                    // MAXIMUM_TOTAL_SIZE does include the MAC header.
	            //

                    genericULong = ndisAdap->MaxFrameSize;

                    if (oid == OID_GEN_MAXIMUM_FRAME_SIZE)
                    {
                        genericULong -= FRAME_HEADER_SIZE;
		    }

//                    MadgePrint2("OID_GEN_MAXIMUM_FRAME_SIZE = %ld\n",
//                        genericULong);

                    break;

                case OID_GEN_LINK_SPEED:

                    //
                    // Is this right? Shouldn't it be 16000000 and 4000000?
                    //

                    genericULong = 
                        (driver_ring_speed(ndisAdap->FtkAdapterHandle) == 16)
                            ? 160000
                            :  40000;
                    break;

                case OID_GEN_TRANSMIT_BUFFER_SPACE:

                    genericULong = 
                        ndisAdap->MaxFrameSize * ndisAdap->FastmacTxSlots;
                    break;

                case OID_GEN_RECEIVE_BUFFER_SPACE:

                    genericULong = 
                        ndisAdap->MaxFrameSize * ndisAdap->FastmacRxSlots;
                    break;

                case OID_GEN_TRANSMIT_BLOCK_SIZE:

                    genericULong = ndisAdap->MaxFrameSize;
                    break;

                case OID_GEN_RECEIVE_BLOCK_SIZE:

                    genericULong = ndisAdap->MaxFrameSize;
                    break;

                case OID_GEN_VENDOR_ID:

                    MADGE_MOVE_MEMORY(
                        vendorID,
                        &ndisAdap->PermanentNodeAddress,
                        3
                        );
                    vendorID[3] = 0x00;
                    break;

                case OID_GEN_VENDOR_DESCRIPTION:

                    sourceBuffer = VendorDescription;
                    sourceLength = sizeof(VendorDescription);
                    break;
    
                case OID_GEN_CURRENT_PACKET_FILTER:

                    genericULong = (ULONG) ndisAdap->CurrentPacketFilter;
                    break;

                case OID_GEN_CURRENT_LOOKAHEAD:

                    genericULong = (ULONG) ndisAdap->CurrentLookahead;

//                    MadgePrint2("OID_GEN_CURRENT_LOOKAHEAD = %ld\n",
//                        genericULong);

                    break;
	
                case OID_GEN_DRIVER_VERSION:

                    genericUShort = (MADGE_NDIS_MAJOR_VERSION << 8) +
                                     MADGE_NDIS_MINOR_VERSION;
                    sourceBuffer  = &genericUShort;
                    sourceLength  = sizeof(USHORT);
                    break;

                case OID_GEN_MAC_OPTIONS:

                    genericULong = (ULONG)
                        (NDIS_MAC_OPTION_TRANSFERS_NOT_PEND |
                         NDIS_MAC_OPTION_RECEIVE_SERIALIZED);
                    break;

                default:

                    MadgePrint2("OID %x not recognised\n", oid);
                    return NDIS_STATUS_INVALID_OID;
            } 
            break;

        /*-----------------------------------------------------------------*/
    
        case OID_TYPE_GENERAL_STATISTICS:

            //
            // Might need these later.
            //

            *bytesWritten               = sourceLength;
            ndisAdap->RequestType       = NdisRequestQueryInformation;
            ndisAdap->RequestOid        = oid;
            ndisAdap->InformationBuffer = infoBuffer;

            switch (oid)
                {
                case OID_GEN_XMIT_OK:

                    genericULong = (ULONG) ndisAdap->FramesTransmitted;
                    break;

                case OID_GEN_RCV_OK:

                    genericULong = (ULONG) ndisAdap->FramesReceived;
                    break;

                case OID_GEN_XMIT_ERROR:

                    genericULong = (ULONG) ndisAdap->FrameTransmitErrors;
                    break;

                case OID_GEN_RCV_ERROR:

                    genericULong = (ULONG) ndisAdap->FrameReceiveErrors;
                    break;

                case OID_GEN_RCV_NO_BUFFER:

                    //
                    // We need to issue a READ_ERROR_LOG SRB to recover an
                    // up to date value for this counter.
                    //

                    if (ndisAdap->JustReadErrorLog != 0 &&
                        ndisAdap->JustReadErrorLog != oid)
                    {
                        genericULong = (ULONG) 
                            ndisAdap->ReceiveCongestionCount;
                    }
                    else if (infoLength >= sourceLength)
                    {
                        driver_get_status(ndisAdap->FtkAdapterHandle);
                        return NDIS_STATUS_PENDING;
                    }
                    break;

                default:

                    MadgePrint2("OID %x not recognised\n", oid);
                    return NDIS_STATUS_INVALID_OID;
            } 
            break;
    
        /*-----------------------------------------------------------------*/

        case OID_TYPE_802_5_OPERATIONAL:

            switch (oid)
                {
                case OID_802_5_PERMANENT_ADDRESS:

                    sourceBuffer = &genericArray;
                    sourceLength = sizeof(ndisAdap->PermanentNodeAddress);

                    MADGE_MOVE_MEMORY(
                        sourceBuffer,
                        &ndisAdap->PermanentNodeAddress,
                        sizeof(ndisAdap->PermanentNodeAddress)
                        );
                    break;
	
                case OID_802_5_CURRENT_ADDRESS:

                    sourceBuffer = &genericArray;
                    sourceLength =
                        sizeof(ndisAdap->OpeningNodeAddress);

                    MADGE_MOVE_MEMORY(
                        sourceBuffer,
                        &ndisAdap->OpeningNodeAddress,
                        sizeof(ndisAdap->OpeningNodeAddress)
                        );
                    break;

                case OID_802_5_CURRENT_FUNCTIONAL:

                    genericULong =
                        ndisAdap->FunctionalAddress & 0xffffffff;
                    break;
		
                case OID_802_5_CURRENT_GROUP:

                    genericULong = 
                        ndisAdap->GroupAddress & 0xffffffff;
                    break;

                case OID_802_5_LAST_OPEN_STATUS:

                    genericULong = ndisAdap->LastOpenStatus;
                    break;

                case OID_802_5_CURRENT_RING_STATUS:

                    genericULong = ndisAdap->CurrentRingStatus;
                    break;

                case OID_802_5_CURRENT_RING_STATE:

                    genericULong = NdisRingStateOpened;
                    break;

                default:

                    MadgePrint2("OID %x not recognised\n", oid);
                    return NDIS_STATUS_INVALID_OID;
            } 
            break;

        /*-----------------------------------------------------------------*/

        case OID_TYPE_802_5_STATISTICS:

            //
            // We do a bit of pre-processing here in case we have to queue 
            // an SRB request. In this instance we want everything ready bar
            // the actual data.
            //

            if (sourceLength > infoLength)
            {
                break;
            }

            *bytesWritten               = sourceLength;
            ndisAdap->RequestType       = NdisRequestQueryInformation;
            ndisAdap->RequestOid        = oid;
            ndisAdap->InformationBuffer = infoBuffer;

            //
            // Now get on with working out the data.
            //

            switch (oid)
            {
                case OID_802_5_LINE_ERRORS:

                    //
                    // We need to issue a READ_ERROR_LOG SRB to recover an
                    // up to date value for this counter.
                    //

                    if (ndisAdap->JustReadErrorLog != 0 &&
                        ndisAdap->JustReadErrorLog != oid)
                    {
                        genericULong = (ULONG) ndisAdap->LineErrors;
                    }
                    else
                    {
                        driver_get_status(ndisAdap->FtkAdapterHandle);
                        return NDIS_STATUS_PENDING;
                    }
                    break;

                case OID_802_5_LOST_FRAMES:

                    //
                    // This counter is managed by the transmit process using
                    // the transmit status returned by FastmacPlus. 
                    //

                    genericULong = (ULONG) ndisAdap->LostFrames;
                    break;

                case OID_802_5_BURST_ERRORS:

                    if (ndisAdap->JustReadErrorLog != 0 &&
                        ndisAdap->JustReadErrorLog != oid)
                    {
                        genericULong= (ULONG) ndisAdap->BurstErrors;
                    }
                    else
                    {
                        driver_get_status(ndisAdap->FtkAdapterHandle);
                        return NDIS_STATUS_PENDING;
                    }
                    break;

                case OID_802_5_AC_ERRORS:

                    if (ndisAdap->JustReadErrorLog != 0 &&
                        ndisAdap->JustReadErrorLog != oid)
                    {
                        genericULong= (ULONG) ndisAdap->AcErrors;
                    }
                    else
                    {
                        driver_get_status(ndisAdap->FtkAdapterHandle);
                        return NDIS_STATUS_PENDING;
                    }
                    break;

                case OID_802_5_FRAME_COPIED_ERRORS:

                    //
                    // This counter is managed by the receive process using
                    // the receive status returned by FastmacPlus. 
                    //

                    genericULong = (ULONG) ndisAdap->FrameCopiedErrors;
                    break;

                case OID_802_5_TOKEN_ERRORS:

                    if (ndisAdap->JustReadErrorLog != 0 &&
                        ndisAdap->JustReadErrorLog != oid)
                    {
                        genericULong = (ULONG) ndisAdap->TokenErrors;
                    }
                    else
                    {
                        driver_get_status(ndisAdap->FtkAdapterHandle);
                        return NDIS_STATUS_PENDING;
                    }
                    break;

                default:

                    MadgePrint2("OID %x not recognised\n", oid);
                    return NDIS_STATUS_INVALID_OID;
            }
            break;
    } 

    //
    // Check memory allocation provided by caller - report required amount
    // if we haven't got enough.
    //

    if (sourceLength > infoLength) 
    {
    	*bytesNeeded = sourceLength;
	return NDIS_STATUS_BUFFER_TOO_SHORT;
    }

    MADGE_MOVE_MEMORY(
        infoBuffer,
        sourceBuffer,
        sourceLength
        );

    *bytesWritten = sourceLength;

    return NDIS_STATUS_SUCCESS;
}


/*---------------------------------------------------------------------------
|
| Function    - MadgeChangeGroupAddress
|
| Parameters  - ndisAdap   -> Pointer to our NDIS level adapter structure.
|               newAddress -> The new group address.
|
| Purpose     - Queue an SRB to change the group address.
|
| Returns     - Nothing.
|
---------------------------------------------------------------------------*/

STATIC VOID
MadgeChangeGroupAddress(
    PMADGE_ADAPTER        ndisAdap,
    TR_FUNCTIONAL_ADDRESS newAddress
    )
{
    MULTI_ADDRESS multiAddress;

//    MadgePrint1("MadgeChangeGroupAddress started\n");

    ndisAdap->GroupAddress = newAddress;
    multiAddress.all       = (DWORD) newAddress;

    ndisAdap->RequestType = NdisRequestSetInformation;

    //
    // And call the FTK to change the address.
    //

    driver_set_group_address(ndisAdap->FtkAdapterHandle, &multiAddress);

//    MadgePrint1("MadgeChangeGroupAddress finished\n");
}


/*---------------------------------------------------------------------------
|
| Function    - MadgeChangeFunctionalAddress
|
| Parameters  - ndisAdap   -> Pointer to our NDIS level adapter structure.
|               newAddress -> The new functional address.
|
| Purpose     - Queue an SRB to change the functional address.
|
| Returns     - Nothing.
|
---------------------------------------------------------------------------*/

STATIC VOID
MadgeChangeFunctionalAddress(
    PMADGE_ADAPTER        ndisAdap,
    TR_FUNCTIONAL_ADDRESS newAddress
    )
{
    MULTI_ADDRESS multiAddress;

//    MadgePrint2("MadgeChangeFunctionalAddress started %08x\n",
//        (UINT) newAddress);

    ndisAdap->FunctionalAddress = newAddress;
    multiAddress.all            = (DWORD) newAddress;

    ndisAdap->RequestType = NdisRequestSetInformation;

    //
    // And call the FTK to change the address.
    //

    driver_set_functional_address(ndisAdap->FtkAdapterHandle, &multiAddress);

//    MadgePrint1("MadgeChangeFunctionalAddress finished\n");
}


/*---------------------------------------------------------------------------
|
| Function    - MadgeChangeFilter
|
| Parameters  - ndisAdap  -> Pointer to our NDIS level adapter structure.
|               newFilter -> The new packet filter.
|
| Purpose     - Change the packet filter.
|
| Returns     - NDIS_STATUS_PENDING if an SRB is required, 
|               NDIS_STATUS_NOT_SUPPORTED if we don't support the filter
|               types, otherwise NDIS_STATUS_SUCCESS.
|
---------------------------------------------------------------------------*/

NDIS_STATUS
MadgeChangeFilter(
    PMADGE_ADAPTER ndisAdap,
    UINT           newFilter
    )
{
    UINT index;
    UINT modifyOpenOptions;
    UINT oldFilter;

    //
    // Lookup table for the various ways we might want to modify the open
    // options of the adapter.
    //

#define MOO_NO_CHANGE (0xffff)
#define MOO_MASK ((WORD) (~(OPEN_OPT_COPY_ALL_MACS | OPEN_OPT_COPY_ALL_LLCS)))

WORD MooLookupTable[] = {
    MOO_NO_CHANGE,
    OPEN_OPT_COPY_ALL_MACS | OPEN_OPT_COPY_ALL_LLCS,
    OPEN_OPT_COPY_ALL_MACS,
    OPEN_OPT_COPY_ALL_MACS | OPEN_OPT_COPY_ALL_LLCS,
    0,
    MOO_NO_CHANGE,
    OPEN_OPT_COPY_ALL_MACS,
    MOO_NO_CHANGE,
    0,
    OPEN_OPT_COPY_ALL_MACS | OPEN_OPT_COPY_ALL_LLCS,
    MOO_NO_CHANGE,
    OPEN_OPT_COPY_ALL_MACS | OPEN_OPT_COPY_ALL_LLCS,
    0,
    MOO_NO_CHANGE,
    OPEN_OPT_COPY_ALL_MACS,
    MOO_NO_CHANGE
    };

//    MadgePrint2("MadgeChangeFilter started filter = %04x\n", 
//        (UINT) newFilter);
    
    //
    // Do some pre-calculation.
    //

    modifyOpenOptions = 0;
    index             = 0;
    oldFilter         = ndisAdap->CurrentPacketFilter;

//    MadgePrint2("Old filter = %04x\n", oldFilter);

    //
    // By default, the card will receive directed frames, broadcast frames, 
    // and matching functional and group address frames. Thus the following 
    // filter types are handled automatically, whether we want them or not: 
    //   NDIS_PACKET_TYPE_DIRECTED         NDIS_PACKET_TYPE_BROADCAST       
    //   NDIS_PACKET_TYPE_FUNCTIONAL       NDIS_PACKET_TYPE_GROUP           
    //                                                                      
    // Of the remaining filters, the following are not supported (see below)
    //   NDIS_PACKET_TYPE_MULTICAST        NDIS_PACKET_TYPE_ALL_FUNCTIONAL  
    //   NDIS_PACKET_TYPE_ALL_MULTICAST    NDIS_PACKET_TYPE_SOURCE_ROUTING  
    //                                                                      
    // This leaves NDIS_PACKET_TYPE_PROMISCUOUS and NDIS_PACKET_TYPE_MAC,   
    // which we can handle if we want to.                                   
    //

    if  ((newFilter & (NDIS_PACKET_TYPE_MULTICAST      |
	   	       NDIS_PACKET_TYPE_ALL_FUNCTIONAL |
		       NDIS_PACKET_TYPE_ALL_MULTICAST  |
                       NDIS_PACKET_TYPE_MAC_FRAME      |
		       NDIS_PACKET_TYPE_SOURCE_ROUTING)) != 0)

    {
        //
        // These filters are not supported - there is no way our MAC/hw can
        // be this selective, although the host software could do its own
        // filtering i.e. enable promiscuous mode, and then throw away all
        // frames except those indicated above. At some stage it might be
        // an idea to do this anyway, together with a caveat that it is not
        // going to be a high performance solution.
        //
        // Anyway, in the mean time, return NDIS_STATUS_NOT_SUPPORTED.
	//

	return NDIS_STATUS_NOT_SUPPORTED;
    }

    //
    // Only allow promiscuous mode if it has been enabled.
    //

    if ((newFilter & (NDIS_PACKET_TYPE_PROMISCUOUS |
                      NDIS_PACKET_TYPE_MAC_FRAME)) != 0)
    {
        if (!ndisAdap->PromiscuousMode)
        {
            return NDIS_STATUS_NOT_SUPPORTED;
        }
    }

    //
    // We've weeded out the illegal ones now - note that no change has been
    // made to the current filter - this is as specified in the paperwork!
    //
    // Make a note of the _adapter_ notion of the filter. Each
    // binding will have its own idea of what it wants, but this is
    // the Filter Database's problem, not ours!
    //

    ndisAdap->CurrentPacketFilter = newFilter;

    //
    // Now we have to work out which bits need setting in the Modify Open 
    // Options SRB - when I looked at this there didn't appear to be any
    // obvious way of simplifying the logic, so I use a look up table to do
    // the decoding instead. You'll just have to take my word for it that I
    // worked all the permutations out correctly!
    //

    if (oldFilter & NDIS_PACKET_TYPE_MAC_FRAME)
    {
        index |= 8;
    }
    if (oldFilter & NDIS_PACKET_TYPE_PROMISCUOUS)
    {
        index |= 4;
    }
    if (newFilter & NDIS_PACKET_TYPE_MAC_FRAME)
    {
        index |= 2;
    }
    if (newFilter & NDIS_PACKET_TYPE_PROMISCUOUS)
    {
        index |= 1;
    }

//    MadgePrint2("index = %d\n", index);

    modifyOpenOptions =
         (ndisAdap->OpenOptions & MOO_MASK) | MooLookupTable[index];

//    MadgePrint2("modifyOpenOptions = %04x\n", modifyOpenOptions);

    //
    // Now see if we need to issue an SRB - note that MOO_NO_CHANGE is not 
    // zero, to distinguish from the case when we actually want to write out
    // zero to turn all the options off.
    //

    if (modifyOpenOptions != MOO_NO_CHANGE)
    {
        //
        // We have to issue a ModifyOpenOptions SRB.
        //

        ndisAdap->RequestType = NdisRequestSetInformation;
        ndisAdap->OpenOptions = (WORD) modifyOpenOptions;

        driver_modify_open_options(
            ndisAdap->FtkAdapterHandle,
            ndisAdap->OpenOptions
            );

//        MadgePrint1("MadgeChangeFilter pended\n");

        return NDIS_STATUS_PENDING;
    }

//    MadgePrint1("MadgeChangeFilter finished\n");
    
    return NDIS_STATUS_SUCCESS;
}

	

/***************************************************************************
*
* Function    - MadgeSetInformation
*
* Parameters  - adapterContext -> Pointer NDIS3 level adapter structure.
*               oid            -> The OID.
*               infoBuffer     -> Pointer to the information buffer.
*               infoLength     -> Length of the information buffer.
*               bytesRead      -> Pointer to a holder for the number of
*                                 bytes we've read.
*               bytesNeeded    -> Pointer to a holder for the number of
*                                 bytes we need.
*
* Purpose     - Set adapter information.
*
* Returns     - An NDIS3 status code.
*
***************************************************************************/
					
NDIS_STATUS
MadgeSetInformation(
    NDIS_HANDLE adapterContext,
    NDIS_OID    oid,
    PVOID       infoBuffer,
    ULONG       infoLength,
    PULONG      bytesRead,
    PULONG      bytesNeeded
    )
{
    PMADGE_ADAPTER ndisAdap;
    NDIS_STATUS    retCode;

//    MadgePrint2("MadgeSetInformation Oid = %08x\n", (UINT) oid);

    //
    // Do some pre-calculation.
    //

    ndisAdap = PMADGE_ADAPTER_FROM_CONTEXT(adapterContext);

    //
    // Process the request.
    //

    switch (oid) 
    {
    	case OID_802_5_CURRENT_FUNCTIONAL:

	    if (infoLength != TR_LENGTH_OF_FUNCTIONAL)
	    {
		*bytesNeeded = TR_LENGTH_OF_FUNCTIONAL;
		retCode      = NDIS_STATUS_INVALID_LENGTH;
	    }
            else
            {
                MadgeChangeFunctionalAddress(
                    ndisAdap, 
                    *((TR_FUNCTIONAL_ADDRESS *) infoBuffer)
                    );
	        *bytesRead = TR_LENGTH_OF_FUNCTIONAL;
                retCode    = NDIS_STATUS_PENDING;
            }
            break;
 
	case OID_802_5_CURRENT_GROUP:

	    if (infoLength != TR_LENGTH_OF_FUNCTIONAL)
	    {
		*bytesNeeded = TR_LENGTH_OF_FUNCTIONAL;
		retCode      = NDIS_STATUS_INVALID_LENGTH;
	    }
	    else
	    {
                MadgeChangeGroupAddress(
                    ndisAdap, 
                    *((TR_FUNCTIONAL_ADDRESS *) infoBuffer)
                    );
	        *bytesRead = TR_LENGTH_OF_FUNCTIONAL;
                retCode    = NDIS_STATUS_PENDING;
            }
	    break;

	case OID_GEN_CURRENT_PACKET_FILTER:

	    if (infoLength != sizeof(UINT))
	    {
		*bytesNeeded = sizeof(UINT);
		retCode      = NDIS_STATUS_INVALID_LENGTH;
	    }
            else
            {
                retCode    = MadgeChangeFilter(
                                 ndisAdap, 
                                 *((UINT *) infoBuffer)
                                 );
	        *bytesRead = sizeof(UINT);
            }
	    break;

	case OID_GEN_CURRENT_LOOKAHEAD:

            //
            // It IS important to record the current lookahead. On WFWG 
            // machines it is not possible to indicate the whole frame
            // as lookahead, so take a note of it here.
            // 

//            MadgePrint3("Set lookahead infoLength = %d (%d)\n", infoLength, sizeof(ULONG));

	    if (infoLength != sizeof(ULONG))
	    {
		*bytesNeeded = sizeof(ULONG);
		retCode      = NDIS_STATUS_INVALID_LENGTH;
	    }
            else
            {
                ndisAdap->CurrentLookahead = 
                    MIN(
                        ndisAdap->MaxFrameSize - FRAME_HEADER_SIZE,
                        MAX(
                            *((ULONG *) infoBuffer),
                            MADGE_MINIMUM_LOOKAHEAD
                            )
                        );
                *bytesRead = sizeof(ULONG);
	        retCode    = NDIS_STATUS_SUCCESS;
            }
            break;

	case OID_GEN_PROTOCOL_OPTIONS:

            //
            // This does nothing - we really don't care about the protocol
            // options at the moment since we are too stupid to make use of
            // them anyway.
            //

	    *bytesRead = 4;
	    retCode    = NDIS_STATUS_SUCCESS;
            break;

	default:

            MadgePrint1("Invalid OID\n");
	    retCode = NDIS_STATUS_INVALID_OID;
            break;
    }

    return retCode;
}
								
/******** End of REQUEST.C ************************************************/