-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtmp_data.c
3244 lines (2751 loc) · 89.1 KB
/
rtmp_data.c
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
/*
***************************************************************************
* Ralink Tech Inc.
* 4F, No. 2 Technology 5th Rd.
* Science-based Industrial Park
* Hsin-chu, Taiwan, R.O.C.
*
* (c) Copyright 2002-2004, Ralink Technology, Inc.
*
* All rights reserved. Ralink's source code is an unpublished work and the
* use of a copyright notice does not imply otherwise. This source code
* contains confidential trade secret material of Ralink Tech. Any attemp
* or participation in deciphering, decoding, reverse engineering or in any
* way altering the source code is stricitly prohibited, unless the prior
* written consent of Ralink Technology, Inc. is obtained.
***************************************************************************
Module Name:
rtmp_data.c
Abstract:
Data path subroutines
Revision History:
Who When What
-------- ---------- ----------------------------------------------
*/
#include "rt_config.h"
VOID STARxEAPOLFrameIndicate(
IN PRTMP_ADAPTER pAd,
IN MAC_TABLE_ENTRY *pEntry,
IN RX_BLK *pRxBlk,
IN UCHAR FromWhichBSSID)
{
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) &&
(pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled) &&
(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) {
/* Set key material and cipherAlg to Asic */
RTMP_ASIC_SHARED_KEY_TABLE(pAd,
BSS0,
idx,
&pAd->StaCfg.DesireSharedKey[idx]);
/* STA doesn't need to set WCID attribute for group key */
/* Assign pairwise key info */
RTMP_SET_WCID_SEC_INFO(pAd,
BSS0,
idx,
CipherAlg,
BSSID_WCID,
SHAREDKEYTABLE);
RTMP_IndicateMediaState(pAd,
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,
0,
OPMODE_STA);
DBGPRINT_RAW(RT_DEBUG_TRACE,
("!!! report EAPOL 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)) {
/* before LINK UP, all DATA frames are rejected */
if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) {
RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket,
NDIS_STATUS_FAILURE);
return;
}
{
/* 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->net_dev,
(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;
}
#ifdef PRE_ANT_SWITCH
#endif /* PRE_ANT_SWITCH */
/*
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;
if ((pHeader->FC.FrDs == 1) && (pHeader->FC.ToDs == 1)) {
#ifdef CLIENT_WDS
if ((pRxWI->WirelessCliID < MAX_LEN_OF_MAC_TABLE)
&& IS_ENTRY_CLIENT(&pAd->MacTab.Content[pRxWI->WirelessCliID])) {
RX_BLK_SET_FLAG(pRxBlk, fRX_WDS);
} else
#endif /* CLIENT_WDS */
{ /* release packet */
RELEASE_NDIS_PACKET(pAd, pRxPacket,
NDIS_STATUS_FAILURE);
return;
}
} else {
#ifdef QOS_DLS_SUPPORT
if (RTMPRcvFrameDLSCheck
(pAd, pHeader, pRxWI->MPDUtotalByteCount, pRxD)) {
return;
}
#endif /* QOS_DLS_SUPPORT */
/* Drop not my BSS frames */
if (pRxWI->WirelessCliID < MAX_LEN_OF_MAC_TABLE)
pEntry = &pAd->MacTab.Content[pRxWI->WirelessCliID];
if (pRxD->MyBss == 0) {
{
/* release packet */
RELEASE_NDIS_PACKET(pAd, pRxPacket,
NDIS_STATUS_FAILURE);
return;
}
}
#ifdef RT3290
// TODO: shiang, find out what's this??
if (pRxD->MyBss)
{
// TODO: shiang, I makr this line due to I still didn't know what's this yet
//pAd->Rssi[pAd->WlanFunCtrl.field.INV_TR_SW0] = pAd->StaCfg.RssiSample.AvgRssi0;
}
#endif /* RT3290 */
pAd->RalinkCounters.RxCountSinceLastNULL++;
#ifdef UAPSD_SUPPORT
if (pAd->StaCfg.UapsdInfo.bAPSDCapable
&& pAd->CommonCfg.APEdcaParm.bAPSDCapable
&& (pHeader->FC.SubType & 0x08))
{
UCHAR *pData;
DBGPRINT(RT_DEBUG_INFO, ("bAPSDCapable\n"));
/* Qos bit 4 */
pData = (PUCHAR) pHeader + LENGTH_802_11;
if ((*pData >> 4) & 0x01)
{
{
DBGPRINT(RT_DEBUG_INFO, ("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))
{
#ifdef RTMP_MAC_PCI
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;
RTMP_SET_PSM_BIT(pAd, PWR_SAVE);
/* if WMM-APSD is failed, try to disable following line */
AsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp);
#endif /* RTMP_MAC_PCI */
}
}
}
if ((pHeader->FC.MoreData)
&& (pAd->CommonCfg.bInServicePeriod)) {
DBGPRINT(RT_DEBUG_TRACE,
("Sending another trigger frame when More Data bit is set to 1\n"));
}
}
#endif /* UAPSD_SUPPORT */
/* 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;
}
if (pAd->StaCfg.BssType == BSS_INFRA) {
/* Infrastructure mode, check address 2 for BSSID */
if (1
#ifdef QOS_DLS_SUPPORT
&& (!pAd->CommonCfg.bDLSCapable)
#endif /* QOS_DLS_SUPPORT */
) {
if (!RTMPEqualMemory(&pHeader->Addr2, &pAd->MlmeAux.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;
}
}
/*/ find pEntry */
if (pRxWI->WirelessCliID < MAX_LEN_OF_MAC_TABLE) {
pEntry = &pAd->MacTab.Content[pRxWI->WirelessCliID];
} else {
RELEASE_NDIS_PACKET(pAd, pRxPacket,
NDIS_STATUS_FAILURE);
return;
}
/* infra or ad-hoc */
if (pAd->StaCfg.BssType == BSS_INFRA) {
RX_BLK_SET_FLAG(pRxBlk, fRX_INFRA);
#if defined(DOT11Z_TDLS_SUPPORT) || defined(QOS_DLS_SUPPORT)
if ((pHeader->FC.FrDs == 0) && (pHeader->FC.ToDs == 0))
RX_BLK_SET_FLAG(pRxBlk, fRX_DLS);
else
#endif
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))
RTMP_UPDATE_PROTECT(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 */
#ifdef CLIENT_WDS
if (RX_BLK_TEST_FLAG(pRxBlk, fRX_WDS)) {
pRxBlk->pData += LENGTH_802_11_WITH_ADDR4;
pRxBlk->DataSize -= LENGTH_802_11_WITH_ADDR4;
} else
#endif /* CLIENT_WDS */
{
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;
/* check if need to resend PS Poll when received packet with MoreData = 1 */
{
if ((RtmpPktPmBitCheck(pAd) == TRUE) && (pHeader->FC.MoreData == 1)) {
if ((((UserPriority == 0) || (UserPriority == 3)) && pAd->CommonCfg.bAPSDAC_BE == 0) ||
(((UserPriority == 1) || (UserPriority == 2)) && pAd->CommonCfg.bAPSDAC_BK == 0) ||
(((UserPriority == 4) || (UserPriority == 5)) && pAd->CommonCfg.bAPSDAC_VI == 0) ||
(((UserPriority == 6) || (UserPriority == 7)) && pAd->CommonCfg.bAPSDAC_VO == 0)) {
/* non-UAPSD delivery-enabled AC */
RTMP_PS_POLL_ENQUEUE(pAd);
}
}
}
/* 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 /* AGGREGATION_SUPPORT */
{
#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 */
#if defined(SOFT_ENCRYPT) || defined(ADHOC_WPA2PSK_SUPPORT)
/* Use software to decrypt the encrypted frame if necessary.
If a received "encrypted" unicast packet(its WEP bit as 1)
and it's passed to driver with "Decrypted" marked as 0 in RxD. */
if ((pHeader->FC.Wep == 1) && (pRxD->Decrypted == 0)) {
PCIPHER_KEY pSwKey = NULL;
/* Cipher key table selection */
if ((pSwKey = RTMPSwCipherKeySelection(pAd,
pRxBlk->pData,
pRxBlk,
pEntry)) == NULL) {
DBGPRINT(RT_DEBUG_TRACE,
("No vaild cipher key for SW decryption!!!\n"));
/* release packet */
RELEASE_NDIS_PACKET(pAd, pRxPacket,
NDIS_STATUS_FAILURE);
return;
}
/* Decryption by Software */
if (RTMPSoftDecryptionAction(pAd,
(PUCHAR) pHeader,
UserPriority,
pSwKey,
pRxBlk->pData,
&(pRxBlk->DataSize)) !=
NDIS_STATUS_SUCCESS) {
/* release packet */
RELEASE_NDIS_PACKET(pAd, pRxPacket,
NDIS_STATUS_FAILURE);
return;
}
/* Record the Decrypted bit as 1 */
pRxD->Decrypted = 1;
}
#endif /* SOFT_ENCRYPT || ADHOC_WPA2PSK_SUPPORT */
/* Case I Process Broadcast & Multicast data frame */
if (pRxD->Bcast || pRxD->Mcast) {
#ifdef STATS_COUNT_SUPPORT
INC_COUNTER64(pAd->WlanCounters.MulticastReceivedFrameCount);
#endif /* STATS_COUNT_SUPPORT */
/* 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;
}
if (ADHOC_ON(pAd)) {
MAC_TABLE_ENTRY *pAdhocEntry = NULL;
pAdhocEntry = MacTableLookup(pAd, pHeader->Addr2);
if (pAdhocEntry)
Update_Rssi_Sample(pAd,
&pAdhocEntry->RssiSample,
pRxWI);
}
Indicate_Legacy_Packet(pAd, pRxBlk, FromWhichBSSID);
return;
} else if (pRxD->U2M) {
pAd->LastRxRate = (USHORT)((pRxWI->MCS) +
(pRxWI->BW << 7) +
(pRxWI->ShortGI << 8) +
(pRxWI->STBC << 9) +
(pRxWI->PHYMODE << 14));
#if defined(DOT11Z_TDLS_SUPPORT) || defined(QOS_DLS_SUPPORT)
if (RX_BLK_TEST_FLAG(pRxBlk, fRX_DLS)) {
MAC_TABLE_ENTRY *pDlsEntry = NULL;
pDlsEntry = &pAd->MacTab.Content[pRxWI->WirelessCliID];
if (pDlsEntry
&& (pRxWI->WirelessCliID < MAX_LEN_OF_MAC_TABLE)) {
Update_Rssi_Sample(pAd, &pDlsEntry->RssiSample,
pRxWI);
NdisAcquireSpinLock(&pAd->MacTabLock);
pDlsEntry->NoDataIdleCount = 0;
NdisReleaseSpinLock(&pAd->MacTabLock);
}
} else
#endif
if (INFRA_ON(pAd)) {
MAC_TABLE_ENTRY *pEntry = &pAd->MacTab.Content[BSSID_WCID];
if (pEntry)
Update_Rssi_Sample(pAd,
&pEntry->RssiSample,
pRxWI);
}else
if (ADHOC_ON(pAd)) {
MAC_TABLE_ENTRY *pAdhocEntry = NULL;
pAdhocEntry = MacTableLookup(pAd, pHeader->Addr2);
if (pAdhocEntry)
Update_Rssi_Sample(pAd,
&pAdhocEntry->RssiSample,
pRxWI);
}
Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, pRxWI);
pAd->StaCfg.LastSNR0 = (UCHAR) (pRxWI->SNR0);
pAd->StaCfg.LastSNR1 = (UCHAR) (pRxWI->SNR1);
#ifdef DOT11N_SS3_SUPPORT
if (pAd->CommonCfg.RxStream == 3)
pAd->StaCfg.LastSNR2 = (UCHAR) (pRxWI->SNR2);
#endif /* DOT11N_SS3_SUPPORT */
pAd->RalinkCounters.OneSecRxOkDataCnt++;
if (pEntry != NULL)
{
pEntry->LastRxRate = pAd->LastRxRate;
pEntry->freqOffset = (CHAR)(pRxWI->FOFFSET);
pEntry->freqOffsetValid = TRUE;
}
#ifdef PRE_ANT_SWITCH
#endif /* PRE_ANT_SWITCH */
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;
}
}
#ifdef XLINK_SUPPORT
else if (pAd->StaCfg.PSPXlink) {
Indicate_Legacy_Packet(pAd, pRxBlk, FromWhichBSSID);
return;
}
#endif /* XLINK_SUPPORT */
ASSERT(0);
/* release packet */
RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
}
VOID STAHandleRxMgmtFrame(
IN PRTMP_ADAPTER pAd,
IN RX_BLK *pRxBlk)
{
PRXWI_STRUC pRxWI = pRxBlk->pRxWI;
PHEADER_802_11 pHeader = pRxBlk->pHeader;
PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket;
UCHAR MinSNR = 0;
do {
UCHAR uRSSI2;
/* check if need to resend PS Poll when received packet with MoreData = 1 */
if ((RtmpPktPmBitCheck(pAd) == TRUE)
&& (pHeader->FC.MoreData == 1)) {
/* for UAPSD, all management frames will be VO priority */
if (pAd->CommonCfg.bAPSDAC_VO == 0) {
/* non-UAPSD delivery-enabled AC */
RTMP_PS_POLL_ENQUEUE(pAd);
}
}
/* TODO: if MoreData == 0, station can go to sleep */
/* 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))
&& (pAd->RxAnt.EvaluatePeriod == 0)) {
Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, pRxWI);
pAd->StaCfg.LastSNR0 = (UCHAR) (pRxWI->SNR0);
pAd->StaCfg.LastSNR1 = (UCHAR) (pRxWI->SNR1);
#ifdef DOT11N_SS3_SUPPORT
pAd->StaCfg.LastSNR2 = (UCHAR) (pRxWI->SNR2);
#endif /* DOT11N_SS3_SUPPORT */
#ifdef PRE_ANT_SWITCH
#endif /* PRE_ANT_SWITCH */
}
if ((pHeader->FC.SubType == SUBTYPE_BEACON) &&
(ADHOC_ON(pAd)) &&
(pRxWI->WirelessCliID < MAX_LEN_OF_MAC_TABLE)) {
MAC_TABLE_ENTRY *pEntry = NULL;
pEntry = &pAd->MacTab.Content[pRxWI->WirelessCliID];
if (pEntry)
Update_Rssi_Sample(pAd, &pEntry->RssiSample,
pRxWI);
}
#ifdef RT30xx
#endif /* RT30xx */
/* 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;
}
if (IS_RT3290(pAd))
{
uRSSI2 = (UCHAR)pRxWI->SNR2;
}
else
{
uRSSI2 = (UCHAR)pRxWI->RSSI2;
}
MinSNR = min((CHAR) pRxWI->SNR0, (CHAR) pRxWI->SNR1);
/* Signal in MLME_QUEUE isn't used, therefore take this item to save min SNR. */
REPORT_MGMT_FRAME_TO_MLME(pAd, pRxWI->WirelessCliID, pHeader,
pRxWI->MPDUtotalByteCount,
pRxWI->RSSI0, pRxWI->RSSI1,
uRSSI2, MinSNR,
OPMODE_STA);
} 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;
BOOLEAN retStatus;
NDIS_STATUS status = NDIS_STATUS_FAILURE;
switch (pHeader->FC.SubType) {
case SUBTYPE_BLOCK_ACK_REQ:
#ifdef DOT11_N_SUPPORT
{
retStatus =
CntlEnqueueForRecv(pAd, pRxWI->WirelessCliID,
(pRxWI->MPDUtotalByteCount),
(PFRAME_BA_REQ) pHeader);
status =
(retStatus ==
TRUE) ? NDIS_STATUS_SUCCESS : NDIS_STATUS_FAILURE;
}
break;
#endif /* DOT11_N_SUPPORT */
case SUBTYPE_BLOCK_ACK:
case SUBTYPE_ACK:
default:
break;
}
RELEASE_NDIS_PACKET(pAd, pRxPacket, status);
}
/*
========================================================================
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;
UINT8 RXWISize = pAd->chipCap.RXWISize;
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;
}
#ifdef RTMP_MAC_PCI
if (RxProcessed++ > MAX_RX_PROCESS_CNT)
{
bReschedule = TRUE;
break;
}
#endif /* RTMP_MAC_PCI */
RxProcessed++;
/*
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)
break;
/* get rx descriptor and buffer */
pRxD = &(RxCell.RxD);
pData = GET_OS_PKT_DATAPTR(pRxPacket);
pRxWI = (PRXWI_STRUC) pData;
pHeader = (PHEADER_802_11) (pData + RXWISize);
#ifdef RT_BIG_ENDIAN
RTMPFrameEndianChange(pAd, (PUCHAR) pHeader, DIR_READ, TRUE);
RTMPWIEndianChange(pAd, (PUCHAR) pRxWI, TYPE_RXWI);
#endif
#ifdef DBG_CTRL_SUPPORT
#ifdef INCLUDE_DEBUG_QUEUE
if (pAd->CommonCfg.DebugFlags & DBF_DBQ_RXWI)
dbQueueEnqueueRxFrame(pData, (UCHAR *)pHeader, pAd->CommonCfg.DebugFlags);
#endif /* INCLUDE_DEBUG_QUEUE */
#endif /* DBG_CTRL_SUPPORT */
/* build RxCell */
RxCell.pRxWI = pRxWI;
RxCell.pHeader = pHeader;
RxCell.pRxPacket = pRxPacket;
RxCell.pData = (UCHAR *) pHeader;
RxCell.DataSize = pRxWI->MPDUtotalByteCount;
RxCell.Flags = 0;
SET_OPMODE_STA(&RxCell);
/* Increase Total receive byte counter after real data received no mater any error or not */
pAd->RalinkCounters.ReceivedByteCount += pRxWI->MPDUtotalByteCount;
pAd->RalinkCounters.OneSecReceivedByteCount += pRxWI->MPDUtotalByteCount;
pAd->RalinkCounters.RxCount++;
#ifdef STATS_COUNT_SUPPORT
INC_COUNTER64(pAd->WlanCounters.ReceivedFragmentCount);
#endif /* STATS_COUNT_SUPPORT */
if (pRxWI->MPDUtotalByteCount < 14)
{
Status = NDIS_STATUS_FAILURE;
continue;
}
if (MONITOR_ON(pAd))
{
STA_MonPktSend(pAd, &RxCell);
continue;
}
/* Check for all RxD errors */
Status = RTMPCheckRxError(pAd, pHeader, pRxWI, pRxD);
/* Handle the received frame */
if (Status == NDIS_STATUS_SUCCESS) {
#ifdef RTMP_FREQ_CALIBRATION_SUPPORT
if (pAd->chipCap.FreqCalibrationSupport)
{
if ((pAd->FreqCalibrationCtrl.bEnableFrequencyCalibration == TRUE)
&& (INFRA_ON(pAd)) && (pRxD->Crc == 0)
&& (pHeader->FC.Type == BTYPE_MGMT)
&& (pHeader->FC.SubType == SUBTYPE_BEACON)
&& (MAC_ADDR_EQUAL(&pAd->CommonCfg.Bssid, &pHeader->Addr2)))
{
pAd->FreqCalibrationCtrl.LatestFreqOffsetOverBeacon =
GetFrequencyOffset(pAd, pRxWI);
pAd->FreqCalibrationCtrl.BeaconPhyMode = (UCHAR) (pRxWI->PHYMODE);
DBGPRINT(RT_DEBUG_INFO,
("%s: Beacon, CRC error = %d, pHeader->Sequence = %d, SA = %02X:%02X:%02X:%02X:%02X:%02X, frequency offset = %d, MCS = %d, BW = %d PHYMODE = %d\n",
__FUNCTION__, pRxD->Crc,
pHeader->Sequence, PRINT_MAC(pHeader->Addr2),
((CHAR) (pRxWI->FOFFSET)), pRxWI->MCS,
pRxWI->BW, pRxWI->PHYMODE));
}
}
#endif /* RTMP_FREQ_CALIBRATION_SUPPORT */
switch (pHeader->FC.Type) {
case BTYPE_DATA:
STAHandleRxDataFrame(pAd, &RxCell);
break;
case BTYPE_MGMT:
STAHandleRxMgmtFrame(pAd, &RxCell);
break;
case BTYPE_CNTL:
STAHandleRxControlFrame(pAd, &RxCell);
break;
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);
}
}
return bReschedule;
}
BOOLEAN STAHandleRxDonePacket(
IN PRTMP_ADAPTER pAd,
IN PNDIS_PACKET pRxPacket,
IN RX_BLK *pRxCell)
{
RT28XX_RXD_STRUC *pRxD;
PRXWI_STRUC pRxWI;
PHEADER_802_11 pHeader;