forked from morrownr/88x2bu-20210702
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtw_wlan_util.c
5664 lines (4680 loc) · 149 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 - 2017 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>
#include <hal_data.h>
#if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN)
#include <linux/inetdevice.h>
#define ETH_TYPE_OFFSET 12
#define PROTOCOL_OFFSET 23
#define IP_OFFSET 30
#define IPv6_OFFSET 38
#define IPv6_PROTOCOL_OFFSET 20
#endif
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;
}
#ifdef CONFIG_BCN_CNT_CONFIRM_HDL
int new_bcn_max = 3;
#endif
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;
if (!psta)
return nss;
nss = GET_HAL_RX_NSS(adapter);
#ifdef CONFIG_80211N_HT
#ifdef CONFIG_80211AC_VHT
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);
#ifdef CONFIG_80211N_HT
#ifdef CONFIG_80211AC_VHT
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;
}
u8 judge_network_type(_adapter *padapter, unsigned char *rate, int ratelen)
{
u8 network_type = 0;
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
if (pmlmeext->cur_channel > 14) {
if (pmlmeinfo->VHT_enable)
network_type = WIRELESS_11AC;
else if (pmlmeinfo->HT_enable)
network_type = WIRELESS_11_5N;
network_type |= WIRELESS_11A;
} else {
if (pmlmeinfo->HT_enable)
network_type = WIRELESS_11_24N;
if ((cckratesonly_included(rate, ratelen)) == _TRUE)
network_type |= WIRELESS_11B;
else if ((cckrates_included(rate, ratelen)) == _TRUE)
network_type |= WIRELESS_11BG;
else
network_type |= WIRELESS_11G;
}
return network_type;
}
unsigned char ratetbl_val_2wifirate(unsigned char rate);
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 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);
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(
PADAPTER 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;
}
}
}
void Set_MSR(_adapter *padapter, u8 type)
{
rtw_hal_set_hwreg(padapter, HW_VAR_MEDIA_STATUS, (u8 *)(&type));
}
inline u8 rtw_get_oper_ch(_adapter *adapter)
{
return adapter_to_dvobj(adapter)->oper_channel;
}
inline void rtw_set_oper_ch(_adapter *adapter, u8 ch)
{
#ifdef DBG_CH_SWITCH
const int len = 128;
char msg[128] = {0};
int cnt = 0;
int i = 0;
#endif /* DBG_CH_SWITCH */
struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
if (dvobj->oper_channel != ch) {
dvobj->on_oper_ch_time = rtw_get_current_time();
#ifdef DBG_CH_SWITCH
cnt += snprintf(msg + cnt, len - cnt, "switch to ch %3u", ch);
for (i = 0; i < dvobj->iface_nums; i++) {
_adapter *iface = dvobj->padapters[i];
cnt += snprintf(msg + cnt, len - cnt, " ["ADPT_FMT":", ADPT_ARG(iface));
if (iface->mlmeextpriv.cur_channel == ch)
cnt += snprintf(msg + cnt, len - cnt, "C");
else
cnt += snprintf(msg + cnt, len - cnt, "_");
if (iface->wdinfo.listen_channel == ch && !rtw_p2p_chk_state(&iface->wdinfo, P2P_STATE_NONE))
cnt += snprintf(msg + cnt, len - cnt, "L");
else
cnt += snprintf(msg + cnt, len - cnt, "_");
cnt += snprintf(msg + cnt, len - cnt, "]");
}
RTW_INFO(FUNC_ADPT_FMT" %s\n", FUNC_ADPT_ARG(adapter), msg);
#endif /* DBG_CH_SWITCH */
}
dvobj->oper_channel = ch;
}
inline u8 rtw_get_oper_bw(_adapter *adapter)
{
return adapter_to_dvobj(adapter)->oper_bwmode;
}
inline void rtw_set_oper_bw(_adapter *adapter, u8 bw)
{
adapter_to_dvobj(adapter)->oper_bwmode = bw;
}
inline u8 rtw_get_oper_choffset(_adapter *adapter)
{
return adapter_to_dvobj(adapter)->oper_ch_offset;
}
inline void rtw_set_oper_choffset(_adapter *adapter, u8 offset)
{
adapter_to_dvobj(adapter)->oper_ch_offset = 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.cur_channel == adapter_to_dvobj(adapter)->oper_channel)
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 center_ch, chnl_offset80 = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
#if (defined(CONFIG_TDLS) && defined(CONFIG_TDLS_CH_SW)) || defined(CONFIG_MCC_MODE)
u8 iqk_info_backup = _FALSE;
#endif
if (padapter->bNotifyChannelChange)
RTW_INFO("[%s] ch = %d, offset = %d, bwmode = %d\n", __FUNCTION__, channel, channel_offset, bwmode);
center_ch = rtw_get_center_ch(channel, bwmode, channel_offset);
if (bwmode == CHANNEL_WIDTH_80) {
if (center_ch > channel)
chnl_offset80 = HAL_PRIME_CHNL_OFFSET_LOWER;
else if (center_ch < channel)
chnl_offset80 = HAL_PRIME_CHNL_OFFSET_UPPER;
else
chnl_offset80 = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
}
_enter_critical_mutex(&(adapter_to_dvobj(padapter)->setch_mutex), NULL);
#ifdef CONFIG_MCC_MODE
if (MCC_EN(padapter)) {
/* driver doesn't set channel setting reg under MCC */
if (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC))
RTW_INFO("Warning: Do not set channel setting reg MCC mode\n");
}
#endif
#ifdef CONFIG_DFS_MASTER
{
struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
bool ori_overlap_radar_detect_ch = rtw_rfctl_overlap_radar_detect_ch(rfctl);
bool new_overlap_radar_detect_ch = _rtw_rfctl_overlap_radar_detect_ch(rfctl, channel, bwmode, channel_offset);
if (new_overlap_radar_detect_ch && IS_CH_WAITING(rfctl)) {
u8 pause = 0xFF;
rtw_hal_set_hwreg(padapter, HW_VAR_TXPAUSE, &pause);
}
#endif /* CONFIG_DFS_MASTER */
/* set Channel */
/* saved channel/bw info */
rtw_set_oper_ch(padapter, channel);
rtw_set_oper_bw(padapter, bwmode);
rtw_set_oper_choffset(padapter, channel_offset);
#if (defined(CONFIG_TDLS) && defined(CONFIG_TDLS_CH_SW)) || defined(CONFIG_MCC_MODE)
/* To check if we need to backup iqk info after switch chnl & bw */
{
u8 take_care_iqk, do_iqk;
rtw_hal_get_hwreg(padapter, HW_VAR_CH_SW_NEED_TO_TAKE_CARE_IQK_INFO, &take_care_iqk);
rtw_hal_get_hwreg(padapter, HW_VAR_DO_IQK, &do_iqk);
if ((take_care_iqk == _TRUE) && (do_iqk == _TRUE))
iqk_info_backup = _TRUE;
}
#endif
rtw_hal_set_chnl_bw(padapter, center_ch, bwmode, channel_offset, chnl_offset80); /* set center channel */
#if (defined(CONFIG_TDLS) && defined(CONFIG_TDLS_CH_SW)) || defined(CONFIG_MCC_MODE)
if (iqk_info_backup == _TRUE)
rtw_hal_ch_sw_iqk_info_backup(padapter);
#endif
#ifdef CONFIG_DFS_MASTER
if (new_overlap_radar_detect_ch)
rtw_odm_radar_detect_enable(padapter);
else if (ori_overlap_radar_detect_ch) {
u8 pause = 0x00;
rtw_odm_radar_detect_disable(padapter);
rtw_hal_set_hwreg(padapter, HW_VAR_TXPAUSE, &pause);
}
}
#endif /* CONFIG_DFS_MASTER */
_exit_critical_mutex(&(adapter_to_dvobj(padapter)->setch_mutex), NULL);
}
__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;
}
int is_IBSS_empty(_adapter *padapter)
{
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;
}
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;
}
void invalidate_cam_all(_adapter *padapter)
{
struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
u8 bmc_id = rtw_iface_bcmc_id_get(padapter);
_irqL irqL;
u8 val8 = 0;
rtw_hal_set_hwreg(padapter, HW_VAR_CAM_INVALID_ALL, &val8);
_enter_critical_bh(&cam_ctl->lock, &irqL);
rtw_sec_cam_map_clr_all(&cam_ctl->used);
#ifndef SEC_DEFAULT_KEY_SEARCH
/* for BMC data TX with force camid */
if (bmc_id != INVALID_SEC_MAC_CAM_ID) {
rtw_sec_cam_map_set(&cam_ctl->used, bmc_id);
if (_rtw_camctl_chk_cap(padapter, SEC_CAP_CHK_EXTRA_SEC))
rtw_sec_cam_map_set(&cam_ctl->used, bmc_id + 1);
}
#endif
_rtw_memset(dvobj->cam_cache, 0, sizeof(struct sec_cam_ent) * SEC_CAM_ENT_NUM_SW_LIMIT);
_exit_critical_bh(&cam_ctl->lock, &irqL);
#ifdef SEC_DEFAULT_KEY_SEARCH//!BMC TX force camid
/* clear default key related key search setting */
rtw_hal_set_hwreg(padapter, HW_VAR_SEC_DK_CFG, (u8 *)_FALSE);
#endif
}
void _clear_cam_entry(_adapter *padapter, u8 entry)
{
unsigned char null_sta[6] = {0};
unsigned char null_key[32] = {0};
rtw_sec_write_cam_ent(padapter, entry, 0, null_sta, null_key);
}
inline void _write_cam(_adapter *adapter, u8 id, u16 ctrl, u8 *mac, u8 *key)
{
#ifdef CONFIG_WRITE_CACHE_ONLY
write_cam_cache(adapter, id , ctrl, mac, key);
#else
rtw_sec_write_cam_ent(adapter, id, ctrl, mac, key);
write_cam_cache(adapter, id , ctrl, mac, key);
#endif
}
inline void write_cam(_adapter *adapter, u8 id, u16 ctrl, u8 *mac, u8 *key)
{
if (ctrl & BIT(9)) {
_write_cam(adapter, id, ctrl, mac, key);
_write_cam(adapter, (id + 1), ctrl | BIT(5), mac, (key + 16));
RTW_INFO_DUMP("key-0: ", key, 16);
RTW_INFO_DUMP("key-1: ", (key + 16), 16);
} else
_write_cam(adapter, id, ctrl, mac, key);
}
inline void clear_cam_entry(_adapter *adapter, u8 id)
{
_clear_cam_entry(adapter, id);
clear_cam_cache(adapter, id);
}
inline void write_cam_from_cache(_adapter *adapter, u8 id)
{
struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
_irqL irqL;
struct sec_cam_ent cache;
_enter_critical_bh(&cam_ctl->lock, &irqL);
_rtw_memcpy(&cache, &dvobj->cam_cache[id], sizeof(struct sec_cam_ent));
_exit_critical_bh(&cam_ctl->lock, &irqL);
rtw_sec_write_cam_ent(adapter, id, cache.ctrl, cache.mac, cache.key);
}
void write_cam_cache(_adapter *adapter, u8 id, u16 ctrl, u8 *mac, u8 *key)
{
struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
_irqL irqL;
_enter_critical_bh(&cam_ctl->lock, &irqL);
dvobj->cam_cache[id].ctrl = ctrl;
_rtw_memcpy(dvobj->cam_cache[id].mac, mac, ETH_ALEN);
_rtw_memcpy(dvobj->cam_cache[id].key, key, 16);
_exit_critical_bh(&cam_ctl->lock, &irqL);
}
void clear_cam_cache(_adapter *adapter, u8 id)
{
struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
_irqL irqL;
_enter_critical_bh(&cam_ctl->lock, &irqL);
_rtw_memset(&(dvobj->cam_cache[id]), 0, sizeof(struct sec_cam_ent));
_exit_critical_bh(&cam_ctl->lock, &irqL);
}
inline bool _rtw_camctl_chk_cap(_adapter *adapter, u8 cap)
{
struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
if (cam_ctl->sec_cap & cap)
return _TRUE;
return _FALSE;
}
inline void _rtw_camctl_set_flags(_adapter *adapter, u32 flags)
{
struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
cam_ctl->flags |= flags;
}
inline void rtw_camctl_set_flags(_adapter *adapter, u32 flags)
{
struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
_irqL irqL;
_enter_critical_bh(&cam_ctl->lock, &irqL);
_rtw_camctl_set_flags(adapter, flags);
_exit_critical_bh(&cam_ctl->lock, &irqL);
}
inline void _rtw_camctl_clr_flags(_adapter *adapter, u32 flags)
{
struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
cam_ctl->flags &= ~flags;
}
inline void rtw_camctl_clr_flags(_adapter *adapter, u32 flags)
{
struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
_irqL irqL;
_enter_critical_bh(&cam_ctl->lock, &irqL);
_rtw_camctl_clr_flags(adapter, flags);
_exit_critical_bh(&cam_ctl->lock, &irqL);
}
inline bool _rtw_camctl_chk_flags(_adapter *adapter, u32 flags)
{
struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
if (cam_ctl->flags & flags)
return _TRUE;
return _FALSE;
}
void dump_sec_cam_map(void *sel, struct sec_cam_bmp *map, u8 max_num)
{
RTW_PRINT_SEL(sel, "0x%08x\n", map->m0);
#if (SEC_CAM_ENT_NUM_SW_LIMIT > 32)
if (max_num && max_num > 32)
RTW_PRINT_SEL(sel, "0x%08x\n", map->m1);
#endif
#if (SEC_CAM_ENT_NUM_SW_LIMIT > 64)
if (max_num && max_num > 64)
RTW_PRINT_SEL(sel, "0x%08x\n", map->m2);
#endif
#if (SEC_CAM_ENT_NUM_SW_LIMIT > 96)
if (max_num && max_num > 96)
RTW_PRINT_SEL(sel, "0x%08x\n", map->m3);
#endif
}
inline bool rtw_sec_camid_is_set(struct sec_cam_bmp *map, u8 id)
{
if (id < 32)
return map->m0 & BIT(id);
#if (SEC_CAM_ENT_NUM_SW_LIMIT > 32)
else if (id < 64)
return map->m1 & BIT(id - 32);
#endif
#if (SEC_CAM_ENT_NUM_SW_LIMIT > 64)
else if (id < 96)
return map->m2 & BIT(id - 64);
#endif
#if (SEC_CAM_ENT_NUM_SW_LIMIT > 96)
else if (id < 128)
return map->m3 & BIT(id - 96);
#endif
else
rtw_warn_on(1);
return 0;
}
inline void rtw_sec_cam_map_set(struct sec_cam_bmp *map, u8 id)
{
if (id < 32)
map->m0 |= BIT(id);
#if (SEC_CAM_ENT_NUM_SW_LIMIT > 32)
else if (id < 64)
map->m1 |= BIT(id - 32);
#endif
#if (SEC_CAM_ENT_NUM_SW_LIMIT > 64)
else if (id < 96)
map->m2 |= BIT(id - 64);
#endif
#if (SEC_CAM_ENT_NUM_SW_LIMIT > 96)
else if (id < 128)
map->m3 |= BIT(id - 96);
#endif
else
rtw_warn_on(1);
}
inline void rtw_sec_cam_map_clr(struct sec_cam_bmp *map, u8 id)
{
if (id < 32)
map->m0 &= ~BIT(id);
#if (SEC_CAM_ENT_NUM_SW_LIMIT > 32)
else if (id < 64)
map->m1 &= ~BIT(id - 32);
#endif
#if (SEC_CAM_ENT_NUM_SW_LIMIT > 64)
else if (id < 96)
map->m2 &= ~BIT(id - 64);
#endif
#if (SEC_CAM_ENT_NUM_SW_LIMIT > 96)
else if (id < 128)
map->m3 &= ~BIT(id - 96);
#endif
else
rtw_warn_on(1);
}
inline void rtw_sec_cam_map_clr_all(struct sec_cam_bmp *map)
{
map->m0 = 0;
#if (SEC_CAM_ENT_NUM_SW_LIMIT > 32)
map->m1 = 0;
#endif
#if (SEC_CAM_ENT_NUM_SW_LIMIT > 64)
map->m2 = 0;
#endif
#if (SEC_CAM_ENT_NUM_SW_LIMIT > 96)
map->m3 = 0;
#endif
}
inline bool rtw_sec_camid_is_drv_forbid(struct cam_ctl_t *cam_ctl, u8 id)
{
struct sec_cam_bmp forbid_map;
forbid_map.m0 = 0x00000ff0;
#if (SEC_CAM_ENT_NUM_SW_LIMIT > 32)
forbid_map.m1 = 0x00000000;
#endif
#if (SEC_CAM_ENT_NUM_SW_LIMIT > 64)
forbid_map.m2 = 0x00000000;
#endif
#if (SEC_CAM_ENT_NUM_SW_LIMIT > 96)
forbid_map.m3 = 0x00000000;
#endif
if (id < 32)
return forbid_map.m0 & BIT(id);
#if (SEC_CAM_ENT_NUM_SW_LIMIT > 32)
else if (id < 64)
return forbid_map.m1 & BIT(id - 32);
#endif
#if (SEC_CAM_ENT_NUM_SW_LIMIT > 64)
else if (id < 96)
return forbid_map.m2 & BIT(id - 64);
#endif
#if (SEC_CAM_ENT_NUM_SW_LIMIT > 96)
else if (id < 128)
return forbid_map.m3 & BIT(id - 96);
#endif
else
rtw_warn_on(1);
return 1;
}
bool _rtw_sec_camid_is_used(struct cam_ctl_t *cam_ctl, u8 id)
{
bool ret = _FALSE;
if (id >= cam_ctl->num) {
rtw_warn_on(1);
goto exit;
}
#if 0 /* for testing */
if (rtw_sec_camid_is_drv_forbid(cam_ctl, id)) {
ret = _TRUE;
goto exit;
}
#endif
ret = rtw_sec_camid_is_set(&cam_ctl->used, id);
exit:
return ret;
}
inline bool rtw_sec_camid_is_used(struct cam_ctl_t *cam_ctl, u8 id)
{
_irqL irqL;
bool ret;
_enter_critical_bh(&cam_ctl->lock, &irqL);
ret = _rtw_sec_camid_is_used(cam_ctl, id);
_exit_critical_bh(&cam_ctl->lock, &irqL);
return ret;
}
u8 rtw_get_sec_camid(_adapter *adapter, u8 max_bk_key_num, u8 *sec_key_id)
{
struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
int i;
_irqL irqL;
u8 sec_cam_num = 0;
_enter_critical_bh(&cam_ctl->lock, &irqL);
for (i = 0; i < cam_ctl->num; i++) {
if (_rtw_sec_camid_is_used(cam_ctl, i)) {
sec_key_id[sec_cam_num++] = i;
if (sec_cam_num == max_bk_key_num)
break;
}
}
_exit_critical_bh(&cam_ctl->lock, &irqL);
return sec_cam_num;
}
inline bool _rtw_camid_is_gk(_adapter *adapter, u8 cam_id)
{
struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
bool ret = _FALSE;
if (cam_id >= cam_ctl->num) {
rtw_warn_on(1);
goto exit;
}