forked from RinCat/RTL88x2BU-Linux-Driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtw_mlme_ext.c
16827 lines (13706 loc) · 491 KB
/
rtw_mlme_ext.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 - 2019 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_MLME_EXT_C_
#include <drv_types.h>
#include <hal_data.h>
struct mlme_handler mlme_sta_tbl[] = {
{WIFI_ASSOCREQ, "OnAssocReq", &OnAssocReq},
{WIFI_ASSOCRSP, "OnAssocRsp", &OnAssocRsp},
{WIFI_REASSOCREQ, "OnReAssocReq", &OnAssocReq},
{WIFI_REASSOCRSP, "OnReAssocRsp", &OnAssocRsp},
{WIFI_PROBEREQ, "OnProbeReq", &OnProbeReq},
{WIFI_PROBERSP, "OnProbeRsp", &OnProbeRsp},
/*----------------------------------------------------------
below 2 are reserved
-----------------------------------------------------------*/
{0, "DoReserved", &DoReserved},
{0, "DoReserved", &DoReserved},
{WIFI_BEACON, "OnBeacon", &OnBeacon},
{WIFI_ATIM, "OnATIM", &OnAtim},
{WIFI_DISASSOC, "OnDisassoc", &OnDisassoc},
{WIFI_AUTH, "OnAuth", &OnAuthClient},
{WIFI_DEAUTH, "OnDeAuth", &OnDeAuth},
{WIFI_ACTION, "OnAction", &OnAction},
{WIFI_ACTION_NOACK, "OnActionNoAck", &OnAction},
};
#ifdef _CONFIG_NATIVEAP_MLME_
struct mlme_handler mlme_ap_tbl[] = {
{WIFI_ASSOCREQ, "OnAssocReq", &OnAssocReq},
{WIFI_ASSOCRSP, "OnAssocRsp", &OnAssocRsp},
{WIFI_REASSOCREQ, "OnReAssocReq", &OnAssocReq},
{WIFI_REASSOCRSP, "OnReAssocRsp", &OnAssocRsp},
{WIFI_PROBEREQ, "OnProbeReq", &OnProbeReq},
{WIFI_PROBERSP, "OnProbeRsp", &OnProbeRsp},
/*----------------------------------------------------------
below 2 are reserved
-----------------------------------------------------------*/
{0, "DoReserved", &DoReserved},
{0, "DoReserved", &DoReserved},
{WIFI_BEACON, "OnBeacon", &OnBeacon},
{WIFI_ATIM, "OnATIM", &OnAtim},
{WIFI_DISASSOC, "OnDisassoc", &OnDisassoc},
{WIFI_AUTH, "OnAuth", &OnAuth},
{WIFI_DEAUTH, "OnDeAuth", &OnDeAuth},
{WIFI_ACTION, "OnAction", &OnAction},
{WIFI_ACTION_NOACK, "OnActionNoAck", &OnAction},
};
#endif
struct action_handler OnAction_tbl[] = {
{RTW_WLAN_CATEGORY_SPECTRUM_MGMT, "ACTION_SPECTRUM_MGMT", on_action_spct},
{RTW_WLAN_CATEGORY_QOS, "ACTION_QOS", &OnAction_qos},
{RTW_WLAN_CATEGORY_DLS, "ACTION_DLS", &OnAction_dls},
{RTW_WLAN_CATEGORY_BACK, "ACTION_BACK", &OnAction_back},
{RTW_WLAN_CATEGORY_PUBLIC, "ACTION_PUBLIC", on_action_public},
{RTW_WLAN_CATEGORY_RADIO_MEAS, "ACTION_RADIO_MEAS", &on_action_rm},
{RTW_WLAN_CATEGORY_FT, "ACTION_FT", &OnAction_ft},
{RTW_WLAN_CATEGORY_HT, "ACTION_HT", &OnAction_ht},
#ifdef CONFIG_IEEE80211W
{RTW_WLAN_CATEGORY_SA_QUERY, "ACTION_SA_QUERY", &OnAction_sa_query},
#else
{RTW_WLAN_CATEGORY_SA_QUERY, "ACTION_SA_QUERY", &DoReserved},
#endif /* CONFIG_IEEE80211W */
#ifdef CONFIG_RTW_WNM
{RTW_WLAN_CATEGORY_WNM, "ACTION_WNM", &on_action_wnm},
#endif
{RTW_WLAN_CATEGORY_UNPROTECTED_WNM, "ACTION_UNPROTECTED_WNM", &DoReserved},
#ifdef CONFIG_RTW_MESH
{RTW_WLAN_CATEGORY_MESH, "ACTION_MESH", &on_action_mesh},
{RTW_WLAN_CATEGORY_SELF_PROTECTED, "ACTION_SELF_PROTECTED", &on_action_self_protected},
#endif
{RTW_WLAN_CATEGORY_WMM, "ACTION_WMM", &OnAction_wmm},
{RTW_WLAN_CATEGORY_VHT, "ACTION_VHT", &OnAction_vht},
{RTW_WLAN_CATEGORY_P2P, "ACTION_P2P", &OnAction_p2p},
#ifdef CONFIG_RTW_TOKEN_BASED_XMIT
{RTW_WLAN_CATEGORY_TBTX, "ACTION_TBTX_TOKEN", &OnAction_tbtx_token}
#endif
};
u8 null_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
/**************************************************
OUI definitions for the vendor specific IE
***************************************************/
unsigned char RTW_WPA_OUI[] = {0x00, 0x50, 0xf2, 0x01};
unsigned char WMM_OUI[] = {0x00, 0x50, 0xf2, 0x02};
unsigned char WPS_OUI[] = {0x00, 0x50, 0xf2, 0x04};
unsigned char P2P_OUI[] = {0x50, 0x6F, 0x9A, 0x09};
unsigned char WFD_OUI[] = {0x50, 0x6F, 0x9A, 0x0A};
unsigned char DPP_OUI[] = {0x50, 0x6F, 0x9A, 0x1A};
unsigned char MULTI_AP_OUI[] = {0x50, 0x6F, 0x9A, 0x1B};
unsigned char WMM_INFO_OUI[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};
unsigned char WMM_PARA_OUI[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
unsigned char WPA_TKIP_CIPHER[4] = {0x00, 0x50, 0xf2, 0x02};
unsigned char RSN_TKIP_CIPHER[4] = {0x00, 0x0f, 0xac, 0x02};
#ifdef CONFIG_RTW_TOKEN_BASED_XMIT
unsigned char REALTEK_TBTX_IE[] = {0x00, 0xe0, 0x4c, 0x01, 0x00, 0x00, 0x00, 0x00};
#endif
extern unsigned char REALTEK_96B_IE[];
static void init_channel_list(_adapter *padapter, RT_CHANNEL_INFO *channel_set
, struct p2p_channels *channel_list)
{
struct registry_priv *regsty = adapter_to_regsty(padapter);
struct p2p_oper_class_map op_class[] = {
{ IEEE80211G, 81, 1, 13, 1, BW20 },
{ IEEE80211G, 82, 14, 14, 1, BW20 },
#if 0 /* Do not enable HT40 on 2 GHz */
{ IEEE80211G, 83, 1, 9, 1, BW40PLUS },
{ IEEE80211G, 84, 5, 13, 1, BW40MINUS },
#endif
{ IEEE80211A, 115, 36, 48, 4, BW20 },
{ IEEE80211A, 116, 36, 44, 8, BW40PLUS },
{ IEEE80211A, 117, 40, 48, 8, BW40MINUS },
{ IEEE80211A, 124, 149, 161, 4, BW20 },
{ IEEE80211A, 125, 149, 169, 4, BW20 },
{ IEEE80211A, 126, 149, 157, 8, BW40PLUS },
{ IEEE80211A, 127, 153, 161, 8, BW40MINUS },
{ -1, 0, 0, 0, 0, BW20 }
};
int cla, op;
cla = 0;
for (op = 0; op_class[op].op_class; op++) {
u8 ch;
struct p2p_oper_class_map *o = &op_class[op];
struct p2p_reg_class *reg = NULL;
for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) {
if (rtw_chset_search_ch(channel_set, ch) == -1)
continue;
#if defined(CONFIG_80211N_HT) || defined(CONFIG_80211AC_VHT)
if ((padapter->registrypriv.ht_enable == 0) && (o->inc == 8))
continue;
if ((REGSTY_IS_BW_5G_SUPPORT(regsty, CHANNEL_WIDTH_40)) &&
((o->bw == BW40MINUS) || (o->bw == BW40PLUS)))
continue;
#endif
if (reg == NULL) {
reg = &channel_list->reg_class[cla];
cla++;
reg->reg_class = o->op_class;
reg->channels = 0;
}
reg->channel[reg->channels] = ch;
reg->channels++;
}
}
channel_list->reg_classes = cla;
}
#if CONFIG_TXPWR_LIMIT
void rtw_txpwr_init_regd(struct rf_ctl_t *rfctl)
{
u8 regd;
struct regd_exc_ent *exc;
struct txpwr_lmt_ent *ent;
_irqL irqL;
_enter_critical_mutex(&rfctl->txpwr_lmt_mutex, &irqL);
rfctl->regd_name = NULL;
if (rfctl->txpwr_regd_num == 0) {
RTW_PRINT("there is no any txpwr_regd\n");
goto release_lock;
}
/* search from exception mapping */
exc = _rtw_regd_exc_search(rfctl
, rfctl->country_ent ? rfctl->country_ent->alpha2 : NULL
, rfctl->ChannelPlan);
if (exc) {
u8 has_country = (exc->country[0] == '\0' && exc->country[1] == '\0') ? 0 : 1;
if (strcmp(exc->regd_name, regd_str(TXPWR_LMT_NONE)) == 0)
rfctl->regd_name = regd_str(TXPWR_LMT_NONE);
else if (strcmp(exc->regd_name, regd_str(TXPWR_LMT_WW)) == 0)
rfctl->regd_name = regd_str(TXPWR_LMT_WW);
else {
ent = _rtw_txpwr_lmt_get_by_name(rfctl, exc->regd_name);
if (ent)
rfctl->regd_name = ent->regd_name;
}
RTW_PRINT("exception mapping country:%c%c domain:0x%02x to%s regd_name:%s\n"
, has_country ? exc->country[0] : '0'
, has_country ? exc->country[1] : '0'
, exc->domain
, rfctl->regd_name ? "" : " unknown"
, exc->regd_name
);
if (rfctl->regd_name)
goto release_lock;
}
#ifdef CONFIG_REGD_SRC_FROM_OS
if (rfctl->regd_src == REGD_SRC_OS) {
if (IS_ALPHA2_WORLDWIDE(rfctl->country_ent->alpha2))
rfctl->regd_name = regd_str(TXPWR_LMT_WW);
else {
char alpha2[3] = {
rfctl->country_ent->alpha2[0], rfctl->country_ent->alpha2[1], 0};
ent = _rtw_txpwr_lmt_get_by_name(rfctl, alpha2);
if (ent)
rfctl->regd_name = ent->regd_name;
}
if (rfctl->regd_name) {
RTW_PRINT("mapping country:%c%c to regd_name:%s\n"
, rfctl->country_ent->alpha2[0]
, rfctl->country_ent->alpha2[1]
, rfctl->regd_name
);
goto release_lock;
}
if (rfctl->ChannelPlan == RTW_CHPLAN_UNSPECIFIED) {
rfctl->regd_name = regd_str(TXPWR_LMT_WW);
RTW_PRINT("mapping unsupported country:%c%c to regd_name:%s\n"
, rfctl->country_ent->alpha2[0]
, rfctl->country_ent->alpha2[1]
, rfctl->regd_name
);
goto release_lock;
}
}
#endif
/* follow default channel plan mapping */
regd = rtw_chplan_get_default_regd(rfctl->ChannelPlan);
if (regd == TXPWR_LMT_NONE)
rfctl->regd_name = regd_str(TXPWR_LMT_NONE);
else if (regd == TXPWR_LMT_WW)
rfctl->regd_name = regd_str(TXPWR_LMT_WW);
else {
ent = _rtw_txpwr_lmt_get_by_name(rfctl, regd_str(regd));
if (ent)
rfctl->regd_name = ent->regd_name;
}
RTW_PRINT("default mapping domain:0x%02x to%s regd_name:%s\n"
, rfctl->ChannelPlan
, rfctl->regd_name ? "" : " unknown"
, regd_str(regd)
);
if (rfctl->regd_name)
goto release_lock;
switch (regd) {
/*
* To support older chips without new predefined regd:
* - use FCC if IC or CHILE or MEXICO not found
* - use ETSI if KCC or ACMA not found
*/
case TXPWR_LMT_IC:
case TXPWR_LMT_KCC:
case TXPWR_LMT_NCC:
case TXPWR_LMT_ACMA:
case TXPWR_LMT_CHILE:
case TXPWR_LMT_MEXICO:
if (regd == TXPWR_LMT_IC || regd == TXPWR_LMT_NCC || regd == TXPWR_LMT_CHILE || regd == TXPWR_LMT_MEXICO)
regd = TXPWR_LMT_FCC;
else if (regd == TXPWR_LMT_KCC || regd == TXPWR_LMT_ACMA)
regd = TXPWR_LMT_ETSI;
ent = _rtw_txpwr_lmt_get_by_name(rfctl, regd_str(regd));
if (ent)
rfctl->regd_name = ent->regd_name;
RTW_PRINT("alternate regd_name:%s %s\n"
, regd_str(regd)
, rfctl->regd_name ? "is used" : "not found"
);
if (rfctl->regd_name)
break;
/* fall through */
default:
rfctl->regd_name = regd_str(TXPWR_LMT_WW);
RTW_PRINT("assign %s for default case\n", regd_str(TXPWR_LMT_WW));
break;
};
release_lock:
_exit_critical_mutex(&rfctl->txpwr_lmt_mutex, &irqL);
}
#endif /* CONFIG_TXPWR_LIMIT */
int rtw_rfctl_init(_adapter *adapter)
{
struct registry_priv *regsty = adapter_to_regsty(adapter);
struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
int ret;
_rtw_mutex_init(&rfctl->offch_mutex);
#if CONFIG_TXPWR_LIMIT
_rtw_mutex_init(&rfctl->txpwr_lmt_mutex);
_rtw_init_listhead(&rfctl->reg_exc_list);
_rtw_init_listhead(&rfctl->txpwr_lmt_list);
#endif
rfctl->ch_sel_within_same_band = 1;
#ifdef CONFIG_DFS_MASTER
rfctl->dfs_region_domain = regsty->dfs_region_domain;
rfctl->cac_start_time = rfctl->cac_end_time = RTW_CAC_STOPPED;
rtw_init_timer(&(rfctl->radar_detect_timer), adapter, rtw_dfs_rd_timer_hdl, rfctl);
#endif
#if CONFIG_DFS_SLAVE_WITH_RADAR_DETECT
rfctl->dfs_slave_with_rd = 1;
#endif
if (regsty->antenna_gain != UNSPECIFIED_MBM)
rfctl->antenna_gain = regsty->antenna_gain;
ret = op_class_pref_init(adapter);
if (ret != _SUCCESS)
op_class_pref_deinit(adapter);
return ret;
}
void rtw_rfctl_deinit(_adapter *adapter)
{
struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
_rtw_mutex_free(&rfctl->offch_mutex);
#if CONFIG_TXPWR_LIMIT
rtw_regd_exc_list_free(rfctl);
rtw_txpwr_lmt_list_free(rfctl);
_rtw_mutex_free(&rfctl->txpwr_lmt_mutex);
#endif
#ifdef CONFIG_REGD_SRC_FROM_OS
if (rfctl->regd_src == REGD_SRC_OS)
rtw_mfree((void *)rfctl->country_ent, sizeof(struct country_chplan));
#endif
op_class_pref_deinit(adapter);
}
void rtw_rfctl_chplan_init(_adapter *adapter)
{
struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
rfctl->max_chan_nums = init_channel_set(adapter);
op_class_pref_apply_regulatory(adapter, REG_CHANGE);
init_channel_list(adapter, rfctl->channel_set, &rfctl->channel_list);
}
void rtw_rfctl_update_op_mode(struct rf_ctl_t *rfctl, u8 ifbmp_mod, u8 if_op)
{
struct dvobj_priv *dvobj = rfctl_to_dvobj(rfctl);
_adapter *iface;
struct mlme_ext_priv *mlmeext;
u8 op_class = 0;
u8 op_ch = 0;
s16 op_txpwr_max;
u8 if_op_class[CONFIG_IFACE_NUMBER] = {0};
u8 if_op_ch[CONFIG_IFACE_NUMBER] = {0};
u8 ch, bw, offset;
u8 u_ch = 0, u_bw, u_offset;
bool notify = 0;
int i;
for (i = 0; i < dvobj->iface_nums; i++) {
iface = dvobj->padapters[i];
if (!iface)
continue;
mlmeext = &iface->mlmeextpriv;
if (ifbmp_mod & BIT(i)) {
if (!if_op)
continue;
} else if (!MLME_IS_ASOC(iface) || MLME_IS_OPCH_SW(iface))
continue;
ch = mlmeext->cur_channel;
bw = mlmeext->cur_bwmode;
offset = mlmeext->cur_ch_offset;
if_op_class[i] = rtw_get_op_class_by_chbw(ch, bw, offset);
if_op_ch[i] = if_op_class[i] ? ch : 0;
if (!u_ch) {
u_ch = ch;
u_bw = bw;
u_offset = offset;
} else {
rtw_warn_on(!rtw_is_chbw_grouped(u_ch, u_bw, u_offset, ch, bw, offset));
rtw_sync_chbw(&ch, &bw, &offset, &u_ch, &u_bw, &u_offset);
}
}
op_class = rtw_get_op_class_by_chbw(u_ch, u_bw, u_offset);
op_ch = op_class ? u_ch : 0;
op_txpwr_max = rtw_rfctl_get_oper_txpwr_max_mbm(rfctl, u_ch, u_bw, u_offset, ifbmp_mod, if_op, 1);
if (op_class != rfctl->op_class
|| op_ch != rfctl->op_ch
|| op_txpwr_max != rfctl->op_txpwr_max
|| _rtw_memcmp(if_op_class, rfctl->if_op_class, sizeof(u8) * CONFIG_IFACE_NUMBER) == _FALSE
|| _rtw_memcmp(if_op_ch, rfctl->if_op_ch, sizeof(u8) * CONFIG_IFACE_NUMBER) == _FALSE)
notify = 1;
rfctl->op_class = op_class;
rfctl->op_ch = op_ch;
rfctl->op_txpwr_max = op_txpwr_max;
_rtw_memcpy(rfctl->if_op_class, if_op_class, sizeof(u8) * CONFIG_IFACE_NUMBER);
_rtw_memcpy(rfctl->if_op_ch, if_op_ch, sizeof(u8) * CONFIG_IFACE_NUMBER);
if (0)
RTW_INFO("radio: %u,%u,%u %d notify:%d\n", u_ch, u_bw, u_offset, op_txpwr_max, notify);
for (i = 0; i < dvobj->iface_nums; i++) {
iface = dvobj->padapters[i];
if (!iface)
continue;
mlmeext = &iface->mlmeextpriv;
if (ifbmp_mod & BIT(i)) {
if (!if_op)
continue;
} else if (!MLME_IS_ASOC(iface))
continue;
if (0)
RTW_INFO(ADPT_FMT": %u,%u,%u\n", ADPT_ARG(iface)
, mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
}
if (notify)
rtw_nlrtw_radio_opmode_notify(rfctl);
#ifdef CONFIG_PLATFORM_CMAP_INTFS
for (i = 0; i < dvobj->iface_nums; i++) {
iface = dvobj->padapters[i];
if (!iface)
continue;
cmap_intfs_nl_bss_status_event(iface, 0);
}
#endif
}
inline u8 rtw_rfctl_get_dfs_domain(struct rf_ctl_t *rfctl)
{
#ifdef CONFIG_DFS_MASTER
return rfctl->dfs_region_domain;
#else
return RTW_DFS_REGD_NONE;
#endif
}
inline u8 rtw_rfctl_dfs_domain_unknown(struct rf_ctl_t *rfctl)
{
#ifdef CONFIG_DFS_MASTER
return rtw_rfctl_get_dfs_domain(rfctl) == RTW_DFS_REGD_NONE;
#else
return 1;
#endif
}
#ifdef CONFIG_DFS_MASTER
/*
* called in rtw_dfs_rd_enable()
* assume the request channel coverage is DFS range
* base on the current status and the request channel coverage to check if need to reset complete CAC time
*/
bool rtw_is_cac_reset_needed(struct rf_ctl_t *rfctl, u8 ch, u8 bw, u8 offset)
{
bool needed = _FALSE;
u32 cur_hi, cur_lo, hi, lo;
if (rfctl->radar_detected == 1) {
needed = _TRUE;
goto exit;
}
if (rfctl->radar_detect_ch == 0) {
needed = _TRUE;
goto exit;
}
if (rtw_chbw_to_freq_range(ch, bw, offset, &hi, &lo) == _FALSE) {
RTW_ERR("request detection range ch:%u, bw:%u, offset:%u\n", ch, bw, offset);
rtw_warn_on(1);
}
if (rtw_chbw_to_freq_range(rfctl->radar_detect_ch, rfctl->radar_detect_bw, rfctl->radar_detect_offset, &cur_hi, &cur_lo) == _FALSE) {
RTW_ERR("cur detection range ch:%u, bw:%u, offset:%u\n", rfctl->radar_detect_ch, rfctl->radar_detect_bw, rfctl->radar_detect_offset);
rtw_warn_on(1);
}
if (hi <= lo || cur_hi <= cur_lo) {
RTW_ERR("hi:%u, lo:%u, cur_hi:%u, cur_lo:%u\n", hi, lo, cur_hi, cur_lo);
rtw_warn_on(1);
}
if (rtw_is_range_a_in_b(hi, lo, cur_hi, cur_lo)) {
/* request is in current detect range */
goto exit;
}
/* check if request channel coverage has new range and the new range is in DFS range */
if (!rtw_is_range_overlap(hi, lo, cur_hi, cur_lo)) {
/* request has no overlap with current */
needed = _TRUE;
} else if (rtw_is_range_a_in_b(cur_hi, cur_lo, hi, lo)) {
/* request is supper set of current */
if ((hi != cur_hi && rtw_chset_is_dfs_range(rfctl->channel_set, hi, cur_hi))
|| (lo != cur_lo && rtw_chset_is_dfs_range(rfctl->channel_set, cur_lo, lo)))
needed = _TRUE;
} else {
/* request is not supper set of current, but has overlap */
if ((lo < cur_lo && rtw_chset_is_dfs_range(rfctl->channel_set, cur_lo, lo))
|| (hi > cur_hi && rtw_chset_is_dfs_range(rfctl->channel_set, hi, cur_hi)))
needed = _TRUE;
}
exit:
return needed;
}
bool _rtw_rfctl_overlap_radar_detect_ch(struct rf_ctl_t *rfctl, u8 ch, u8 bw, u8 offset)
{
bool ret = _FALSE;
u32 hi = 0, lo = 0;
u32 r_hi = 0, r_lo = 0;
int i;
if (rfctl->radar_detect_by_others)
goto exit;
if (rfctl->radar_detect_ch == 0)
goto exit;
if (rtw_chbw_to_freq_range(ch, bw, offset, &hi, &lo) == _FALSE) {
rtw_warn_on(1);
goto exit;
}
if (rtw_chbw_to_freq_range(rfctl->radar_detect_ch
, rfctl->radar_detect_bw, rfctl->radar_detect_offset
, &r_hi, &r_lo) == _FALSE) {
rtw_warn_on(1);
goto exit;
}
if (rtw_is_range_overlap(hi, lo, r_hi, r_lo))
ret = _TRUE;
exit:
return ret;
}
bool rtw_rfctl_overlap_radar_detect_ch(struct rf_ctl_t *rfctl)
{
return _rtw_rfctl_overlap_radar_detect_ch(rfctl
, rfctl_to_dvobj(rfctl)->oper_channel
, rfctl_to_dvobj(rfctl)->oper_bwmode
, rfctl_to_dvobj(rfctl)->oper_ch_offset);
}
bool rtw_rfctl_is_tx_blocked_by_ch_waiting(struct rf_ctl_t *rfctl)
{
return rtw_rfctl_overlap_radar_detect_ch(rfctl) && IS_CH_WAITING(rfctl);
}
bool rtw_chset_is_chbw_non_ocp(RT_CHANNEL_INFO *ch_set, u8 ch, u8 bw, u8 offset)
{
bool ret = _FALSE;
u32 hi = 0, lo = 0;
int i;
if (rtw_chbw_to_freq_range(ch, bw, offset, &hi, &lo) == _FALSE)
goto exit;
for (i = 0; i < MAX_CHANNEL_NUM && ch_set[i].ChannelNum != 0; i++) {
if (!rtw_ch2freq(ch_set[i].ChannelNum)) {
rtw_warn_on(1);
continue;
}
if (!CH_IS_NON_OCP(&ch_set[i]))
continue;
if (lo <= rtw_ch2freq(ch_set[i].ChannelNum)
&& rtw_ch2freq(ch_set[i].ChannelNum) <= hi
) {
ret = _TRUE;
break;
}
}
exit:
return ret;
}
bool rtw_chset_is_ch_non_ocp(RT_CHANNEL_INFO *ch_set, u8 ch)
{
return rtw_chset_is_chbw_non_ocp(ch_set, ch, CHANNEL_WIDTH_20, HAL_PRIME_CHNL_OFFSET_DONT_CARE);
}
u32 rtw_chset_get_ch_non_ocp_ms(RT_CHANNEL_INFO *ch_set, u8 ch, u8 bw, u8 offset)
{
int ms = 0;
systime current_time;
u32 hi = 0, lo = 0;
int i;
if (rtw_chbw_to_freq_range(ch, bw, offset, &hi, &lo) == _FALSE)
goto exit;
current_time = rtw_get_current_time();
for (i = 0; i < MAX_CHANNEL_NUM && ch_set[i].ChannelNum != 0; i++) {
if (!rtw_ch2freq(ch_set[i].ChannelNum)) {
rtw_warn_on(1);
continue;
}
if (!CH_IS_NON_OCP(&ch_set[i]))
continue;
if (lo <= rtw_ch2freq(ch_set[i].ChannelNum)
&& rtw_ch2freq(ch_set[i].ChannelNum) <= hi
) {
if (rtw_systime_to_ms(ch_set[i].non_ocp_end_time - current_time) > ms)
ms = rtw_systime_to_ms(ch_set[i].non_ocp_end_time - current_time);
}
}
exit:
return ms;
}
/**
* rtw_chset_update_non_ocp - update non_ocp_end_time according to the given @ch, @bw, @offset into @ch_set
* @ch_set: the given channel set
* @ch: channel number on which radar is detected
* @bw: bandwidth on which radar is detected
* @offset: bandwidth offset on which radar is detected
* @ms: ms to add from now to update non_ocp_end_time, ms < 0 means use NON_OCP_TIME_MS
*/
static bool _rtw_chset_update_non_ocp(RT_CHANNEL_INFO *ch_set, u8 ch, u8 bw, u8 offset, int ms)
{
u32 hi = 0, lo = 0;
int i;
bool updated = 0;
if (rtw_chbw_to_freq_range(ch, bw, offset, &hi, &lo) == _FALSE)
goto exit;
for (i = 0; i < MAX_CHANNEL_NUM && ch_set[i].ChannelNum != 0; i++) {
if (!rtw_ch2freq(ch_set[i].ChannelNum)) {
rtw_warn_on(1);
continue;
}
if (lo <= rtw_ch2freq(ch_set[i].ChannelNum)
&& rtw_ch2freq(ch_set[i].ChannelNum) <= hi
) {
if (ms >= 0)
ch_set[i].non_ocp_end_time = rtw_get_current_time() + rtw_ms_to_systime(ms);
else
ch_set[i].non_ocp_end_time = rtw_get_current_time() + rtw_ms_to_systime(NON_OCP_TIME_MS);
ch_set[i].flags |= RTW_CHF_NON_OCP;
updated = 1;
}
}
exit:
return updated;
}
inline bool rtw_chset_update_non_ocp(RT_CHANNEL_INFO *ch_set, u8 ch, u8 bw, u8 offset)
{
return _rtw_chset_update_non_ocp(ch_set, ch, bw, offset, -1);
}
inline bool rtw_chset_update_non_ocp_ms(RT_CHANNEL_INFO *ch_set, u8 ch, u8 bw, u8 offset, int ms)
{
return _rtw_chset_update_non_ocp(ch_set, ch, bw, offset, ms);
}
static bool rtw_chset_chk_non_ocp_finish_for_chbw(struct rf_ctl_t *rfctl, u8 ch, u8 bw, u8 offset)
{
RT_CHANNEL_INFO *ch_set = rfctl->channel_set;
u8 cch;
u8 *op_chs;
u8 op_ch_num;
int i;
int ch_idx;
bool ret = 0;
cch = rtw_get_center_ch(ch, bw, offset);
if (!rtw_get_op_chs_by_cch_bw(cch, bw, &op_chs, &op_ch_num))
goto exit;
for (i = 0; i < op_ch_num; i++) {
if (0)
RTW_INFO("%u,%u,%u - cch:%u, bw:%u, op_ch:%u\n", ch, bw, offset, cch, bw, *(op_chs + i));
ch_idx = rtw_chset_search_ch(ch_set, *(op_chs + i));
if (ch_idx == -1)
break;
if (!(ch_set[ch_idx].flags & RTW_CHF_NON_OCP) || CH_IS_NON_OCP(&ch_set[ch_idx]))
break;
}
if (op_ch_num != 0 && i == op_ch_num) {
ret = 1;
/* clear RTTW_CHF_NON_OCP flag */
for (i = 0; i < op_ch_num; i++) {
ch_idx = rtw_chset_search_ch(ch_set, *(op_chs + i));
ch_set[ch_idx].flags &= ~RTW_CHF_NON_OCP;
}
rtw_nlrtw_nop_finish_event(dvobj_get_primary_adapter(rfctl_to_dvobj(rfctl)), cch, bw);
}
exit:
return ret;
}
/* called by watchdog to clear RTW_CHF_NON_OCP and generate NON_OCP finish event */
void rtw_chset_chk_non_ocp_finish(struct rf_ctl_t *rfctl)
{
u8 ch, bw, offset;
int i;
bw = CHANNEL_WIDTH_160;
while (1) {
for (i = 0; i < rfctl->max_chan_nums; i++) {
ch = rfctl->channel_set[i].ChannelNum;
if (!(rfctl->channel_set[i].flags & RTW_CHF_NON_OCP))
continue;
if (!rtw_get_offset_by_chbw(ch, bw, &offset))
continue;
rtw_chset_chk_non_ocp_finish_for_chbw(rfctl, ch, bw, offset);
}
if (bw-- == CHANNEL_WIDTH_20)
break;
}
}
u32 rtw_get_ch_waiting_ms(struct rf_ctl_t *rfctl, u8 ch, u8 bw, u8 offset, u32 *r_non_ocp_ms, u32 *r_cac_ms)
{
struct dvobj_priv *dvobj = rfctl_to_dvobj(rfctl);
u32 non_ocp_ms;
u32 cac_ms;
u8 in_rd_range = 0; /* if in current radar detection range*/
if (rtw_chset_is_chbw_non_ocp(rfctl->channel_set, ch, bw, offset))
non_ocp_ms = rtw_chset_get_ch_non_ocp_ms(rfctl->channel_set, ch, bw, offset);
else
non_ocp_ms = 0;
if (rfctl->radar_detect_enabled) {
u32 cur_hi, cur_lo, hi, lo;
if (rtw_chbw_to_freq_range(ch, bw, offset, &hi, &lo) == _FALSE) {
RTW_ERR("input range ch:%u, bw:%u, offset:%u\n", ch, bw, offset);
rtw_warn_on(1);
}
if (rtw_chbw_to_freq_range(rfctl->radar_detect_ch, rfctl->radar_detect_bw, rfctl->radar_detect_offset, &cur_hi, &cur_lo) == _FALSE) {
RTW_ERR("cur detection range ch:%u, bw:%u, offset:%u\n", rfctl->radar_detect_ch, rfctl->radar_detect_bw, rfctl->radar_detect_offset);
rtw_warn_on(1);
}
if (rtw_is_range_a_in_b(hi, lo, cur_hi, cur_lo))
in_rd_range = 1;
}
if (!rtw_chset_is_dfs_chbw(rfctl->channel_set, ch, bw, offset))
cac_ms = 0;
else if (in_rd_range && !non_ocp_ms) {
if (IS_CH_WAITING(rfctl))
cac_ms = rtw_systime_to_ms(rfctl->cac_end_time - rtw_get_current_time());
else
cac_ms = 0;
} else if (rtw_is_long_cac_ch(ch, bw, offset, rtw_rfctl_get_dfs_domain(rfctl)))
cac_ms = CAC_TIME_CE_MS;
else
cac_ms = CAC_TIME_MS;
if (r_non_ocp_ms)
*r_non_ocp_ms = non_ocp_ms;
if (r_cac_ms)
*r_cac_ms = cac_ms;
return non_ocp_ms + cac_ms;
}
void rtw_reset_cac(struct rf_ctl_t *rfctl, u8 ch, u8 bw, u8 offset)
{
u32 non_ocp_ms;
u32 cac_ms;
rtw_get_ch_waiting_ms(rfctl
, ch
, bw
, offset
, &non_ocp_ms
, &cac_ms
);
rfctl->cac_start_time = rtw_get_current_time() + rtw_ms_to_systime(non_ocp_ms);
rfctl->cac_end_time = rfctl->cac_start_time + rtw_ms_to_systime(cac_ms);
/* skip special value */
if (rfctl->cac_start_time == RTW_CAC_STOPPED) {
rfctl->cac_start_time++;
rfctl->cac_end_time++;
}
if (rfctl->cac_end_time == RTW_CAC_STOPPED)
rfctl->cac_end_time++;
}
u32 rtw_force_stop_cac(struct rf_ctl_t *rfctl, u32 timeout_ms)
{
struct dvobj_priv *dvobj = rfctl_to_dvobj(rfctl);
systime start;
u32 pass_ms;
start = rtw_get_current_time();
rfctl->cac_force_stop = 1;
while (rtw_get_passing_time_ms(start) <= timeout_ms
&& IS_UNDER_CAC(rfctl)
) {
if (dev_is_surprise_removed(dvobj) || dev_is_drv_stopped(dvobj))
break;
rtw_msleep_os(20);
}
if (IS_UNDER_CAC(rfctl)) {
if (!dev_is_surprise_removed(dvobj) && !dev_is_drv_stopped(dvobj))
RTW_INFO("%s waiting for cac stop timeout!\n", __func__);
}
rfctl->cac_force_stop = 0;
pass_ms = rtw_get_passing_time_ms(start);
return pass_ms;
}
#endif /* CONFIG_DFS_MASTER */
/* choose channel with shortest waiting (non ocp + cac) time */
bool rtw_choose_shortest_waiting_ch(struct rf_ctl_t *rfctl, u8 sel_ch, u8 max_bw
, u8 *dec_ch, u8 *dec_bw, u8 *dec_offset
, u8 e_flags, u8 d_flags, u8 cur_ch, bool by_int_info, u8 mesh_only)
{
#ifndef DBG_CHOOSE_SHORTEST_WAITING_CH
#define DBG_CHOOSE_SHORTEST_WAITING_CH 0
#endif
struct dvobj_priv *dvobj = rfctl_to_dvobj(rfctl);
#ifdef CONFIG_RTW_ACS
HAL_DATA_TYPE *hal_data = GET_HAL_DATA(dvobj_get_primary_adapter(dvobj));
#endif
struct registry_priv *regsty = dvobj_to_regsty(dvobj);
u8 ch, bw, offset;
u8 ch_c = 0, bw_c = 0, offset_c = 0;
int i;
u32 min_waiting_ms = 0;
u16 int_factor_c = 0;
if (!dec_ch || !dec_bw || !dec_offset) {
rtw_warn_on(1);
return _FALSE;
}
RTW_INFO("%s: sel_ch:%u max_bw:%u e_flags:0x%02x d_flags:0x%02x cur_ch:%u within_sb:%d%s%s\n"
, __func__, sel_ch, max_bw, e_flags, d_flags, cur_ch, rfctl->ch_sel_within_same_band
, by_int_info ? " int" : "", mesh_only ? " mesh_only" : "");
/* full search and narrow bw judegement first to avoid potetial judegement timing issue */
for (bw = CHANNEL_WIDTH_20; bw <= max_bw; bw++) {
if (!hal_is_bw_support(dvobj_get_primary_adapter(dvobj), bw))
continue;
for (i = 0; i < rfctl->max_chan_nums; i++) {
u32 non_ocp_ms = 0;
u32 cac_ms = 0;
u32 waiting_ms = 0;
u16 int_factor = 0;
bool dfs_ch;
bool non_ocp;
bool long_cac;
ch = rfctl->channel_set[i].ChannelNum;
if (sel_ch) {
if (ch != sel_ch)
continue;
} else if (rfctl->ch_sel_within_same_band && !rtw_is_same_band(cur_ch, ch))
continue;
if (ch > 14) {
if (bw > REGSTY_BW_5G(regsty))
continue;
} else {
if (bw > REGSTY_BW_2G(regsty))
continue;
}
if (mesh_only && ch >= 5 && ch <= 9 && bw > CHANNEL_WIDTH_20)
continue;
if (!rtw_get_offset_by_chbw(ch, bw, &offset))
continue;
if (!rtw_chset_is_chbw_valid(rfctl->channel_set, ch, bw, offset, 0, 0))
continue;
if ((e_flags & RTW_CHF_DFS) || (d_flags & RTW_CHF_DFS)) {
dfs_ch = rtw_chset_is_dfs_chbw(rfctl->channel_set, ch, bw, offset);
if (((e_flags & RTW_CHF_DFS) && !dfs_ch)
|| ((d_flags & RTW_CHF_DFS) && dfs_ch))
continue;
}
if ((e_flags & RTW_CHF_LONG_CAC) || (d_flags & RTW_CHF_LONG_CAC)) {
long_cac = rtw_is_long_cac_ch(ch, bw, offset, rtw_rfctl_get_dfs_domain(rfctl));
if (((e_flags & RTW_CHF_LONG_CAC) && !long_cac)
|| ((d_flags & RTW_CHF_LONG_CAC) && long_cac))
continue;
}
if ((e_flags & RTW_CHF_NON_OCP) || (d_flags & RTW_CHF_NON_OCP)) {
non_ocp = rtw_chset_is_chbw_non_ocp(rfctl->channel_set, ch, bw, offset);
if (((e_flags & RTW_CHF_NON_OCP) && !non_ocp)
|| ((d_flags & RTW_CHF_NON_OCP) && non_ocp))
continue;
}
#ifdef CONFIG_DFS_MASTER
waiting_ms = rtw_get_ch_waiting_ms(rfctl, ch, bw, offset, &non_ocp_ms, &cac_ms);
#endif
#ifdef CONFIG_RTW_ACS
if (by_int_info) {
/* for now, consider only primary channel */
int_factor = hal_data->acs.interference_time[i];
}
#endif
if (DBG_CHOOSE_SHORTEST_WAITING_CH)
RTW_INFO("%s:%u,%u,%u %u(non_ocp:%u, cac:%u), int:%u\n"
, __func__, ch, bw, offset, waiting_ms, non_ocp_ms, cac_ms, int_factor);
if (ch_c == 0
/* first: smaller wating time */
|| min_waiting_ms > waiting_ms
/* then: less interference */
|| (min_waiting_ms == waiting_ms && int_factor_c > int_factor)
/* then: wider bw */
|| (min_waiting_ms == waiting_ms && int_factor_c == int_factor && bw > bw_c)
/* if all condition equal, same channel -> same band prefer */
|| (min_waiting_ms == waiting_ms && int_factor_c == int_factor && bw == bw_c
&& ((cur_ch != ch_c && cur_ch == ch)
|| (!rtw_is_same_band(cur_ch, ch_c) && rtw_is_same_band(cur_ch, ch)))
)
) {
ch_c = ch;
bw_c = bw;
offset_c = offset;
min_waiting_ms = waiting_ms;
int_factor_c = int_factor;
}
}
}
if (ch_c != 0) {
RTW_INFO("%s: select %u,%u,%u waiting_ms:%u\n"