summaryrefslogblamecommitdiffstats
path: root/private/ntos/dlc/llcrcv.c
blob: 5a5f77b9750de0f9f938d683f774471f23da78d7 (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
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079






























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                                            
/*++

Copyright (c) 1991  Microsoft Corporation

Module Name:

    llcrcv.c

Abstract:

    The module implements the NDIS receive indication handling and
    its routing to upper protocol modules or to link state machines.

    To understand the link related procedure of this module, you should read
    Chapters 11 and 12 in IBM Token-Ring Architecture Reference.

    Contents:
        LlcNdisReceiveIndication
        LlcNdisReceiveComplete
        ProcessType1_Frames
        MakeRcvIndication
        ProcessType2_Frames
        ProcessNewSabme
        LlcTransferData
        LlcNdisTransferDataComplete
        safe_memcpy
        FramingDiscoveryCacheHit

Author:

    Antti Saarenheimo (o-anttis) 18-MAY-1991

Revision History:

    19-Nov-1992 rfirth
        RtlMoveMemory on MIPS, copying from shared TR buffer fails (see rubric
        for safe_memcpy). Changed to private memory mover for this particular
        case

    02-May-1994 rfirth
        Added caching for auto-framing discovery (TEST/XID/SABME-UA)

--*/

#include <dlc.h>
#include <llc.h>

//
// private prototypes...
//

VOID
safe_memcpy(
    OUT PUCHAR Destination,
    IN PUCHAR Source,
    IN ULONG Length
    );

BOOLEAN
FramingDiscoveryCacheHit(
    IN PADAPTER_CONTEXT pAdapterContext,
    IN PBINDING_CONTEXT pBindingContext
    );

//
// Local lookup tables to receive the correct frames for a direct station
//

static USHORT ReceiveMasks[LLC_PACKET_MAX] = {
    DLC_RCV_8022_FRAMES,
    DLC_RCV_MAC_FRAMES,
    DLC_RCV_DIX_FRAMES,
    DLC_RCV_OTHER_DESTINATION
};

static UCHAR FrameTypes[LLC_PACKET_MAX] = {
    LLC_DIRECT_8022,
    LLC_DIRECT_MAC,
    LLC_DIRECT_ETHERNET_TYPE,
    (UCHAR)(-1)
};

//
// functions
//


NDIS_STATUS
LlcNdisReceiveIndication(
    IN PADAPTER_CONTEXT pAdapterContext,
    IN NDIS_HANDLE MacReceiveContext,
    IN PVOID pHeadBuf,
    IN UINT cbHeadBuf,
    IN PVOID pLookBuf,
    IN UINT cbLookBuf,
    IN UINT cbPacketSize
    )

/*++

Routine Description:

    This routine receives control from the physical provider as an
    indication that a frame has been received on the physical link
    endpoint (That was from SteveJ's NBF, the guy must have a degree in
    the english literature).  This routine is very time critical!

    We first check the frame type (token-ring, 802.3 ethernet or dix),
    then check its data link address (802.2 saps or ethernet type)
    and then we route it to the upper protocol that has opened the
    address, that the frame was sent to.  The link level frames
    are first run through the protocol state machine, and only
    the accepted I- frames are indicated to upper level.

Arguments:

    pAdapterContext     - The Adapter Binding specified at initialization time

    MacReceiveContext   - Note: different from binding handle, mac needs this
                          to support re-entrant receive indications

    pHeadBuf            - pointer to a buffer containing the packet header

    cbHeadBuf           - size of the header

    pLookBuf            - pointer to a buffer containing the negotiated minimum
                          amount of buffer I get to look at, not including header

    cbLookBuf           - the size of the above. May be less than asked for, if
                          that's all there is

    cbPacketSize        - Overall size of the packet, not including the header

Assumes:

    pHeadBuf contains all the header information:

        802.3   6 bytes destination address
                6 bytes source address
                2 bytes big-endian length or packet type (DIX frames)

        802.5   1 byte Access Control
                1 byte Frame Control
                6 bytes destination address
                6 bytes source address
                0-18 bytes source routing

        FDDI    1 byte Frame Control
                6 bytes destination address
                6 bytes source address

    From this we can assume for Token Ring that if cbHeadBuf is >14 (decimal)
    then there IS source routing information in the packet

Return Value:

    NDIS_STATUS:

        NDIS_STATUS_SUCCESS
            Packet accepted

        NDIS_STATUS_NOT_RECOGNIZED
            Packet not recognized by protocol

        NDIS_any_other_thing if I understand, but can't handle.

--*/

{
    LLC_HEADER llcHdr;
    LAN802_ADDRESS Source;
    LAN802_ADDRESS Destination;
    USHORT EthernetTypeOrLength;
    PDATA_LINK pLink;
    PLLC_SAP pSap;
    UCHAR PacketType = LLC_PACKET_8022;
    UCHAR cbLanHeader = 14;
    KIRQL OldIrql;
    UCHAR packet[36];   // enough space for 14-byte header, 18-byte source
                        // routing, 1-byte DSAP, 1-byte SSAP & 2-byte LPDU
    PLLC_OBJECT pObject;

    UNREFERENCED_PARAMETER(OldIrql);

    ASSUME_IRQL(DISPATCH_LEVEL);

    //
    // we assume at least 13 bytes in the header for all media types. Also
    // assume that the header is no larger than the packet buffer
    //

    ASSERT(cbHeadBuf >= 13);
    ASSERT(cbHeadBuf <= sizeof(packet));

	if ( cbHeadBuf > LLC_MAX_LAN_HEADER ) {
		return NDIS_STATUS_NOT_RECOGNIZED;
	}

    LlcMemCpy(packet, pHeadBuf, cbHeadBuf);
    LlcMemCpy(packet+cbHeadBuf, pLookBuf, sizeof(packet) - cbHeadBuf);
    cbPacketSize += cbHeadBuf;

    //
    // First we do the inital checking for the frame and read
    // the destination and source address and LLC header to
    // DWORD aligned addresses. We avoid any bigendiand/
    // small endiand problematic by forgotting the second high
    // byte in the addresses. The lowest ULONG is used only as
    // an raw data. The bytes can be accesses in any way.
    // The macros read LLC header in a small endiand safe way.
    //

    switch (pAdapterContext->NdisMedium) {
    case NdisMedium802_3:
        LlcMemCpy(Destination.Node.auchAddress, packet, 6);
        LlcMemCpy(Source.Node.auchAddress, packet + 6, 6);

        //
        // The 802.3 LLC frames have always the length field!
        // A 802.3 MAC should discard all Ethernet frames
        // longer than 1500 bytes.
        //
        // X'80D5 is a special ethernet type used when 802.2 frame
        // is encapsulated inside a ethernet type header.
        // (Ethernet type/size is in a reverse order for
        // Intel architecture)
        //

        EthernetTypeOrLength = (USHORT)packet[12] * 256 + (USHORT)packet[13];

        if (EthernetTypeOrLength < 3) {
            return NDIS_STATUS_INVALID_PACKET;
        }

        //
        // If the ethernet length/type field is more than 1500, the
        // frame is dix frame and the length field is a dix ethernet
        // address.  Otherwise the frame is a normal 802.3 frame,
        // that has always LLC header inside it.
        //

        if (EthernetTypeOrLength > 1500) {
            if (EthernetTypeOrLength == 0x80D5) {

                //
                // This is a special 'IBM SNA over ethernet' type,
                // that consists of the length field, 1 byte padding
                // and complete 802.2 LLC header (including the info field).
                //

                cbLanHeader = 17;
                (PUCHAR)pLookBuf += 3;
                cbLookBuf -= 3;

                //
                // The DIX frame size is stored as a big-endian USHORT at offset
                // 15 in the LAN header. Add 17 for the DIX LAN header:
                //
                //      6 bytes destination address
                //      6 bytes source address
                //      2 bytes DIX identifier (0x80D5)
                //      2 byte big-endian information frame length
                //      1 byte pad
                //

                pAdapterContext->cbPacketSize = (USHORT)packet[14] * 256
                                              + (USHORT)packet[15]
                                              + 17;

                //
                // we now keep an indicator which explicitly defines that this
                // frame has (SNA) DIX framing
                //

                pAdapterContext->IsSnaDixFrame = TRUE;
            } else {

                //
                // This is some other DIX format frame. We don't know what the
                // format of this is (app-specific). We hand the entire packet
                // to the app and let it sort out the format. The frame may be
                // padded in which case the app gets the padding too
                //

                //
                // This is still Ethernet, so cbHeadBuf is 14, even though
                // the actual LAN header is only 12
                //

                PacketType = LLC_PACKET_DIX;
                pAdapterContext->cbPacketSize = cbPacketSize;

                //
                // this frame is not SNA DIX, although it is generically a DIX
                // frame. It will be indicated via a specific DIX SAP, not as
                // a general ethernet frame
                //

                pAdapterContext->IsSnaDixFrame = FALSE;
            }
        } else {

            //
            // Ethernet packets include always the padding,
            // we use the actual size saved in 802.3 header.
            // Include also the header: 6 + 6 + 2
            //

            pAdapterContext->cbPacketSize = EthernetTypeOrLength + 14;

            //
            // this is an 802.3 frame - not DIX at all
            //

            pAdapterContext->IsSnaDixFrame = FALSE;
        }
        break;

    case NdisMedium802_5:
        LlcMemCpy(Destination.Node.auchAddress, packet + 2, 6);
        LlcMemCpy(Source.Node.auchAddress, packet + 8, 6);

        //
        // cbHeadBuf always has the correct LAN header length for Token Ring
        //

        cbLanHeader = cbHeadBuf;

        pAdapterContext->cbPacketSize = cbPacketSize;

        //
        // bit7 and bit6 in FC byte defines the frame type in token ring.
        // 00 => MAC frame (no LLC), 01 => LLC, 10,11 => reserved.
        // We send all other frames to direct except 01 (LLC)
        //

        if ((packet[1] & 0xC0) == 0x40) {

            //
            // check if we have routing info?
            //

            if (Source.Node.auchAddress[0] & 0x80) {

                //
                // reset the source routing indicator in the
                // source address (it would screw up the link search)
                //

                Source.Node.auchAddress[0] &= 0x7f;

                //
                // Discard all invalid TR frames, they'd corrupt the memory
                //

                if (cbLanHeader > MAX_TR_LAN_HEADER_SIZE) {
                    return NDIS_STATUS_NOT_RECOGNIZED;
                }
            }
        } else {

            //
            // this is a MAC frame destined to direct station
            //

            PacketType = LLC_PACKET_MAC;
        }
        break;

    case NdisMediumFddi:
        LlcMemCpy(Destination.Node.auchAddress, packet + 1, 6);
        LlcMemCpy(Source.Node.auchAddress, packet + 7, 6);

        //
        // cbHeadBuf always has the correct LAN header length for FDDI
        //

        cbLanHeader = cbHeadBuf;

        pAdapterContext->cbPacketSize = cbPacketSize;

        //
        // bit5 and bit4 in FC byte define the FDDI frame type:
        //
        //      00 => MAC or SMT
        //      01 => LLC
        //      10 => implementer (?)
        //      11 => reserved
        //
        // do same as TR: LLC frames to link/SAP, everything else to direct
        // station
        //

        if ((packet[0] & 0x30) != 0x10) {
            PacketType = LLC_PACKET_MAC;
        }
        break;

#if LLC_DBG
    default:
        LlcInvalidObjectType();
        break;
#endif

    }

    pAdapterContext->FrameType = FrameTypes[PacketType];

    //
    // Direct interface gets all non LLC frames and also all LLC frames
    // that were not sent to this station (ie. different destination
    // address field and having no broadcast bit (bit7) set in
    // destination address)).  Ie. promiscuous mode, this data link
    // version does not support promiscuous mode.
    //

    if (Destination.Node.auchAddress[0] & pAdapterContext->IsBroadcast) {
        pAdapterContext->ulBroadcastAddress = Destination.Address.ulLow;
        pAdapterContext->usBroadcastAddress = Destination.Address.usHigh;
    } else {
        pAdapterContext->ulBroadcastAddress = 0;

        //
        // We must also be able to handle the promiscuous packets
        //

        if (Destination.Address.ulLow != pAdapterContext->Adapter.Address.ulLow
        && Destination.Address.usHigh != pAdapterContext->Adapter.Address.usHigh) {
            PacketType = LLC_PACKET_OTHER_DESTINATION;
        }
    }

    //
    // Setup the current receive indication context,
    // there can be only one simultaneous receive indication from
    // a network adapter simultaneously.  We save the necessary
    // data into adapter context to save unnecessary stack operations
    //

    pAdapterContext->NdisRcvStatus = NDIS_STATUS_NOT_RECOGNIZED;
    pAdapterContext->LinkRcvStatus = STATUS_SUCCESS;
    pAdapterContext->MacReceiveContext = MacReceiveContext;
    pAdapterContext->pHeadBuf = (PUCHAR)pHeadBuf;
    pAdapterContext->cbHeadBuf = cbHeadBuf;
    pAdapterContext->pLookBuf = (PUCHAR)pLookBuf;
    pAdapterContext->cbLookBuf = cbLookBuf;
    pAdapterContext->RcvLanHeaderLength = (USHORT)cbLanHeader;

    ACQUIRE_DRIVER_LOCK();

    ACQUIRE_SPIN_LOCK(&pAdapterContext->ObjectDataBase);

    switch(PacketType) {
    case LLC_PACKET_8022:

        //
        // Read the whole LLC frame (a maybe an extra byte,
        // if this is a U frame).
        // Note: Source and destination saps are swapped in
        //       the received frames
        //

        Source.Address.SrcSap = llcHdr.S.Dsap = packet[cbLanHeader];
        llcHdr.S.Ssap = packet[cbLanHeader + 1];
        Source.Address.DestSap = llcHdr.S.Ssap & (UCHAR)0xfe;
        llcHdr.S.Command = packet[cbLanHeader + 2];
        llcHdr.S.Nr = packet[cbLanHeader + 3];

        if (pSap = pAdapterContext->apSapBindings[llcHdr.U.Dsap]) {

            //
            // The broadcast addresses cannot be destined to link stations
            //

            if (pAdapterContext->ulBroadcastAddress == 0) {
                SEARCH_LINK(pAdapterContext, Source, pLink);
                if (pLink) {

                    //
                    // Process all connection oriented frames, the procedure
                    // will call ProcessType1_Frames, if it finds that the
                    // frame is connectionless.
                    // (We should bring the whole subprocedure here,
                    // because it isn't called elsewhere).
                    //

                    ProcessType2_Frames(pAdapterContext, pLink, llcHdr);
                } else {

                    //
                    // Process all connectionless frames and
                    // SABMEs (connection requests to create a
                    // new link station)
                    //

                    ProcessType1_Frames(pAdapterContext, pSap, llcHdr);
                }
            } else {

                //
                // Process the broadcasts, this cannot have
                // nothing to do with the links
                //

                ProcessType1_Frames(pAdapterContext, pSap, llcHdr);
            }
        } else {

            //
            // The SAP has not been defined, but we must still respond
            // to the TEST and XID commands sent to the NULL SAP.
            // They must be echoed back to the sender
            //

            if ((llcHdr.U.Dsap == LLC_SSAP_NULL)
            && !(llcHdr.U.Ssap & LLC_SSAP_RESPONSE)) {

                //
                // if the remote machine is already in the framing discovery
                // cache but is using the other framing type then discard this
                // TEST/XID command/response
                //

//                if (FramingDiscoveryCacheHit(pAdapterContext, pSap->Gen.pLlcBinding)) {
//                    break;
//                }

                RespondTestOrXid(pAdapterContext, llcHdr, LLC_SSAP_NULL);
            } else if (pAdapterContext->pDirectStation != NULL) {
                pAdapterContext->usRcvMask = ReceiveMasks[PacketType];
                MakeRcvIndication(pAdapterContext, (PLLC_OBJECT)pAdapterContext->pDirectStation);
            }
        }
        break;

    case LLC_PACKET_DIX:

        //
        // Search the DIX packet from the database
        //

        pObject = (PLLC_OBJECT)pAdapterContext->aDixStations[EthernetTypeOrLength % MAX_DIX_TABLE];
        if (pObject) {
            pAdapterContext->EthernetType = EthernetTypeOrLength;
        } else {
            pObject = (PLLC_OBJECT)pAdapterContext->pDirectStation;
            if (pObject) {
                pAdapterContext->usRcvMask = ReceiveMasks[PacketType];
            }
        }
        if (pObject) {
            MakeRcvIndication(pAdapterContext, pObject);
        }
        break;

    case LLC_PACKET_OTHER_DESTINATION:
    case LLC_PACKET_MAC:

        //
        // discard the return status of the direct stations!
        // The combining of the returns statuses would take too much time
        // NDIS 3.0 isn't actually any more intrested if frame is copied.
        //

        if (pObject = (PLLC_OBJECT)pAdapterContext->pDirectStation) {
            pAdapterContext->usRcvMask = ReceiveMasks[PacketType];
            MakeRcvIndication(pAdapterContext, pObject);
        }
        break;

#if LLC_DBG
    default:
        LlcInvalidObjectType();
        break;
#endif

    }

    RELEASE_SPIN_LOCK(&pAdapterContext->ObjectDataBase);

    RELEASE_DRIVER_LOCK();

    return pAdapterContext->NdisRcvStatus;
}


VOID
LlcNdisReceiveComplete(
    IN PADAPTER_CONTEXT pAdapterContext
    )

/*++

Routine Description:

    The routine handles the receive complete indications.  The receive
    completion is made by NDIS when the network hardware have been
    enabled again for receive. In a UP Nt this does mean, that a
    new frame could be received, because we are still on DPC level and
    the receive indication is still in DPC queue to wait us to complete.
    Actually that is OK, because otherwise the stack would overflow,
    if there would be too many received packets.

Arguments:

    pAdapterContext - adapter context

Return Value:

    None

--*/

{
    //
    // seems that 3Com FDDI card is calling this at PASSIVE_LEVEL
    //

    ASSUME_IRQL(ANY_IRQL);

    ACQUIRE_DRIVER_LOCK();

    //
    // Skip the whole background process if there is nothing to do.
    // its the default case, when we are receiving I or UI data.
    //

    if (pAdapterContext->LlcPacketInSendQueue
    || !IsListEmpty(&pAdapterContext->QueueCommands)
    || !IsListEmpty(&pAdapterContext->QueueEvents)) {

        ACQUIRE_SPIN_LOCK(&pAdapterContext->SendSpinLock);

        BackgroundProcessAndUnlock(pAdapterContext);
    }

    RELEASE_DRIVER_LOCK();
}


VOID
ProcessType1_Frames(
    IN PADAPTER_CONTEXT pAdapterContext,
    IN PLLC_SAP pSap,
    IN LLC_HEADER LlcHeader
    )

/*++

Routine Description:

    Route UI, TEST or XID frames to the LLC client

Arguments:

    pAdapterContext - The Adapter Binding specified at initialization time.
    pSap            - pointer to the SAP object of data link driver
    LlcHeader       - 802.2 header is copied to stack to make its access fast

Return Value:

    None.

--*/

{
    UCHAR DlcCommand;

    ASSUME_IRQL(DISPATCH_LEVEL);

    //
    // Update the counter, we must later check the lost frames
    // (no buffers available for the received UI- frames)
    //

    pSap->Statistics.FramesReceived++;

    //
    // We must use the link station state machine with any other
    // command except UI frames and broadcasts, if the link exists.
    //

    if ((LlcHeader.U.Command & ~LLC_U_POLL_FINAL) == LLC_UI) {
        pAdapterContext->FrameType = LLC_UI_FRAME;
        MakeRcvIndication(pAdapterContext, (PLLC_OBJECT)pSap);
        return;

        //
        // Check next if the frame is a XID or TEST frame
        //

    } else if ((LlcHeader.U.Command & ~LLC_U_POLL_FINAL) == LLC_TEST) {

        //
        // if the remote machine is already in the framing discovery cache but
        // is using the other framing type then discard this TEST command/response
        //

        //
        // RLF 06/23/94
        //
        // If this is a Response from SAP 0 then don't check the cache. The
        // reason is that currently DLC will automatically generate responses
        // to TESTs and XIDs sent to SAP 0. It will generate 802.3 and DIX
        // irrespective of whether it is configured for DIX or not. The upshot
        // is that a DIX-only machine can currently send an 802.3 response
        // which when we run it through the cache, causes us to assume the other
        // machine is configured for 802.3, not DIX. In communicado.
        // For TEST and XIDs from SAP 0, we have to let the app receive the
        // duplicate and decide what to do with it
        //

        if (LlcHeader.U.Ssap != (LLC_SSAP_NULL | LLC_SSAP_RESPONSE)) {
            if (FramingDiscoveryCacheHit(pAdapterContext, pSap->Gen.pLlcBinding)) {
                return;
            }
        }
        if (!(LlcHeader.U.Ssap & LLC_SSAP_RESPONSE)) {

            //
            // The Test commands are always echoed back
            // (the Command/Response bit was reset => this is command)
            //

            RespondTestOrXid(pAdapterContext, LlcHeader, pSap->SourceSap);
            pAdapterContext->NdisRcvStatus = NDIS_STATUS_SUCCESS;
            return;
        } else {
            DlcCommand = LLC_TEST_RESPONSE_NOT_FINAL;
        }
    } else if ((LlcHeader.U.Command & ~LLC_U_POLL_FINAL) == LLC_XID) {

        //
        // if the remote machine is already in the framing discovery cache but
        // is using the other framing type then discard this XID command/response
        //

        //
        // RLF 06/23/94
        //
        // If this is a Response from SAP 0 then don't check the cache. See above
        //

        if (LlcHeader.U.Ssap != (LLC_SSAP_NULL | LLC_SSAP_RESPONSE)) {
            if (FramingDiscoveryCacheHit(pAdapterContext, pSap->Gen.pLlcBinding)) {
                return;
            }
        }

        //
        // The upper level protocol may ask data link driver to handle the XIDs
        //

        if (!(LlcHeader.U.Ssap & LLC_SSAP_RESPONSE)) {
            if (pSap->OpenOptions & LLC_HANDLE_XID_COMMANDS) {
                RespondTestOrXid(pAdapterContext, LlcHeader, pSap->SourceSap);
                pAdapterContext->NdisRcvStatus = NDIS_STATUS_SUCCESS;
                return;
            } else {
                DlcCommand = LLC_XID_COMMAND_NOT_POLL;
            }
        } else {
            DlcCommand = LLC_XID_RESPONSE_NOT_FINAL;
        }
    } else if ((LlcHeader.U.Command & ~LLC_U_POLL_FINAL) == LLC_SABME) {

        //
        // can't open a connection by broadcasting a SABME
        //

        if (pAdapterContext->ulBroadcastAddress != 0) {
            return;
        }

        //
        // if the remote machine is already in the framing discovery cache but
        // is using the other framing type then discard this SABME
        //

        if (FramingDiscoveryCacheHit(pAdapterContext, pSap->Gen.pLlcBinding)) {
            return;
        }

        //
        // This is a remote connection request
        //

        ProcessNewSabme(pAdapterContext, pSap, LlcHeader);
        pAdapterContext->NdisRcvStatus = NDIS_STATUS_SUCCESS;
        return;
    } else {
        return;
    }

    if (LlcHeader.auchRawBytes[2] & LLC_U_POLL_FINAL) {
        DlcCommand -= 2;
    }

    pAdapterContext->FrameType = DlcCommand;
    MakeRcvIndication(pAdapterContext, (PLLC_OBJECT)pSap);
}


VOID
MakeRcvIndication(
    IN PADAPTER_CONTEXT pAdapterContext,
    IN PLLC_OBJECT pStation
    )

/*++

Routine Description:

    Procedure makes a generic receive indication for all frames
    received by SAP or direct stations.

Arguments:

    pAdapterContext - adapter context of the received packet
    pStation        - SAP or DIRECT station

Return Value:

    None.

--*/

{
    ASSUME_IRQL(DISPATCH_LEVEL);

    //
    // SAP and direct stations can be shared by several link clients
    // (if they have been opened in shared mode).  Route the packet
    // to all clints registered to this SAP or direct station
    // A link station may have only one owner.
    //

    for (; pStation; pStation = (PLLC_OBJECT)pStation->Gen.pNext) {

        //
        // Rotate the direct frames to all direct stations except if
        // the frame has already been captured by the current client.
        // We use 32-bit client context to identify the client,
        // that had already received the frame to its SAP or link station.
        //
        // Broadcasts are indicated only when they match with the
        // group or functional address defined for this binding.
        // The global broadcast is passed through, if it is enabled.
        //

        if (

            //
            // 1. Check is this is destinated frame (broadcast is null) or
            //    if the packet is a broadcast with a matching group address
            //

            ((pAdapterContext->ulBroadcastAddress == 0)
            || (pAdapterContext->ulBroadcastAddress == 0xFFFFFFFFL)
            || ((pAdapterContext->ulBroadcastAddress & pStation->Gen.pLlcBinding->Functional.ulAddress)
            && ((pAdapterContext->ulBroadcastAddress & pStation->Gen.pLlcBinding->ulFunctionalZeroBits) == 0)
            && (pAdapterContext->usBroadcastAddress == pAdapterContext->usHighFunctionalBits))
            || ((pAdapterContext->ulBroadcastAddress == pStation->Gen.pLlcBinding->ulBroadcastAddress)
            && (pAdapterContext->usBroadcastAddress == pStation->Gen.pLlcBinding->usBroadcastAddress)))

            //
            // 2. If the station type is DIX, then the ethernet type
            //    must be the same as the station's ethernet type

            && ((pStation->Gen.ObjectType != LLC_DIX_OBJECT)
            || (pStation->Dix.ObjectAddress == pAdapterContext->EthernetType))

            //
            // 3. If the packet is a direct frame, then its receive mask
            //    must match with the received frame.
            //

            && ((pStation->Gen.ObjectType != LLC_DIRECT_OBJECT)
            || (pStation->Dir.OpenOptions & pAdapterContext->usRcvMask))) {

            UINT Status;

            //
            // Update the counter, we must later check the lost frames
            // (if no buffers available for the received frames)
            //

            pStation->Sap.Statistics.FramesReceived++;
            pAdapterContext->NdisRcvStatus = NDIS_STATUS_SUCCESS;
            Status = pStation->Gen.pLlcBinding->pfReceiveIndication(
                pStation->Gen.pLlcBinding->hClientContext,
                pStation->Gen.hClientHandle,
                pAdapterContext->FrameType,
                pAdapterContext->pLookBuf,
                pAdapterContext->cbPacketSize - pAdapterContext->RcvLanHeaderLength
                );

            //
            // Protocol may discard the packet and its indication.
            //

            if (Status != STATUS_SUCCESS) {
                pStation->Sap.Statistics.DataLostCounter++;
                if (Status == DLC_STATUS_NO_RECEIVE_COMMAND) {
                    pStation->Sap.Statistics.FramesDiscardedNoRcv++;
                }
            }
        }
    }
}


VOID
ProcessType2_Frames(
    IN PADAPTER_CONTEXT pAdapterContext,
    IN OUT PDATA_LINK pLink,
    IN LLC_HEADER LlcHeader
    )

/*++

Routine Description:

    Procedure preprocess LLC Type2 frames for the actual state machine.
    Type 2 LLC frames are: I, RR, RNR, REJ, SABME, DISC, UA, DM, FRMR.
    The data is indicated to the upper protocol module, if it sequence
    number of the I- frame is valid, but the receive may still fail,
    if the data packet is discarded by the 802.2 state machine.
    The data is first indicated to the client, because we must set
    first the state machine to the local busy state, if the upper
    protocol module has not enough buffers to receive the data.

Arguments:

    pAdapterContext - The Adapter Binding specified at initialization time.
    pLink           - link station data
    LlcHeader       - LLC header

Return Value:

    None.

--*/

{
    UCHAR uchInput;
    BOOLEAN boolPollFinal;
    UINT status;

    ASSUME_IRQL(DISPATCH_LEVEL);

    //
    // The last received command is included in the DLC statistics
    //

    pLink->LastCmdOrRespReceived = LlcHeader.U.Command;

    //
    // Handle first I frames, they are the most common!
    //

    if (!(LlcHeader.U.Command & LLC_NOT_I_FRAME)) {

        //
        // Check first the sync of the I- frame: The send sequence
        // number should be what we are expected or some packets sare lost.
        //

        uchInput = IS_I_r0;     // In Sequence Information frame by default

        //
        // we discard all I-frames, that are bigger than the
        // maximum defined for this link station.
        // This must be the best way to solve wrong packet size.
        // FRMR disconnects the packets and the invalid transmit
        // command should fail in the sending side.
        //

        pLink->Nr = LlcHeader.I.Nr & (UCHAR)0xfe;
        if (pLink->MaxIField + pAdapterContext->RcvLanHeaderLength
        + sizeof(LLC_HEADER) < pAdapterContext->cbPacketSize) {
            uchInput = LPDU_INVALID_r0;
        } else if ((LlcHeader.I.Ns & (UCHAR)0xfe) != pLink->Vr) {

            //
            // Out of Sequence Information frame (we didn't expect this!)
            //

            uchInput = OS_I_r0;

            //
            // When we are out of receive buffers, we want to know
            // the buffer space required by all expected frames.
            // There may be several coming I-frames in the send queues,
            // bridges and in the receive buffers of the adapter when a
            // link enters a local busy state.  We save the size of
            // all received sequential I-frames during a local busy state
            // to know how much buffer space we must commit before we
            // can clear the local busy state.
            //

            if ((pLink->Flags & DLC_LOCAL_BUSY_BUFFER)
            && (LlcHeader.I.Ns & (UCHAR)0xfe) == pLink->VrDuringLocalBusy) {
                pLink->VrDuringLocalBusy += 2;
                pLink->BufferCommitment += BufGetPacketSize(pAdapterContext->cbPacketSize);
            }

            //
            // The valid frames has modulo: Va <= Nr <= Vs,
            // Ie. the Receive sequence number should belong to
            // a frame that has been sent but not acknowledged.
            // The extra check in the beginning makes the most common
            // code path faster: usually the other is waiting the next frame.
            //

        } else if (pLink->Nr != pLink->Vs) {

            //
            // There may by something wrong with the receive sequence number
            //

            if (pLink->Vs >= pLink->Va) {
                if (pLink->Nr < pLink->Va || pLink->Nr > pLink->Vs) {
                    uchInput = LPDU_INVALID_r0;
                }
            } else {
                if (pLink->Nr > pLink->Vs && pLink->Nr < pLink->Va) {
                    uchInput = LPDU_INVALID_r0;
                }
            }
        }

        //
        // We must first indcate the frame to the upper protocol and
        // then check, if it was accepted by the state machine.
        // If a I- frame cannot be received by the upper protocol
        // driver, then it must be dropped to the floor and be not
        // indicated to the state machine (=> the frame will be lost
        // for the LLC protocol)
        //

        //
        // RLF 04/13/93
        //
        // if the link is in local busy (user) state then don't indicate the
        // frame, but RNR it
        //

        if ((uchInput == IS_I_r0) && !(pLink->Flags & DLC_LOCAL_BUSY_USER)) {

            DLC_STATUS Status;

            pAdapterContext->LinkRcvStatus = STATUS_PENDING;
            Status = pLink->Gen.pLlcBinding->pfReceiveIndication(
                pLink->Gen.pLlcBinding->hClientContext,
                pLink->Gen.hClientHandle,
                LLC_I_FRAME,
                pAdapterContext->pLookBuf,
                pAdapterContext->cbPacketSize - pAdapterContext->RcvLanHeaderLength
                );

            //
            // We use local busy to stop the send to the link.
            // IBM link station flow control management supports
            // local busy state enabling because of "out of receive buffers"
            // or "no outstanding receive".
            //

            if (Status != STATUS_SUCCESS) {
                if (Status == DLC_STATUS_NO_RECEIVE_COMMAND
                || Status == DLC_STATUS_OUT_OF_RCV_BUFFERS) {

                    ACQUIRE_SPIN_LOCK(&pAdapterContext->SendSpinLock);

                    //
                    // We will enter to a local busy state because of
                    // out of buffers. Save the buffer size required
                    // to receive this data.
                    //

                    pLink->VrDuringLocalBusy = pLink->Vr;
                    pLink->BufferCommitment = BufGetPacketSize(pAdapterContext->cbPacketSize);

                    //
                    // We do not need to care, if the local busy state
                    // is already set or not.  The state machine just
                    // returns an error status, but we do not care
                    // about it.  The dlc status code trigger indication
                    // to the upper levels, if the state machine accepted
                    // the command.
                    //

                    pLink->Flags |= DLC_LOCAL_BUSY_BUFFER;
                    pLink->DlcStatus.StatusCode |= INDICATE_LOCAL_STATION_BUSY;
                    RunStateMachineCommand(pLink, ENTER_LCL_Busy);

                    RELEASE_SPIN_LOCK(&pAdapterContext->SendSpinLock);
                }
            }
        }

        ACQUIRE_SPIN_LOCK(&pAdapterContext->SendSpinLock);

        //
        // The most common case is handled as a special case.
        // We can save maybe 30 instrunctions.
        //

        if (uchInput == IS_I_r0 && pLink->State == LINK_OPENED) {
            UpdateVa(pLink);
            pLink->Vr += 2;
            pAdapterContext->LinkRcvStatus = STATUS_SUCCESS;

            //
            // IS_I_c1 = Update_Va; Rcv_BTU; [Send_ACK]
            // IS_I_r|IS_I_c0 = Update_Va; Rcv_BTU; TT2; Ir_Ct=N3; [RR_r](1)
            //

            if ((LlcHeader.I.Nr & LLC_I_S_POLL_FINAL)
            && !(LlcHeader.I.Ssap & LLC_SSAP_RESPONSE)) {
                StopTimer(&pLink->T2);
                pLink->Ir_Ct = pLink->N3;
                SendLlcFrame(pLink, (UCHAR)(DLC_RR_TOKEN | DLC_TOKEN_RESPONSE | 1));
            } else {
                SendAck(pLink);
            }
        } else {
            uchInput += (UINT)(LlcHeader.I.Nr & LLC_I_S_POLL_FINAL);

            if (!(LlcHeader.I.Ssap & LLC_SSAP_RESPONSE)) {
                uchInput += DLC_TOKEN_COMMAND;
            }

            //
            // Nr will be some garbage in the case of U commands,
            // but the Poll/Final flag is not used when the U- commands
            // are processed.
            // ----
            // If the state machine returns an error to link receive status,
            // then the receive command completion cancels the received
            // frame.
            //

            pAdapterContext->LinkRcvStatus = RunStateMachine(
                pLink,
                (USHORT)uchInput,
                (BOOLEAN)((LlcHeader.S.Nr & LLC_I_S_POLL_FINAL) ? 1 : 0),
                (BOOLEAN)(LlcHeader.S.Ssap & LLC_SSAP_RESPONSE)
                );
        }

        RELEASE_SPIN_LOCK(&pAdapterContext->SendSpinLock);

        //
        // Update the error counters if something went wrong with
        // the receive.
        //

        if (pAdapterContext->LinkRcvStatus != STATUS_SUCCESS) {

            //
            // We will count all I frames not actually acknowledged
            // as errors (this could be counted also other way).
            //

            pLink->Statistics.I_FrameReceiveErrors++;
            if (pLink->Statistics.I_FrameReceiveErrors == 0x80) {
                pLink->DlcStatus.StatusCode |= INDICATE_DLC_COUNTER_OVERFLOW;
            }
        } else {

            //
            // update statistics: in-sequency frames OK, all others
            // must be  errors.
            // This may not be the best place to count successful I-frames,
            // because the state machine has not yet acknowledged this frame,
            // We may be in a wrong state to receive any data (eg. local busy)
            //

            pLink->Statistics.I_FramesReceived++;
            if (pLink->Statistics.I_FramesReceived == 0x8000) {
                pLink->DlcStatus.StatusCode |= INDICATE_DLC_COUNTER_OVERFLOW;
            }
            pLink->pSap->Statistics.FramesReceived++;
        }

        //
        // We may complete this only if the transfer data has
        // already completed (and there is a receive completion
        // packet built up in).
        //

        if (pLink->Gen.pLlcBinding->TransferDataPacket.pPacket != NULL
        && pLink->Gen.pLlcBinding->TransferDataPacket.pPacket->Data.Completion.Status != NDIS_STATUS_PENDING) {

            //
            // The NDIS status is saved in the completion status, we
            // will use state machine status instead, if the state
            // machine returned an error.
            //

            if (pAdapterContext->LinkRcvStatus != STATUS_SUCCESS) {
                pLink->Gen.pLlcBinding->TransferDataPacket.pPacket->Data.Completion.Status = pAdapterContext->LinkRcvStatus;
            }
            pLink->Gen.pLlcBinding->pfCommandComplete(
                pLink->Gen.pLlcBinding->hClientContext,
                pLink->Gen.pLlcBinding->TransferDataPacket.pPacket->Data.Completion.hClientHandle,
                pLink->Gen.pLlcBinding->TransferDataPacket.pPacket
                );
            pLink->Gen.pLlcBinding->TransferDataPacket.pPacket = NULL;
        }

        //
        // ******** EXIT ***********
        //

        return;
    } else if (!(LlcHeader.S.Command & LLC_U_TYPE_BIT)) {

        //
        // Handle S (Supervisory) commands (RR, REJ, RNR)
        //

        switch (LlcHeader.S.Command) {
        case LLC_RR:
            uchInput = RR_r0;
            break;

        case LLC_RNR:
            uchInput = RNR_r0;
            break;

        case LLC_REJ:
            uchInput = REJ_r0;
            break;

        default:
            uchInput = LPDU_INVALID_r0;
            break;
        }

        //
        // The valid frames has modulo: Va <= Nr <= Vs,
        // Ie. the Receive sequence number should belong to
        // a frame that has been sent but not acknowledged.
        // The extra check in the beginning makes the most common
        // code path faster: usually the other is waiting the next frame.
        // (keep the rest code the same as in I path, even a very
        // primitive optimizer will puts these code paths together)
        //

        pLink->Nr = LlcHeader.I.Nr & (UCHAR)0xfe;
        if (pLink->Nr != pLink->Vs) {

            //
            // Check the received sequence number
            //

            if (pLink->Vs >= pLink->Va) {
                if (pLink->Nr < pLink->Va || pLink->Nr > pLink->Vs) {
                    uchInput = LPDU_INVALID_r0;
                }
            } else {
                if (pLink->Nr > pLink->Vs && pLink->Nr < pLink->Va) {
                    uchInput = LPDU_INVALID_r0;
                }
            }
        }
        uchInput += (UINT)(LlcHeader.S.Nr & LLC_I_S_POLL_FINAL);
        boolPollFinal = (BOOLEAN)(LlcHeader.S.Nr & LLC_I_S_POLL_FINAL);

        if (!(LlcHeader.S.Ssap & LLC_SSAP_RESPONSE)) {
            uchInput += DLC_TOKEN_COMMAND;
        }
    } else {

        //
        // Handle U (Unnumbered) command frames
        // (FRMR, DM, UA, DISC, SABME, XID, TEST)
        //

        switch (LlcHeader.U.Command & ~LLC_U_POLL_FINAL) {
        case LLC_DISC:
            uchInput = DISC0;
            break;

        case LLC_SABME:
            uchInput = SABME0;
            break;

        case LLC_DM:
            uchInput = DM0;
            break;

        case LLC_UA:
            uchInput = UA0;
            break;

        case LLC_FRMR:
            uchInput =  FRMR0;
            break;

        default:

            //
            // we don't handle XID and TEST frames here!
            //

            ProcessType1_Frames(pAdapterContext, pLink->pSap, LlcHeader);
            return;
            break;
        };

        //
        // We set an uniform poll/final bit for procedure call
        //

        boolPollFinal = FALSE;
        if (LlcHeader.U.Command & LLC_U_POLL_FINAL) {
            uchInput += 1;
            boolPollFinal = TRUE;
        }
    }

    ACQUIRE_SPIN_LOCK(&pAdapterContext->SendSpinLock);

    //
    // Note: the 3rd parameter must be 0 or 1, fortunately the
    // the poll/final bit is bit0 in S and I frames.
    //

    status = RunStateMachine(pLink,
                             (USHORT)uchInput,
                             boolPollFinal,
                             (BOOLEAN)(LlcHeader.S.Ssap & LLC_SSAP_RESPONSE)
                             );

    //
    // if this frame is a UA AND it was accepted by the FSM AND the framing type
    // is currently unspecified then set it to the type in the UA frame received.
    // If this is not an ethernet adapter or we are not in AUTO mode then the
    // framing type for this link is set to the framing type in the binding
    // context (as it was before)
    //

    if ((status == STATUS_SUCCESS)
    && (uchInput == UA0)
    && (pLink->FramingType == LLC_SEND_UNSPECIFIED)) {

        //
        // RLF 05/09/94
        //
        // If we received a UA in response to a SABME that we sent out as DIX
        // and 802.3, then record the framing type. This will be used for all
        // subsequent frames sent on this link
        //

        pLink->FramingType = (IS_SNA_DIX_FRAME(pAdapterContext)
                           && IS_AUTO_BINDING(pLink->Gen.pLlcBinding))
                           ? LLC_SEND_802_3_TO_DIX
                           : pLink->Gen.pLlcBinding->InternalAddressTranslation
                           ;
    }

    RELEASE_SPIN_LOCK(&pAdapterContext->SendSpinLock);
}


VOID
ProcessNewSabme(
    IN PADAPTER_CONTEXT pAdapterContext,
    IN PLLC_SAP pSap,
    IN LLC_HEADER LlcHeader
    )

/*++

Routine Description:

    Procedure processes the remote connection requtest: SABME.
    It allocates a new link from the pool of closed links in
    the SAP and runs the state machine.

Arguments:

    pAdapterContext - The Adapter Binding specified at initialization time.
    pSap            - the current SAP handle
    LlcHeader       - LLC header

Return Value:

    None.

--*/

{
    PDATA_LINK pLink;
    DLC_STATUS Status;

    ASSUME_IRQL(DISPATCH_LEVEL);

    RELEASE_SPIN_LOCK(&pAdapterContext->ObjectDataBase);

    //
    // The destination sap cannot be a group SAP any more,
    // thus we don't need to mask the lowest bit aways
    //

    Status = LlcOpenLinkStation(
                pSap,
                (UCHAR)(LlcHeader.auchRawBytes[DLC_SSAP_OFFSET] & 0xfe),
                NULL,
                pAdapterContext->pHeadBuf,
                NULL,        // no client handle => DLC driver must create it
                (PVOID*)&pLink
                );

    ACQUIRE_SPIN_LOCK(&pAdapterContext->ObjectDataBase);

    //
    // We can do nothing, if we are out of resources
    //

    if (Status != STATUS_SUCCESS) {
        return;
    }

    ACQUIRE_SPIN_LOCK(&pAdapterContext->SendSpinLock);

    //
    // RLF 05/09/94
    //
    // We need to keep a per-connection indication of the framing type if the
    // adapter was opened in AUTO mode (else we generate 802.3 UA to DIX SABME)
    // Only do this for Ethernet adapters (we only set the SNA DIX frame
    // indicator in that case)
    //

    pLink->FramingType = (IS_SNA_DIX_FRAME(pAdapterContext)
                       && IS_AUTO_BINDING(pLink->Gen.pLlcBinding))
                       ? LLC_SEND_802_3_TO_DIX
                       : pLink->Gen.pLlcBinding->InternalAddressTranslation
                       ;

    //
    // now create the Link Station by running the FSM with ACTIVATE_LS as input.
    // This just initializes the link station 'object'. Then run the FSM again,
    // this time with the SABME command as input
    //

    RunStateMachineCommand(pLink, ACTIVATE_LS);
    RunStateMachine(
        pLink,
        (USHORT)((LlcHeader.U.Command & LLC_U_POLL_FINAL) ? SABME1 : SABME0),
        (BOOLEAN)((LlcHeader.U.Command & LLC_U_POLL_FINAL) ? 1 : 0),
        (BOOLEAN)TRUE
        );

    RELEASE_SPIN_LOCK(&pAdapterContext->SendSpinLock);
}


VOID
LlcTransferData(
    IN PBINDING_CONTEXT pBindingContext,
    IN PLLC_PACKET pPacket,
    IN PMDL pMdl,
    IN UINT uiCopyOffset,
    IN UINT cbCopyLength
    )

/*++

Routine Description:

    This function copies only the data part of the received frame - that is
    the area after the LLC and DLC headers. If NDIS handed us all the data
    in the lookahead buffer, then WE can copy it out. Otherwise we have to
    call NDIS to get the data.

    If this is a DIX format frame, then NDIS thinks that the LAN header is
    14 bytes, but we know it is 17. We have to tell NDIS to copy from 3 bytes
    further into the data part of the received frame than we would normally
    have to

Arguments:

    pBindingContext - binding handle
    pPacket         - receive context packet
    pMdl            - pointer to MDL describing data to copy
    uiCopyOffset    - offset from start of mapped buffer to copy from
    cbCopyLength    - length to copy

Return Value:

    None.

--*/

{
    PADAPTER_CONTEXT pAdapterContext = pBindingContext->pAdapterContext;

    pPacket->Data.Completion.CompletedCommand = LLC_RECEIVE_COMPLETION;

    //
    // if the amount of data to copy is contained within the lookahead buffer
    // then we can copy the data.
    //
    // Remember: pAdapterContext->cbLookBuf and pLookBuf have been correctly
    // adjusted in the case of a DIX format frame
    //

    if (pAdapterContext->cbLookBuf - uiCopyOffset >= cbCopyLength) {

        PUCHAR pSrcBuffer;
        UINT BufferLength;

        pSrcBuffer = pAdapterContext->pLookBuf + uiCopyOffset;

        do {
            if (cbCopyLength > MmGetMdlByteCount(pMdl)) {
                BufferLength = MmGetMdlByteCount(pMdl);
            } else {
                BufferLength = cbCopyLength;
            }

            //
            // In 386 memcpy is faster than RtlMoveMemory, it also
            // makes the full register optimization much easier, because
            // all registers are available (no proc calls within loop)
            //

            //
            // !!!! Can't use LlcMemCpy here: On mips expands to RtlMoveMemory
            //      which uses FP registers. This won't work with shared memory
            //      on TR card
            //

            safe_memcpy(MmGetSystemAddressForMdl(pMdl), pSrcBuffer, BufferLength);
            pMdl = pMdl->Next;
            pSrcBuffer += BufferLength;
            cbCopyLength -= BufferLength;
        } while (cbCopyLength);
        pPacket->Data.Completion.Status = STATUS_SUCCESS;
        pBindingContext->TransferDataPacket.pPacket = pPacket;

    } else {

        //
        // too bad: there is more data to copy than is available in the look
        // ahead buffer. We have to call NDIS to perform the copy
        //

        UINT BytesCopied;

        //
        // if this is an Ethernet adapter and the received LAN header length is
        // more than 14 bytes then this is a DIX frame. We need to let NDIS know
        // that we want to copy data from 3 bytes in from where it thinks the
        // DLC header starts
        //

        UINT additionalOffset = (pAdapterContext->NdisMedium == NdisMedium802_3)
                                    ? (pAdapterContext->RcvLanHeaderLength > 14)
                                        ? 3
                                        : 0
                                    : 0;

#if DBG
        if (additionalOffset) {
            ASSERT(pAdapterContext->RcvLanHeaderLength == 17);
        }
#endif

        //
        // Theoretically NdisTransferData may not complete
        // immediately, and we cannot add to the completion
        // list, because the command is not really complete.
        // We may save it to adapter context to wait the
        // NdisTransferData to complete.
        //

        if (pBindingContext->TransferDataPacket.pPacket != NULL) {

            //
            // BUG-BUG-BUG-BUG-BUG-BUG-BUG-BUG-BUG-BUG-BUG-BUG-BUG-BUG-BUG
            //
            // If the same LLC client tries to receive the same buffer
            // many times (eg. when receive a packet to a group sap) and
            // if NDIS would complete those commands asynchronously, then
            // we cannot receive the frame with NdisTransferData.
            // Fortunately all NDIS implemnetations completes NdisTransferData
            // synchronously.
            // Solution: We could chain new packets to the existing data transfer
            //     packet, and copy the data, when the first data transfer request
            //     completes.  This would mean a lot of code, that would never
            //     used by anyone.  We would also need MDL to MDL copy function.
            //     The first data transfer could also be a smaller that another
            //     after it => would not work in a very general case, but
            //     would work with the group saps (all receives would be the same
            //     => direct MDL -> MDL copy would be OK.
            //
            // BUG-BUG-BUG-BUG-BUG-BUG-BUG-BUG-BUG-BUG-BUG-BUG-BUG-BUG-BUG
            //

            pPacket->Data.Completion.Status = DLC_STATUS_ASYNC_DATA_TRANSFER_FAILED;

            pBindingContext->pfCommandComplete(pBindingContext->hClientContext,
                                               pPacket->Data.Completion.hClientHandle,
                                               pPacket
                                               );
        }

        pBindingContext->TransferDataPacket.pPacket = pPacket;
        pPacket->pBinding = pBindingContext;
        ResetNdisPacket(&pBindingContext->TransferDataPacket);
        NdisChainBufferAtFront((PNDIS_PACKET)&pBindingContext->TransferDataPacket, pMdl);

        //
        // ADAMBA - Removed pAdapterContext->RcvLanHeaderLength
        // from ByteOffset (the fourth param).
        //

        NdisTransferData((PNDIS_STATUS)&pPacket->Data.Completion.Status,
                         pAdapterContext->NdisBindingHandle,
                         pAdapterContext->MacReceiveContext,

                         //
                         // if this is a DIX frame we have to move the data
                         // pointer ahead by the amount in additionalOffset
                         // (should always be 3 in this case) and reduce the
                         // amount of data to copy by the same number
                         //

                         uiCopyOffset + additionalOffset,

                         //
                         // we DON'T need to account for the additionalOffset
                         // in the length to be copied though
                         //

                         cbCopyLength,
                         (PNDIS_PACKET)&pBindingContext->TransferDataPacket,
                         &BytesCopied
                         );
    }

    //
    // We must queue a packet for the final receive completion,
    // But we cannot do it until TransferData is completed
    // (it is actually always completed, but this code is just
    // for sure).
    //

    if (pPacket->Data.Completion.Status != NDIS_STATUS_PENDING
    && pAdapterContext->LinkRcvStatus != STATUS_PENDING) {

        //
        // We receive the data before it is checked by the link station.
        // The upper protocol must just setup asynchronous receive
        // and later in LLC_RECEIVE_COMPLETION handling to
        // discard the receive, if it failed or accept if
        // it was OK for NDIS and link station.
        //

        if (pAdapterContext->LinkRcvStatus != STATUS_SUCCESS) {
            pPacket->Data.Completion.Status = pAdapterContext->LinkRcvStatus;
        }

        ACQUIRE_DRIVER_LOCK();

        pBindingContext->pfCommandComplete(pBindingContext->hClientContext,
                                           pPacket->Data.Completion.hClientHandle,
                                           pPacket
                                           );

        RELEASE_DRIVER_LOCK();

        pBindingContext->TransferDataPacket.pPacket = NULL;
    }
}


VOID
LlcNdisTransferDataComplete(
    IN PADAPTER_CONTEXT pAdapterContext,
    IN PNDIS_PACKET pPacket,
    IN NDIS_STATUS NdisStatus,
    IN UINT uiBytesTransferred
    )

/*++

Routine Description:

    The routine handles NdisCompleteDataTransfer indication and
    queues the indication of the completed receive operation.

Arguments:

    pAdapterContext     - adapter context
    pPacket             - NDIS packet used in the data transfer
    NdisStatus          - status of the completed data transfer
    uiBytesTransferred  - who needs this, I am not interested in
                          the partially succeeded data transfers,

Return Value:

    None.

--*/

{
    KIRQL OldIrql;

    UNREFERENCED_PARAMETER(uiBytesTransferred);
    UNREFERENCED_PARAMETER(OldIrql);

    ASSUME_IRQL(DISPATCH_LEVEL);

    ACQUIRE_DRIVER_LOCK();

    if (((PLLC_TRANSFER_PACKET)pPacket)->pPacket != NULL) {
        ((PLLC_TRANSFER_PACKET)pPacket)->pPacket->Data.Completion.Status = NdisStatus;

        //
        // I- frames have two statuses.  The link state machine is executed
        // after the NdisDataTransfer and thus its returned status may still
        // cancel the command. There are no spin locks around the return status
        // handling, but this should still work fine. It actually does not
        // matter if we return NDIS or state machine error code
        //

        if (pAdapterContext->LinkRcvStatus != STATUS_PENDING) {
            if (pAdapterContext->LinkRcvStatus != STATUS_SUCCESS) {
                ((PLLC_TRANSFER_PACKET)pPacket)->pPacket->Data.Completion.Status = pAdapterContext->LinkRcvStatus;
            }
            ((PLLC_TRANSFER_PACKET)pPacket)->pPacket->pBinding->pfCommandComplete(
                    ((PLLC_TRANSFER_PACKET)pPacket)->pPacket->pBinding->hClientContext,
                    ((PLLC_TRANSFER_PACKET)pPacket)->pPacket->Data.Completion.hClientHandle,
                    ((PLLC_TRANSFER_PACKET)pPacket)->pPacket
                    );
            ((PLLC_TRANSFER_PACKET)pPacket)->pPacket = NULL;
        }
    }

    RELEASE_DRIVER_LOCK();
}


VOID
safe_memcpy(
    OUT PUCHAR Destination,
    IN PUCHAR Source,
    IN ULONG Length
    )

/*++

Routine Description:

    This is here because on a MIPS machine, LlcMemCpy expands to RtlMoveMemory
    which wants to use 64-bit floating point (CP1) registers for memory moves
    where both source and destination are aligned on 8-byte boundaries and
    where the length is a multiple of 32 bytes. If the source or destination
    buffer is actually the shared memory of a TR card, then the 64-bit moves
    (saw it on read, presume same for write) can only access memory in 32-bit
    chunks and 01 02 03 04 05 06 07 08 gets converted to 01 02 03 04 01 02 03 04.
    So this function attempts to do basically the same, without all the smarts
    as the original, but doesn't employ coprocessor registers to achieve the
    move. Hence slower, but safer

Arguments:

    Destination - where we're copying to
    Source      - where we're copying from
    Length      - how many bytes to move

Return Value:

    None.

--*/

{
    ULONG difference = (ULONG)Destination - (ULONG)Source;
    INT i;

    if (!(difference && Length)) {
        return;
    }

    //
    // if the destination overlaps the source then do reverse copy. Add a little
    // optimization - a la RtlMoveMemory - try to copy as many bytes as DWORDS.
    // However, on MIPS, both source and destination must be DWORD aligned to
    // do this. If both aren't then fall-back to BYTE copy
    //

    if (difference < Length) {
        if (!(((ULONG)Destination & 3) || ((ULONG)Source & 3))) {
            Destination += Length;
            Source += Length;

            for (i = Length % 4; i; --i) {
                *--Destination = *--Source;
            }
            for (i = Length / 4; i; --i) {
                *--((PULONG)Destination) = *--((PULONG)Source);
            }
        } else {
            Destination += Length;
            Source += Length;

            while (Length--) {
                *--Destination = *--Source;
            }
        }
    } else {
        if (!(((ULONG)Destination & 3) || ((ULONG)Source & 3))) {
            for (i = Length / 4; i; --i) {
                *((PULONG)Destination)++ = *((PULONG)Source)++;
            }
            for (i = Length % 4; i; --i) {
                *Destination++ = *Source++;
            }
        } else {
            while (Length--) {
                *Destination++ = *Source++;
            }
        }
    }
}


BOOLEAN
FramingDiscoveryCacheHit(
    IN PADAPTER_CONTEXT pAdapterContext,
    IN PBINDING_CONTEXT pBindingContext
    )

/*++

Routine Description:

    This function is called when we receive a TEST/XID/SABME frame AND the
    adapter binding was created with LLC_ETHERNET_TYPE_AUTO AND we opened an
    ethernet adapter.

    The frame has either 802.3 or DIX framing. For all command and response TEST
    and XID frames and all SABME frames received, we keep note of the MAC address
    where the frame originated and its framing type.

    The first time we receive one of the above frames from a particular MAC
    address, the info will not be in the cache. So we add it. Subsequent frames
    of the above type (all others are passed through) with the same framing type
    as that in the cache will be indicated to the higher layers. If one of the
    above frame types arrives with THE OPPOSITE framing type (i.e. DIX instead
    of 802.3) then when we look in the cache for the MAC address we will find
    that it is already there, but with a different framing type (i.e. 802.3
    instead of DIX). In this case, we assume that the frame is an automatic
    duplicate and we discard it

    NOTE: We don't have to worry about UA because we only expect one SABME to
    be accepted: either we're sending the duplicate SABME and the target machine
    is configured for 802.3 or DIX, BUT NOT BOTH, or the receiving machine is
    another NT box running this DLC (with caching enabled!) and it will filter
    out the duplicate. Hence, in both situations, only one UA response should be
    generated per the SABME 'event'

    ASSUMES: The tick count returned from the system never wraps (! 2^63/10^7
    == 29,247+ years)

Arguments:

    pAdapterContext - pointer to ADAPTER_CONTEXT which has been filled in with
                      pHeadBuf pointing to - at least - the first 14 bytes in
                      the frame header
    pBindingContext - pointer to BINDING_CONTEXT containing the EthernetType
                      and if LLC_ETHERNET_TYPE_AUTO, the address of the framing
                      discovery cache

Return Value:

    BOOLEAN
        TRUE    - the MAC address was found in the cache WITH THE OTHER FRAMING
                  TYPE. Therefore the current frame should be discarded
        FALSE   - the MAC address/framing type combination was not found. The
                  frame should be indicated to the higher layer. If caching is
                  enabled, the frame has been added to the cache

--*/

{
    ULONG i;
    ULONG lruIndex;
    LARGE_INTEGER timeStamp;
    NODE_ADDRESS nodeAddress;
    PFRAMING_DISCOVERY_CACHE_ENTRY pCache;
    UCHAR framingType;

    //
    // if the binding context was not created with LLC_ETHERNET_TYPE_AUTO (and
    // therefore by implication, adapter is not ethernet) OR framing discovery
    // caching is disabled (the value read from the registry was zero) then bail
    // out with a not-found indication
    //

    if ((pBindingContext->EthernetType != LLC_ETHERNET_TYPE_AUTO)
    || (pBindingContext->FramingDiscoveryCacheEntries == 0)) {

#if defined(DEBUG_DISCOVERY)

        DbgPrint("FramingDiscoveryCacheHit: Not AUTO or 0 cache: returning FALSE\n");

#endif

        return FALSE;
    }

#if defined(DEBUG_DISCOVERY)

    {
        //
        // BUGBUG - even though this is debug code, we shouldn't really be
        //          indexing so far into pHeadBuf. Its only guaranteed to be
        //          14 bytes long. Should be looking in pLookBuf[5] and [2]
        //

        UCHAR frame = (pAdapterContext->pHeadBuf[12] == 0x80)
                    ? pAdapterContext->pHeadBuf[19]
                    : pAdapterContext->pHeadBuf[16];

        frame &= ~0x10; // knock off Poll/Final bit

        DbgPrint("FramingDiscoveryCacheHit: Received: %02x-%02x-%02x-%02x-%02x-%02x %s %s (%02x)\n",
                 pAdapterContext->pHeadBuf[6],
                 pAdapterContext->pHeadBuf[7],
                 pAdapterContext->pHeadBuf[8],
                 pAdapterContext->pHeadBuf[9],
                 pAdapterContext->pHeadBuf[10],
                 pAdapterContext->pHeadBuf[11],
                 (pAdapterContext->pHeadBuf[12] == 0x80)
                    ? "DIX"
                    : "802.3",
                 (frame == 0xE3)
                    ? "TEST"
                    : (frame == 0xAF)
                        ? "XID"
                        : (frame == 0x6F)
                            ? "SABME"
                            : (frame == 0x63)
                                ? "UA"
                                : "???",
                 frame
                 );
    }

#endif

    //
    // set up and perform a linear search of the cache (it should be reasonably
    // small and the comparisons are ULONG & USHORT, so not time critical
    //

    lruIndex = 0;

    //
    // better make sure we don't get data misalignment on MIPS
    //

    nodeAddress.Words.Top4 = *(ULONG UNALIGNED *)&pAdapterContext->pHeadBuf[6];
    nodeAddress.Words.Bottom2 = *(USHORT UNALIGNED *)&pAdapterContext->pHeadBuf[10];
    pCache = pBindingContext->FramingDiscoveryCache;

    //
    // framingType is the type we are looking for in the cache, not the type
    // in the frame
    //

    framingType = ((pAdapterContext->pHeadBuf[12] == 0x80)
                && (pAdapterContext->pHeadBuf[13] == 0xD5))
                ? FRAMING_TYPE_802_3
                : FRAMING_TYPE_DIX
                ;

    //
    // get the current tick count for comparison of time stamps
    //

    KeQueryTickCount(&timeStamp);

    //
    // linear search the cache
    //

    for (i = 0; i < pBindingContext->FramingDiscoveryCacheEntries; ++i) {
        if (pCache[i].InUse) {
            if ((pCache[i].NodeAddress.Words.Top4 == nodeAddress.Words.Top4)
            && (pCache[i].NodeAddress.Words.Bottom2 == nodeAddress.Words.Bottom2)) {

                //
                // we found the destination MAC address. If it has the opposite
                // framing type to that in the frame just received, return TRUE
                // else FALSE. In both cases refresh the time stamp
                //

                pCache[i].TimeStamp = timeStamp;

#if defined(DEBUG_DISCOVERY)

                DbgPrint("FramingDiscoveryCacheHit: Returning %s. Index = %d\n\n",
                         (pCache[i].FramingType == framingType) ? "TRUE" : "FALSE",
                         i
                         );

#endif

                return (pCache[i].FramingType == framingType);
            } else if (pCache[i].TimeStamp.QuadPart < timeStamp.QuadPart) {

                //
                // if we need to throw out a cache entry, we throw out the one
                // with the oldest time stamp
                //

                timeStamp = pCache[i].TimeStamp;
                lruIndex = i;
            }
        } else {

            //
            // we have hit an unused entry. The destination address/framing type
            // cannot be in the cache: add the received address/framing type at
            // this unused location
            //

            lruIndex = i;
            break;
        }
    }

    //
    // the destination address/framing type combination are not in the cache.
    // Add them. Throw out an entry if necessary
    //

#if defined(DEBUG_DISCOVERY)

    DbgPrint("FramingDiscoveryCacheHit: Adding/Throwing out %d (time stamp %08x.%08x\n",
             lruIndex,
             pCache[lruIndex].TimeStamp.HighPart,
             pCache[lruIndex].TimeStamp.LowPart
             );

#endif

    pCache[lruIndex].NodeAddress.Words.Top4 = nodeAddress.Words.Top4;
    pCache[lruIndex].NodeAddress.Words.Bottom2 = nodeAddress.Words.Bottom2;
    pCache[lruIndex].InUse = TRUE;
    pCache[lruIndex].FramingType = (framingType == FRAMING_TYPE_DIX)
                                 ? FRAMING_TYPE_802_3
                                 : FRAMING_TYPE_DIX
                                 ;
    pCache[lruIndex].TimeStamp = timeStamp;

    //
    // return FALSE meaning the destination address/framing type just received
    // was not in the cache (but it is now)
    //

#if defined(DEBUG_DISCOVERY)

    DbgPrint("FramingDiscoveryCacheHit: Returning FALSE\n\n");

#endif

    return FALSE;
}