-
Notifications
You must be signed in to change notification settings - Fork 0
/
dls.c
2736 lines (2416 loc) · 78.1 KB
/
dls.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 2005, 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:
dls.c
Abstract:
Handle WMM-DLS state machine
Revision History:
Who When What
-------- ---------- ----------------------------------------------
Rory Chen 02-14-2006
Arvin Tai 06-03-2008 Modified for RT28xx
*/
#include "rt_config.h"
/*
==========================================================================
Description:
dls state machine init, including state transition and timer init
Parameters:
Sm - pointer to the dls state machine
Note:
The state machine looks like this
DLS_IDLE
MT2_MLME_DLS_REQUEST MlmeDlsReqAction
MT2_PEER_DLS_REQUEST PeerDlsReqAction
MT2_PEER_DLS_RESPONSE PeerDlsRspAction
MT2_MLME_DLS_TEARDOWN MlmeTearDownAction
MT2_PEER_DLS_TEARDOWN PeerTearDownAction
IRQL = PASSIVE_LEVEL
==========================================================================
*/
void DlsStateMachineInit(
IN PRTMP_ADAPTER pAd,
IN STATE_MACHINE *Sm,
OUT STATE_MACHINE_FUNC Trans[])
{
UCHAR i;
StateMachineInit(Sm, (STATE_MACHINE_FUNC *) Trans, MAX_DLS_STATE,
MAX_DLS_MSG, (STATE_MACHINE_FUNC) Drop, DLS_IDLE,
DLS_MACHINE_BASE);
/* the first column */
StateMachineSetAction(Sm, DLS_IDLE, MT2_MLME_DLS_REQ,
(STATE_MACHINE_FUNC) MlmeDlsReqAction);
StateMachineSetAction(Sm, DLS_IDLE, MT2_PEER_DLS_REQ,
(STATE_MACHINE_FUNC) PeerDlsReqAction);
StateMachineSetAction(Sm, DLS_IDLE, MT2_PEER_DLS_RSP,
(STATE_MACHINE_FUNC) PeerDlsRspAction);
StateMachineSetAction(Sm, DLS_IDLE, MT2_MLME_DLS_TEAR_DOWN,
(STATE_MACHINE_FUNC) MlmeDlsTearDownAction);
StateMachineSetAction(Sm, DLS_IDLE, MT2_PEER_DLS_TEAR_DOWN,
(STATE_MACHINE_FUNC) PeerDlsTearDownAction);
for (i = 0; i < MAX_NUM_OF_DLS_ENTRY; i++) {
pAd->StaCfg.DLSEntry[i].pAd = pAd;
RTMPInitTimer(pAd, &pAd->StaCfg.DLSEntry[i].Timer,
GET_TIMER_FUNCTION(DlsTimeoutAction), pAd, FALSE);
}
}
/*
==========================================================================
Description:
IRQL = DISPATCH_LEVEL
==========================================================================
*/
VOID MlmeDlsReqAction(
IN PRTMP_ADAPTER pAd,
IN MLME_QUEUE_ELEM *Elem)
{
PUCHAR pOutBuffer = NULL;
NDIS_STATUS NStatus;
ULONG FrameLen = 0;
HEADER_802_11 DlsReqHdr;
PRT_802_11_DLS pDLS = NULL;
UCHAR Category = CATEGORY_DLS;
UCHAR Action = ACTION_DLS_REQUEST;
ULONG tmp;
USHORT reason;
ULONG Timeout;
BOOLEAN TimerCancelled;
if (!MlmeDlsReqSanity(pAd, Elem->Msg, Elem->MsgLen, &pDLS, &reason))
return;
DBGPRINT(RT_DEBUG_TRACE, ("DLS - MlmeDlsReqAction() \n"));
NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */
if (NStatus != NDIS_STATUS_SUCCESS) {
DBGPRINT(RT_DEBUG_ERROR,
("DLS - MlmeDlsReqAction() allocate memory failed \n"));
return;
}
ActHeaderInit(pAd, &DlsReqHdr, pAd->CommonCfg.Bssid,
pAd->CurrentAddress, pAd->CommonCfg.Bssid);
/* Build basic frame first */
MakeOutgoingFrame(pOutBuffer, &FrameLen,
sizeof (HEADER_802_11), &DlsReqHdr,
1, &Category,
1, &Action,
6, &pDLS->MacAddr,
6, pAd->CurrentAddress,
2, &pAd->StaActive.CapabilityInfo,
2, &pDLS->TimeOut,
1, &SupRateIe,
1, &pAd->MlmeAux.SupRateLen,
pAd->MlmeAux.SupRateLen, pAd->MlmeAux.SupRate,
END_OF_ARGS);
if (pAd->MlmeAux.ExtRateLen != 0) {
MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
1, &ExtRateIe,
1, &pAd->MlmeAux.ExtRateLen,
pAd->MlmeAux.ExtRateLen, pAd->MlmeAux.ExtRate,
END_OF_ARGS);
FrameLen += tmp;
}
#ifdef DOT11_N_SUPPORT
if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)) {
UCHAR HtLen;
#ifdef RT_BIG_ENDIAN
HT_CAPABILITY_IE HtCapabilityTmp;
#endif
/* add HT Capability IE */
HtLen = sizeof (HT_CAPABILITY_IE);
#ifndef RT_BIG_ENDIAN
MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
1, &HtCapIe,
1, &HtLen,
HtLen, &pAd->CommonCfg.HtCapability,
END_OF_ARGS);
#else
NdisMoveMemory(&HtCapabilityTmp, &pAd->CommonCfg.HtCapability,
HtLen);
*(USHORT *) (&HtCapabilityTmp.HtCapInfo) =
SWAP16(*(USHORT *) (&HtCapabilityTmp.HtCapInfo));
*(USHORT *) (&HtCapabilityTmp.ExtHtCapInfo) =
SWAP16(*(USHORT *) (&HtCapabilityTmp.ExtHtCapInfo));
MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
1, &HtCapIe,
1, &HtLen,
HtLen, &HtCapabilityTmp, END_OF_ARGS);
#endif
FrameLen = FrameLen + tmp;
}
#endif /* DOT11_N_SUPPORT */
RTMPCancelTimer(&pDLS->Timer, &TimerCancelled);
Timeout = DLS_TIMEOUT;
RTMPSetTimer(&pDLS->Timer, Timeout);
MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
MlmeFreeMemory(pAd, pOutBuffer);
}
/*
==========================================================================
Description:
IRQL = DISPATCH_LEVEL
==========================================================================
*/
VOID PeerDlsReqAction(
IN PRTMP_ADAPTER pAd,
IN MLME_QUEUE_ELEM *Elem)
{
PUCHAR pOutBuffer = NULL;
NDIS_STATUS NStatus;
ULONG FrameLen = 0;
USHORT StatusCode = MLME_SUCCESS;
HEADER_802_11 DlsRspHdr;
UCHAR Category = CATEGORY_DLS;
UCHAR Action = ACTION_DLS_RESPONSE;
ULONG tmp;
USHORT CapabilityInfo;
UCHAR DA[MAC_ADDR_LEN], SA[MAC_ADDR_LEN];
USHORT DLSTimeOut;
SHORT i;
ULONG Timeout;
BOOLEAN TimerCancelled;
PRT_802_11_DLS pDLS = NULL;
UCHAR MaxSupportedRateIn500Kbps = 0;
UCHAR SupportedRatesLen;
UCHAR SupportedRates[MAX_LEN_OF_SUPPORTED_RATES];
UCHAR HtCapabilityLen;
HT_CAPABILITY_IE HtCapability;
if (!PeerDlsReqSanity
(pAd, Elem->Msg, Elem->MsgLen, DA, SA, &CapabilityInfo, &DLSTimeOut,
&SupportedRatesLen, &SupportedRates[0], &HtCapabilityLen,
&HtCapability))
return;
/* supported rates array may not be sorted. sort it and find the maximum rate */
for (i = 0; i < SupportedRatesLen; i++) {
if (MaxSupportedRateIn500Kbps < (SupportedRates[i] & 0x7f))
MaxSupportedRateIn500Kbps = SupportedRates[i] & 0x7f;
}
DBGPRINT(RT_DEBUG_TRACE,
("DLS - PeerDlsReqAction() from %02x:%02x:%02x:%02x:%02x:%02x\n",
SA[0], SA[1], SA[2], SA[3], SA[4], SA[5]));
NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */
if (NStatus != NDIS_STATUS_SUCCESS) {
DBGPRINT(RT_DEBUG_ERROR,
("DLS - PeerDlsReqAction() allocate memory failed \n"));
return;
}
if (!INFRA_ON(pAd)) {
StatusCode = MLME_REQUEST_DECLINED;
} else if (!pAd->CommonCfg.bWmmCapable) {
StatusCode = MLME_DEST_STA_IS_NOT_A_QSTA;
} else if (!pAd->CommonCfg.bDLSCapable) {
StatusCode = MLME_REQUEST_DECLINED;
} else {
/* find table to update parameters */
for (i = (MAX_NUM_OF_DLS_ENTRY - 1); i >= 0; i--) {
if (pAd->StaCfg.DLSEntry[i].Valid
&& MAC_ADDR_EQUAL(SA,
pAd->StaCfg.DLSEntry[i].
MacAddr)) {
if (pAd->StaCfg.AuthMode >=
Ndis802_11AuthModeWPA)
pAd->StaCfg.DLSEntry[i].Status =
DLS_WAIT_KEY;
else {
RTMPCancelTimer(&pAd->StaCfg.
DLSEntry[i].Timer,
&TimerCancelled);
pAd->StaCfg.DLSEntry[i].Status =
DLS_FINISH;
}
pAd->StaCfg.DLSEntry[i].Sequence = 0;
pAd->StaCfg.DLSEntry[i].TimeOut = DLSTimeOut;
pAd->StaCfg.DLSEntry[i].CountDownTimer =
DLSTimeOut;
if (HtCapabilityLen != 0)
pAd->StaCfg.DLSEntry[i].bHTCap = TRUE;
else
pAd->StaCfg.DLSEntry[i].bHTCap = FALSE;
pDLS = &pAd->StaCfg.DLSEntry[i];
break;
}
}
/* can not find in table, create a new one */
if (i < 0) {
DBGPRINT(RT_DEBUG_TRACE,
("DLS - PeerDlsReqAction() can not find same entry \n"));
for (i = (MAX_NUM_OF_DLS_ENTRY - 1);
i >= MAX_NUM_OF_INIT_DLS_ENTRY; i--) {
if (!pAd->StaCfg.DLSEntry[i].Valid) {
MAC_TABLE_ENTRY *pEntry;
UCHAR MaxSupportedRate = RATE_11;
if (pAd->StaCfg.AuthMode >=
Ndis802_11AuthModeWPA) {
pAd->StaCfg.DLSEntry[i].Status =
DLS_WAIT_KEY;
} else {
RTMPCancelTimer(&pAd->StaCfg.
DLSEntry[i].
Timer,
&TimerCancelled);
pAd->StaCfg.DLSEntry[i].Status =
DLS_FINISH;
}
pAd->StaCfg.DLSEntry[i].Sequence = 0;
pAd->StaCfg.DLSEntry[i].Valid = TRUE;
pAd->StaCfg.DLSEntry[i].TimeOut =
DLSTimeOut;
pAd->StaCfg.DLSEntry[i].CountDownTimer =
DLSTimeOut;
NdisMoveMemory(pAd->StaCfg.DLSEntry[i].
MacAddr, SA,
MAC_ADDR_LEN);
if (HtCapabilityLen != 0)
pAd->StaCfg.DLSEntry[i].bHTCap =
TRUE;
else
pAd->StaCfg.DLSEntry[i].bHTCap =
FALSE;
pDLS = &pAd->StaCfg.DLSEntry[i];
pEntry =
MacTableInsertDlsEntry(pAd, SA, i);
switch (MaxSupportedRateIn500Kbps) {
case 108:
MaxSupportedRate = RATE_54;
break;
case 96:
MaxSupportedRate = RATE_48;
break;
case 72:
MaxSupportedRate = RATE_36;
break;
case 48:
MaxSupportedRate = RATE_24;
break;
case 36:
MaxSupportedRate = RATE_18;
break;
case 24:
MaxSupportedRate = RATE_12;
break;
case 18:
MaxSupportedRate = RATE_9;
break;
case 12:
MaxSupportedRate = RATE_6;
break;
case 22:
MaxSupportedRate = RATE_11;
break;
case 11:
MaxSupportedRate = RATE_5_5;
break;
case 4:
MaxSupportedRate = RATE_2;
break;
case 2:
MaxSupportedRate = RATE_1;
break;
default:
MaxSupportedRate = RATE_11;
break;
}
pEntry->MaxSupportedRate =
min(pAd->CommonCfg.MaxTxRate,
MaxSupportedRate);
if (pEntry->MaxSupportedRate <
RATE_FIRST_OFDM_RATE) {
pEntry->MaxHTPhyMode.field.
MODE = MODE_CCK;
pEntry->MaxHTPhyMode.field.MCS =
pEntry->MaxSupportedRate;
pEntry->MinHTPhyMode.field.
MODE = MODE_CCK;
pEntry->MinHTPhyMode.field.MCS =
pEntry->MaxSupportedRate;
pEntry->HTPhyMode.field.MODE =
MODE_CCK;
pEntry->HTPhyMode.field.MCS =
pEntry->MaxSupportedRate;
} else {
pEntry->MaxHTPhyMode.field.
MODE = MODE_OFDM;
pEntry->MaxHTPhyMode.field.MCS =
OfdmRateToRxwiMCS[pEntry->
MaxSupportedRate];
pEntry->MinHTPhyMode.field.
MODE = MODE_OFDM;
pEntry->MinHTPhyMode.field.MCS =
OfdmRateToRxwiMCS[pEntry->
MaxSupportedRate];
pEntry->HTPhyMode.field.MODE =
MODE_OFDM;
pEntry->HTPhyMode.field.MCS =
OfdmRateToRxwiMCS[pEntry->
MaxSupportedRate];
}
pEntry->MaxHTPhyMode.field.BW = BW_20;
pEntry->MinHTPhyMode.field.BW = BW_20;
#ifdef DOT11_N_SUPPORT
pEntry->HTCapability.MCSSet[0] = 0;
pEntry->HTCapability.MCSSet[1] = 0;
/* If this Entry supports 802.11n, upgrade to HT rate. */
if ((HtCapabilityLen != 0)
&& (pAd->CommonCfg.PhyMode >=
PHY_11ABGN_MIXED)) {
UCHAR j, bitmask; /*k,bitmask; */
CHAR ii;
DBGPRINT(RT_DEBUG_TRACE,
("DLS - PeerDlsReqAction() Receive Peer HT Capable STA from %02x:%02x:%02x:%02x:%02x:%02x\n",
SA[0], SA[1], SA[2],
SA[3], SA[4], SA[5]));
if ((HtCapability.HtCapInfo.GF)
&& (pAd->CommonCfg.DesiredHtPhy.GF)) {
pEntry->MaxHTPhyMode.field.MODE = MODE_HTGREENFIELD;
} else {
pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
pAd->MacTab.fAnyStationNonGF = TRUE;
pAd->CommonCfg.AddHTInfo.AddHtInfo2.NonGfPresent = 1;
}
if ((HtCapability.HtCapInfo.ChannelWidth)
&& (pAd->CommonCfg.DesiredHtPhy.ChannelWidth)) {
pEntry->MaxHTPhyMode.field.BW = BW_40;
pEntry->MaxHTPhyMode.field.ShortGI = ((pAd->CommonCfg.DesiredHtPhy.ShortGIfor40) & (HtCapability.HtCapInfo.ShortGIfor40));
} else {
pEntry->MaxHTPhyMode.field.BW = BW_20;
pEntry->MaxHTPhyMode.field.ShortGI = ((pAd->CommonCfg.DesiredHtPhy.ShortGIfor20) & (HtCapability.HtCapInfo.ShortGIfor20));
pAd->MacTab.fAnyStation20Only = TRUE;
}
/* find max fixed rate */
for (ii = 15; ii >= 0; ii--) {
j = ii / 8;
bitmask = (1 << (ii - (j * 8)));
if ((pAd->StaCfg.DesiredHtPhyInfo.MCSSet[j] & bitmask)
&& (HtCapability.MCSSet[j] & bitmask)) {
pEntry->MaxHTPhyMode.field.MCS = ii;
break;
}
if (ii == 0)
break;
}
if (pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO) {
DBGPRINT(RT_DEBUG_OFF,
("@@@ pAd->CommonCfg.RegTransmitSetting.field.MCS = %d\n",
pAd->StaCfg.DesiredTransmitSetting.field.MCS));
if (pAd->StaCfg.DesiredTransmitSetting.field.MCS == 32) {
/* Fix MCS as HT Duplicated Mode */
pEntry->MaxHTPhyMode.field.BW = 1;
pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
pEntry->MaxHTPhyMode.field.STBC = 0;
pEntry->MaxHTPhyMode.field.ShortGI = 0;
pEntry->MaxHTPhyMode.field.MCS = 32;
} else if (pEntry->MaxHTPhyMode.field.MCS >pAd->StaCfg.HTPhyMode.field.MCS) {
/* STA supports fixed MCS */
pEntry->MaxHTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
}
}
pEntry->MaxHTPhyMode.field.STBC =
(HtCapability.HtCapInfo.RxSTBC & (pAd->CommonCfg.DesiredHtPhy.TxSTBC));
pEntry->MpduDensity =
HtCapability.HtCapParm.MpduDensity;
pEntry->MaxRAmpduFactor =
HtCapability.HtCapParm.MaxRAmpduFactor;
pEntry->MmpsMode =
(UCHAR) HtCapability.HtCapInfo.MimoPs;
pEntry->AMsduSize =
(UCHAR) HtCapability.HtCapInfo.AMsduSize;
pEntry->HTPhyMode.word =
pEntry->MaxHTPhyMode.word;
if (HtCapability.HtCapInfo.ShortGIfor20)
CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_SGI20_CAPABLE);
if (HtCapability.HtCapInfo.ShortGIfor40)
CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_SGI40_CAPABLE);
if (HtCapability.HtCapInfo.TxSTBC)
CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_TxSTBC_CAPABLE);
if (HtCapability.HtCapInfo.RxSTBC)
CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_RxSTBC_CAPABLE);
if (HtCapability.ExtHtCapInfo.PlusHTC)
CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_HTC_CAPABLE);
if (pAd->CommonCfg.bRdg
&& HtCapability.ExtHtCapInfo.RDGSupport)
CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_RDG_CAPABLE);
if (HtCapability.ExtHtCapInfo.MCSFeedback == 0x03)
CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_MCSFEEDBACK_CAPABLE);
NdisMoveMemory(&pEntry->HTCapability,
&HtCapability, sizeof(HT_CAPABILITY_IE));
}
#endif /* DOT11_N_SUPPORT */
pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;
pEntry->CurrTxRate = pEntry->MaxSupportedRate;
CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE);
if (pAd->StaCfg.bAutoTxRateSwitch == TRUE) {
UCHAR TableSize = 0;
MlmeSelectTxRateTable(pAd,
pEntry,
&pEntry->pTable,
&TableSize,
&pEntry->CurrTxRateIndex);
pEntry->bAutoTxRateSwitch = TRUE;
} else {
pEntry->HTPhyMode.field.MODE = pAd->StaCfg.HTPhyMode.field.MODE;
pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
pEntry->bAutoTxRateSwitch = FALSE;
RTMPUpdateLegacyTxSetting((UCHAR) pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode, pEntry);
}
pEntry->RateLen = SupportedRatesLen;
break;
}
}
}
StatusCode = MLME_SUCCESS;
/* can not find in table, create a new one */
if (i < 0) {
StatusCode = MLME_QOS_UNSPECIFY;
DBGPRINT(RT_DEBUG_ERROR,
("DLS - PeerDlsReqAction() DLSEntry table full(only can support %d DLS session) \n",
MAX_NUM_OF_DLS_ENTRY -
MAX_NUM_OF_INIT_DLS_ENTRY));
} else {
DBGPRINT(RT_DEBUG_TRACE,
("DLS - PeerDlsReqAction() use entry(%d) %02x:%02x:%02x:%02x:%02x:%02x\n",
i, SA[0], SA[1], SA[2], SA[3], SA[4], SA[5]));
}
}
ActHeaderInit(pAd, &DlsRspHdr, pAd->CommonCfg.Bssid,
pAd->CurrentAddress, pAd->CommonCfg.Bssid);
/* Build basic frame first */
if (StatusCode == MLME_SUCCESS) {
MakeOutgoingFrame(pOutBuffer, &FrameLen,
sizeof (HEADER_802_11), &DlsRspHdr,
1, &Category,
1, &Action,
2, &StatusCode,
6, SA,
6, pAd->CurrentAddress,
2, &pAd->StaActive.CapabilityInfo,
1, &SupRateIe,
1, &pAd->MlmeAux.SupRateLen,
pAd->MlmeAux.SupRateLen, pAd->MlmeAux.SupRate,
END_OF_ARGS);
if (pAd->MlmeAux.ExtRateLen != 0) {
MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
1, &ExtRateIe,
1, &pAd->MlmeAux.ExtRateLen,
pAd->MlmeAux.ExtRateLen,
pAd->MlmeAux.ExtRate, END_OF_ARGS);
FrameLen += tmp;
}
#ifdef DOT11_N_SUPPORT
if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)) {
UCHAR HtLen;
#ifdef RT_BIG_ENDIAN
HT_CAPABILITY_IE HtCapabilityTmp;
#endif
/* add HT Capability IE */
HtLen = sizeof (HT_CAPABILITY_IE);
#ifndef RT_BIG_ENDIAN
MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
1, &HtCapIe,
1, &HtLen,
HtLen, &pAd->CommonCfg.HtCapability,
END_OF_ARGS);
#else
NdisMoveMemory(&HtCapabilityTmp,
&pAd->CommonCfg.HtCapability, HtLen);
*(USHORT *) (&HtCapabilityTmp.HtCapInfo) =
SWAP16(*(USHORT *) (&HtCapabilityTmp.HtCapInfo));
*(USHORT *) (&HtCapabilityTmp.ExtHtCapInfo) =
SWAP16(*(USHORT *) (&HtCapabilityTmp.ExtHtCapInfo));
MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
1, &HtCapIe,
1, &HtLen,
HtLen, &HtCapabilityTmp, END_OF_ARGS);
#endif
FrameLen = FrameLen + tmp;
}
#endif /* DOT11_N_SUPPORT */
if (pDLS && (pDLS->Status != DLS_FINISH)) {
RTMPCancelTimer(&pDLS->Timer, &TimerCancelled);
Timeout = DLS_TIMEOUT;
RTMPSetTimer(&pDLS->Timer, Timeout);
}
} else {
MakeOutgoingFrame(pOutBuffer, &FrameLen,
sizeof (HEADER_802_11), &DlsRspHdr,
1, &Category,
1, &Action,
2, &StatusCode,
6, SA, 6, pAd->CurrentAddress, END_OF_ARGS);
}
MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
MlmeFreeMemory(pAd, pOutBuffer);
}
/*
==========================================================================
Description:
IRQL = DISPATCH_LEVEL
==========================================================================
*/
VOID PeerDlsRspAction(
IN PRTMP_ADAPTER pAd,
IN MLME_QUEUE_ELEM *Elem)
{
USHORT CapabilityInfo;
UCHAR DA[MAC_ADDR_LEN], SA[MAC_ADDR_LEN];
USHORT StatusCode;
SHORT i;
BOOLEAN TimerCancelled;
UCHAR MaxSupportedRateIn500Kbps = 0;
UCHAR SupportedRatesLen;
UCHAR SupportedRates[MAX_LEN_OF_SUPPORTED_RATES];
UCHAR HtCapabilityLen;
HT_CAPABILITY_IE HtCapability;
if (!pAd->CommonCfg.bDLSCapable)
return;
if (!INFRA_ON(pAd))
return;
if (!PeerDlsRspSanity
(pAd, Elem->Msg, Elem->MsgLen, DA, SA, &CapabilityInfo, &StatusCode,
&SupportedRatesLen, &SupportedRates[0], &HtCapabilityLen,
&HtCapability))
return;
/* supported rates array may not be sorted. sort it and find the maximum rate */
for (i = 0; i < SupportedRatesLen; i++) {
if (MaxSupportedRateIn500Kbps < (SupportedRates[i] & 0x7f))
MaxSupportedRateIn500Kbps = SupportedRates[i] & 0x7f;
}
DBGPRINT(RT_DEBUG_TRACE,
("DLS - PeerDlsRspAction() from %02x:%02x:%02x:%02x:%02x:%02x with StatusCode=%d, CapabilityInfo=0x%x\n",
SA[0], SA[1], SA[2], SA[3], SA[4], SA[5], StatusCode,
CapabilityInfo));
for (i = 0; i < MAX_NUM_OF_INIT_DLS_ENTRY; i++) {
if (pAd->StaCfg.DLSEntry[i].Valid
&& MAC_ADDR_EQUAL(SA, pAd->StaCfg.DLSEntry[i].MacAddr)) {
if (StatusCode == MLME_SUCCESS) {
MAC_TABLE_ENTRY *pEntry;
UCHAR MaxSupportedRate = RATE_11;
pEntry = MacTableInsertDlsEntry(pAd, SA, i);
switch (MaxSupportedRateIn500Kbps) {
case 108:
MaxSupportedRate = RATE_54;
break;
case 96:
MaxSupportedRate = RATE_48;
break;
case 72:
MaxSupportedRate = RATE_36;
break;
case 48:
MaxSupportedRate = RATE_24;
break;
case 36:
MaxSupportedRate = RATE_18;
break;
case 24:
MaxSupportedRate = RATE_12;
break;
case 18:
MaxSupportedRate = RATE_9;
break;
case 12:
MaxSupportedRate = RATE_6;
break;
case 22:
MaxSupportedRate = RATE_11;
break;
case 11:
MaxSupportedRate = RATE_5_5;
break;
case 4:
MaxSupportedRate = RATE_2;
break;
case 2:
MaxSupportedRate = RATE_1;
break;
default:
MaxSupportedRate = RATE_11;
break;
}
pEntry->MaxSupportedRate =
min(pAd->CommonCfg.MaxTxRate,
MaxSupportedRate);
if (pEntry->MaxSupportedRate <
RATE_FIRST_OFDM_RATE) {
pEntry->MaxHTPhyMode.field.MODE =
MODE_CCK;
pEntry->MaxHTPhyMode.field.MCS =
pEntry->MaxSupportedRate;
pEntry->MinHTPhyMode.field.MODE =
MODE_CCK;
pEntry->MinHTPhyMode.field.MCS =
pEntry->MaxSupportedRate;
pEntry->HTPhyMode.field.MODE = MODE_CCK;
pEntry->HTPhyMode.field.MCS =
pEntry->MaxSupportedRate;
} else {
pEntry->MaxHTPhyMode.field.MODE =
MODE_OFDM;
pEntry->MaxHTPhyMode.field.MCS =
OfdmRateToRxwiMCS[pEntry->
MaxSupportedRate];
pEntry->MinHTPhyMode.field.MODE =
MODE_OFDM;
pEntry->MinHTPhyMode.field.MCS =
OfdmRateToRxwiMCS[pEntry->
MaxSupportedRate];
pEntry->HTPhyMode.field.MODE =
MODE_OFDM;
pEntry->HTPhyMode.field.MCS =
OfdmRateToRxwiMCS[pEntry->
MaxSupportedRate];
}
pEntry->MaxHTPhyMode.field.BW = BW_20;
pEntry->MinHTPhyMode.field.BW = BW_20;
#ifdef DOT11_N_SUPPORT
pEntry->HTCapability.MCSSet[0] = 0;
pEntry->HTCapability.MCSSet[1] = 0;
/* If this Entry supports 802.11n, upgrade to HT rate. */
if ((HtCapabilityLen != 0)
&& (pAd->CommonCfg.PhyMode >=
PHY_11ABGN_MIXED)) {
UCHAR j, bitmask; /*k,bitmask; */
CHAR ii;
DBGPRINT(RT_DEBUG_OFF,
("DLS - PeerDlsRspAction Receive Peer HT Capable STA from %02x:%02x:%02x:%02x:%02x:%02x\n",
SA[0], SA[1], SA[2], SA[3],
SA[4], SA[5]));
if ((HtCapability.HtCapInfo.GF)
&& (pAd->CommonCfg.DesiredHtPhy.
GF)) {
pEntry->MaxHTPhyMode.field.
MODE = MODE_HTGREENFIELD;
} else {
pEntry->MaxHTPhyMode.field.
MODE = MODE_HTMIX;
pAd->MacTab.fAnyStationNonGF =
TRUE;
pAd->CommonCfg.AddHTInfo.
AddHtInfo2.NonGfPresent = 1;
}
if ((HtCapability.HtCapInfo.
ChannelWidth)
&& (pAd->CommonCfg.DesiredHtPhy.
ChannelWidth)) {
pEntry->MaxHTPhyMode.field.BW =
BW_40;
pEntry->MaxHTPhyMode.field.
ShortGI =
((pAd->CommonCfg.
DesiredHtPhy.
ShortGIfor40) &
(HtCapability.HtCapInfo.
ShortGIfor40));
} else {
pEntry->MaxHTPhyMode.field.BW =
BW_20;
pEntry->MaxHTPhyMode.field.
ShortGI =
((pAd->CommonCfg.
DesiredHtPhy.
ShortGIfor20) &
(HtCapability.HtCapInfo.
ShortGIfor20));
pAd->MacTab.fAnyStation20Only =
TRUE;
}
/* find max fixed rate */
for (ii = 15; ii >= 0; ii--) {
j = ii / 8;
bitmask = (1 << (ii - (j * 8)));
if ((pAd->StaCfg.
DesiredHtPhyInfo.
MCSSet[j] & bitmask)
&& (HtCapability.
MCSSet[j] & bitmask)) {
pEntry->MaxHTPhyMode.
field.MCS = ii;
break;
}
if (ii == 0)
break;
}
if (pAd->StaCfg.DesiredTransmitSetting.
field.MCS != MCS_AUTO) {
if (pAd->StaCfg.
DesiredTransmitSetting.
field.MCS == 32) {
/* Fix MCS as HT Duplicated Mode */
pEntry->MaxHTPhyMode.
field.BW = 1;
pEntry->MaxHTPhyMode.
field.MODE =
MODE_HTMIX;
pEntry->MaxHTPhyMode.
field.STBC = 0;
pEntry->MaxHTPhyMode.
field.ShortGI = 0;
pEntry->MaxHTPhyMode.
field.MCS = 32;
} else if (pEntry->MaxHTPhyMode.
field.MCS >
pAd->StaCfg.
HTPhyMode.field.
MCS) {
/* STA supports fixed MCS */
pEntry->MaxHTPhyMode.
field.MCS =
pAd->StaCfg.
HTPhyMode.field.MCS;
}
}
pEntry->MaxHTPhyMode.field.STBC =
(HtCapability.HtCapInfo.
RxSTBC & (pAd->CommonCfg.
DesiredHtPhy.TxSTBC));
pEntry->MpduDensity =
HtCapability.HtCapParm.MpduDensity;
pEntry->MaxRAmpduFactor =
HtCapability.HtCapParm.
MaxRAmpduFactor;
pEntry->MmpsMode =
(UCHAR) HtCapability.HtCapInfo.
MimoPs;
pEntry->AMsduSize =
(UCHAR) HtCapability.HtCapInfo.
AMsduSize;
pEntry->HTPhyMode.word =
pEntry->MaxHTPhyMode.word;
if (HtCapability.HtCapInfo.ShortGIfor20)
CLIENT_STATUS_SET_FLAG(pEntry,
fCLIENT_STATUS_SGI20_CAPABLE);
if (HtCapability.HtCapInfo.ShortGIfor40)
CLIENT_STATUS_SET_FLAG(pEntry,
fCLIENT_STATUS_SGI40_CAPABLE);
if (HtCapability.HtCapInfo.TxSTBC)
CLIENT_STATUS_SET_FLAG(pEntry,
fCLIENT_STATUS_TxSTBC_CAPABLE);
if (HtCapability.HtCapInfo.RxSTBC)
CLIENT_STATUS_SET_FLAG(pEntry,
fCLIENT_STATUS_RxSTBC_CAPABLE);
if (HtCapability.ExtHtCapInfo.PlusHTC)
CLIENT_STATUS_SET_FLAG(pEntry,
fCLIENT_STATUS_HTC_CAPABLE);
if (pAd->CommonCfg.bRdg
&& HtCapability.ExtHtCapInfo.
RDGSupport)
CLIENT_STATUS_SET_FLAG(pEntry,
fCLIENT_STATUS_RDG_CAPABLE);
if (HtCapability.ExtHtCapInfo.
MCSFeedback == 0x03)
CLIENT_STATUS_SET_FLAG(pEntry,
fCLIENT_STATUS_MCSFEEDBACK_CAPABLE);
NdisMoveMemory(&pEntry->HTCapability,
&HtCapability,
sizeof
(HT_CAPABILITY_IE));
}
#endif /* DOT11_N_SUPPORT */
pEntry->HTPhyMode.word =
pEntry->MaxHTPhyMode.word;
pEntry->CurrTxRate = pEntry->MaxSupportedRate;
CLIENT_STATUS_SET_FLAG(pEntry,
fCLIENT_STATUS_WMM_CAPABLE);
if (pAd->StaCfg.bAutoTxRateSwitch == TRUE) {
UCHAR TableSize = 0;
MlmeSelectTxRateTable(pAd, pEntry,
&pEntry->pTable,
&TableSize,
&pEntry->CurrTxRateIndex);
pEntry->bAutoTxRateSwitch = TRUE;
} else {
pEntry->HTPhyMode.field.MODE =
pAd->StaCfg.HTPhyMode.field.MODE;
pEntry->HTPhyMode.field.MCS =
pAd->StaCfg.HTPhyMode.field.MCS;
pEntry->bAutoTxRateSwitch = FALSE;
RTMPUpdateLegacyTxSetting((UCHAR) pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode,
pEntry);
}
pEntry->RateLen = SupportedRatesLen;
if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) {
/* If support WPA or WPA2, start STAKey hand shake, */
/* If failed hand shake, just tear down peer DLS */
if (RTMPSendSTAKeyRequest
(pAd,
pAd->StaCfg.DLSEntry[i].MacAddr) != NDIS_STATUS_SUCCESS) {
MLME_DLS_REQ_STRUCT MlmeDlsReq;
USHORT reason = REASON_QOS_CIPHER_NOT_SUPPORT;
DlsParmFill(pAd, &MlmeDlsReq,
&pAd->StaCfg.DLSEntry[i],
reason);
MlmeEnqueue(pAd,
DLS_STATE_MACHINE,
MT2_MLME_DLS_TEAR_DOWN,
sizeof(MLME_DLS_REQ_STRUCT),
&MlmeDlsReq, 0);
pAd->StaCfg.DLSEntry[i].Status =DLS_NONE;
pAd->StaCfg.DLSEntry[i].Valid =FALSE;
DBGPRINT(RT_DEBUG_ERROR,
("DLS - PeerDlsRspAction failed when call RTMPSendSTAKeyRequest \n"));
} else {
pAd->StaCfg.DLSEntry[i].Status = DLS_WAIT_KEY;
DBGPRINT(RT_DEBUG_TRACE,
("DLS - waiting for STAKey handshake procedure\n"));
}
} else {
RTMPCancelTimer(&pAd->StaCfg.
DLSEntry[i].Timer,
&TimerCancelled);
pAd->StaCfg.DLSEntry[i].Status =
DLS_FINISH;
DBGPRINT(RT_DEBUG_TRACE,
("DLS - PeerDlsRspAction() from %02x:%02x:%02x:%02x:%02x:%02x Succeed with WEP or no security\n",
SA[0], SA[1], SA[2], SA[3],
SA[4], SA[5]));
}
/*initialize seq no for DLS frames. */
pAd->StaCfg.DLSEntry[i].Sequence = 0;
if (HtCapabilityLen != 0)
pAd->StaCfg.DLSEntry[i].bHTCap = TRUE;
else
pAd->StaCfg.DLSEntry[i].bHTCap = FALSE;
} else {
/* DLS setup procedure failed. */
pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
pAd->StaCfg.DLSEntry[i].Valid = FALSE;
RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer,
&TimerCancelled);
DBGPRINT(RT_DEBUG_ERROR,
("DLS - PeerDlsRspAction failed with StatusCode=%d \n",
StatusCode));
}
}
}
if (i >= MAX_NUM_OF_INIT_DLS_ENTRY) {
DBGPRINT(RT_DEBUG_TRACE,
("DLS - PeerDlsRspAction() update timeout value \n"));
for (i = (MAX_NUM_OF_DLS_ENTRY - 1);
i >= MAX_NUM_OF_INIT_DLS_ENTRY; i--) {
if (pAd->StaCfg.DLSEntry[i].Valid
&& MAC_ADDR_EQUAL(SA,
pAd->StaCfg.DLSEntry[i].
MacAddr)) {
if (StatusCode == MLME_SUCCESS) {
MAC_TABLE_ENTRY *pEntry;