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
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
|
/*
*************************************************************************
* Ralink Tech Inc.
* 5F., No.36, Taiyuan St., Jhubei City,
* Hsinchu County 302,
* Taiwan, R.O.C.
*
* (c) Copyright 2002-2007, Ralink Technology, Inc.
*
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
*************************************************************************
Module Name:
rtmp_data.c
Abstract:
Data path subroutines
Revision History:
Who When What
-------- ---------- ----------------------------------------------
John Aug/17/04 major modification for RT2561/2661
Jan Lee Mar/17/06 major modification for RT2860 New Ring Design
*/
#include "../rt_config.h"
VOID STARxEAPOLFrameIndicate(
IN PRTMP_ADAPTER pAd,
IN MAC_TABLE_ENTRY *pEntry,
IN RX_BLK *pRxBlk,
IN UCHAR FromWhichBSSID)
{
PRT28XX_RXD_STRUC pRxD = &(pRxBlk->RxD);
PRXWI_STRUC pRxWI = pRxBlk->pRxWI;
UCHAR *pTmpBuf;
#ifdef WPA_SUPPLICANT_SUPPORT
if (pAd->StaCfg.WpaSupplicantUP)
{
// All EAPoL frames have to pass to upper layer (ex. WPA_SUPPLICANT daemon)
// TBD : process fragmented EAPol frames
{
// In 802.1x mode, if the received frame is EAP-SUCCESS packet, turn on the PortSecured variable
if ( pAd->StaCfg.IEEE8021X == TRUE &&
(EAP_CODE_SUCCESS == WpaCheckEapCode(pAd, pRxBlk->pData, pRxBlk->DataSize, LENGTH_802_1_H)))
{
PUCHAR Key;
UCHAR CipherAlg;
int idx = 0;
DBGPRINT_RAW(RT_DEBUG_TRACE, ("Receive EAP-SUCCESS Packet\n"));
STA_PORT_SECURED(pAd);
if (pAd->StaCfg.IEEE8021x_required_keys == FALSE)
{
idx = pAd->StaCfg.DesireSharedKeyId;
CipherAlg = pAd->StaCfg.DesireSharedKey[idx].CipherAlg;
Key = pAd->StaCfg.DesireSharedKey[idx].Key;
if (pAd->StaCfg.DesireSharedKey[idx].KeyLen > 0)
{
MAC_TABLE_ENTRY *pEntry = &pAd->MacTab.Content[BSSID_WCID];
// Set key material and cipherAlg to Asic
AsicAddSharedKeyEntry(pAd, BSS0, idx, CipherAlg, Key, NULL, NULL);
// Assign group key info
RTMPAddWcidAttributeEntry(pAd, BSS0, idx, CipherAlg, NULL);
// Assign pairwise key info
RTMPAddWcidAttributeEntry(pAd, BSS0, idx, CipherAlg, pEntry);
pAd->IndicateMediaState = NdisMediaStateConnected;
pAd->ExtraInfo = GENERAL_LINK_UP;
// For Preventing ShardKey Table is cleared by remove key procedure.
pAd->SharedKey[BSS0][idx].CipherAlg = CipherAlg;
pAd->SharedKey[BSS0][idx].KeyLen = pAd->StaCfg.DesireSharedKey[idx].KeyLen;
NdisMoveMemory(pAd->SharedKey[BSS0][idx].Key,
pAd->StaCfg.DesireSharedKey[idx].Key,
pAd->StaCfg.DesireSharedKey[idx].KeyLen);
}
}
}
Indicate_Legacy_Packet(pAd, pRxBlk, FromWhichBSSID);
return;
}
}
else
#endif // WPA_SUPPLICANT_SUPPORT //
{
// Special DATA frame that has to pass to MLME
// 1. Cisco Aironet frames for CCX2. We need pass it to MLME for special process
// 2. EAPOL handshaking frames when driver supplicant enabled, pass to MLME for special process
{
pTmpBuf = pRxBlk->pData - LENGTH_802_11;
NdisMoveMemory(pTmpBuf, pRxBlk->pHeader, LENGTH_802_11);
REPORT_MGMT_FRAME_TO_MLME(pAd, pRxWI->WirelessCliID, pTmpBuf, pRxBlk->DataSize + LENGTH_802_11, pRxWI->RSSI0, pRxWI->RSSI1, pRxWI->RSSI2, pRxD->PlcpSignal);
DBGPRINT_RAW(RT_DEBUG_TRACE, ("!!! report EAPOL/AIRONET DATA to MLME (len=%d) !!!\n", pRxBlk->DataSize));
}
}
RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
return;
}
VOID STARxDataFrameAnnounce(
IN PRTMP_ADAPTER pAd,
IN MAC_TABLE_ENTRY *pEntry,
IN RX_BLK *pRxBlk,
IN UCHAR FromWhichBSSID)
{
// non-EAP frame
if (!RTMPCheckWPAframe(pAd, pEntry, pRxBlk->pData, pRxBlk->DataSize, FromWhichBSSID))
{
{
// drop all non-EAP DATA frame before
// this client's Port-Access-Control is secured
if (pRxBlk->pHeader->FC.Wep)
{
// unsupported cipher suite
if (pAd->StaCfg.WepStatus == Ndis802_11EncryptionDisabled)
{
// release packet
RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
return;
}
}
else
{
// encryption in-use but receive a non-EAPOL clear text frame, drop it
if ((pAd->StaCfg.WepStatus != Ndis802_11EncryptionDisabled) &&
(pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
{
// release packet
RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
return;
}
}
}
RX_BLK_CLEAR_FLAG(pRxBlk, fRX_EAP);
if (!RX_BLK_TEST_FLAG(pRxBlk, fRX_ARALINK))
{
// Normal legacy, AMPDU or AMSDU
CmmRxnonRalinkFrameIndicate(pAd, pRxBlk, FromWhichBSSID);
}
else
{
// ARALINK
CmmRxRalinkFrameIndicate(pAd, pEntry, pRxBlk, FromWhichBSSID);
}
#ifdef QOS_DLS_SUPPORT
RX_BLK_CLEAR_FLAG(pRxBlk, fRX_DLS);
#endif // QOS_DLS_SUPPORT //
}
else
{
RX_BLK_SET_FLAG(pRxBlk, fRX_EAP);
#ifdef DOT11_N_SUPPORT
if (RX_BLK_TEST_FLAG(pRxBlk, fRX_AMPDU) && (pAd->CommonCfg.bDisableReordering == 0))
{
Indicate_AMPDU_Packet(pAd, pRxBlk, FromWhichBSSID);
}
else
#endif // DOT11_N_SUPPORT //
{
// Determin the destination of the EAP frame
// to WPA state machine or upper layer
STARxEAPOLFrameIndicate(pAd, pEntry, pRxBlk, FromWhichBSSID);
}
}
}
// For TKIP frame, calculate the MIC value
BOOLEAN STACheckTkipMICValue(
IN PRTMP_ADAPTER pAd,
IN MAC_TABLE_ENTRY *pEntry,
IN RX_BLK *pRxBlk)
{
PHEADER_802_11 pHeader = pRxBlk->pHeader;
UCHAR *pData = pRxBlk->pData;
USHORT DataSize = pRxBlk->DataSize;
UCHAR UserPriority = pRxBlk->UserPriority;
PCIPHER_KEY pWpaKey;
UCHAR *pDA, *pSA;
pWpaKey = &pAd->SharedKey[BSS0][pRxBlk->pRxWI->KeyIndex];
pDA = pHeader->Addr1;
if (RX_BLK_TEST_FLAG(pRxBlk, fRX_INFRA))
{
pSA = pHeader->Addr3;
}
else
{
pSA = pHeader->Addr2;
}
if (RTMPTkipCompareMICValue(pAd,
pData,
pDA,
pSA,
pWpaKey->RxMic,
UserPriority,
DataSize) == FALSE)
{
DBGPRINT_RAW(RT_DEBUG_ERROR,("Rx MIC Value error 2\n"));
#ifdef WPA_SUPPLICANT_SUPPORT
if (pAd->StaCfg.WpaSupplicantUP)
{
WpaSendMicFailureToWpaSupplicant(pAd, (pWpaKey->Type == PAIRWISEKEY) ? TRUE : FALSE);
}
else
#endif // WPA_SUPPLICANT_SUPPORT //
{
RTMPReportMicError(pAd, pWpaKey);
}
// release packet
RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
return FALSE;
}
return TRUE;
}
//
// All Rx routines use RX_BLK structure to hande rx events
// It is very important to build pRxBlk attributes
// 1. pHeader pointer to 802.11 Header
// 2. pData pointer to payload including LLC (just skip Header)
// 3. set payload size including LLC to DataSize
// 4. set some flags with RX_BLK_SET_FLAG()
//
VOID STAHandleRxDataFrame(
IN PRTMP_ADAPTER pAd,
IN RX_BLK *pRxBlk)
{
PRT28XX_RXD_STRUC pRxD = &(pRxBlk->RxD);
PRXWI_STRUC pRxWI = pRxBlk->pRxWI;
PHEADER_802_11 pHeader = pRxBlk->pHeader;
PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket;
BOOLEAN bFragment = FALSE;
MAC_TABLE_ENTRY *pEntry = NULL;
UCHAR FromWhichBSSID = BSS0;
UCHAR UserPriority = 0;
{
// before LINK UP, all DATA frames are rejected
if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
{
// release packet
RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
return;
}
#ifdef QOS_DLS_SUPPORT
//if ((pHeader->FC.FrDs == 0) && (pHeader->FC.ToDs == 0))
if (RTMPRcvFrameDLSCheck(pAd, pHeader, pRxWI->MPDUtotalByteCount, pRxD))
{
return;
}
#endif // QOS_DLS_SUPPORT //
// Drop not my BSS frames
if (pRxD->MyBss == 0)
{
{
// release packet
RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
return;
}
}
pAd->RalinkCounters.RxCountSinceLastNULL++;
if (pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable && (pHeader->FC.SubType & 0x08))
{
UCHAR *pData;
DBGPRINT(RT_DEBUG_TRACE,("bAPSDCapable\n"));
// Qos bit 4
pData = (PUCHAR)pHeader + LENGTH_802_11;
if ((*pData >> 4) & 0x01)
{
DBGPRINT(RT_DEBUG_TRACE,("RxDone- Rcv EOSP frame, driver may fall into sleep\n"));
pAd->CommonCfg.bInServicePeriod = FALSE;
// Force driver to fall into sleep mode when rcv EOSP frame
if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
{
USHORT TbttNumToNextWakeUp;
USHORT NextDtim = pAd->StaCfg.DtimPeriod;
ULONG Now;
NdisGetSystemUpTime(&Now);
NextDtim -= (USHORT)(Now - pAd->StaCfg.LastBeaconRxTime)/pAd->CommonCfg.BeaconPeriod;
TbttNumToNextWakeUp = pAd->StaCfg.DefaultListenCount;
if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM) && (TbttNumToNextWakeUp > NextDtim))
TbttNumToNextWakeUp = NextDtim;
MlmeSetPsmBit(pAd, PWR_SAVE);
// if WMM-APSD is failed, try to disable following line
AsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp);
}
}
if ((pHeader->FC.MoreData) && (pAd->CommonCfg.bInServicePeriod))
{
DBGPRINT(RT_DEBUG_TRACE,("Sending another trigger frame when More Data bit is set to 1\n"));
}
}
// Drop NULL, CF-ACK(no data), CF-POLL(no data), and CF-ACK+CF-POLL(no data) data frame
if ((pHeader->FC.SubType & 0x04)) // bit 2 : no DATA
{
// release packet
RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
return;
}
// Drop not my BSS frame (we can not only check the MyBss bit in RxD)
#ifdef QOS_DLS_SUPPORT
if (!pAd->CommonCfg.bDLSCapable)
{
#endif // QOS_DLS_SUPPORT //
if (INFRA_ON(pAd))
{
// Infrastructure mode, check address 2 for BSSID
if (!RTMPEqualMemory(&pHeader->Addr2, &pAd->CommonCfg.Bssid, 6))
{
// Receive frame not my BSSID
// release packet
RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
return;
}
}
else // Ad-Hoc mode or Not associated
{
// Ad-Hoc mode, check address 3 for BSSID
if (!RTMPEqualMemory(&pHeader->Addr3, &pAd->CommonCfg.Bssid, 6))
{
// Receive frame not my BSSID
// release packet
RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
return;
}
}
#ifdef QOS_DLS_SUPPORT
}
#endif // QOS_DLS_SUPPORT //
//
// find pEntry
//
if (pRxWI->WirelessCliID < MAX_LEN_OF_MAC_TABLE)
{
pEntry = &pAd->MacTab.Content[pRxWI->WirelessCliID];
}
else
{
// 1. release packet if infra mode
// 2. new a pEntry if ad-hoc mode
RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
return;
}
// infra or ad-hoc
if (INFRA_ON(pAd))
{
RX_BLK_SET_FLAG(pRxBlk, fRX_INFRA);
#ifdef QOS_DLS_SUPPORT
if ((pHeader->FC.FrDs == 0) && (pHeader->FC.ToDs == 0))
RX_BLK_SET_FLAG(pRxBlk, fRX_DLS);
else
#endif // QOS_DLS_SUPPORT //
ASSERT(pRxWI->WirelessCliID == BSSID_WCID);
}
// check Atheros Client
if ((pEntry->bIAmBadAtheros == FALSE) && (pRxD->AMPDU == 1) && (pHeader->FC.Retry ))
{
pEntry->bIAmBadAtheros = TRUE;
pAd->CommonCfg.IOTestParm.bCurrentAtheros = TRUE;
pAd->CommonCfg.IOTestParm.bLastAtheros = TRUE;
if (!STA_AES_ON(pAd))
{
AsicUpdateProtect(pAd, 8, ALLN_SETPROTECT, TRUE, FALSE);
}
}
}
pRxBlk->pData = (UCHAR *)pHeader;
//
// update RxBlk->pData, DataSize
// 802.11 Header, QOS, HTC, Hw Padding
//
// 1. skip 802.11 HEADER
{
pRxBlk->pData += LENGTH_802_11;
pRxBlk->DataSize -= LENGTH_802_11;
}
// 2. QOS
if (pHeader->FC.SubType & 0x08)
{
RX_BLK_SET_FLAG(pRxBlk, fRX_QOS);
UserPriority = *(pRxBlk->pData) & 0x0f;
// bit 7 in QoS Control field signals the HT A-MSDU format
if ((*pRxBlk->pData) & 0x80)
{
RX_BLK_SET_FLAG(pRxBlk, fRX_AMSDU);
}
// skip QOS contorl field
pRxBlk->pData += 2;
pRxBlk->DataSize -=2;
}
pRxBlk->UserPriority = UserPriority;
// 3. Order bit: A-Ralink or HTC+
if (pHeader->FC.Order)
{
#ifdef AGGREGATION_SUPPORT
if ((pRxWI->PHYMODE <= MODE_OFDM) && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED)))
{
RX_BLK_SET_FLAG(pRxBlk, fRX_ARALINK);
}
else
#endif
{
#ifdef DOT11_N_SUPPORT
RX_BLK_SET_FLAG(pRxBlk, fRX_HTC);
// skip HTC contorl field
pRxBlk->pData += 4;
pRxBlk->DataSize -= 4;
#endif // DOT11_N_SUPPORT //
}
}
// 4. skip HW padding
if (pRxD->L2PAD)
{
// just move pData pointer
// because DataSize excluding HW padding
RX_BLK_SET_FLAG(pRxBlk, fRX_PAD);
pRxBlk->pData += 2;
}
#ifdef DOT11_N_SUPPORT
if (pRxD->BA)
{
RX_BLK_SET_FLAG(pRxBlk, fRX_AMPDU);
}
#endif // DOT11_N_SUPPORT //
//
// Case I Process Broadcast & Multicast data frame
//
if (pRxD->Bcast || pRxD->Mcast)
{
INC_COUNTER64(pAd->WlanCounters.MulticastReceivedFrameCount);
// Drop Mcast/Bcast frame with fragment bit on
if (pHeader->FC.MoreFrag)
{
// release packet
RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
return;
}
// Filter out Bcast frame which AP relayed for us
if (pHeader->FC.FrDs && MAC_ADDR_EQUAL(pHeader->Addr3, pAd->CurrentAddress))
{
// release packet
RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
return;
}
Indicate_Legacy_Packet(pAd, pRxBlk, FromWhichBSSID);
return;
}
else if (pRxD->U2M)
{
pAd->LastRxRate = (USHORT)((pRxWI->MCS) + (pRxWI->BW <<7) + (pRxWI->ShortGI <<8)+ (pRxWI->PHYMODE <<14)) ;
#ifdef QOS_DLS_SUPPORT
if (RX_BLK_TEST_FLAG(pRxBlk, fRX_DLS))
{
MAC_TABLE_ENTRY *pDlsEntry = NULL;
pDlsEntry = DlsEntryTableLookupByWcid(pAd, pRxWI->WirelessCliID, pHeader->Addr2, TRUE);
if(pDlsEntry)
Update_Rssi_Sample(pAd, &pDlsEntry->RssiSample, pRxWI);
}
else
#endif // QOS_DLS_SUPPORT //
if (ADHOC_ON(pAd))
{
pEntry = MacTableLookup(pAd, pHeader->Addr2);
if (pEntry)
Update_Rssi_Sample(pAd, &pEntry->RssiSample, pRxWI);
}
Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, pRxWI);
pAd->StaCfg.LastSNR0 = (UCHAR)(pRxWI->SNR0);
pAd->StaCfg.LastSNR1 = (UCHAR)(pRxWI->SNR1);
pAd->RalinkCounters.OneSecRxOkDataCnt++;
if (!((pHeader->Frag == 0) && (pHeader->FC.MoreFrag == 0)))
{
// re-assemble the fragmented packets
// return complete frame (pRxPacket) or NULL
bFragment = TRUE;
pRxPacket = RTMPDeFragmentDataFrame(pAd, pRxBlk);
}
if (pRxPacket)
{
pEntry = &pAd->MacTab.Content[pRxWI->WirelessCliID];
// process complete frame
if (bFragment && (pRxD->Decrypted) && (pEntry->WepStatus == Ndis802_11Encryption2Enabled))
{
// Minus MIC length
pRxBlk->DataSize -= 8;
// For TKIP frame, calculate the MIC value
if (STACheckTkipMICValue(pAd, pEntry, pRxBlk) == FALSE)
{
return;
}
}
STARxDataFrameAnnounce(pAd, pEntry, pRxBlk, FromWhichBSSID);
return;
}
else
{
// just return
// because RTMPDeFragmentDataFrame() will release rx packet,
// if packet is fragmented
return;
}
}
ASSERT(0);
// release packet
RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
}
VOID STAHandleRxMgmtFrame(
IN PRTMP_ADAPTER pAd,
IN RX_BLK *pRxBlk)
{
PRT28XX_RXD_STRUC pRxD = &(pRxBlk->RxD);
PRXWI_STRUC pRxWI = pRxBlk->pRxWI;
PHEADER_802_11 pHeader = pRxBlk->pHeader;
PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket;
do
{
// We should collect RSSI not only U2M data but also my beacon
if ((pHeader->FC.SubType == SUBTYPE_BEACON) && (MAC_ADDR_EQUAL(&pAd->CommonCfg.Bssid, &pHeader->Addr2)))
{
Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, pRxWI);
pAd->StaCfg.LastSNR0 = (UCHAR)(pRxWI->SNR0);
pAd->StaCfg.LastSNR1 = (UCHAR)(pRxWI->SNR1);
}
// First check the size, it MUST not exceed the mlme queue size
if (pRxWI->MPDUtotalByteCount > MGMT_DMA_BUFFER_SIZE)
{
DBGPRINT_ERR(("STAHandleRxMgmtFrame: frame too large, size = %d \n", pRxWI->MPDUtotalByteCount));
break;
}
REPORT_MGMT_FRAME_TO_MLME(pAd, pRxWI->WirelessCliID, pHeader, pRxWI->MPDUtotalByteCount,
pRxWI->RSSI0, pRxWI->RSSI1, pRxWI->RSSI2, pRxD->PlcpSignal);
} while (FALSE);
RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_SUCCESS);
}
VOID STAHandleRxControlFrame(
IN PRTMP_ADAPTER pAd,
IN RX_BLK *pRxBlk)
{
#ifdef DOT11_N_SUPPORT
PRXWI_STRUC pRxWI = pRxBlk->pRxWI;
#endif // DOT11_N_SUPPORT //
PHEADER_802_11 pHeader = pRxBlk->pHeader;
PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket;
switch (pHeader->FC.SubType)
{
case SUBTYPE_BLOCK_ACK_REQ:
#ifdef DOT11_N_SUPPORT
{
CntlEnqueueForRecv(pAd, pRxWI->WirelessCliID, (pRxWI->MPDUtotalByteCount), (PFRAME_BA_REQ)pHeader);
}
break;
#endif // DOT11_N_SUPPORT //
case SUBTYPE_BLOCK_ACK:
case SUBTYPE_ACK:
default:
break;
}
RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
}
/*
========================================================================
Routine Description:
Process RxDone interrupt, running in DPC level
Arguments:
pAd Pointer to our adapter
Return Value:
None
IRQL = DISPATCH_LEVEL
Note:
This routine has to maintain Rx ring read pointer.
Need to consider QOS DATA format when converting to 802.3
========================================================================
*/
BOOLEAN STARxDoneInterruptHandle(
IN PRTMP_ADAPTER pAd,
IN BOOLEAN argc)
{
NDIS_STATUS Status;
UINT32 RxProcessed, RxPending;
BOOLEAN bReschedule = FALSE;
RT28XX_RXD_STRUC *pRxD;
UCHAR *pData;
PRXWI_STRUC pRxWI;
PNDIS_PACKET pRxPacket;
PHEADER_802_11 pHeader;
RX_BLK RxCell;
RxProcessed = RxPending = 0;
// process whole rx ring
while (1)
{
if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF |
fRTMP_ADAPTER_RESET_IN_PROGRESS |
fRTMP_ADAPTER_HALT_IN_PROGRESS |
fRTMP_ADAPTER_NIC_NOT_EXIST) ||
!RTMP_TEST_FLAG(pAd,fRTMP_ADAPTER_START_UP))
{
break;
}
if (RxProcessed++ > MAX_RX_PROCESS_CNT)
{
// need to reschedule rx handle
bReschedule = TRUE;
break;
}
RxProcessed ++; // test
// 1. allocate a new data packet into rx ring to replace received packet
// then processing the received packet
// 2. the callee must take charge of release of packet
// 3. As far as driver is concerned ,
// the rx packet must
// a. be indicated to upper layer or
// b. be released if it is discarded
pRxPacket = GetPacketFromRxRing(pAd, &(RxCell.RxD), &bReschedule, &RxPending);
if (pRxPacket == NULL)
{
// no more packet to process
break;
}
// get rx ring descriptor
pRxD = &(RxCell.RxD);
// get rx data buffer
pData = GET_OS_PKT_DATAPTR(pRxPacket);
pRxWI = (PRXWI_STRUC) pData;
pHeader = (PHEADER_802_11) (pData+RXWI_SIZE) ;
#ifdef RT_BIG_ENDIAN
RTMPFrameEndianChange(pAd, (PUCHAR)pHeader, DIR_READ, TRUE);
RTMPWIEndianChange((PUCHAR)pRxWI, TYPE_RXWI);
#endif
// build RxCell
RxCell.pRxWI = pRxWI;
RxCell.pHeader = pHeader;
RxCell.pRxPacket = pRxPacket;
RxCell.pData = (UCHAR *) pHeader;
RxCell.DataSize = pRxWI->MPDUtotalByteCount;
RxCell.Flags = 0;
// Increase Total receive byte counter after real data received no mater any error or not
pAd->RalinkCounters.ReceivedByteCount += pRxWI->MPDUtotalByteCount;
pAd->RalinkCounters.RxCount ++;
INC_COUNTER64(pAd->WlanCounters.ReceivedFragmentCount);
if (pRxWI->MPDUtotalByteCount < 14)
Status = NDIS_STATUS_FAILURE;
if (MONITOR_ON(pAd))
{
send_monitor_packets(pAd, &RxCell);
break;
}
/* RT2870 invokes STARxDoneInterruptHandle() in rtusb_bulk.c */
// Check for all RxD errors
Status = RTMPCheckRxError(pAd, pHeader, pRxWI, pRxD);
// Handle the received frame
if (Status == NDIS_STATUS_SUCCESS)
{
switch (pHeader->FC.Type)
{
// CASE I, receive a DATA frame
case BTYPE_DATA:
{
// process DATA frame
STAHandleRxDataFrame(pAd, &RxCell);
}
break;
// CASE II, receive a MGMT frame
case BTYPE_MGMT:
{
STAHandleRxMgmtFrame(pAd, &RxCell);
}
break;
// CASE III. receive a CNTL frame
case BTYPE_CNTL:
{
STAHandleRxControlFrame(pAd, &RxCell);
}
break;
// discard other type
default:
RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
break;
}
}
else
{
pAd->Counters8023.RxErrors++;
// discard this frame
RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
}
}
// fRTMP_PS_GO_TO_SLEEP_NOW is set if receiving beacon.
if (RTMP_TEST_PSFLAG(pAd, fRTMP_PS_GO_TO_SLEEP_NOW) && (INFRA_ON(pAd)))
{
RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_GO_TO_SLEEP_NOW);
AsicSleepThenAutoWakeup(pAd, pAd->ThisTbttNumToNextWakeUp);
bReschedule = FALSE;
}
return bReschedule;
}
/*
========================================================================
Routine Description:
Arguments:
pAd Pointer to our adapter
IRQL = DISPATCH_LEVEL
========================================================================
*/
VOID RTMPHandleTwakeupInterrupt(
IN PRTMP_ADAPTER pAd)
{
AsicForceWakeup(pAd, DOT11POWERSAVE);
}
/*
========================================================================
Routine Description:
Early checking and OS-depened parsing for Tx packet send to our STA driver.
Arguments:
NDIS_HANDLE MiniportAdapterContext Pointer refer to the device handle, i.e., the pAd.
PPNDIS_PACKET ppPacketArray The packet array need to do transmission.
UINT NumberOfPackets Number of packet in packet array.
Return Value:
NONE
Note:
This function do early checking and classification for send-out packet.
You only can put OS-depened & STA related code in here.
========================================================================
*/
VOID STASendPackets(
IN NDIS_HANDLE MiniportAdapterContext,
IN PPNDIS_PACKET ppPacketArray,
IN UINT NumberOfPackets)
{
UINT Index;
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) MiniportAdapterContext;
PNDIS_PACKET pPacket;
BOOLEAN allowToSend = FALSE;
for (Index = 0; Index < NumberOfPackets; Index++)
{
pPacket = ppPacketArray[Index];
do
{
if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) ||
RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS) ||
RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))
{
// Drop send request since hardware is in reset state
break;
}
else if (!INFRA_ON(pAd) && !ADHOC_ON(pAd))
{
// Drop send request since there are no physical connection yet
break;
}
else
{
// Record that orignal packet source is from NDIS layer,so that
// later on driver knows how to release this NDIS PACKET
#ifdef QOS_DLS_SUPPORT
MAC_TABLE_ENTRY *pEntry;
PUCHAR pSrcBufVA = GET_OS_PKT_DATAPTR(pPacket);
pEntry = MacTableLookup(pAd, pSrcBufVA);
if (pEntry && (pEntry->ValidAsDls == TRUE))
{
RTMP_SET_PACKET_WCID(pPacket, pEntry->Aid);
}
else
#endif // QOS_DLS_SUPPORT //
RTMP_SET_PACKET_WCID(pPacket, 0); // this field is useless when in STA mode
RTMP_SET_PACKET_SOURCE(pPacket, PKTSRC_NDIS);
NDIS_SET_PACKET_STATUS(pPacket, NDIS_STATUS_PENDING);
pAd->RalinkCounters.PendingNdisPacketCount++;
allowToSend = TRUE;
}
} while(FALSE);
if (allowToSend == TRUE)
STASendPacket(pAd, pPacket);
else
RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
}
// Dequeue outgoing frames from TxSwQueue[] and process it
RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
}
/*
========================================================================
Routine Description:
This routine is used to do packet parsing and classification for Tx packet
to STA device, and it will en-queue packets to our TxSwQueue depends on AC
class.
Arguments:
pAd Pointer to our adapter
pPacket Pointer to send packet
Return Value:
NDIS_STATUS_SUCCESS If succes to queue the packet into TxSwQueue.
NDIS_STATUS_FAILURE If failed to do en-queue.
Note:
You only can put OS-indepened & STA related code in here.
========================================================================
*/
NDIS_STATUS STASendPacket(
IN PRTMP_ADAPTER pAd,
IN PNDIS_PACKET pPacket)
{
PACKET_INFO PacketInfo;
PUCHAR pSrcBufVA;
UINT SrcBufLen;
UINT AllowFragSize;
UCHAR NumberOfFrag;
UCHAR QueIdx, UserPriority;
MAC_TABLE_ENTRY *pEntry = NULL;
unsigned int IrqFlags;
UCHAR FlgIsIP = 0;
UCHAR Rate;
// Prepare packet information structure for buffer descriptor
// chained within a single NDIS packet.
RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen);
if (pSrcBufVA == NULL)
{
DBGPRINT(RT_DEBUG_ERROR,("STASendPacket --> pSrcBufVA == NULL !!!SrcBufLen=%x\n",SrcBufLen));
// Resourece is low, system did not allocate virtual address
// return NDIS_STATUS_FAILURE directly to upper layer
RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
return NDIS_STATUS_FAILURE;
}
if (SrcBufLen < 14)
{
DBGPRINT(RT_DEBUG_ERROR,("STASendPacket --> Ndis Packet buffer error !!!\n"));
RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
return (NDIS_STATUS_FAILURE);
}
// In HT rate adhoc mode, A-MPDU is often used. So need to lookup BA Table and MAC Entry.
// Note multicast packets in adhoc also use BSSID_WCID index.
{
if(INFRA_ON(pAd))
{
#ifdef QOS_DLS_SUPPORT
USHORT tmpWcid;
tmpWcid = RTMP_GET_PACKET_WCID(pPacket);
if (VALID_WCID(tmpWcid) &&
(pAd->MacTab.Content[tmpWcid].ValidAsDls== TRUE))
{
pEntry = &pAd->MacTab.Content[tmpWcid];
Rate = pAd->MacTab.Content[tmpWcid].CurrTxRate;
}
else
#endif // QOS_DLS_SUPPORT //
{
pEntry = &pAd->MacTab.Content[BSSID_WCID];
RTMP_SET_PACKET_WCID(pPacket, BSSID_WCID);
Rate = pAd->CommonCfg.TxRate;
}
}
else if (ADHOC_ON(pAd))
{
if (*pSrcBufVA & 0x01)
{
RTMP_SET_PACKET_WCID(pPacket, MCAST_WCID);
pEntry = &pAd->MacTab.Content[MCAST_WCID];
}
else
{
pEntry = MacTableLookup(pAd, pSrcBufVA);
}
Rate = pAd->CommonCfg.TxRate;
}
}
if (!pEntry)
{
DBGPRINT(RT_DEBUG_ERROR,("STASendPacket->Cannot find pEntry(%2x:%2x:%2x:%2x:%2x:%2x) in MacTab!\n", PRINT_MAC(pSrcBufVA)));
// Resourece is low, system did not allocate virtual address
// return NDIS_STATUS_FAILURE directly to upper layer
RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
return NDIS_STATUS_FAILURE;
}
if (ADHOC_ON(pAd)
)
{
RTMP_SET_PACKET_WCID(pPacket, (UCHAR)pEntry->Aid);
}
//
// Check the Ethernet Frame type of this packet, and set the RTMP_SET_PACKET_SPECIFIC flags.
// Here we set the PACKET_SPECIFIC flags(LLC, VLAN, DHCP/ARP, EAPOL).
RTMPCheckEtherType(pAd, pPacket);
//
// WPA 802.1x secured port control - drop all non-802.1x frame before port secured
//
if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
(pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
(pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
(pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
#ifdef WPA_SUPPLICANT_SUPPORT
|| (pAd->StaCfg.IEEE8021X == TRUE)
#endif // WPA_SUPPLICANT_SUPPORT //
#ifdef LEAP_SUPPORT
|| (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
#endif // LEAP_SUPPORT //
)
&& ((pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED) || (pAd->StaCfg.MicErrCnt >= 2))
&& (RTMP_GET_PACKET_EAPOL(pPacket)== FALSE)
)
{
DBGPRINT(RT_DEBUG_TRACE,("STASendPacket --> Drop packet before port secured !!!\n"));
RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
return (NDIS_STATUS_FAILURE);
}
// STEP 1. Decide number of fragments required to deliver this MSDU.
// The estimation here is not very accurate because difficult to
// take encryption overhead into consideration here. The result
// "NumberOfFrag" is then just used to pre-check if enough free
// TXD are available to hold this MSDU.
if (*pSrcBufVA & 0x01) // fragmentation not allowed on multicast & broadcast
NumberOfFrag = 1;
else if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED))
NumberOfFrag = 1; // Aggregation overwhelms fragmentation
else if (CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_AMSDU_INUSED))
NumberOfFrag = 1; // Aggregation overwhelms fragmentation
#ifdef DOT11_N_SUPPORT
else if ((pAd->StaCfg.HTPhyMode.field.MODE == MODE_HTMIX) || (pAd->StaCfg.HTPhyMode.field.MODE == MODE_HTGREENFIELD))
NumberOfFrag = 1; // MIMO RATE overwhelms fragmentation
#endif // DOT11_N_SUPPORT //
else
{
// The calculated "NumberOfFrag" is a rough estimation because of various
// encryption/encapsulation overhead not taken into consideration. This number is just
// used to make sure enough free TXD are available before fragmentation takes place.
// In case the actual required number of fragments of an NDIS packet
// excceeds "NumberOfFrag"caculated here and not enough free TXD available, the
// last fragment (i.e. last MPDU) will be dropped in RTMPHardTransmit() due to out of
// resource, and the NDIS packet will be indicated NDIS_STATUS_FAILURE. This should
// rarely happen and the penalty is just like a TX RETRY fail. Affordable.
AllowFragSize = (pAd->CommonCfg.FragmentThreshold) - LENGTH_802_11 - LENGTH_CRC;
NumberOfFrag = ((PacketInfo.TotalPacketLength - LENGTH_802_3 + LENGTH_802_1_H) / AllowFragSize) + 1;
// To get accurate number of fragmentation, Minus 1 if the size just match to allowable fragment size
if (((PacketInfo.TotalPacketLength - LENGTH_802_3 + LENGTH_802_1_H) % AllowFragSize) == 0)
{
NumberOfFrag--;
}
}
// Save fragment number to Ndis packet reserved field
RTMP_SET_PACKET_FRAGMENTS(pPacket, NumberOfFrag);
// STEP 2. Check the requirement of RTS:
// If multiple fragment required, RTS is required only for the first fragment
// if the fragment size large than RTS threshold
// For RT28xx, Let ASIC send RTS/CTS
RTMP_SET_PACKET_RTS(pPacket, 0);
RTMP_SET_PACKET_TXRATE(pPacket, pAd->CommonCfg.TxRate);
//
// STEP 3. Traffic classification. outcome = <UserPriority, QueIdx>
//
UserPriority = 0;
QueIdx = QID_AC_BE;
if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED))
{
USHORT Protocol;
UCHAR LlcSnapLen = 0, Byte0, Byte1;
do
{
// get Ethernet protocol field
Protocol = (USHORT)((pSrcBufVA[12] << 8) + pSrcBufVA[13]);
if (Protocol <= 1500)
{
// get Ethernet protocol field from LLC/SNAP
if (Sniff2BytesFromNdisBuffer(PacketInfo.pFirstBuffer, LENGTH_802_3 + 6, &Byte0, &Byte1) != NDIS_STATUS_SUCCESS)
break;
Protocol = (USHORT)((Byte0 << 8) + Byte1);
LlcSnapLen = 8;
}
// always AC_BE for non-IP packet
if (Protocol != 0x0800)
break;
// get IP header
if (Sniff2BytesFromNdisBuffer(PacketInfo.pFirstBuffer, LENGTH_802_3 + LlcSnapLen, &Byte0, &Byte1) != NDIS_STATUS_SUCCESS)
break;
// return AC_BE if packet is not IPv4
if ((Byte0 & 0xf0) != 0x40)
break;
FlgIsIP = 1;
UserPriority = (Byte1 & 0xe0) >> 5;
QueIdx = MapUserPriorityToAccessCategory[UserPriority];
// TODO: have to check ACM bit. apply TSPEC if ACM is ON
// TODO: downgrade UP & QueIdx before passing ACM
if (pAd->CommonCfg.APEdcaParm.bACM[QueIdx])
{
UserPriority = 0;
QueIdx = QID_AC_BE;
}
} while (FALSE);
}
RTMP_SET_PACKET_UP(pPacket, UserPriority);
// Make sure SendTxWait queue resource won't be used by other threads
RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags);
if (pAd->TxSwQueue[QueIdx].Number >= MAX_PACKETS_IN_QUEUE)
{
RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags);
#ifdef BLOCK_NET_IF
StopNetIfQueue(pAd, QueIdx, pPacket);
#endif // BLOCK_NET_IF //
RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
return NDIS_STATUS_FAILURE;
}
else
{
InsertTailQueue(&pAd->TxSwQueue[QueIdx], PACKET_TO_QUEUE_ENTRY(pPacket));
}
RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags);
#ifdef DOT11_N_SUPPORT
if ((pAd->CommonCfg.BACapability.field.AutoBA == TRUE)&&
(pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE))
{
if (((pEntry->TXBAbitmap & (1<<UserPriority)) == 0) &&
((pEntry->BADeclineBitmap & (1<<UserPriority)) == 0) &&
(pEntry->PortSecured == WPA_802_1X_PORT_SECURED)
// For IOT compatibility, if
// 1. It is Ralink chip or
// 2. It is OPEN or AES mode,
// then BA session can be bulit.
&& ((pEntry->ValidAsCLI && pAd->MlmeAux.APRalinkIe != 0x0) ||
(pEntry->WepStatus == Ndis802_11WEPDisabled || pEntry->WepStatus == Ndis802_11Encryption3Enabled))
)
{
BAOriSessionSetUp(pAd, pEntry, 0, 0, 10, FALSE);
}
}
#endif // DOT11_N_SUPPORT //
pAd->RalinkCounters.OneSecOsTxCount[QueIdx]++; // TODO: for debug only. to be removed
return NDIS_STATUS_SUCCESS;
}
/*
========================================================================
Routine Description:
This subroutine will scan through releative ring descriptor to find
out avaliable free ring descriptor and compare with request size.
Arguments:
pAd Pointer to our adapter
QueIdx Selected TX Ring
Return Value:
NDIS_STATUS_FAILURE Not enough free descriptor
NDIS_STATUS_SUCCESS Enough free descriptor
IRQL = PASSIVE_LEVEL
IRQL = DISPATCH_LEVEL
Note:
========================================================================
*/
NDIS_STATUS RTMPFreeTXDRequest(
IN PRTMP_ADAPTER pAd,
IN UCHAR QueIdx,
IN UCHAR NumberRequired,
IN PUCHAR FreeNumberIs)
{
ULONG FreeNumber = 0;
NDIS_STATUS Status = NDIS_STATUS_FAILURE;
switch (QueIdx)
{
case QID_AC_BK:
case QID_AC_BE:
case QID_AC_VI:
case QID_AC_VO:
case QID_HCCA:
if (pAd->TxRing[QueIdx].TxSwFreeIdx > pAd->TxRing[QueIdx].TxCpuIdx)
FreeNumber = pAd->TxRing[QueIdx].TxSwFreeIdx - pAd->TxRing[QueIdx].TxCpuIdx - 1;
else
FreeNumber = pAd->TxRing[QueIdx].TxSwFreeIdx + TX_RING_SIZE - pAd->TxRing[QueIdx].TxCpuIdx - 1;
if (FreeNumber >= NumberRequired)
Status = NDIS_STATUS_SUCCESS;
break;
case QID_MGMT:
if (pAd->MgmtRing.TxSwFreeIdx > pAd->MgmtRing.TxCpuIdx)
FreeNumber = pAd->MgmtRing.TxSwFreeIdx - pAd->MgmtRing.TxCpuIdx - 1;
else
FreeNumber = pAd->MgmtRing.TxSwFreeIdx + MGMT_RING_SIZE - pAd->MgmtRing.TxCpuIdx - 1;
if (FreeNumber >= NumberRequired)
Status = NDIS_STATUS_SUCCESS;
break;
default:
DBGPRINT(RT_DEBUG_ERROR,("RTMPFreeTXDRequest::Invalid QueIdx(=%d)\n", QueIdx));
break;
}
*FreeNumberIs = (UCHAR)FreeNumber;
return (Status);
}
VOID RTMPSendDisassociationFrame(
IN PRTMP_ADAPTER pAd)
{
}
VOID RTMPSendNullFrame(
IN PRTMP_ADAPTER pAd,
IN UCHAR TxRate,
IN BOOLEAN bQosNull)
{
UCHAR NullFrame[48];
ULONG Length;
PHEADER_802_11 pHeader_802_11;
// WPA 802.1x secured port control
if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
(pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
(pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
(pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
#ifdef WPA_SUPPLICANT_SUPPORT
|| (pAd->StaCfg.IEEE8021X == TRUE)
#endif
) &&
(pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
{
return;
}
NdisZeroMemory(NullFrame, 48);
Length = sizeof(HEADER_802_11);
pHeader_802_11 = (PHEADER_802_11) NullFrame;
pHeader_802_11->FC.Type = BTYPE_DATA;
pHeader_802_11->FC.SubType = SUBTYPE_NULL_FUNC;
pHeader_802_11->FC.ToDs = 1;
COPY_MAC_ADDR(pHeader_802_11->Addr1, pAd->CommonCfg.Bssid);
COPY_MAC_ADDR(pHeader_802_11->Addr2, pAd->CurrentAddress);
COPY_MAC_ADDR(pHeader_802_11->Addr3, pAd->CommonCfg.Bssid);
if (pAd->CommonCfg.bAPSDForcePowerSave)
{
pHeader_802_11->FC.PwrMgmt = PWR_SAVE;
}
else
{
pHeader_802_11->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE) ? 1: 0;
}
pHeader_802_11->Duration = pAd->CommonCfg.Dsifs + RTMPCalcDuration(pAd, TxRate, 14);
pAd->Sequence++;
pHeader_802_11->Sequence = pAd->Sequence;
// Prepare QosNull function frame
if (bQosNull)
{
pHeader_802_11->FC.SubType = SUBTYPE_QOS_NULL;
// copy QOS control bytes
NullFrame[Length] = 0;
NullFrame[Length+1] = 0;
Length += 2;// if pad with 2 bytes for alignment, APSD will fail
}
HAL_KickOutNullFrameTx(pAd, 0, NullFrame, Length);
}
// IRQL = DISPATCH_LEVEL
VOID RTMPSendRTSFrame(
IN PRTMP_ADAPTER pAd,
IN PUCHAR pDA,
IN unsigned int NextMpduSize,
IN UCHAR TxRate,
IN UCHAR RTSRate,
IN USHORT AckDuration,
IN UCHAR QueIdx,
IN UCHAR FrameGap)
{
}
// --------------------------------------------------------
// FIND ENCRYPT KEY AND DECIDE CIPHER ALGORITHM
// Find the WPA key, either Group or Pairwise Key
// LEAP + TKIP also use WPA key.
// --------------------------------------------------------
// Decide WEP bit and cipher suite to be used. Same cipher suite should be used for whole fragment burst
// In Cisco CCX 2.0 Leap Authentication
// WepStatus is Ndis802_11Encryption1Enabled but the key will use PairwiseKey
// Instead of the SharedKey, SharedKey Length may be Zero.
VOID STAFindCipherAlgorithm(
IN PRTMP_ADAPTER pAd,
IN TX_BLK *pTxBlk)
{
NDIS_802_11_ENCRYPTION_STATUS Cipher; // To indicate cipher used for this packet
UCHAR CipherAlg = CIPHER_NONE; // cipher alogrithm
UCHAR KeyIdx = 0xff;
PUCHAR pSrcBufVA;
PCIPHER_KEY pKey = NULL;
pSrcBufVA = GET_OS_PKT_DATAPTR(pTxBlk->pPacket);
{
// Select Cipher
if ((*pSrcBufVA & 0x01) && (ADHOC_ON(pAd)))
Cipher = pAd->StaCfg.GroupCipher; // Cipher for Multicast or Broadcast
else
Cipher = pAd->StaCfg.PairCipher; // Cipher for Unicast
if (RTMP_GET_PACKET_EAPOL(pTxBlk->pPacket))
{
ASSERT(pAd->SharedKey[BSS0][0].CipherAlg <= CIPHER_CKIP128);
// 4-way handshaking frame must be clear
if (!(TX_BLK_TEST_FLAG(pTxBlk, fTX_bClearEAPFrame)) && (pAd->SharedKey[BSS0][0].CipherAlg) &&
(pAd->SharedKey[BSS0][0].KeyLen))
{
CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
KeyIdx = 0;
}
}
else if (Cipher == Ndis802_11Encryption1Enabled)
{
#ifdef LEAP_SUPPORT
if (pAd->StaCfg.CkipFlag & 0x10) // Cisco CKIP KP is on
{
if (LEAP_CCKM_ON(pAd))
{
if (((*pSrcBufVA & 0x01) && (ADHOC_ON(pAd))))
KeyIdx = 1;
else
KeyIdx = 0;
}
else
KeyIdx = pAd->StaCfg.DefaultKeyId;
}
else if (pAd->StaCfg.CkipFlag & 0x08) // only CKIP CMIC
KeyIdx = pAd->StaCfg.DefaultKeyId;
else if (LEAP_CCKM_ON(pAd))
{
if ((*pSrcBufVA & 0x01) && (ADHOC_ON(pAd)))
KeyIdx = 1;
else
KeyIdx = 0;
}
else // standard WEP64 or WEP128
#endif // LEAP_SUPPORT //
KeyIdx = pAd->StaCfg.DefaultKeyId;
}
else if ((Cipher == Ndis802_11Encryption2Enabled) ||
(Cipher == Ndis802_11Encryption3Enabled))
{
if ((*pSrcBufVA & 0x01) && (ADHOC_ON(pAd))) // multicast
KeyIdx = pAd->StaCfg.DefaultKeyId;
else if (pAd->SharedKey[BSS0][0].KeyLen)
KeyIdx = 0;
else
KeyIdx = pAd->StaCfg.DefaultKeyId;
}
if (KeyIdx == 0xff)
CipherAlg = CIPHER_NONE;
else if ((Cipher == Ndis802_11EncryptionDisabled) || (pAd->SharedKey[BSS0][KeyIdx].KeyLen == 0))
CipherAlg = CIPHER_NONE;
#ifdef WPA_SUPPLICANT_SUPPORT
else if ( pAd->StaCfg.WpaSupplicantUP &&
(Cipher == Ndis802_11Encryption1Enabled) &&
(pAd->StaCfg.IEEE8021X == TRUE) &&
(pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
CipherAlg = CIPHER_NONE;
#endif // WPA_SUPPLICANT_SUPPORT //
else
{
//Header_802_11.FC.Wep = 1;
CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
pKey = &pAd->SharedKey[BSS0][KeyIdx];
}
}
pTxBlk->CipherAlg = CipherAlg;
pTxBlk->pKey = pKey;
}
VOID STABuildCommon802_11Header(
IN PRTMP_ADAPTER pAd,
IN TX_BLK *pTxBlk)
{
HEADER_802_11 *pHeader_802_11;
#ifdef QOS_DLS_SUPPORT
BOOLEAN bDLSFrame = FALSE;
INT DlsEntryIndex = 0;
#endif // QOS_DLS_SUPPORT //
//
// MAKE A COMMON 802.11 HEADER
//
// normal wlan header size : 24 octets
pTxBlk->MpduHeaderLen = sizeof(HEADER_802_11);
pHeader_802_11 = (HEADER_802_11 *) &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
NdisZeroMemory(pHeader_802_11, sizeof(HEADER_802_11));
pHeader_802_11->FC.FrDs = 0;
pHeader_802_11->FC.Type = BTYPE_DATA;
pHeader_802_11->FC.SubType = ((TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM)) ? SUBTYPE_QDATA : SUBTYPE_DATA);
#ifdef QOS_DLS_SUPPORT
if (INFRA_ON(pAd))
{
// Check if the frame can be sent through DLS direct link interface
// If packet can be sent through DLS, then force aggregation disable. (Hard to determine peer STA's capability)
DlsEntryIndex = RTMPCheckDLSFrame(pAd, pTxBlk->pSrcBufHeader);
if (DlsEntryIndex >= 0)
bDLSFrame = TRUE;
else
bDLSFrame = FALSE;
}
#endif // QOS_DLS_SUPPORT //
if (pTxBlk->pMacEntry)
{
if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bForceNonQoS))
{
pHeader_802_11->Sequence = pTxBlk->pMacEntry->NonQosDataSeq;
pTxBlk->pMacEntry->NonQosDataSeq = (pTxBlk->pMacEntry->NonQosDataSeq+1) & MAXSEQ;
}
else
{
#ifdef QOS_DLS_SUPPORT
if (bDLSFrame)
{
pHeader_802_11->Sequence = pAd->StaCfg.DLSEntry[DlsEntryIndex].Sequence;
pAd->StaCfg.DLSEntry[DlsEntryIndex].Sequence = (pAd->StaCfg.DLSEntry[DlsEntryIndex].Sequence+1) & MAXSEQ;
}
else
#endif // QOS_DLS_SUPPORT //
{
pHeader_802_11->Sequence = pTxBlk->pMacEntry->TxSeq[pTxBlk->UserPriority];
pTxBlk->pMacEntry->TxSeq[pTxBlk->UserPriority] = (pTxBlk->pMacEntry->TxSeq[pTxBlk->UserPriority]+1) & MAXSEQ;
}
}
}
else
{
pHeader_802_11->Sequence = pAd->Sequence;
pAd->Sequence = (pAd->Sequence+1) & MAXSEQ; // next sequence
}
pHeader_802_11->Frag = 0;
pHeader_802_11->FC.MoreData = TX_BLK_TEST_FLAG(pTxBlk, fTX_bMoreData);
{
if (INFRA_ON(pAd))
{
#ifdef QOS_DLS_SUPPORT
if (bDLSFrame)
{
COPY_MAC_ADDR(pHeader_802_11->Addr1, pTxBlk->pSrcBufHeader);
COPY_MAC_ADDR(pHeader_802_11->Addr2, pAd->CurrentAddress);
COPY_MAC_ADDR(pHeader_802_11->Addr3, pAd->CommonCfg.Bssid);
pHeader_802_11->FC.ToDs = 0;
}
else
#endif // QOS_DLS_SUPPORT //
{
COPY_MAC_ADDR(pHeader_802_11->Addr1, pAd->CommonCfg.Bssid);
COPY_MAC_ADDR(pHeader_802_11->Addr2, pAd->CurrentAddress);
COPY_MAC_ADDR(pHeader_802_11->Addr3, pTxBlk->pSrcBufHeader);
pHeader_802_11->FC.ToDs = 1;
}
}
else if (ADHOC_ON(pAd))
{
COPY_MAC_ADDR(pHeader_802_11->Addr1, pTxBlk->pSrcBufHeader);
COPY_MAC_ADDR(pHeader_802_11->Addr2, pAd->CurrentAddress);
COPY_MAC_ADDR(pHeader_802_11->Addr3, pAd->CommonCfg.Bssid);
pHeader_802_11->FC.ToDs = 0;
}
}
if (pTxBlk->CipherAlg != CIPHER_NONE)
pHeader_802_11->FC.Wep = 1;
// -----------------------------------------------------------------
// STEP 2. MAKE A COMMON 802.11 HEADER SHARED BY ENTIRE FRAGMENT BURST. Fill sequence later.
// -----------------------------------------------------------------
if (pAd->CommonCfg.bAPSDForcePowerSave)
pHeader_802_11->FC.PwrMgmt = PWR_SAVE;
else
pHeader_802_11->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE);
}
#ifdef DOT11_N_SUPPORT
VOID STABuildCache802_11Header(
IN RTMP_ADAPTER *pAd,
IN TX_BLK *pTxBlk,
IN UCHAR *pHeader)
{
MAC_TABLE_ENTRY *pMacEntry;
PHEADER_802_11 pHeader80211;
pHeader80211 = (PHEADER_802_11)pHeader;
pMacEntry = pTxBlk->pMacEntry;
//
// Update the cached 802.11 HEADER
//
// normal wlan header size : 24 octets
pTxBlk->MpduHeaderLen = sizeof(HEADER_802_11);
// More Bit
pHeader80211->FC.MoreData = TX_BLK_TEST_FLAG(pTxBlk, fTX_bMoreData);
// Sequence
pHeader80211->Sequence = pMacEntry->TxSeq[pTxBlk->UserPriority];
pMacEntry->TxSeq[pTxBlk->UserPriority] = (pMacEntry->TxSeq[pTxBlk->UserPriority]+1) & MAXSEQ;
{
// Check if the frame can be sent through DLS direct link interface
// If packet can be sent through DLS, then force aggregation disable. (Hard to determine peer STA's capability)
#ifdef QOS_DLS_SUPPORT
BOOLEAN bDLSFrame = FALSE;
INT DlsEntryIndex = 0;
DlsEntryIndex = RTMPCheckDLSFrame(pAd, pTxBlk->pSrcBufHeader);
if (DlsEntryIndex >= 0)
bDLSFrame = TRUE;
else
bDLSFrame = FALSE;
#endif // QOS_DLS_SUPPORT //
// The addr3 of normal packet send from DS is Dest Mac address.
#ifdef QOS_DLS_SUPPORT
if (bDLSFrame)
{
COPY_MAC_ADDR(pHeader80211->Addr1, pTxBlk->pSrcBufHeader);
COPY_MAC_ADDR(pHeader80211->Addr3, pAd->CommonCfg.Bssid);
pHeader80211->FC.ToDs = 0;
}
else
#endif // QOS_DLS_SUPPORT //
if (ADHOC_ON(pAd))
COPY_MAC_ADDR(pHeader80211->Addr3, pAd->CommonCfg.Bssid);
else
COPY_MAC_ADDR(pHeader80211->Addr3, pTxBlk->pSrcBufHeader);
}
// -----------------------------------------------------------------
// STEP 2. MAKE A COMMON 802.11 HEADER SHARED BY ENTIRE FRAGMENT BURST. Fill sequence later.
// -----------------------------------------------------------------
if (pAd->CommonCfg.bAPSDForcePowerSave)
pHeader80211->FC.PwrMgmt = PWR_SAVE;
else
pHeader80211->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE);
}
#endif // DOT11_N_SUPPORT //
static inline PUCHAR STA_Build_ARalink_Frame_Header(
IN RTMP_ADAPTER *pAd,
IN TX_BLK *pTxBlk)
{
PUCHAR pHeaderBufPtr;
HEADER_802_11 *pHeader_802_11;
PNDIS_PACKET pNextPacket;
UINT32 nextBufLen;
PQUEUE_ENTRY pQEntry;
STAFindCipherAlgorithm(pAd, pTxBlk);
STABuildCommon802_11Header(pAd, pTxBlk);
pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
pHeader_802_11 = (HEADER_802_11 *) pHeaderBufPtr;
// steal "order" bit to mark "aggregation"
pHeader_802_11->FC.Order = 1;
// skip common header
pHeaderBufPtr += pTxBlk->MpduHeaderLen;
if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM))
{
//
// build QOS Control bytes
//
*pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);
*(pHeaderBufPtr+1) = 0;
pHeaderBufPtr +=2;
pTxBlk->MpduHeaderLen += 2;
}
// padding at front of LLC header. LLC header should at 4-bytes aligment.
pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr;
pHeaderBufPtr = (PCHAR)ROUND_UP(pHeaderBufPtr, 4);
pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen);
// For RA Aggregation,
// put the 2nd MSDU length(extra 2-byte field) after QOS_CONTROL in little endian format
pQEntry = pTxBlk->TxPacketList.Head;
pNextPacket = QUEUE_ENTRY_TO_PKT(pQEntry);
nextBufLen = GET_OS_PKT_LEN(pNextPacket);
if (RTMP_GET_PACKET_VLAN(pNextPacket))
nextBufLen -= LENGTH_802_1Q;
*pHeaderBufPtr = (UCHAR)nextBufLen & 0xff;
*(pHeaderBufPtr+1) = (UCHAR)(nextBufLen >> 8);
pHeaderBufPtr += 2;
pTxBlk->MpduHeaderLen += 2;
return pHeaderBufPtr;
}
#ifdef DOT11_N_SUPPORT
static inline PUCHAR STA_Build_AMSDU_Frame_Header(
IN RTMP_ADAPTER *pAd,
IN TX_BLK *pTxBlk)
{
PUCHAR pHeaderBufPtr;//, pSaveBufPtr;
HEADER_802_11 *pHeader_802_11;
STAFindCipherAlgorithm(pAd, pTxBlk);
STABuildCommon802_11Header(pAd, pTxBlk);
pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
pHeader_802_11 = (HEADER_802_11 *) pHeaderBufPtr;
// skip common header
pHeaderBufPtr += pTxBlk->MpduHeaderLen;
//
// build QOS Control bytes
//
*pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);
//
// A-MSDU packet
//
*pHeaderBufPtr |= 0x80;
*(pHeaderBufPtr+1) = 0;
pHeaderBufPtr +=2;
pTxBlk->MpduHeaderLen += 2;
//pSaveBufPtr = pHeaderBufPtr;
//
// padding at front of LLC header
// LLC header should locate at 4-octets aligment
//
// @@@ MpduHeaderLen excluding padding @@@
//
pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr;
pHeaderBufPtr = (PCHAR) ROUND_UP(pHeaderBufPtr, 4);
pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen);
return pHeaderBufPtr;
}
VOID STA_AMPDU_Frame_Tx(
IN PRTMP_ADAPTER pAd,
IN TX_BLK *pTxBlk)
{
HEADER_802_11 *pHeader_802_11;
PUCHAR pHeaderBufPtr;
USHORT FreeNumber;
MAC_TABLE_ENTRY *pMacEntry;
BOOLEAN bVLANPkt;
PQUEUE_ENTRY pQEntry;
ASSERT(pTxBlk);
while(pTxBlk->TxPacketList.Head)
{
pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
if ( RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE)
{
RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);
continue;
}
bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);
pMacEntry = pTxBlk->pMacEntry;
if (pMacEntry->isCached)
{
// NOTE: Please make sure the size of pMacEntry->CachedBuf[] is smaller than pTxBlk->HeaderBuf[]!!!!
NdisMoveMemory((PUCHAR)&pTxBlk->HeaderBuf[TXINFO_SIZE], (PUCHAR)&pMacEntry->CachedBuf[0], TXWI_SIZE + sizeof(HEADER_802_11));
pHeaderBufPtr = (PUCHAR)(&pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE]);
STABuildCache802_11Header(pAd, pTxBlk, pHeaderBufPtr);
}
else
{
STAFindCipherAlgorithm(pAd, pTxBlk);
STABuildCommon802_11Header(pAd, pTxBlk);
pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
}
pHeader_802_11 = (HEADER_802_11 *) pHeaderBufPtr;
// skip common header
pHeaderBufPtr += pTxBlk->MpduHeaderLen;
//
// build QOS Control bytes
//
*pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);
*(pHeaderBufPtr+1) = 0;
pHeaderBufPtr +=2;
pTxBlk->MpduHeaderLen += 2;
//
// build HTC+
// HTC control filed following QoS field
//
if ((pAd->CommonCfg.bRdg == TRUE) && CLIENT_STATUS_TEST_FLAG(pTxBlk->pMacEntry, fCLIENT_STATUS_RDG_CAPABLE))
{
if (pMacEntry->isCached == FALSE)
{
// mark HTC bit
pHeader_802_11->FC.Order = 1;
NdisZeroMemory(pHeaderBufPtr, 4);
*(pHeaderBufPtr+3) |= 0x80;
}
pHeaderBufPtr += 4;
pTxBlk->MpduHeaderLen += 4;
}
//pTxBlk->MpduHeaderLen = pHeaderBufPtr - pTxBlk->HeaderBuf - TXWI_SIZE - TXINFO_SIZE;
ASSERT(pTxBlk->MpduHeaderLen >= 24);
// skip 802.3 header
pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;
pTxBlk->SrcBufLen -= LENGTH_802_3;
// skip vlan tag
if (bVLANPkt)
{
pTxBlk->pSrcBufData += LENGTH_802_1Q;
pTxBlk->SrcBufLen -= LENGTH_802_1Q;
}
//
// padding at front of LLC header
// LLC header should locate at 4-octets aligment
//
// @@@ MpduHeaderLen excluding padding @@@
//
pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr;
pHeaderBufPtr = (PCHAR) ROUND_UP(pHeaderBufPtr, 4);
pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen);
{
//
// Insert LLC-SNAP encapsulation - 8 octets
//
EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(pTxBlk->pSrcBufData-2, pTxBlk->pExtraLlcSnapEncap);
if (pTxBlk->pExtraLlcSnapEncap)
{
NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6);
pHeaderBufPtr += 6;
// get 2 octets (TypeofLen)
NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData-2, 2);
pHeaderBufPtr += 2;
pTxBlk->MpduHeaderLen += LENGTH_802_1_H;
}
}
if (pMacEntry->isCached)
{
RTMPWriteTxWI_Cache(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);
}
else
{
RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);
NdisZeroMemory((PUCHAR)(&pMacEntry->CachedBuf[0]), sizeof(pMacEntry->CachedBuf));
NdisMoveMemory((PUCHAR)(&pMacEntry->CachedBuf[0]), (PUCHAR)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), (pHeaderBufPtr - (PUCHAR)(&pTxBlk->HeaderBuf[TXINFO_SIZE])));
pMacEntry->isCached = TRUE;
}
// calculate Transmitted AMPDU count and ByteCount
{
pAd->RalinkCounters.TransmittedMPDUsInAMPDUCount.u.LowPart ++;
pAd->RalinkCounters.TransmittedOctetsInAMPDUCount.QuadPart += pTxBlk->SrcBufLen;
}
//FreeNumber = GET_TXRING_FREENO(pAd, QueIdx);
HAL_WriteTxResource(pAd, pTxBlk, TRUE, &FreeNumber);
//
// Kick out Tx
//
if (!RTMP_TEST_PSFLAG(pAd, fRTMP_PS_DISABLE_TX))
HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);
pAd->RalinkCounters.KickTxCount++;
pAd->RalinkCounters.OneSecTxDoneCount++;
}
}
VOID STA_AMSDU_Frame_Tx(
IN PRTMP_ADAPTER pAd,
IN TX_BLK *pTxBlk)
{
PUCHAR pHeaderBufPtr;
USHORT FreeNumber;
USHORT subFramePayloadLen = 0; // AMSDU Subframe length without AMSDU-Header / Padding.
USHORT totalMPDUSize=0;
UCHAR *subFrameHeader;
UCHAR padding = 0;
USHORT FirstTx = 0, LastTxIdx = 0;
BOOLEAN bVLANPkt;
int frameNum = 0;
PQUEUE_ENTRY pQEntry;
ASSERT(pTxBlk);
ASSERT((pTxBlk->TxPacketList.Number > 1));
while(pTxBlk->TxPacketList.Head)
{
pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE)
{
RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);
continue;
}
bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);
// skip 802.3 header
pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;
pTxBlk->SrcBufLen -= LENGTH_802_3;
// skip vlan tag
if (bVLANPkt)
{
pTxBlk->pSrcBufData += LENGTH_802_1Q;
pTxBlk->SrcBufLen -= LENGTH_802_1Q;
}
if (frameNum == 0)
{
pHeaderBufPtr = STA_Build_AMSDU_Frame_Header(pAd, pTxBlk);
// NOTE: TxWI->MPDUtotalByteCount will be updated after final frame was handled.
RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);
}
else
{
pHeaderBufPtr = &pTxBlk->HeaderBuf[0];
padding = ROUND_UP(LENGTH_AMSDU_SUBFRAMEHEAD + subFramePayloadLen, 4) - (LENGTH_AMSDU_SUBFRAMEHEAD + subFramePayloadLen);
NdisZeroMemory(pHeaderBufPtr, padding + LENGTH_AMSDU_SUBFRAMEHEAD);
pHeaderBufPtr += padding;
pTxBlk->MpduHeaderLen = padding;
}
//
// A-MSDU subframe
// DA(6)+SA(6)+Length(2) + LLC/SNAP Encap
//
subFrameHeader = pHeaderBufPtr;
subFramePayloadLen = pTxBlk->SrcBufLen;
NdisMoveMemory(subFrameHeader, pTxBlk->pSrcBufHeader, 12);
pHeaderBufPtr += LENGTH_AMSDU_SUBFRAMEHEAD;
pTxBlk->MpduHeaderLen += LENGTH_AMSDU_SUBFRAMEHEAD;
//
// Insert LLC-SNAP encapsulation - 8 octets
//
EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(pTxBlk->pSrcBufData-2, pTxBlk->pExtraLlcSnapEncap);
subFramePayloadLen = pTxBlk->SrcBufLen;
if (pTxBlk->pExtraLlcSnapEncap)
{
NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6);
pHeaderBufPtr += 6;
// get 2 octets (TypeofLen)
NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData-2, 2);
pHeaderBufPtr += 2;
pTxBlk->MpduHeaderLen += LENGTH_802_1_H;
subFramePayloadLen += LENGTH_802_1_H;
}
// update subFrame Length field
subFrameHeader[12] = (subFramePayloadLen & 0xFF00) >> 8;
subFrameHeader[13] = subFramePayloadLen & 0xFF;
totalMPDUSize += pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen;
if (frameNum ==0)
FirstTx = HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, &FreeNumber);
else
LastTxIdx = HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, &FreeNumber);
frameNum++;
pAd->RalinkCounters.KickTxCount++;
pAd->RalinkCounters.OneSecTxDoneCount++;
// calculate Transmitted AMSDU Count and ByteCount
{
pAd->RalinkCounters.TransmittedAMSDUCount.u.LowPart ++;
pAd->RalinkCounters.TransmittedOctetsInAMSDU.QuadPart += totalMPDUSize;
}
}
HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, FirstTx);
HAL_LastTxIdx(pAd, pTxBlk->QueIdx, LastTxIdx);
//
// Kick out Tx
//
if (!RTMP_TEST_PSFLAG(pAd, fRTMP_PS_DISABLE_TX))
HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);
}
#endif // DOT11_N_SUPPORT //
VOID STA_Legacy_Frame_Tx(
IN PRTMP_ADAPTER pAd,
IN TX_BLK *pTxBlk)
{
HEADER_802_11 *pHeader_802_11;
PUCHAR pHeaderBufPtr;
USHORT FreeNumber;
BOOLEAN bVLANPkt;
PQUEUE_ENTRY pQEntry;
ASSERT(pTxBlk);
pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE)
{
RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);
return;
}
if (pTxBlk->TxFrameType == TX_MCAST_FRAME)
{
INC_COUNTER64(pAd->WlanCounters.MulticastTransmittedFrameCount);
}
if (RTMP_GET_PACKET_RTS(pTxBlk->pPacket))
TX_BLK_SET_FLAG(pTxBlk, fTX_bRtsRequired);
else
TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bRtsRequired);
bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);
if (pTxBlk->TxRate < pAd->CommonCfg.MinTxRate)
pTxBlk->TxRate = pAd->CommonCfg.MinTxRate;
STAFindCipherAlgorithm(pAd, pTxBlk);
STABuildCommon802_11Header(pAd, pTxBlk);
// skip 802.3 header
pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;
pTxBlk->SrcBufLen -= LENGTH_802_3;
// skip vlan tag
if (bVLANPkt)
{
pTxBlk->pSrcBufData += LENGTH_802_1Q;
pTxBlk->SrcBufLen -= LENGTH_802_1Q;
}
pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
pHeader_802_11 = (HEADER_802_11 *) pHeaderBufPtr;
// skip common header
pHeaderBufPtr += pTxBlk->MpduHeaderLen;
if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM))
{
//
// build QOS Control bytes
//
*pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);
*(pHeaderBufPtr+1) = 0;
pHeaderBufPtr +=2;
pTxBlk->MpduHeaderLen += 2;
}
// The remaining content of MPDU header should locate at 4-octets aligment
pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr;
pHeaderBufPtr = (PCHAR) ROUND_UP(pHeaderBufPtr, 4);
pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen);
{
//
// Insert LLC-SNAP encapsulation - 8 octets
//
//
// if original Ethernet frame contains no LLC/SNAP,
// then an extra LLC/SNAP encap is required
//
EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(pTxBlk->pSrcBufHeader, pTxBlk->pExtraLlcSnapEncap);
if (pTxBlk->pExtraLlcSnapEncap)
{
UCHAR vlan_size;
NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6);
pHeaderBufPtr += 6;
// skip vlan tag
vlan_size = (bVLANPkt) ? LENGTH_802_1Q : 0;
// get 2 octets (TypeofLen)
NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufHeader+12+vlan_size, 2);
pHeaderBufPtr += 2;
pTxBlk->MpduHeaderLen += LENGTH_802_1_H;
}
}
//
// prepare for TXWI
// use Wcid as Key Index
//
RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);
//FreeNumber = GET_TXRING_FREENO(pAd, QueIdx);
HAL_WriteTxResource(pAd, pTxBlk, TRUE, &FreeNumber);
pAd->RalinkCounters.KickTxCount++;
pAd->RalinkCounters.OneSecTxDoneCount++;
//
// Kick out Tx
//
if (!RTMP_TEST_PSFLAG(pAd, fRTMP_PS_DISABLE_TX))
HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);
}
VOID STA_ARalink_Frame_Tx(
IN PRTMP_ADAPTER pAd,
IN TX_BLK *pTxBlk)
{
PUCHAR pHeaderBufPtr;
USHORT FreeNumber;
USHORT totalMPDUSize=0;
USHORT FirstTx, LastTxIdx;
int frameNum = 0;
BOOLEAN bVLANPkt;
PQUEUE_ENTRY pQEntry;
ASSERT(pTxBlk);
ASSERT((pTxBlk->TxPacketList.Number== 2));
FirstTx = LastTxIdx = 0; // Is it ok init they as 0?
while(pTxBlk->TxPacketList.Head)
{
pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE)
{
RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);
continue;
}
bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);
// skip 802.3 header
pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;
pTxBlk->SrcBufLen -= LENGTH_802_3;
// skip vlan tag
if (bVLANPkt)
{
pTxBlk->pSrcBufData += LENGTH_802_1Q;
pTxBlk->SrcBufLen -= LENGTH_802_1Q;
}
if (frameNum == 0)
{ // For first frame, we need to create the 802.11 header + padding(optional) + RA-AGG-LEN + SNAP Header
pHeaderBufPtr = STA_Build_ARalink_Frame_Header(pAd, pTxBlk);
// It's ok write the TxWI here, because the TxWI->MPDUtotalByteCount
// will be updated after final frame was handled.
RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);
//
// Insert LLC-SNAP encapsulation - 8 octets
//
EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(pTxBlk->pSrcBufData-2, pTxBlk->pExtraLlcSnapEncap);
if (pTxBlk->pExtraLlcSnapEncap)
{
NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6);
pHeaderBufPtr += 6;
// get 2 octets (TypeofLen)
NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData-2, 2);
pHeaderBufPtr += 2;
pTxBlk->MpduHeaderLen += LENGTH_802_1_H;
}
}
else
{ // For second aggregated frame, we need create the 802.3 header to headerBuf, because PCI will copy it to SDPtr0.
pHeaderBufPtr = &pTxBlk->HeaderBuf[0];
pTxBlk->MpduHeaderLen = 0;
// A-Ralink sub-sequent frame header is the same as 802.3 header.
// DA(6)+SA(6)+FrameType(2)
NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufHeader, 12);
pHeaderBufPtr += 12;
// get 2 octets (TypeofLen)
NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData-2, 2);
pHeaderBufPtr += 2;
pTxBlk->MpduHeaderLen = LENGTH_ARALINK_SUBFRAMEHEAD;
}
totalMPDUSize += pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen;
//FreeNumber = GET_TXRING_FREENO(pAd, QueIdx);
if (frameNum ==0)
FirstTx = HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, &FreeNumber);
else
LastTxIdx = HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, &FreeNumber);
frameNum++;
pAd->RalinkCounters.OneSecTxAggregationCount++;
pAd->RalinkCounters.KickTxCount++;
pAd->RalinkCounters.OneSecTxDoneCount++;
}
HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, FirstTx);
HAL_LastTxIdx(pAd, pTxBlk->QueIdx, LastTxIdx);
//
// Kick out Tx
//
if (!RTMP_TEST_PSFLAG(pAd, fRTMP_PS_DISABLE_TX))
HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);
}
VOID STA_Fragment_Frame_Tx(
IN RTMP_ADAPTER *pAd,
IN TX_BLK *pTxBlk)
{
HEADER_802_11 *pHeader_802_11;
PUCHAR pHeaderBufPtr;
USHORT FreeNumber;
UCHAR fragNum = 0;
PACKET_INFO PacketInfo;
USHORT EncryptionOverhead = 0;
UINT32 FreeMpduSize, SrcRemainingBytes;
USHORT AckDuration;
UINT NextMpduSize;
BOOLEAN bVLANPkt;
PQUEUE_ENTRY pQEntry;
ASSERT(pTxBlk);
pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE)
{
RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);
return;
}
ASSERT(TX_BLK_TEST_FLAG(pTxBlk, fTX_bAllowFrag));
bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);
STAFindCipherAlgorithm(pAd, pTxBlk);
STABuildCommon802_11Header(pAd, pTxBlk);
if (pTxBlk->CipherAlg == CIPHER_TKIP)
{
pTxBlk->pPacket = duplicate_pkt_with_TKIP_MIC(pAd, pTxBlk->pPacket);
if (pTxBlk->pPacket == NULL)
return;
RTMP_QueryPacketInfo(pTxBlk->pPacket, &PacketInfo, &pTxBlk->pSrcBufHeader, &pTxBlk->SrcBufLen);
}
// skip 802.3 header
pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;
pTxBlk->SrcBufLen -= LENGTH_802_3;
// skip vlan tag
if (bVLANPkt)
{
pTxBlk->pSrcBufData += LENGTH_802_1Q;
pTxBlk->SrcBufLen -= LENGTH_802_1Q;
}
pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
pHeader_802_11 = (HEADER_802_11 *)pHeaderBufPtr;
// skip common header
pHeaderBufPtr += pTxBlk->MpduHeaderLen;
if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM))
{
//
// build QOS Control bytes
//
*pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);
*(pHeaderBufPtr+1) = 0;
pHeaderBufPtr +=2;
pTxBlk->MpduHeaderLen += 2;
}
//
// padding at front of LLC header
// LLC header should locate at 4-octets aligment
//
pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr;
pHeaderBufPtr = (PCHAR) ROUND_UP(pHeaderBufPtr, 4);
pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen);
//
// Insert LLC-SNAP encapsulation - 8 octets
//
//
// if original Ethernet frame contains no LLC/SNAP,
// then an extra LLC/SNAP encap is required
//
EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(pTxBlk->pSrcBufHeader, pTxBlk->pExtraLlcSnapEncap);
if (pTxBlk->pExtraLlcSnapEncap)
{
UCHAR vlan_size;
NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6);
pHeaderBufPtr += 6;
// skip vlan tag
vlan_size = (bVLANPkt) ? LENGTH_802_1Q : 0;
// get 2 octets (TypeofLen)
NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufHeader+12+vlan_size, 2);
pHeaderBufPtr += 2;
pTxBlk->MpduHeaderLen += LENGTH_802_1_H;
}
// If TKIP is used and fragmentation is required. Driver has to
// append TKIP MIC at tail of the scatter buffer
// MAC ASIC will only perform IV/EIV/ICV insertion but no TKIP MIC
if (pTxBlk->CipherAlg == CIPHER_TKIP)
{
// NOTE: DON'T refer the skb->len directly after following copy. Becasue the length is not adjust
// to correct lenght, refer to pTxBlk->SrcBufLen for the packet length in following progress.
NdisMoveMemory(pTxBlk->pSrcBufData + pTxBlk->SrcBufLen, &pAd->PrivateInfo.Tx.MIC[0], 8);
//skb_put((RTPKT_TO_OSPKT(pTxBlk->pPacket))->tail, 8);
pTxBlk->SrcBufLen += 8;
pTxBlk->TotalFrameLen += 8;
pTxBlk->CipherAlg = CIPHER_TKIP_NO_MIC;
}
//
// calcuate the overhead bytes that encryption algorithm may add. This
// affects the calculate of "duration" field
//
if ((pTxBlk->CipherAlg == CIPHER_WEP64) || (pTxBlk->CipherAlg == CIPHER_WEP128))
EncryptionOverhead = 8; //WEP: IV[4] + ICV[4];
else if (pTxBlk->CipherAlg == CIPHER_TKIP_NO_MIC)
EncryptionOverhead = 12;//TKIP: IV[4] + EIV[4] + ICV[4], MIC will be added to TotalPacketLength
else if (pTxBlk->CipherAlg == CIPHER_TKIP)
EncryptionOverhead = 20;//TKIP: IV[4] + EIV[4] + ICV[4] + MIC[8]
else if (pTxBlk->CipherAlg == CIPHER_AES)
EncryptionOverhead = 16; // AES: IV[4] + EIV[4] + MIC[8]
else
EncryptionOverhead = 0;
// decide how much time an ACK/CTS frame will consume in the air
AckDuration = RTMPCalcDuration(pAd, pAd->CommonCfg.ExpectedACKRate[pTxBlk->TxRate], 14);
// Init the total payload length of this frame.
SrcRemainingBytes = pTxBlk->SrcBufLen;
pTxBlk->TotalFragNum = 0xff;
do {
FreeMpduSize = pAd->CommonCfg.FragmentThreshold - LENGTH_CRC;
FreeMpduSize -= pTxBlk->MpduHeaderLen;
if (SrcRemainingBytes <= FreeMpduSize)
{ // this is the last or only fragment
pTxBlk->SrcBufLen = SrcRemainingBytes;
pHeader_802_11->FC.MoreFrag = 0;
pHeader_802_11->Duration = pAd->CommonCfg.Dsifs + AckDuration;
// Indicate the lower layer that this's the last fragment.
pTxBlk->TotalFragNum = fragNum;
}
else
{ // more fragment is required
pTxBlk->SrcBufLen = FreeMpduSize;
NextMpduSize = min(((UINT)SrcRemainingBytes - pTxBlk->SrcBufLen), ((UINT)pAd->CommonCfg.FragmentThreshold));
pHeader_802_11->FC.MoreFrag = 1;
pHeader_802_11->Duration = (3 * pAd->CommonCfg.Dsifs) + (2 * AckDuration) + RTMPCalcDuration(pAd, pTxBlk->TxRate, NextMpduSize + EncryptionOverhead);
}
if (fragNum == 0)
pTxBlk->FrameGap = IFS_HTTXOP;
else
pTxBlk->FrameGap = IFS_SIFS;
RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);
HAL_WriteFragTxResource(pAd, pTxBlk, fragNum, &FreeNumber);
pAd->RalinkCounters.KickTxCount++;
pAd->RalinkCounters.OneSecTxDoneCount++;
// Update the frame number, remaining size of the NDIS packet payload.
// space for 802.11 header.
if (fragNum == 0 && pTxBlk->pExtraLlcSnapEncap)
pTxBlk->MpduHeaderLen -= LENGTH_802_1_H;
fragNum++;
SrcRemainingBytes -= pTxBlk->SrcBufLen;
pTxBlk->pSrcBufData += pTxBlk->SrcBufLen;
pHeader_802_11->Frag++; // increase Frag #
}while(SrcRemainingBytes > 0);
//
// Kick out Tx
//
HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);
}
#define RELEASE_FRAMES_OF_TXBLK(_pAd, _pTxBlk, _pQEntry, _Status) \
while(_pTxBlk->TxPacketList.Head) \
{ \
_pQEntry = RemoveHeadQueue(&_pTxBlk->TxPacketList); \
RELEASE_NDIS_PACKET(_pAd, QUEUE_ENTRY_TO_PACKET(_pQEntry), _Status); \
}
/*
========================================================================
Routine Description:
Copy frame from waiting queue into relative ring buffer and set
appropriate ASIC register to kick hardware encryption before really
sent out to air.
Arguments:
pAd Pointer to our adapter
PNDIS_PACKET Pointer to outgoing Ndis frame
NumberOfFrag Number of fragment required
Return Value:
None
IRQL = DISPATCH_LEVEL
Note:
========================================================================
*/
NDIS_STATUS STAHardTransmit(
IN PRTMP_ADAPTER pAd,
IN TX_BLK *pTxBlk,
IN UCHAR QueIdx)
{
NDIS_PACKET *pPacket;
PQUEUE_ENTRY pQEntry;
// ---------------------------------------------
// STEP 0. DO SANITY CHECK AND SOME EARLY PREPARATION.
// ---------------------------------------------
//
ASSERT(pTxBlk->TxPacketList.Number);
if (pTxBlk->TxPacketList.Head == NULL)
{
DBGPRINT(RT_DEBUG_ERROR, ("pTxBlk->TotalFrameNum == %ld!\n", pTxBlk->TxPacketList.Number));
return NDIS_STATUS_FAILURE;
}
pPacket = QUEUE_ENTRY_TO_PACKET(pTxBlk->TxPacketList.Head);
#if 0 //def CARRIER_DETECTION_SUPPORT // Roger sync Carrier
if ((pAd->CommonCfg.CarrierDetect.Enable == TRUE) && (isCarrierDetectExist(pAd) == TRUE))
{
DBGPRINT(RT_DEBUG_INFO,("STAHardTransmit --> radar detect not in normal mode !!!\n"));
RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
return (NDIS_STATUS_FAILURE);
}
#endif // CARRIER_DETECTION_SUPPORT //
// ------------------------------------------------------------------
// STEP 1. WAKE UP PHY
// outgoing frame always wakeup PHY to prevent frame lost and
// turn off PSM bit to improve performance
// ------------------------------------------------------------------
// not to change PSM bit, just send this frame out?
if ((pAd->StaCfg.Psm == PWR_SAVE) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
{
DBGPRINT_RAW(RT_DEBUG_TRACE, ("AsicForceWakeup At HardTx\n"));
AsicForceWakeup(pAd, FROM_TX);
}
// It should not change PSM bit, when APSD turn on.
if ((!(pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable) && (pAd->CommonCfg.bAPSDForcePowerSave == FALSE))
|| (RTMP_GET_PACKET_EAPOL(pTxBlk->pPacket))
|| (RTMP_GET_PACKET_WAI(pTxBlk->pPacket)))
{
if ((pAd->StaCfg.Psm == PWR_SAVE) &&
(pAd->StaCfg.WindowsPowerMode == Ndis802_11PowerModeFast_PSP))
MlmeSetPsmBit(pAd, PWR_ACTIVE);
}
switch (pTxBlk->TxFrameType)
{
#ifdef DOT11_N_SUPPORT
case TX_AMPDU_FRAME:
STA_AMPDU_Frame_Tx(pAd, pTxBlk);
break;
case TX_AMSDU_FRAME:
STA_AMSDU_Frame_Tx(pAd, pTxBlk);
break;
#endif // DOT11_N_SUPPORT //
case TX_LEGACY_FRAME:
STA_Legacy_Frame_Tx(pAd, pTxBlk);
break;
case TX_MCAST_FRAME:
STA_Legacy_Frame_Tx(pAd, pTxBlk);
break;
case TX_RALINK_FRAME:
STA_ARalink_Frame_Tx(pAd, pTxBlk);
break;
case TX_FRAG_FRAME:
STA_Fragment_Frame_Tx(pAd, pTxBlk);
break;
default:
{
// It should not happened!
DBGPRINT(RT_DEBUG_ERROR, ("Send a pacekt was not classified!! It should not happen!\n"));
while(pTxBlk->TxPacketList.Number)
{
pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
if (pPacket)
RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
}
}
break;
}
return (NDIS_STATUS_SUCCESS);
}
ULONG HashBytesPolynomial(UCHAR *value, unsigned int len)
{
unsigned char *word = value;
unsigned int ret = 0;
unsigned int i;
for(i=0; i < len; i++)
{
int mod = i % 32;
ret ^=(unsigned int) (word[i]) << mod;
ret ^=(unsigned int) (word[i]) >> (32 - mod);
}
return ret;
}
VOID Sta_Announce_or_Forward_802_3_Packet(
IN PRTMP_ADAPTER pAd,
IN PNDIS_PACKET pPacket,
IN UCHAR FromWhichBSSID)
{
if (TRUE
)
{
announce_802_3_packet(pAd, pPacket);
}
else
{
// release packet
RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
}
}
|