forked from HRex39/rtl8852be
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtw_ap.c
6734 lines (5506 loc) · 190 KB
/
rtw_ap.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_AP_C_
#include <drv_types.h>
#ifdef CONFIG_AP_MODE
extern unsigned char RTW_WPA_OUI[];
extern unsigned char WMM_OUI[];
extern unsigned char WPS_OUI[];
extern unsigned char P2P_OUI[];
extern unsigned char WFD_OUI[];
void init_mlme_ap_info(_adapter *padapter)
{
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
_rtw_spinlock_init(&pmlmepriv->bcn_update_lock);
/* pmlmeext->bstart_bss = _FALSE; */
}
void free_mlme_ap_info(_adapter *padapter)
{
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
stop_ap_mode(padapter);
_rtw_spinlock_free(&pmlmepriv->bcn_update_lock);
}
/*
* Set TIM IE
* return length of total TIM IE
*/
u8 rtw_set_tim_ie(u8 dtim_cnt, u8 dtim_period
, const u8 *tim_bmp, u8 tim_bmp_len, u8 *tim_ie)
{
u8 *p = tim_ie;
u8 i, n1, n2;
u8 bmp_len;
if (rtw_bmp_not_empty(tim_bmp, tim_bmp_len)) {
/* find the first nonzero octet in tim_bitmap */
for (i = 0; i < tim_bmp_len; i++)
if (tim_bmp[i])
break;
n1 = i & 0xFE;
/* find the last nonzero octet in tim_bitmap, except octet 0 */
for (i = tim_bmp_len - 1; i > 0; i--)
if (tim_bmp[i])
break;
n2 = i;
bmp_len = n2 - n1 + 1;
} else {
n1 = n2 = 0;
bmp_len = 1;
}
*p++ = WLAN_EID_TIM;
*p++ = 2 + 1 + bmp_len;
*p++ = dtim_cnt;
*p++ = dtim_period;
*p++ = (rtw_bmp_is_set(tim_bmp, tim_bmp_len, 0) ? BIT0 : 0) | n1;
_rtw_memcpy(p, tim_bmp + n1, bmp_len);
#if 0
RTW_INFO("n1:%u, n2:%u, bmp_offset:%u, bmp_len:%u\n", n1, n2, n1 / 2, bmp_len);
RTW_INFO_DUMP("tim_ie: ", tim_ie + 2, 2 + 1 + bmp_len);
#endif
return 2 + 2 + 1 + bmp_len;
}
static void update_BCNTIM(_adapter *padapter)
{
struct sta_priv *pstapriv = &padapter->stapriv;
struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
WLAN_BSSID_EX *pnetwork_mlmeext = &(pmlmeinfo->network);
unsigned char *pie = pnetwork_mlmeext->IEs;
#if 0
/* update TIM IE */
/* if(rtw_tim_map_anyone_be_set(padapter, pstapriv->tim_bitmap)) */
#endif
if (_TRUE) {
u8 *p, *dst_ie, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
uint offset, tmp_len, tim_ielen, tim_ie_offset, remainder_ielen;
p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, _TIM_IE_, &tim_ielen, pnetwork_mlmeext->IELength - _FIXED_IE_LENGTH_);
if (p != NULL && tim_ielen > 0) {
tim_ielen += 2;
premainder_ie = p + tim_ielen;
tim_ie_offset = (sint)(p - pie);
remainder_ielen = pnetwork_mlmeext->IELength - tim_ie_offset - tim_ielen;
/*append TIM IE from dst_ie offset*/
dst_ie = p;
} else {
tim_ielen = 0;
/*calculate head_len*/
offset = _FIXED_IE_LENGTH_;
/* get ssid_ie len */
p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, _SSID_IE_, &tmp_len, (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_));
if (p != NULL)
offset += tmp_len + 2;
/*get supported rates len*/
p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_, &tmp_len, (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_));
if (p != NULL)
offset += tmp_len + 2;
/*DS Parameter Set IE, len=3*/
offset += 3;
premainder_ie = pie + offset;
remainder_ielen = pnetwork_mlmeext->IELength - offset - tim_ielen;
/*append TIM IE from offset*/
dst_ie = pie + offset;
}
if (remainder_ielen > 0) {
pbackup_remainder_ie = rtw_malloc(remainder_ielen);
if (pbackup_remainder_ie && premainder_ie)
_rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
}
/* append TIM IE */
dst_ie += rtw_set_tim_ie(0, 1, pstapriv->tim_bitmap, pstapriv->aid_bmp_len, dst_ie);
/*copy remainder IE*/
if (pbackup_remainder_ie) {
_rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
rtw_mfree(pbackup_remainder_ie, remainder_ielen);
}
offset = (uint)(dst_ie - pie);
pnetwork_mlmeext->IELength = offset + remainder_ielen;
}
}
void rtw_add_bcn_ie(_adapter *padapter, WLAN_BSSID_EX *pnetwork, u8 index, u8 *data, u8 len)
{
PNDIS_802_11_VARIABLE_IEs pIE;
u8 bmatch = _FALSE;
u8 *pie = pnetwork->IEs;
u8 *p = NULL, *dst_ie = NULL, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
u32 i, offset, ielen = 0, ie_offset, remainder_ielen = 0;
/* Search element id (index) exits or not */
for (i = sizeof(NDIS_802_11_FIXED_IEs); i < pnetwork->IELength;) {
pIE = (PNDIS_802_11_VARIABLE_IEs)(pnetwork->IEs + i);
if (pIE->ElementID > index)
break;
else if (pIE->ElementID == index) { /* already exist the same IE */
p = (u8 *)pIE;
ielen = pIE->Length;
bmatch = _TRUE;
break;
}
p = (u8 *)pIE;
ielen = pIE->Length;
i += (pIE->Length + 2);
}
/* Backup remainder IE */
if (p != NULL && ielen > 0) {
ielen += 2;
premainder_ie = p + ielen;
ie_offset = (sint)(p - pie);
remainder_ielen = pnetwork->IELength - ie_offset - ielen;
if (bmatch)
dst_ie = p;
else
dst_ie = (p + ielen);
}
if (dst_ie == NULL)
return;
if (remainder_ielen > 0) {
pbackup_remainder_ie = rtw_malloc(remainder_ielen);
if (pbackup_remainder_ie && premainder_ie)
_rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
}
*dst_ie++ = index;
*dst_ie++ = len;
_rtw_memcpy(dst_ie, data, len);
dst_ie += len;
/* Append remainder IE */
if (pbackup_remainder_ie) {
_rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
rtw_mfree(pbackup_remainder_ie, remainder_ielen);
}
offset = (uint)(dst_ie - pie);
pnetwork->IELength = offset + remainder_ielen;
}
void rtw_remove_bcn_ie(_adapter *padapter, WLAN_BSSID_EX *pnetwork, u8 index)
{
u8 *p, *dst_ie = NULL, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
uint offset, ielen, ie_offset, remainder_ielen = 0;
u8 *pie = pnetwork->IEs;
p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, index, &ielen, pnetwork->IELength - _FIXED_IE_LENGTH_);
if (p != NULL && ielen > 0) {
ielen += 2;
premainder_ie = p + ielen;
ie_offset = (sint)(p - pie);
remainder_ielen = pnetwork->IELength - ie_offset - ielen;
dst_ie = p;
} else
return;
if (remainder_ielen > 0) {
pbackup_remainder_ie = rtw_malloc(remainder_ielen);
if (pbackup_remainder_ie && premainder_ie)
_rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
}
/* copy remainder IE */
if (pbackup_remainder_ie) {
_rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
rtw_mfree(pbackup_remainder_ie, remainder_ielen);
}
offset = (uint)(dst_ie - pie);
pnetwork->IELength = offset + remainder_ielen;
}
void rtw_remove_bcn_ie_ex(_adapter *padapter, WLAN_BSSID_EX *pnetwork, u8 index, u8* pindex_ex, u8 index_ex_len)
{
u8 *p, *dst_ie = NULL, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
uint offset, ielen, ie_offset, remainder_ielen = 0;
u8 *pie = pnetwork->IEs;
p = rtw_get_ie_ex(pie + _FIXED_IE_LENGTH_, pnetwork->IELength - _FIXED_IE_LENGTH_, index, pindex_ex, index_ex_len, NULL, &ielen);
if (p != NULL && ielen > 0) {
premainder_ie = p + ielen;
ie_offset = (sint)(p - pie);
remainder_ielen = pnetwork->IELength - ie_offset - ielen;
dst_ie = p;
} else
return;
if (remainder_ielen > 0) {
pbackup_remainder_ie = rtw_malloc(remainder_ielen);
if (pbackup_remainder_ie && premainder_ie)
_rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
}
/* copy remainder IE */
if (pbackup_remainder_ie) {
_rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
rtw_mfree(pbackup_remainder_ie, remainder_ielen);
}
offset = (uint)(dst_ie - pie);
pnetwork->IELength = offset + remainder_ielen;
}
u8 chk_sta_is_alive(struct sta_info *psta);
u8 chk_sta_is_alive(struct sta_info *psta)
{
u8 ret = _FALSE;
#ifdef DBG_EXPIRATION_CHK
RTW_INFO("sta:"MAC_FMT", rssi:%d, rx:"STA_PKTS_FMT", expire_to:%u, %s%ssq_len:%u\n"
, MAC_ARG(psta->phl_sta->mac_addr)
, 0 /* TODO: psta->phl_sta->hal_sta->rssi_stat.rssi */
/* , STA_RX_PKTS_ARG(psta) */
, STA_RX_PKTS_DIFF_ARG(psta)
, psta->expire_to
, psta->state & WIFI_SLEEP_STATE ? "PS, " : ""
, psta->state & WIFI_STA_ALIVE_CHK_STATE ? "SAC, " : ""
, psta->sleepq_len
);
#endif
/* if(sta_last_rx_pkts(psta) == sta_rx_pkts(psta)) */
if ((psta->sta_stats.last_rx_data_pkts + psta->sta_stats.last_rx_ctrl_pkts) == (psta->sta_stats.rx_data_pkts + psta->sta_stats.rx_ctrl_pkts)) {
#if 0
if (psta->state & WIFI_SLEEP_STATE)
ret = _TRUE;
#endif
} else
ret = _TRUE;
#ifdef CONFIG_RTW_MESH
if (MLME_IS_MESH(psta->padapter)) {
u8 bcn_alive, hwmp_alive;
hwmp_alive = (psta->sta_stats.rx_hwmp_pkts !=
psta->sta_stats.last_rx_hwmp_pkts);
bcn_alive = (psta->sta_stats.rx_beacon_pkts !=
psta->sta_stats.last_rx_beacon_pkts);
/* The reference for nexthop_lookup */
psta->alive = ret || hwmp_alive || bcn_alive;
/* The reference for expire_timeout_chk */
/* Exclude bcn_alive to avoid a misjudge condition
that a peer unexpectedly leave and restart quickly*/
ret = ret || hwmp_alive;
}
#endif
sta_update_last_rx_pkts(psta);
return ret;
}
/**
* issue_aka_chk_frame - issue active keep alive check frame
* aka = active keep alive
*/
#ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
static int issue_aka_chk_frame(_adapter *adapter, struct sta_info *psta)
{
int ret = _FAIL;
u8 *target_addr = psta->phl_sta->mac_addr;
if (MLME_IS_AP(adapter)) {
/* issue null data to check sta alive */
if (psta->state & WIFI_SLEEP_STATE)
ret = issue_nulldata(adapter, target_addr, 0, 1, 50);
else
ret = issue_nulldata(adapter, target_addr, 0, 3, 50);
}
#ifdef CONFIG_RTW_MESH
if (MLME_IS_MESH(adapter)) {
struct rtw_mesh_path *mpath;
rtw_rcu_read_lock();
mpath = rtw_mesh_path_lookup(adapter, target_addr);
if (!mpath) {
mpath = rtw_mesh_path_add(adapter, target_addr);
if (IS_ERR(mpath)) {
rtw_rcu_read_unlock();
RTW_ERR(FUNC_ADPT_FMT" rtw_mesh_path_add for "MAC_FMT" fail.\n",
FUNC_ADPT_ARG(adapter), MAC_ARG(target_addr));
return _FAIL;
}
}
if (mpath->flags & RTW_MESH_PATH_ACTIVE)
ret = _SUCCESS;
else {
u8 flags = RTW_PREQ_Q_F_START | RTW_PREQ_Q_F_PEER_AKA;
/* issue PREQ to check peer alive */
rtw_mesh_queue_preq(mpath, flags);
ret = _FALSE;
}
rtw_rcu_read_unlock();
}
#endif
return ret;
}
#endif
void expire_timeout_chk(_adapter *padapter)
{
_list *phead, *plist;
u8 updated = _FALSE;
struct sta_info *psta = NULL;
struct sta_priv *pstapriv = &padapter->stapriv;
u8 chk_alive_num = 0;
char chk_alive_list[NUM_STA];
int i;
int stainfo_offset;
u8 flush_num = 0;
char flush_list[NUM_STA]={0};
#ifdef CONFIG_RTW_MESH
if (MLME_IS_MESH(padapter)
&& check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE)
) {
struct rtw_mesh_cfg *mcfg = &padapter->mesh_cfg;
rtw_mesh_path_expire(padapter);
/* TBD: up layer timeout mechanism */
/* if (!mcfg->plink_timeout)
return; */
#ifndef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
return;
#endif
}
#endif
#ifdef CONFIG_RTW_WDS
rtw_wds_path_expire(padapter);
#endif
_rtw_spinlock_bh(&pstapriv->auth_list_lock);
phead = &pstapriv->auth_list;
plist = get_next(phead);
/* check auth_queue */
#ifdef DBG_EXPIRATION_CHK
if (rtw_end_of_queue_search(phead, plist) == _FALSE) {
RTW_INFO(FUNC_ADPT_FMT" auth_list, cnt:%u\n"
, FUNC_ADPT_ARG(padapter), pstapriv->auth_list_cnt);
}
#endif
while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
psta = LIST_CONTAINOR(plist, struct sta_info, auth_list);
plist = get_next(plist);
#ifdef CONFIG_ATMEL_RC_PATCH
if (_rtw_memcmp((void *)(pstapriv->atmel_rc_pattern), (void *)(psta->phl_sta->mac_addr), ETH_ALEN) == _TRUE)
continue;
if (psta->flag_atmel_rc)
continue;
#endif
if (psta->expire_to > 0) {
psta->expire_to--;
if (psta->expire_to == 0) {
stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
if (stainfo_offset_valid(stainfo_offset))
flush_list[flush_num++] = stainfo_offset;
else
rtw_warn_on(1);
}
}
}
_rtw_spinunlock_bh(&pstapriv->auth_list_lock);
for (i = 0; i < flush_num; i++) {
psta = rtw_get_stainfo_by_offset(pstapriv, flush_list[i]);
RTW_INFO(FUNC_ADPT_FMT" auth expire "MAC_FMT"\n"
, FUNC_ADPT_ARG(padapter), MAC_ARG(psta->phl_sta->mac_addr));
rtw_free_stainfo(padapter, psta);
psta = NULL;
}
_rtw_spinlock_bh(&pstapriv->asoc_list_lock);
phead = &pstapriv->asoc_list;
plist = get_next(phead);
/* check asoc_queue */
#ifdef DBG_EXPIRATION_CHK
if (rtw_end_of_queue_search(phead, plist) == _FALSE) {
RTW_INFO(FUNC_ADPT_FMT" asoc_list, cnt:%u\n"
, FUNC_ADPT_ARG(padapter), pstapriv->asoc_list_cnt);
}
#endif
while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
plist = get_next(plist);
#ifdef CONFIG_ATMEL_RC_PATCH
RTW_INFO("%s:%d psta=%p, %02x,%02x||%02x,%02x \n\n", __func__, __LINE__,
psta, pstapriv->atmel_rc_pattern[0], pstapriv->atmel_rc_pattern[5], psta->phl_sta->mac_addr[0], psta->phl_sta->mac_addr[5]);
if (_rtw_memcmp((void *)pstapriv->atmel_rc_pattern, (void *)(psta->phl_sta->mac_addr), ETH_ALEN) == _TRUE)
continue;
if (psta->flag_atmel_rc)
continue;
RTW_INFO("%s: debug line:%d\n", __func__, __LINE__);
#endif
#ifdef CONFIG_AUTO_AP_MODE
if (psta->isrc)
continue;
#endif
if (chk_sta_is_alive(psta) || !psta->expire_to) {
psta->expire_to = pstapriv->expire_to;
psta->keep_alive_trycnt = 0;
#if !defined(CONFIG_ACTIVE_KEEP_ALIVE_CHECK) && defined(CONFIG_80211N_HT)
psta->under_exist_checking = 0;
#endif
} else
psta->expire_to--;
#if !defined(CONFIG_ACTIVE_KEEP_ALIVE_CHECK) && defined(CONFIG_80211N_HT)
if ((psta->flags & WLAN_STA_HT) && (psta->htpriv.agg_enable_bitmap || psta->under_exist_checking)) {
/* check sta by delba(addba) for 11n STA */
/* ToDo: use CCX report to check for all STAs */
/* RTW_INFO("asoc check by DELBA/ADDBA! (pstapriv->expire_to=%d s)(psta->expire_to=%d s), [%02x, %d]\n", pstapriv->expire_to*2, psta->expire_to*2, psta->htpriv.agg_enable_bitmap, psta->under_exist_checking); */
if (psta->expire_to <= (pstapriv->expire_to - 50)) {
RTW_INFO("asoc expire by DELBA/ADDBA! (%d s)\n", (pstapriv->expire_to - psta->expire_to) * 2);
psta->under_exist_checking = 0;
psta->expire_to = 0;
} else if (psta->expire_to <= (pstapriv->expire_to - 3) && (psta->under_exist_checking == 0)) {
RTW_INFO("asoc check by DELBA/ADDBA! (%d s)\n", (pstapriv->expire_to - psta->expire_to) * 2);
psta->under_exist_checking = 1;
/* tear down TX AMPDU */
send_delba(padapter, 1, psta->phl_sta->mac_addr);/* */ /* originator */
psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
}
}
#endif /* !defined(CONFIG_ACTIVE_KEEP_ALIVE_CHECK) && defined(CONFIG_80211N_HT) */
if (psta->expire_to <= 0) {
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
if (padapter->registrypriv.wifi_spec == 1) {
psta->expire_to = pstapriv->expire_to;
continue;
}
#ifndef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
#ifdef CONFIG_80211N_HT
#define KEEP_ALIVE_TRYCNT (3)
if (psta->keep_alive_trycnt > 0 && psta->keep_alive_trycnt <= KEEP_ALIVE_TRYCNT) {
if (psta->state & WIFI_STA_ALIVE_CHK_STATE)
psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
else
psta->keep_alive_trycnt = 0;
} else if ((psta->keep_alive_trycnt > KEEP_ALIVE_TRYCNT) && !(psta->state & WIFI_STA_ALIVE_CHK_STATE))
psta->keep_alive_trycnt = 0;
if ((psta->htpriv.ht_option == _TRUE) && (psta->htpriv.ampdu_enable == _TRUE)) {
uint priority = 1; /* test using BK */
u8 issued = 0;
/* issued = (psta->htpriv.agg_enable_bitmap>>priority)&0x1; */
issued |= (psta->htpriv.candidate_tid_bitmap >> priority) & 0x1;
if (0 == issued) {
if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
psta->htpriv.candidate_tid_bitmap |= BIT((u8)priority);
if (psta->state & WIFI_SLEEP_STATE)
psta->expire_to = 2; /* 2x2=4 sec */
else
psta->expire_to = 1; /* 2 sec */
psta->state |= WIFI_STA_ALIVE_CHK_STATE;
/* add_ba_hdl(padapter, (u8*)paddbareq_parm); */
RTW_INFO("issue addba_req to check if sta alive, keep_alive_trycnt=%d\n", psta->keep_alive_trycnt);
issue_addba_req(padapter, psta->phl_sta->mac_addr, (u8)priority);
_set_timer(&psta->addba_retry_timer, ADDBA_TO);
psta->keep_alive_trycnt++;
continue;
}
}
}
if (psta->keep_alive_trycnt > 0 && psta->state & WIFI_STA_ALIVE_CHK_STATE) {
psta->keep_alive_trycnt = 0;
psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
RTW_INFO("change to another methods to check alive if staion is at ps mode\n");
}
#endif /* CONFIG_80211N_HT */
#endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
if (psta->state & WIFI_SLEEP_STATE) {
if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
/* to check if alive by another methods if staion is at ps mode. */
psta->expire_to = pstapriv->expire_to;
psta->state |= WIFI_STA_ALIVE_CHK_STATE;
/* RTW_INFO("alive chk, sta:" MAC_FMT " is at ps mode!\n", MAC_ARG(psta->phl_sta->mac_addr)); */
/* to update bcn with tim_bitmap for this station */
rtw_tim_map_set(padapter, pstapriv->tim_bitmap, psta->phl_sta->aid);
rtw_update_beacon(padapter, _TIM_IE_, NULL, _TRUE, 0);
if (!pmlmeext->active_keep_alive_check)
continue;
}
}
{
int stainfo_offset;
stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
if (stainfo_offset_valid(stainfo_offset))
chk_alive_list[chk_alive_num++] = stainfo_offset;
continue;
}
} else {
/* TODO: Aging mechanism to digest frames in sleep_q to avoid running out of xmitframe */
if (psta->sleepq_len > (NR_XMITFRAME / pstapriv->asoc_list_cnt)
&& padapter->xmitpriv.free_xmitframe_cnt < ((NR_XMITFRAME / pstapriv->asoc_list_cnt) / 2)
) {
RTW_INFO(FUNC_ADPT_FMT" sta:"MAC_FMT", sleepq_len:%u, free_xmitframe_cnt:%u, asoc_list_cnt:%u, clear sleep_q\n"
, FUNC_ADPT_ARG(padapter), MAC_ARG(psta->phl_sta->mac_addr)
, psta->sleepq_len, padapter->xmitpriv.free_xmitframe_cnt, pstapriv->asoc_list_cnt);
wakeup_sta_to_xmit(padapter, psta);
}
}
}
_rtw_spinunlock_bh(&pstapriv->asoc_list_lock);
if (chk_alive_num) {
#if defined(CONFIG_ACTIVE_KEEP_ALIVE_CHECK)
u8 backup_ch = 0, backup_bw = 0, backup_offset = 0;
u8 union_ch = 0, union_bw = 0, union_offset = 0;
u8 switch_channel_by_drv = _TRUE;
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
#endif
char del_asoc_list[NUM_STA];
_rtw_memset(del_asoc_list, NUM_STA, NUM_STA);
#ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
if (pmlmeext->active_keep_alive_check) {
if (!rtw_mi_get_ch_setting_union(padapter, &union_ch, &union_bw, &union_offset)
|| pmlmeext->chandef.chan != union_ch)
switch_channel_by_drv = _FALSE;
/* switch to correct channel of current network before issue keep-alive frames */
if (switch_channel_by_drv == _TRUE && rtw_get_oper_ch(padapter) != pmlmeext->chandef.chan) {
backup_ch = rtw_get_oper_ch(padapter);
backup_bw = rtw_get_oper_bw(padapter);
backup_offset = rtw_get_oper_choffset(padapter);
set_channel_bwmode(padapter, union_ch, union_offset, union_bw, _FALSE);
}
}
#endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
/* check loop */
for (i = 0; i < chk_alive_num; i++) {
#ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
int ret = _FAIL;
#endif
psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]);
#ifdef CONFIG_ATMEL_RC_PATCH
if (_rtw_memcmp(pstapriv->atmel_rc_pattern, psta->phl_sta->mac_addr, ETH_ALEN) == _TRUE)
continue;
if (psta->flag_atmel_rc)
continue;
#endif
if (!(psta->state & WIFI_ASOC_STATE))
continue;
#ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
if (pmlmeext->active_keep_alive_check) {
/* issue active keep alive frame to check */
ret = issue_aka_chk_frame(padapter, psta);
psta->keep_alive_trycnt++;
if (ret == _SUCCESS) {
RTW_INFO(FUNC_ADPT_FMT" asoc check, "MAC_FMT" is alive\n"
, FUNC_ADPT_ARG(padapter), MAC_ARG(psta->phl_sta->mac_addr));
psta->expire_to = pstapriv->expire_to;
psta->keep_alive_trycnt = 0;
continue;
} else if (psta->keep_alive_trycnt <= 3) {
RTW_INFO(FUNC_ADPT_FMT" asoc check, "MAC_FMT" keep_alive_trycnt=%d\n"
, FUNC_ADPT_ARG(padapter) , MAC_ARG(psta->phl_sta->mac_addr), psta->keep_alive_trycnt);
psta->expire_to = 1;
continue;
}
}
#endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
psta->keep_alive_trycnt = 0;
del_asoc_list[i] = chk_alive_list[i];
_rtw_spinlock_bh(&pstapriv->asoc_list_lock);
if (rtw_is_list_empty(&psta->asoc_list) == _FALSE) {
rtw_list_delete(&psta->asoc_list);
pstapriv->asoc_list_cnt--;
#ifdef CONFIG_RTW_TOKEN_BASED_XMIT
if (psta->tbtx_enable)
pstapriv->tbtx_asoc_list_cnt--;
#endif
STA_SET_MESH_PLINK(psta, NULL);
}
_rtw_spinunlock_bh(&pstapriv->asoc_list_lock);
}
/* delete loop */
for (i = 0; i < chk_alive_num; i++) {
u8 sta_addr[ETH_ALEN];
if (del_asoc_list[i] >= NUM_STA)
continue;
psta = rtw_get_stainfo_by_offset(pstapriv, del_asoc_list[i]);
_rtw_memcpy(sta_addr, psta->phl_sta->mac_addr, ETH_ALEN);
RTW_INFO(FUNC_ADPT_FMT" asoc expire "MAC_FMT", state=0x%x\n"
, FUNC_ADPT_ARG(padapter), MAC_ARG(psta->phl_sta->mac_addr), psta->state);
updated |= ap_free_sta(padapter, psta, _FALSE, WLAN_REASON_DEAUTH_LEAVING, _FALSE, _FALSE);
#ifdef CONFIG_RTW_MESH
if (MLME_IS_MESH(padapter))
rtw_mesh_expire_peer(padapter, sta_addr);
#endif
}
#ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
if (pmlmeext->active_keep_alive_check) {
/* back to the original operation channel */
if (switch_channel_by_drv == _TRUE && backup_ch > 0)
set_channel_bwmode(padapter, backup_ch, backup_offset, backup_bw, _FALSE);
}
#endif
}
associated_clients_update(padapter, updated, STA_INFO_UPDATE_ALL);
}
#ifdef CONFIG_BMC_TX_RATE_SELECT
u8 rtw_ap_find_mini_tx_rate(_adapter *adapter)
{
_list *phead, *plist;
u8 mini_tx_rate = DESC_RATEVHTSS4MCS9, sta_tx_rate;
struct sta_info *psta = NULL;
struct sta_priv *pstapriv = &adapter->stapriv;
_rtw_spinlock_bh(&pstapriv->asoc_list_lock);
phead = &pstapriv->asoc_list;
plist = get_next(phead);
while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
plist = get_next(plist);
sta_tx_rate = psta->phl_sta->ra_info.curr_tx_rate & 0x7F;
if (sta_tx_rate < mini_tx_rate)
mini_tx_rate = sta_tx_rate;
}
_rtw_spinunlock_bh(&pstapriv->asoc_list_lock);
return mini_tx_rate;
}
u8 rtw_ap_find_bmc_rate(_adapter *adapter, u8 tx_rate)
{
u8 tx_ini_rate = DESC_RATE6M;
switch (tx_rate) {
case DESC_RATEVHTSS3MCS9:
case DESC_RATEVHTSS3MCS8:
case DESC_RATEVHTSS3MCS7:
case DESC_RATEVHTSS3MCS6:
case DESC_RATEVHTSS3MCS5:
case DESC_RATEVHTSS3MCS4:
case DESC_RATEVHTSS3MCS3:
case DESC_RATEVHTSS2MCS9:
case DESC_RATEVHTSS2MCS8:
case DESC_RATEVHTSS2MCS7:
case DESC_RATEVHTSS2MCS6:
case DESC_RATEVHTSS2MCS5:
case DESC_RATEVHTSS2MCS4:
case DESC_RATEVHTSS2MCS3:
case DESC_RATEVHTSS1MCS9:
case DESC_RATEVHTSS1MCS8:
case DESC_RATEVHTSS1MCS7:
case DESC_RATEVHTSS1MCS6:
case DESC_RATEVHTSS1MCS5:
case DESC_RATEVHTSS1MCS4:
case DESC_RATEVHTSS1MCS3:
case DESC_RATEMCS15:
case DESC_RATEMCS14:
case DESC_RATEMCS13:
case DESC_RATEMCS12:
case DESC_RATEMCS11:
case DESC_RATEMCS7:
case DESC_RATEMCS6:
case DESC_RATEMCS5:
case DESC_RATEMCS4:
case DESC_RATEMCS3:
case DESC_RATE54M:
case DESC_RATE48M:
case DESC_RATE36M:
case DESC_RATE24M:
tx_ini_rate = DESC_RATE24M;
break;
case DESC_RATEVHTSS3MCS2:
case DESC_RATEVHTSS3MCS1:
case DESC_RATEVHTSS2MCS2:
case DESC_RATEVHTSS2MCS1:
case DESC_RATEVHTSS1MCS2:
case DESC_RATEVHTSS1MCS1:
case DESC_RATEMCS10:
case DESC_RATEMCS9:
case DESC_RATEMCS2:
case DESC_RATEMCS1:
case DESC_RATE18M:
case DESC_RATE12M:
tx_ini_rate = DESC_RATE12M;
break;
case DESC_RATEVHTSS3MCS0:
case DESC_RATEVHTSS2MCS0:
case DESC_RATEVHTSS1MCS0:
case DESC_RATEMCS8:
case DESC_RATEMCS0:
case DESC_RATE9M:
case DESC_RATE6M:
tx_ini_rate = DESC_RATE6M;
break;
case DESC_RATE11M:
case DESC_RATE5_5M:
case DESC_RATE2M:
case DESC_RATE1M:
tx_ini_rate = DESC_RATE1M;
break;
default:
tx_ini_rate = DESC_RATE6M;
break;
}
if (WIFI_ROLE_IS_ON_5G(adapter))
if (tx_ini_rate < DESC_RATE6M)
tx_ini_rate = DESC_RATE6M;
return tx_ini_rate;
}
void rtw_update_bmc_sta_tx_rate(_adapter *adapter)
{
struct sta_info *psta = NULL;
u8 tx_rate;
psta = rtw_get_bcmc_stainfo(adapter);
if (psta == NULL) {
RTW_ERR(ADPT_FMT "could not get bmc_sta !!\n", ADPT_ARG(adapter));
return;
}
if (adapter->bmc_tx_rate != MGN_UNKNOWN) {
psta->init_rate = adapter->bmc_tx_rate;
goto _exit;
}
if (adapter->stapriv.asoc_sta_count <= 2)
goto _exit;
tx_rate = rtw_ap_find_mini_tx_rate(adapter);
#ifdef CONFIG_BMC_TX_LOW_RATE
tx_rate = rtw_ap_find_bmc_rate(adapter, tx_rate);
#endif
psta->init_rate = hwrate_to_mrate(tx_rate);
_exit:
RTW_INFO(ADPT_FMT" BMC Tx rate - %s\n", ADPT_ARG(adapter), MGN_RATE_STR(psta->init_rate));
}
#endif
void rtw_init_bmc_sta_tx_rate(_adapter *padapter, struct sta_info *psta)
{
/* ToDo: need API to query hal_sta->ra_info.ramask */
#if 0
#ifdef CONFIG_BMC_TX_LOW_RATE
struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
#endif
u8 rate_idx = 0;
u8 brate_table[] = {MGN_1M, MGN_2M, MGN_5_5M, MGN_11M,
MGN_6M, MGN_9M, MGN_12M, MGN_18M, MGN_24M, MGN_36M, MGN_48M, MGN_54M};
if (!MLME_IS_AP(padapter) && !MLME_IS_MESH(padapter))
return;
if (padapter->bmc_tx_rate != MGN_UNKNOWN)
psta->init_rate = padapter->bmc_tx_rate;
else {
#ifdef CONFIG_BMC_TX_LOW_RATE
if (IsEnableHWOFDM(pmlmeext->cur_wireless_mode) && (psta->phl_sta->ra_info.ramask && 0xFF0))
rate_idx = get_lowest_rate_idx_ex(psta->phl_sta->ra_info.ramask, 4); /*from basic rate*/
else
rate_idx = get_lowest_rate_idx(psta->phl_sta->ra_info.ramask); /*from basic rate*/
#else
rate_idx = get_highest_rate_idx(psta->phl_sta->ra_info.ramask); /*from basic rate*/
#endif
if (rate_idx < 12)
psta->init_rate = brate_table[rate_idx];
else
psta->init_rate = MGN_1M;
}
#endif
RTW_INFO(ADPT_FMT" BMC Init Tx rate - %s\n", ADPT_ARG(padapter), MGN_RATE_STR(psta->init_rate));
}
#if defined(CONFIG_80211N_HT) && defined(CONFIG_BEAMFORMING)
void update_sta_info_apmode_ht_bf_cap(_adapter *padapter, struct sta_info *psta)
{
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
struct ht_priv *phtpriv_sta = &psta->htpriv;
u8 cur_beamform_cap = 0;
/*Config Tx beamforming setting*/
if (TEST_FLAG(phtpriv_ap->beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE) &&
GET_HT_CAP_TXBF_EXPLICIT_COMP_STEERING_CAP((u8 *)(&phtpriv_sta->ht_cap))) {
SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE);
/*Shift to BEAMFORMING_HT_BEAMFORMEE_CHNL_EST_CAP*/
SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_CHNL_ESTIMATION_NUM_ANTENNAS((u8 *)(&phtpriv_sta->ht_cap)) << 6);
}
if (TEST_FLAG(phtpriv_ap->beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE) &&
GET_HT_CAP_TXBF_EXPLICIT_COMP_FEEDBACK_CAP((u8 *)(&phtpriv_sta->ht_cap))) {
SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE);
/*Shift to BEAMFORMING_HT_BEAMFORMER_STEER_NUM*/
SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS((u8 *)(&phtpriv_sta->ht_cap)) << 4);
}
if (cur_beamform_cap)
RTW_INFO("Client STA(%d) HT Beamforming Cap = 0x%02X\n", psta->phl_sta->aid, cur_beamform_cap);
phtpriv_sta->beamform_cap = cur_beamform_cap;
}
#endif /*CONFIG_80211N_HT && CONFIG_BEAMFORMING*/
/* notes:
* AID: 1~MAX for sta and 0 for bc/mc in ap/adhoc mode */
void update_sta_info_apmode(_adapter *padapter, struct sta_info *psta)
{
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
struct security_priv *psecuritypriv = &padapter->securitypriv;
struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
struct rtw_wifi_role_t *wrole = padapter->phl_role;
struct protocol_cap_t *proto_role_cap = &(wrole->proto_role_cap);
#ifdef CONFIG_80211N_HT
struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
struct ht_priv *phtpriv_sta = &psta->htpriv;
#endif /* CONFIG_80211N_HT */
u8 cur_ldpc_cap = 0, cur_stbc_cap = 0;
/* set intf_tag to if1 */
/* psta->intf_tag = 0; */
RTW_INFO("%s\n", __FUNCTION__);
/*alloc macid when call rtw_alloc_stainfo(),release macid when call rtw_free_stainfo()*/
if (!MLME_IS_MESH(padapter) && psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)
psta->ieee8021x_blocked = _TRUE;
else
psta->ieee8021x_blocked = _FALSE;
/* update sta's cap */
psta->phl_sta->chandef.chan = pmlmeext->chandef.chan;
psta->phl_sta->chandef.band = (psta->phl_sta->chandef.chan > 14) ? BAND_ON_5G : BAND_ON_24G;
/* ERP */
VCS_update(padapter, psta);
#ifdef CONFIG_80211N_HT
/* HT related cap */
if (phtpriv_sta->ht_option) {
/* check if sta supports rx ampdu */
phtpriv_sta->ampdu_enable = phtpriv_ap->ampdu_enable;
phtpriv_sta->rx_ampdu_min_spacing = (phtpriv_sta->ht_cap.ampdu_params_info & IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2;
/* bwmode */
if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH))