forked from HRex39/rtl8852be
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtw_wlan_util.c
3148 lines (2608 loc) · 82.7 KB
/
rtw_wlan_util.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
/******************************************************************************
*
* Copyright(c) 2007 - 2021 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* 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.
*
*****************************************************************************/
#define _RTW_WLAN_UTIL_C_
#include <drv_types.h>
unsigned char ARTHEROS_OUI1[] = {0x00, 0x03, 0x7f};
unsigned char ARTHEROS_OUI2[] = {0x00, 0x13, 0x74};
unsigned char BROADCOM_OUI1[] = {0x00, 0x10, 0x18};
unsigned char BROADCOM_OUI2[] = {0x00, 0x0a, 0xf7};
unsigned char BROADCOM_OUI3[] = {0x00, 0x05, 0xb5};
unsigned char CISCO_OUI[] = {0x00, 0x40, 0x96};
unsigned char MARVELL_OUI[] = {0x00, 0x50, 0x43};
unsigned char RALINK_OUI[] = {0x00, 0x0c, 0x43};
unsigned char REALTEK_OUI[] = {0x00, 0xe0, 0x4c};
unsigned char AIRGOCAP_OUI[] = {0x00, 0x0a, 0xf5};
unsigned char REALTEK_96B_IE[] = {0x00, 0xe0, 0x4c, 0x02, 0x01, 0x20};
extern unsigned char RTW_WPA_OUI[];
extern unsigned char WPA_TKIP_CIPHER[4];
extern unsigned char RSN_TKIP_CIPHER[4];
#define R2T_PHY_DELAY (0)
/* #define WAIT_FOR_BCN_TO_MIN (3000) */
#define WAIT_FOR_BCN_TO_MIN (6000)
#define WAIT_FOR_BCN_TO_MAX (20000)
static u8 rtw_basic_rate_cck[4] = {
IEEE80211_CCK_RATE_1MB | IEEE80211_BASIC_RATE_MASK, IEEE80211_CCK_RATE_2MB | IEEE80211_BASIC_RATE_MASK,
IEEE80211_CCK_RATE_5MB | IEEE80211_BASIC_RATE_MASK, IEEE80211_CCK_RATE_11MB | IEEE80211_BASIC_RATE_MASK
};
static u8 rtw_basic_rate_ofdm[3] = {
IEEE80211_OFDM_RATE_6MB | IEEE80211_BASIC_RATE_MASK, IEEE80211_OFDM_RATE_12MB | IEEE80211_BASIC_RATE_MASK,
IEEE80211_OFDM_RATE_24MB | IEEE80211_BASIC_RATE_MASK
};
static u8 rtw_basic_rate_mix[7] = {
IEEE80211_CCK_RATE_1MB | IEEE80211_BASIC_RATE_MASK, IEEE80211_CCK_RATE_2MB | IEEE80211_BASIC_RATE_MASK,
IEEE80211_CCK_RATE_5MB | IEEE80211_BASIC_RATE_MASK, IEEE80211_CCK_RATE_11MB | IEEE80211_BASIC_RATE_MASK,
IEEE80211_OFDM_RATE_6MB | IEEE80211_BASIC_RATE_MASK, IEEE80211_OFDM_RATE_12MB | IEEE80211_BASIC_RATE_MASK,
IEEE80211_OFDM_RATE_24MB | IEEE80211_BASIC_RATE_MASK
};
extern u8 WIFI_CCKRATES[];
bool rtw_is_cck_rate(u8 rate)
{
int i;
for (i = 0; i < 4; i++)
if ((WIFI_CCKRATES[i] & 0x7F) == (rate & 0x7F))
return 1;
return 0;
}
extern u8 WIFI_OFDMRATES[];
bool rtw_is_ofdm_rate(u8 rate)
{
int i;
for (i = 0; i < 8; i++)
if ((WIFI_OFDMRATES[i] & 0x7F) == (rate & 0x7F))
return 1;
return 0;
}
/* test if rate is defined in rtw_basic_rate_cck */
bool rtw_is_basic_rate_cck(u8 rate)
{
int i;
for (i = 0; i < 4; i++)
if ((rtw_basic_rate_cck[i] & 0x7F) == (rate & 0x7F))
return 1;
return 0;
}
/* test if rate is defined in rtw_basic_rate_ofdm */
bool rtw_is_basic_rate_ofdm(u8 rate)
{
int i;
for (i = 0; i < 3; i++)
if ((rtw_basic_rate_ofdm[i] & 0x7F) == (rate & 0x7F))
return 1;
return 0;
}
/* test if rate is defined in rtw_basic_rate_mix */
bool rtw_is_basic_rate_mix(u8 rate)
{
int i;
for (i = 0; i < 7; i++)
if ((rtw_basic_rate_mix[i] & 0x7F) == (rate & 0x7F))
return 1;
return 0;
}
int cckrates_included(unsigned char *rate, int ratelen)
{
int i;
for (i = 0; i < ratelen; i++) {
if ((((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||
(((rate[i]) & 0x7f) == 11) || (((rate[i]) & 0x7f) == 22))
return _TRUE;
}
return _FALSE;
}
int cckratesonly_included(unsigned char *rate, int ratelen)
{
int i;
for (i = 0; i < ratelen; i++) {
if ((((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
(((rate[i]) & 0x7f) != 11) && (((rate[i]) & 0x7f) != 22))
return _FALSE;
}
return _TRUE;
}
s8 rtw_get_sta_rx_nss(_adapter *adapter, struct sta_info *psta)
{
s8 nss = 1;
struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
if (!psta)
return nss;
nss = GET_HAL_RX_NSS(dvobj);
#ifdef CONFIG_80211N_HT
#ifdef CONFIG_80211AC_VHT
#ifdef CONFIG_80211AX_HE
if (psta->hepriv.he_option)
nss = psta->phl_sta->asoc_cap.nss_tx;
else
#endif /* CONFIG_80211AX_HE */
if (psta->vhtpriv.vht_option)
nss = rtw_min(nss, rtw_vht_mcsmap_to_nss(psta->vhtpriv.vht_mcs_map));
else
#endif /* CONFIG_80211AC_VHT */
if (psta->htpriv.ht_option)
nss = rtw_min(nss, rtw_ht_mcsset_to_nss(psta->htpriv.ht_cap.supp_mcs_set));
#endif /*CONFIG_80211N_HT*/
RTW_INFO("%s: %d ss\n", __func__, nss);
return nss;
}
s8 rtw_get_sta_tx_nss(_adapter *adapter, struct sta_info *psta)
{
s8 nss = 1;
if (!psta)
return nss;
nss = GET_HAL_TX_NSS(adapter_to_dvobj(adapter));
#ifdef CONFIG_80211N_HT
#ifdef CONFIG_80211AC_VHT
#ifdef CONFIG_80211AX_HE
if (psta->hepriv.he_option)
nss = psta->phl_sta->asoc_cap.nss_rx;
else
#endif /* CONFIG_80211AX_HE */
if (psta->vhtpriv.vht_option)
nss = rtw_min(nss, rtw_vht_mcsmap_to_nss(psta->vhtpriv.vht_mcs_map));
else
#endif /* CONFIG_80211AC_VHT */
if (psta->htpriv.ht_option)
nss = rtw_min(nss, rtw_ht_mcsset_to_nss(psta->htpriv.ht_cap.supp_mcs_set));
#endif /*CONFIG_80211N_HT*/
RTW_INFO("%s: %d SS\n", __func__, nss);
return nss;
}
unsigned char ratetbl_val_2wifirate(unsigned char rate)
{
unsigned char val = 0;
switch (rate & 0x7f) {
case 0:
val = IEEE80211_CCK_RATE_1MB;
break;
case 1:
val = IEEE80211_CCK_RATE_2MB;
break;
case 2:
val = IEEE80211_CCK_RATE_5MB;
break;
case 3:
val = IEEE80211_CCK_RATE_11MB;
break;
case 4:
val = IEEE80211_OFDM_RATE_6MB;
break;
case 5:
val = IEEE80211_OFDM_RATE_9MB;
break;
case 6:
val = IEEE80211_OFDM_RATE_12MB;
break;
case 7:
val = IEEE80211_OFDM_RATE_18MB;
break;
case 8:
val = IEEE80211_OFDM_RATE_24MB;
break;
case 9:
val = IEEE80211_OFDM_RATE_36MB;
break;
case 10:
val = IEEE80211_OFDM_RATE_48MB;
break;
case 11:
val = IEEE80211_OFDM_RATE_54MB;
break;
}
return val;
}
int is_basicrate(_adapter *padapter, unsigned char rate)
{
int i;
unsigned char val;
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
for (i = 0; i < NumRates; i++) {
val = pmlmeext->basicrate[i];
if ((val != 0xff) && (val != 0xfe)) {
if (rate == ratetbl_val_2wifirate(val))
return _TRUE;
}
}
return _FALSE;
}
unsigned int ratetbl2rateset(_adapter *padapter, unsigned char *rateset)
{
int i;
unsigned char rate;
unsigned int len = 0;
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
for (i = 0; i < NumRates; i++) {
rate = pmlmeext->datarate[i];
if (rtw_get_oper_ch(padapter) > 14 && rate < _6M_RATE_) /*5G no support CCK rate*/
continue;
switch (rate) {
case 0xff:
return len;
case 0xfe:
continue;
default:
rate = ratetbl_val_2wifirate(rate);
if (is_basicrate(padapter, rate) == _TRUE)
rate |= IEEE80211_BASIC_RATE_MASK;
rateset[len] = rate;
len++;
break;
}
}
return len;
}
void get_rate_set(_adapter *padapter, unsigned char *pbssrate, int *bssrate_len)
{
unsigned char supportedrates[NumRates];
_rtw_memset(supportedrates, 0, NumRates);
*bssrate_len = ratetbl2rateset(padapter, supportedrates);
_rtw_memcpy(pbssrate, supportedrates, *bssrate_len);
}
void set_mcs_rate_by_mask(u8 *mcs_set, u32 mask)
{
u8 mcs_rate_1r = (u8)(mask & 0xff);
u8 mcs_rate_2r = (u8)((mask >> 8) & 0xff);
u8 mcs_rate_3r = (u8)((mask >> 16) & 0xff);
u8 mcs_rate_4r = (u8)((mask >> 24) & 0xff);
mcs_set[0] &= mcs_rate_1r;
mcs_set[1] &= mcs_rate_2r;
mcs_set[2] &= mcs_rate_3r;
mcs_set[3] &= mcs_rate_4r;
}
void UpdateBrateTbl(
_adapter *adapter,
u8 *mBratesOS
)
{
u8 i;
u8 rate;
/* 1M, 2M, 5.5M, 11M, 6M, 12M, 24M are mandatory. */
for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
rate = mBratesOS[i] & 0x7f;
switch (rate) {
case IEEE80211_CCK_RATE_1MB:
case IEEE80211_CCK_RATE_2MB:
case IEEE80211_CCK_RATE_5MB:
case IEEE80211_CCK_RATE_11MB:
case IEEE80211_OFDM_RATE_6MB:
case IEEE80211_OFDM_RATE_12MB:
case IEEE80211_OFDM_RATE_24MB:
mBratesOS[i] |= IEEE80211_BASIC_RATE_MASK;
break;
}
}
}
void UpdateBrateTblForSoftAP(u8 *bssrateset, u32 bssratelen)
{
u8 i;
u8 rate;
for (i = 0; i < bssratelen; i++) {
rate = bssrateset[i] & 0x7f;
switch (rate) {
case IEEE80211_CCK_RATE_1MB:
case IEEE80211_CCK_RATE_2MB:
case IEEE80211_CCK_RATE_5MB:
case IEEE80211_CCK_RATE_11MB:
bssrateset[i] |= IEEE80211_BASIC_RATE_MASK;
break;
}
}
}
/*rtw_phl_mr_get_chandef(dvobj->phl, adapter->phl_role, &chandef); => mr union chan*/
/*rtw_phl_get_cur_hal_chdef(adapter->phl_role, &chandef) => hal chan*/
void rtw_get_oper_chdef(_adapter *adapter, struct rtw_chan_def *chandef)
{
if (!adapter->phl_role)
return;
if (rtw_phl_get_cur_hal_chdef(adapter->phl_role, chandef) != RTW_PHL_STATUS_SUCCESS)
RTW_ERR("%s failed\n", __func__);
}
u8 rtw_get_oper_band(_adapter *adapter)
{
struct rtw_chan_def cur_chandef = {0};
rtw_get_oper_chdef(adapter, &cur_chandef);
return cur_chandef.band;
}
u8 rtw_get_oper_ch(_adapter *adapter)
{
struct rtw_chan_def cur_chandef = {0};
rtw_get_oper_chdef(adapter, &cur_chandef);
return cur_chandef.chan;
}
u8 rtw_get_oper_bw(_adapter *adapter)
{
struct rtw_chan_def cur_chandef = {0};
rtw_get_oper_chdef(adapter, &cur_chandef);
return cur_chandef.bw;
}
u8 rtw_get_oper_choffset(_adapter *adapter)
{
struct rtw_chan_def cur_chandef = {0};
rtw_get_oper_chdef(adapter, &cur_chandef);
return cur_chandef.offset;
}
inline systime rtw_get_on_oper_ch_time(_adapter *adapter)
{
return adapter_to_dvobj(adapter)->on_oper_ch_time;
}
inline systime rtw_get_on_cur_ch_time(_adapter *adapter)
{
if (adapter->mlmeextpriv.chandef.chan == rtw_get_oper_ch(adapter))
return adapter_to_dvobj(adapter)->on_oper_ch_time;
else
return 0;
}
void set_channel_bwmode(_adapter *padapter,
unsigned char channel,
unsigned char channel_offset,
unsigned short bwmode,
u8 do_rfk)
{
rtw_hw_set_ch_bw(padapter, channel, (enum channel_width)bwmode,
channel_offset, do_rfk);
}
__inline u8 *get_my_bssid(WLAN_BSSID_EX *pnetwork)
{
return pnetwork->MacAddress;
}
u16 get_beacon_interval(WLAN_BSSID_EX *bss)
{
unsigned short val;
_rtw_memcpy((unsigned char *)&val, rtw_get_beacon_interval_from_ie(bss->IEs), 2);
return le16_to_cpu(val);
}
int is_client_associated_to_ap(_adapter *padapter)
{
struct mlme_ext_priv *pmlmeext;
struct mlme_ext_info *pmlmeinfo;
if (!padapter)
return _FAIL;
pmlmeext = &padapter->mlmeextpriv;
pmlmeinfo = &(pmlmeext->mlmext_info);
if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE))
return _TRUE;
else
return _FAIL;
}
int is_client_associated_to_ibss(_adapter *padapter)
{
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE))
return _TRUE;
else
return _FAIL;
}
/*GEORGIA_TODO_FIXIT*/
#define GET_H2CCMD_MSRRPT_PARM_OPMODE(__pH2CCmd) LE_BITS_TO_1BYTE(((u8 *)(__pH2CCmd)), 0, 1)
#define GET_H2CCMD_MSRRPT_PARM_ROLE(__pH2CCmd) LE_BITS_TO_1BYTE(((u8 *)(__pH2CCmd)), 4, 4)
int is_IBSS_empty(_adapter *padapter)
{
/* ToDo */
#if 0
int i;
struct macid_ctl_t *macid_ctl = &padapter->dvobj->macid_ctl;
for (i = 0; i < macid_ctl->num; i++) {
if (!rtw_macid_is_used(macid_ctl, i))
continue;
if (!rtw_macid_is_iface_specific(macid_ctl, i, padapter))
continue;
if (!GET_H2CCMD_MSRRPT_PARM_OPMODE(&macid_ctl->h2c_msr[i]))
continue;
if (GET_H2CCMD_MSRRPT_PARM_ROLE(&macid_ctl->h2c_msr[i]) == H2C_MSR_ROLE_ADHOC)
return _FAIL;
}
#endif
return _TRUE;
}
unsigned int decide_wait_for_beacon_timeout(unsigned int bcn_interval)
{
if ((bcn_interval << 2) < WAIT_FOR_BCN_TO_MIN)
return WAIT_FOR_BCN_TO_MIN;
else if ((bcn_interval << 2) > WAIT_FOR_BCN_TO_MAX)
return WAIT_FOR_BCN_TO_MAX;
else
return bcn_interval << 2;
}
#if defined(CONFIG_P2P) && defined(CONFIG_WFD)
void rtw_process_wfd_ie(_adapter *adapter, u8 *wfd_ie, u8 wfd_ielen, const char *tag)
{
struct wifidirect_info *wdinfo = &adapter->wdinfo;
u8 *attr_content;
u32 attr_contentlen = 0;
if (!rtw_hw_chk_wl_func(adapter_to_dvobj(adapter), WL_FUNC_MIRACAST))
return;
RTW_INFO("[%s] Found WFD IE\n", tag);
attr_content = rtw_get_wfd_attr_content(wfd_ie, wfd_ielen, WFD_ATTR_DEVICE_INFO, NULL, &attr_contentlen);
if (attr_content && attr_contentlen) {
wdinfo->wfd_info->peer_rtsp_ctrlport = RTW_GET_BE16(attr_content + 2);
RTW_INFO("[%s] Peer PORT NUM = %d\n", tag, wdinfo->wfd_info->peer_rtsp_ctrlport);
}
}
void rtw_process_wfd_ies(_adapter *adapter, u8 *ies, u8 ies_len, const char *tag)
{
u8 *wfd_ie;
u32 wfd_ielen;
if (!rtw_hw_chk_wl_func(adapter_to_dvobj(adapter), WL_FUNC_MIRACAST))
return;
wfd_ie = rtw_get_wfd_ie(ies, ies_len, NULL, &wfd_ielen);
while (wfd_ie) {
rtw_process_wfd_ie(adapter, wfd_ie, wfd_ielen, tag);
wfd_ie = rtw_get_wfd_ie(wfd_ie + wfd_ielen, (ies + ies_len) - (wfd_ie + wfd_ielen), NULL, &wfd_ielen);
}
}
#endif /* defined(CONFIG_P2P) && defined(CONFIG_WFD) */
int WMM_param_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
{
/* struct registry_priv *pregpriv = &padapter->registrypriv; */
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
if (pmlmepriv->qospriv.qos_option == 0) {
pmlmeinfo->WMM_enable = 0;
return _FALSE;
}
if (_rtw_memcmp(&(pmlmeinfo->WMM_param), (pIE->data + 6), sizeof(struct WMM_para_element)))
return _FALSE;
else
_rtw_memcpy(&(pmlmeinfo->WMM_param), (pIE->data + 6), sizeof(struct WMM_para_element));
pmlmeinfo->WMM_enable = 1;
return _TRUE;
#if 0
if (pregpriv->wifi_spec == 1) {
if (pmlmeinfo->WMM_enable == 1) {
/* todo: compare the parameter set count & decide wheher to update or not */
return _FAIL;
} else {
pmlmeinfo->WMM_enable = 1;
_rtw_rtw_memcpy(&(pmlmeinfo->WMM_param), (pIE->data + 6), sizeof(struct WMM_para_element));
return _TRUE;
}
} else {
pmlmeinfo->WMM_enable = 0;
return _FAIL;
}
#endif
}
#ifdef CONFIG_RTW_TOKEN_BASED_XMIT
u8 rtw_is_tbtx_capabilty(u8 *p, u8 len){
int i;
u8 tbtx_cap_ie[8] = {0x00, 0xe0, 0x4c, 0x01, 0x00, 0x00, 0x00, 0x00};
for (i = 0; i < len; i++) {
if (*(p + i) != tbtx_cap_ie[i])
return _FALSE;
else
continue;
}
return _TRUE;
}
#endif
void WMMOnAssocRsp(_adapter *padapter)
{
u8 ACI, ACM, AIFS, ECWMin, ECWMax, aSifsTime;
u8 acm_mask;
u16 TXOP;
u32 acParm, i;
u32 edca[4], inx[4];
u8 ac_be = 0;
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
struct registry_priv *pregpriv = &padapter->registrypriv;
#ifdef CONFIG_WMMPS_STA
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
struct qos_priv *pqospriv = &pmlmepriv->qospriv;
#endif /* CONFIG_WMMPS_STA */
acm_mask = 0;
if (WIFI_ROLE_IS_ON_5G(padapter) ||
(pmlmeext->cur_wireless_mode & WLAN_MD_11N))
aSifsTime = 16;
else
aSifsTime = 10;
if (pmlmeinfo->WMM_enable == 0) {
padapter->mlmepriv.acm_mask = 0;
AIFS = aSifsTime + (2 * pmlmeinfo->slotTime);
if (pmlmeext->cur_wireless_mode & (WLAN_MD_11G | WLAN_MD_11A)) {
ECWMin = 4;
ECWMax = 10;
} else if (pmlmeext->cur_wireless_mode & WLAN_MD_11B) {
ECWMin = 5;
ECWMax = 10;
} else {
ECWMin = 4;
ECWMax = 10;
}
TXOP = 0;
acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
rtw_hw_set_edca(padapter, 0, acParm);
rtw_hw_set_edca(padapter, 1, acParm);
rtw_hw_set_edca(padapter, 2, acParm);
ECWMin = 2;
ECWMax = 3;
TXOP = 0x2f;
acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
rtw_hw_set_edca(padapter, 3, acParm);
} else {
edca[0] = edca[1] = edca[2] = edca[3] = 0;
for (i = 0; i < 4; i++) {
ACI = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN >> 5) & 0x03;
ACM = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN >> 4) & 0x01;
/* AIFS = AIFSN * slot time + SIFS - r2t phy delay */
AIFS = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN & 0x0f) * pmlmeinfo->slotTime + aSifsTime;
ECWMin = (pmlmeinfo->WMM_param.ac_param[i].CW & 0x0f);
ECWMax = (pmlmeinfo->WMM_param.ac_param[i].CW & 0xf0) >> 4;
TXOP = le16_to_cpu(pmlmeinfo->WMM_param.ac_param[i].TXOP_limit);
acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
rtw_hw_set_edca(padapter, ACI, acParm);
switch (ACI) {
case 0x0:
acm_mask |= (ACM ? BIT(1) : 0);
edca[XMIT_BE_QUEUE] = acParm;
break;
case 0x1:
/* acm_mask |= (ACM? BIT(0):0); */
edca[XMIT_BK_QUEUE] = acParm;
break;
case 0x2:
acm_mask |= (ACM ? BIT(2) : 0);
edca[XMIT_VI_QUEUE] = acParm;
break;
case 0x3:
acm_mask |= (ACM ? BIT(3) : 0);
edca[XMIT_VO_QUEUE] = acParm;
break;
}
RTW_INFO("WMM(%x): %x, %x\n", ACI, ACM, acParm);
if (i == ac_be) {
padapter->last_edca = acParm;
acParm = rtw_get_turbo_edca(padapter, AIFS, ECWMin, ECWMax, TXOP);
if (acParm) {
rtw_hw_set_edca(padapter, ACI, acParm);
padapter->last_edca = acParm;
}
}
}
if (padapter->registrypriv.acm_method == 1)
rtw_hal_set_hwreg(padapter, HW_VAR_ACM_CTRL, (u8 *)(&acm_mask));
else
padapter->mlmepriv.acm_mask = acm_mask;
inx[0] = 0;
inx[1] = 1;
inx[2] = 2;
inx[3] = 3;
if (pregpriv->wifi_spec == 1) {
u32 j, tmp, change_inx = _FALSE;
/* entry indx: 0->vo, 1->vi, 2->be, 3->bk. */
for (i = 0; i < 4; i++) {
for (j = i + 1; j < 4; j++) {
/* compare CW and AIFS */
if ((edca[j] & 0xFFFF) < (edca[i] & 0xFFFF))
change_inx = _TRUE;
else if ((edca[j] & 0xFFFF) == (edca[i] & 0xFFFF)) {
/* compare TXOP */
if ((edca[j] >> 16) > (edca[i] >> 16))
change_inx = _TRUE;
}
if (change_inx) {
tmp = edca[i];
edca[i] = edca[j];
edca[j] = tmp;
tmp = inx[i];
inx[i] = inx[j];
inx[j] = tmp;
change_inx = _FALSE;
}
}
}
}
for (i = 0; i < 4; i++) {
pxmitpriv->wmm_para_seq[i] = inx[i];
RTW_INFO("wmm_para_seq(%d): %d\n", i, pxmitpriv->wmm_para_seq[i]);
}
#ifdef CONFIG_WMMPS_STA
/* if AP supports UAPSD function, driver must set each uapsd TID to coresponding mac register 0x693 */
if (pmlmeinfo->WMM_param.QoS_info & AP_SUPPORTED_UAPSD) {
pqospriv->uapsd_ap_supported = 1;
rtw_hal_set_hwreg(padapter, HW_VAR_UAPSD_TID, NULL);
}
#endif /* CONFIG_WMMPS_STA */
}
}
static void bwmode_update_check(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
{
#ifdef CONFIG_80211N_HT
unsigned char new_bwmode;
unsigned char new_ch_offset;
struct HT_info_element *pHT_info;
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
struct registry_priv *pregistrypriv = &padapter->registrypriv;
struct ht_priv *phtpriv = &pmlmepriv->htpriv;
u8 cbw40_enable = 0;
if (!pIE)
return;
if (phtpriv->ht_option == _FALSE)
return;
if (pmlmeext->chandef.bw >= CHANNEL_WIDTH_80)
return;
if (pIE->Length > sizeof(struct HT_info_element))
return;
pHT_info = (struct HT_info_element *)pIE->data;
if (rtw_hw_chk_bw_cap(adapter_to_dvobj(padapter), BW_CAP_40M)) {
if (pmlmeext->chandef.chan > 14) {
if (REGSTY_IS_BW_5G_SUPPORT(pregistrypriv, CHANNEL_WIDTH_40))
cbw40_enable = 1;
} else {
if (REGSTY_IS_BW_2G_SUPPORT(pregistrypriv, CHANNEL_WIDTH_40))
cbw40_enable = 1;
}
}
if ((pHT_info->infos[0] & BIT(2)) && cbw40_enable) {
new_bwmode = CHANNEL_WIDTH_40;
switch (pHT_info->infos[0] & 0x3) {
case 1:
new_ch_offset = CHAN_OFFSET_UPPER;
break;
case 3:
new_ch_offset = CHAN_OFFSET_LOWER;
break;
default:
new_bwmode = CHANNEL_WIDTH_20;
new_ch_offset = CHAN_OFFSET_NO_EXT;
break;
}
} else {
new_bwmode = CHANNEL_WIDTH_20;
new_ch_offset = CHAN_OFFSET_NO_EXT;
}
if ((new_bwmode != pmlmeext->chandef.bw || new_ch_offset != pmlmeext->chandef.offset)
&& new_bwmode < pmlmeext->chandef.bw
) {
pmlmeinfo->bwmode_updated = _TRUE;
pmlmeext->chandef.bw = new_bwmode;
pmlmeext->chandef.offset = new_ch_offset;
/* update HT info also */
HT_info_handler(padapter, pIE);
} else
pmlmeinfo->bwmode_updated = _FALSE;
if (_TRUE == pmlmeinfo->bwmode_updated) {
struct sta_info *psta;
WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network);
struct sta_priv *pstapriv = &padapter->stapriv;
/* set_channel_bwmode(padapter, pmlmeext->chandef.chan, pmlmeext->chandef.offset, pmlmeext->chandef.bw); */
/* update ap's stainfo */
psta = rtw_get_stainfo(pstapriv, cur_network->MacAddress);
if (psta) {
struct ht_priv *phtpriv_sta = &psta->htpriv;
if (phtpriv_sta->ht_option) {
/* bwmode */
psta->phl_sta->chandef.bw = pmlmeext->chandef.bw;
phtpriv_sta->ch_offset = pmlmeext->chandef.offset;
} else {
psta->phl_sta->chandef.bw = CHANNEL_WIDTH_20;
phtpriv_sta->ch_offset = CHAN_OFFSET_NO_EXT;
}
rtw_phl_cmd_change_stainfo(adapter_to_dvobj(padapter)->phl,
psta->phl_sta,
STA_CHG_RAMASK,
NULL,
0,
PHL_CMD_NO_WAIT,
0);
}
/* pmlmeinfo->bwmode_updated = _FALSE; */ /* bwmode_updated done, reset it! */
}
#endif /* CONFIG_80211N_HT */
}
#ifdef ROKU_PRIVATE
void Supported_rate_infra_ap(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
{
unsigned int i;
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
if (pIE == NULL)
return;
for (i = 0 ; i < pIE->Length; i++)
pmlmeinfo->SupportedRates_infra_ap[i] = (pIE->data[i]);
}
void Extended_Supported_rate_infra_ap(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
{
unsigned int i, j;
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
if (pIE == NULL)
return;
if (pIE->Length > 0) {
for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
if (pmlmeinfo->SupportedRates_infra_ap[i] == 0)
break;
}
for (j = 0; j < pIE->Length; j++)
pmlmeinfo->SupportedRates_infra_ap[i+j] = (pIE->data[j]);
}
}
void HT_get_ss_from_mcs_set(u8 *mcs_set, u8 *Rx_ss)
{
u8 i, j;
u8 r_ss = 0, t_ss = 0;
for (i = 0; i < 4; i++) {
if ((mcs_set[3-i] & 0xff) != 0x00) {
r_ss = 4-i;
break;
}
}
*Rx_ss = r_ss;
}
void HT_caps_handler_infra_ap(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
{
unsigned int i;
u8 cur_stbc_cap_infra_ap = 0;
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
struct ht_priv_infra_ap *phtpriv = &pmlmepriv->htpriv_infra_ap;
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
if (pIE == NULL)
return;
pmlmeinfo->ht_vht_received |= BIT(0);
/*copy MCS_SET*/
for (i = 3; i < 19; i++)
phtpriv->MCS_set_infra_ap[i-3] = (pIE->data[i]);
/*get number of stream from mcs set*/
HT_get_ss_from_mcs_set(phtpriv->MCS_set_infra_ap, &phtpriv->Rx_ss_infra_ap);
phtpriv->rx_highest_data_rate_infra_ap = le16_to_cpu(GET_HT_CAP_ELE_RX_HIGHEST_DATA_RATE(pIE->data));
phtpriv->ldpc_cap_infra_ap = GET_HT_CAP_ELE_LDPC_CAP(pIE->data);
if (GET_HT_CAP_ELE_RX_STBC(pIE->data))
SET_FLAG(cur_stbc_cap_infra_ap, STBC_HT_ENABLE_RX);
if (GET_HT_CAP_ELE_TX_STBC(pIE->data))
SET_FLAG(cur_stbc_cap_infra_ap, STBC_HT_ENABLE_TX);
phtpriv->stbc_cap_infra_ap = cur_stbc_cap_infra_ap;
/*store ap info SGI 20m 40m*/
phtpriv->sgi_20m_infra_ap = GET_HT_CAP_ELE_SHORT_GI20M(pIE->data);
phtpriv->sgi_40m_infra_ap = GET_HT_CAP_ELE_SHORT_GI40M(pIE->data);
/*store ap info for supported channel bandwidth*/
phtpriv->channel_width_infra_ap = GET_HT_CAP_ELE_CHL_WIDTH(pIE->data);
}
#endif /* ROKU_PRIVATE */
void HT_caps_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
{
#ifdef CONFIG_80211N_HT
unsigned int i;
u8 max_AMPDU_len, min_MPDU_spacing;
u8 cur_ldpc_cap = 0, cur_stbc_cap = 0, cur_beamform_cap = 0, rx_nss = 0;
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
struct ht_priv *phtpriv = &pmlmepriv->htpriv;
struct sta_info *sta = NULL;
struct rtw_phl_stainfo_t *phl_sta = NULL;
struct rtw_wifi_role_t *wrole = padapter->phl_role;
struct protocol_cap_t *proto_role_cap = &(wrole->proto_role_cap);
#ifdef CONFIG_DISABLE_MCS13TO15
struct registry_priv *pregistrypriv = &padapter->registrypriv;
#endif
if (pIE == NULL)
return;
if (phtpriv->ht_option == _FALSE)
return;
pmlmeinfo->HT_caps_enable = 1;
for (i = 0; i < (pIE->Length); i++) {
if (i != 2) {
/* Commented by Albert 2010/07/12 */
/* Got the endian issue here. */
pmlmeinfo->HT_caps.u.HT_cap[i] &= (pIE->data[i]);
} else {
/* AMPDU Parameters field */
/* Get MIN of MAX AMPDU Length Exp */