forked from morrownr/88x2bu-20210702
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtw_beamforming.c
2194 lines (1811 loc) · 60.4 KB
/
rtw_beamforming.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_BEAMFORMING_C_
#include <drv_types.h>
#include <hal_data.h>
#ifdef CONFIG_BEAMFORMING
#ifdef RTW_BEAMFORMING_VERSION_2
struct ndpa_sta_info {
u16 aid:12;
u16 feedback_type:1;
u16 nc_index:3;
};
static void _get_txvector_parameter(PADAPTER adapter, struct sta_info *sta, u8 *g_id, u16 *p_aid)
{
struct mlme_priv *mlme;
u16 aid;
u8 *bssid;
u16 val16;
u8 i;
mlme = &adapter->mlmepriv;
if (check_fwstate(mlme, WIFI_AP_STATE)) {
/*
* Sent by an AP and addressed to a STA associated with that AP
* or sent by a DLS or TDLS STA in a direct path to
* a DLS or TDLS peer STA
*/
aid = sta->cmn.aid;
bssid = adapter_mac_addr(adapter);
RTW_INFO("%s: AID=0x%x BSSID=" MAC_FMT "\n",
__FUNCTION__, sta->cmn.aid, MAC_ARG(bssid));
/* AID[0:8] */
aid &= 0x1FF;
/* BSSID[44:47] xor BSSID[40:43] */
val16 = ((bssid[5] & 0xF0) >> 4) ^ (bssid[5] & 0xF);
/* (dec(AID[0:8]) + dec(BSSID)*2^5) mod 2^9 */
*p_aid = (aid + (val16 << 5)) & 0x1FF;
*g_id = 63;
} else if ((check_fwstate(mlme, WIFI_ADHOC_STATE) == _TRUE)
|| (check_fwstate(mlme, WIFI_ADHOC_MASTER_STATE) == _TRUE)) {
/*
* Otherwise, includes
* 1. Sent to an IBSS STA
* 2. Sent by an AP to a non associated STA
* 3. Sent to a STA for which it is not known
* which condition is applicable
*/
*p_aid = 0;
*g_id = 63;
} else {
/* Addressed to AP */
bssid = sta->cmn.mac_addr;
RTW_INFO("%s: BSSID=" MAC_FMT "\n", __FUNCTION__, MAC_ARG(bssid));
/* BSSID[39:47] */
*p_aid = (bssid[5] << 1) | (bssid[4] >> 7);
*g_id = 0;
}
RTW_INFO("%s: GROUP_ID=0x%02x PARTIAL_AID=0x%04x\n",
__FUNCTION__, *g_id, *p_aid);
}
/*
* Parameters
* adapter struct _adapter*
* sta struct sta_info*
* sta_bf_cap beamforming capabe of sta
* sounding_dim Number of Sounding Dimensions
* comp_steering Compressed Steering Number of Beamformer Antennas Supported
*/
static void _get_sta_beamform_cap(PADAPTER adapter, struct sta_info *sta,
u8 *sta_bf_cap, u8 *sounding_dim, u8 *comp_steering)
{
struct beamforming_info *info;
struct mlme_priv *mlme;
struct ht_priv *ht;
u16 ht_bf_cap;
#ifdef CONFIG_80211AC_VHT
struct vht_priv *vht;
u16 vht_bf_cap;
#endif /* CONFIG_80211AC_VHT */
*sta_bf_cap = 0;
*sounding_dim = 0;
*comp_steering = 0;
info = GET_BEAMFORM_INFO(adapter);
ht = &adapter->mlmepriv.htpriv;
#ifdef CONFIG_80211AC_VHT
vht = &adapter->mlmepriv.vhtpriv;
#endif /* CONFIG_80211AC_VHT */
mlme = &adapter->mlmepriv;
if (is_supported_ht(sta->wireless_mode) == _FALSE)
goto get_bfcap_next;
/* HT */
if (check_fwstate(mlme, WIFI_AP_STATE)) {
/* Get peer clinet's BF cap: the cap. is intersected with associated AP.*/
ht_bf_cap = sta->htpriv.beamform_cap;
RTW_INFO("At AP state, peer sta's ht_bf_cap=0x%x\n", ht_bf_cap);
if (TEST_FLAG(ht_bf_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE)) {
info->beamforming_cap |= BEAMFORMER_CAP_HT_EXPLICIT;
*sta_bf_cap |= BEAMFORMEE_CAP_HT_EXPLICIT;
*comp_steering = (ht_bf_cap & BEAMFORMING_HT_BEAMFORMER_STEER_NUM) >> 4;
RTW_INFO("%s: we support BEAMFORMER_CAP_HT_EXPLICIT\n", __func__);
}
if (TEST_FLAG(ht_bf_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE)) {
info->beamforming_cap |= BEAMFORMEE_CAP_HT_EXPLICIT;
*sta_bf_cap |= BEAMFORMER_CAP_HT_EXPLICIT;
*sounding_dim = (ht_bf_cap & BEAMFORMING_HT_BEAMFORMEE_CHNL_EST_CAP) >> 6;
RTW_INFO("%s: we support BEAMFORMEE_CAP_HT_EXPLICIT\n", __func__);
}
} else {
/* Get adapter's BF Cap: the cap. is intersected with associated AP.*/
ht_bf_cap = ht->beamform_cap;
RTW_INFO("At non-AP state, adapter's ht_bf_cap=0x%x\n", ht_bf_cap);
if (TEST_FLAG(ht_bf_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE)) {
info->beamforming_cap |= BEAMFORMEE_CAP_HT_EXPLICIT;
*sta_bf_cap |= BEAMFORMER_CAP_HT_EXPLICIT;
*sounding_dim = (ht_bf_cap & BEAMFORMING_HT_BEAMFORMEE_CHNL_EST_CAP) >> 6;
RTW_INFO("%s: we support BEAMFORMEE_CAP_HT_EXPLICIT\n", __func__);
}
if (TEST_FLAG(ht_bf_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE)) {
info->beamforming_cap |= BEAMFORMER_CAP_HT_EXPLICIT;
*sta_bf_cap |= BEAMFORMEE_CAP_HT_EXPLICIT;
*comp_steering = (ht_bf_cap & BEAMFORMING_HT_BEAMFORMER_STEER_NUM) >> 4;
RTW_INFO("%s: we support BEAMFORMER_CAP_HT_EXPLICIT\n", __func__);
}
}
get_bfcap_next:
#ifdef CONFIG_80211AC_VHT
if (is_supported_vht(sta->wireless_mode) == _FALSE)
return;
/* VHT */
if (check_fwstate(mlme, WIFI_AP_STATE)) {
/* Get peer clinet's BF cap: the cap. is intersected with associated AP.*/
vht_bf_cap = sta->vhtpriv.beamform_cap;
RTW_INFO("At AP state, peer sta's vht_bf_cap=0x%x\n", vht_bf_cap);
/* We are SU Beamformer because the STA is SU Beamformee */
if (TEST_FLAG(vht_bf_cap, BEAMFORMING_VHT_BEAMFORMEE_ENABLE)) {
info->beamforming_cap |= BEAMFORMER_CAP_VHT_SU;
*sta_bf_cap |= BEAMFORMEE_CAP_VHT_SU;
RTW_INFO("%s: we support BEAMFORMER_CAP_VHT_SU\n", __func__);
/* We are MU Beamformer because the STA is MU Beamformee */
if (TEST_FLAG(vht_bf_cap, BEAMFORMING_VHT_MU_MIMO_STA_ENABLE)) {
info->beamforming_cap |= BEAMFORMER_CAP_VHT_MU;
*sta_bf_cap |= BEAMFORMEE_CAP_VHT_MU;
RTW_INFO("%s: we support BEAMFORMER_CAP_VHT_MU\n", __func__);
}
*comp_steering = (vht_bf_cap & BEAMFORMING_VHT_BEAMFORMER_STS_CAP) >> 8;
}
/* We are SU Beamformee because the STA is SU Beamformer */
if (TEST_FLAG(vht_bf_cap, BEAMFORMING_VHT_BEAMFORMER_ENABLE)) {
info->beamforming_cap |= BEAMFORMEE_CAP_VHT_SU;
*sta_bf_cap |= BEAMFORMER_CAP_VHT_SU;
RTW_INFO("%s: we support BEAMFORMEE_CAP_VHT_SU\n", __func__);
/* The STA is MU Beamformer, but we(AP) should not be MU Beamformee */
if (TEST_FLAG(vht_bf_cap, BEAMFORMING_VHT_MU_MIMO_AP_ENABLE)) {
RTW_WARN("%s: Associated STA should not be a MU BFer.\n", __func__);
}
*sounding_dim = (vht_bf_cap & BEAMFORMING_VHT_BEAMFORMEE_SOUND_DIM) >> 12;
}
} else {
/* Get adapter's BF Cap: the cap. is intersected with associated AP.*/
vht_bf_cap = vht->beamform_cap;
RTW_INFO("At non-AP state, adapter's vht_bf_cap=0x%x\n", vht_bf_cap);
/* We are SU Beamformee */
if (TEST_FLAG(vht_bf_cap, BEAMFORMING_VHT_BEAMFORMEE_ENABLE)) {
info->beamforming_cap |= BEAMFORMEE_CAP_VHT_SU;
*sta_bf_cap |= BEAMFORMER_CAP_VHT_SU;
RTW_INFO("%s: we support BEAMFORMEE_CAP_VHT_SU\n", __func__);
/* We are MU Beamformee */
if (TEST_FLAG(vht_bf_cap, BEAMFORMING_VHT_MU_MIMO_STA_ENABLE)) {
info->beamforming_cap |= BEAMFORMEE_CAP_VHT_MU;
*sta_bf_cap |= BEAMFORMER_CAP_VHT_MU;
RTW_INFO("%s: we support BEAMFORMEE_CAP_VHT_MU\n", __func__);
}
*sounding_dim = (vht_bf_cap & BEAMFORMING_VHT_BEAMFORMEE_SOUND_DIM) >> 12;
}
/* We are SU Beamformer */
if (TEST_FLAG(vht_bf_cap, BEAMFORMING_VHT_BEAMFORMER_ENABLE)) {
info->beamforming_cap |= BEAMFORMER_CAP_VHT_SU;
*sta_bf_cap |= BEAMFORMEE_CAP_VHT_SU;
RTW_INFO("%s: we support BEAMFORMER_CAP_VHT_SU\n", __func__);
/* We are MU Beamformer, but client should not be a MU Beamformer */
if (TEST_FLAG(vht_bf_cap, BEAMFORMING_VHT_MU_MIMO_AP_ENABLE)) {
RTW_WARN("%s: non-AP state should not support MU BFer.\n", __func__);
}
*comp_steering = (vht_bf_cap & BEAMFORMING_VHT_BEAMFORMER_STS_CAP) >> 8;
}
}
#endif /* CONFIG_80211AC_VHT */
}
static u8 _send_ht_ndpa_packet(PADAPTER adapter, u8 *ra, enum channel_width bw)
{
/* General */
struct xmit_priv *pxmitpriv;
struct mlme_ext_priv *pmlmeext;
struct mlme_ext_info *pmlmeinfo;
struct xmit_frame *pmgntframe;
/* Beamforming */
struct beamforming_info *info;
struct beamformee_entry *bfee;
struct ndpa_sta_info sta_info;
u8 ActionHdr[4] = {ACT_CAT_VENDOR, 0x00, 0xE0, 0x4C};
/* MISC */
struct pkt_attrib *attrib;
struct rtw_ieee80211_hdr *pwlanhdr;
enum MGN_RATE txrate;
u8 *pframe;
u16 duration = 0;
u8 aSifsTime = 0;
RTW_INFO("+%s: Send to " MAC_FMT "\n", __FUNCTION__, MAC_ARG(ra));
pxmitpriv = &adapter->xmitpriv;
pmlmeext = &adapter->mlmeextpriv;
pmlmeinfo = &pmlmeext->mlmext_info;
bfee = rtw_bf_bfee_get_entry_by_addr(adapter, ra);
if (!bfee) {
RTW_ERR("%s: Cann't find beamformee entry!\n", __FUNCTION__);
return _FALSE;
}
pmgntframe = alloc_mgtxmitframe(pxmitpriv);
if (!pmgntframe) {
RTW_ERR("%s: alloc mgnt frame fail!\n", __FUNCTION__);
return _FALSE;
}
txrate = beamforming_get_htndp_tx_rate(GET_PDM_ODM(adapter), bfee->comp_steering_num_of_bfer);
/* update attribute */
attrib = &pmgntframe->attrib;
update_mgntframe_attrib(adapter, attrib);
/*attrib->type = WIFI_MGT_TYPE;*/ /* set in update_mgntframe_attrib() */
attrib->subtype = WIFI_ACTION_NOACK;
attrib->bwmode = bw;
/*attrib->qsel = QSLT_MGNT;*/ /* set in update_mgntframe_attrib() */
attrib->order = 1;
attrib->rate = (u8)txrate;
attrib->bf_pkt_type = 0;
_rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
/* Frame control */
pwlanhdr->frame_ctl = 0;
set_frame_sub_type(pframe, attrib->subtype);
set_order_bit(pframe);
/* Duration */
if (pmlmeext->cur_wireless_mode == WIRELESS_11B)
aSifsTime = 10;
else
aSifsTime = 16;
duration = 2 * aSifsTime + 40;
if (bw == CHANNEL_WIDTH_40)
duration += 87;
else
duration += 180;
set_duration(pframe, duration);
/* DA */
_rtw_memcpy(pwlanhdr->addr1, ra, ETH_ALEN);
/* SA */
_rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(adapter), ETH_ALEN);
/* BSSID */
_rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&pmlmeinfo->network), ETH_ALEN);
/* HT control field */
SET_HT_CTRL_CSI_STEERING(pframe + 24, 3);
SET_HT_CTRL_NDP_ANNOUNCEMENT(pframe + 24, 1);
/*
* Frame Body
* Category field: vender-specific value, 0x7F
* OUI: 0x00E04C
*/
_rtw_memcpy(pframe + 28, ActionHdr, 4);
attrib->pktlen = 32;
attrib->last_txcmdsz = attrib->pktlen;
dump_mgntframe(adapter, pmgntframe);
return _TRUE;
}
static u8 _send_vht_ndpa_packet(PADAPTER adapter, u8 *ra, u16 aid, enum channel_width bw)
{
/* General */
struct xmit_priv *pxmitpriv;
struct mlme_ext_priv *pmlmeext;
struct xmit_frame *pmgntframe;
/* Beamforming */
struct beamforming_info *info;
struct beamformee_entry *bfee;
struct ndpa_sta_info sta_info;
/* MISC */
struct pkt_attrib *attrib;
struct rtw_ieee80211_hdr *pwlanhdr;
u8 *pframe;
enum MGN_RATE txrate;
u16 duration = 0;
u8 sequence = 0, aSifsTime = 0;
RTW_INFO("+%s: Send to " MAC_FMT "\n", __FUNCTION__, MAC_ARG(ra));
pxmitpriv = &adapter->xmitpriv;
pmlmeext = &adapter->mlmeextpriv;
info = GET_BEAMFORM_INFO(adapter);
bfee = rtw_bf_bfee_get_entry_by_addr(adapter, ra);
if (!bfee) {
RTW_ERR("%s: Cann't find beamformee entry!\n", __FUNCTION__);
return _FALSE;
}
pmgntframe = alloc_mgtxmitframe(pxmitpriv);
if (!pmgntframe) {
RTW_ERR("%s: alloc mgnt frame fail!\n", __FUNCTION__);
return _FALSE;
}
txrate = beamforming_get_vht_ndp_tx_rate(GET_PDM_ODM(adapter), bfee->comp_steering_num_of_bfer);
/* update attribute */
attrib = &pmgntframe->attrib;
update_mgntframe_attrib(adapter, attrib);
/*pattrib->type = WIFI_MGT_TYPE;*/ /* set in update_mgntframe_attrib() */
attrib->subtype = WIFI_NDPA;
attrib->bwmode = bw;
/*attrib->qsel = QSLT_MGNT;*/ /* set in update_mgntframe_attrib() */
attrib->rate = (u8)txrate;
attrib->bf_pkt_type = 0;
_rtw_memset(pmgntframe->buf_addr, 0, TXDESC_OFFSET + WLANHDR_OFFSET);
pframe = pmgntframe->buf_addr + TXDESC_OFFSET;
pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
/* Frame control */
pwlanhdr->frame_ctl = 0;
set_frame_sub_type(pframe, attrib->subtype);
/* Duration */
if (is_supported_5g(pmlmeext->cur_wireless_mode) || is_supported_ht(pmlmeext->cur_wireless_mode))
aSifsTime = 16;
else
aSifsTime = 10;
duration = 2 * aSifsTime + 44;
if (bw == CHANNEL_WIDTH_80)
duration += 40;
else if (bw == CHANNEL_WIDTH_40)
duration += 87;
else
duration += 180;
set_duration(pframe, duration);
/* RA */
_rtw_memcpy(pwlanhdr->addr1, ra, ETH_ALEN);
/* TA */
_rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(adapter), ETH_ALEN);
/* Sounding Sequence, bit0~1 is reserved */
sequence = info->sounding_sequence << 2;
if (info->sounding_sequence >= 0x3f)
info->sounding_sequence = 0;
else
info->sounding_sequence++;
_rtw_memcpy(pframe + 16, &sequence, 1);
/* STA Info */
/*
* "AID12" Equal to 0 if the STA is an AP, mesh STA or
* STA that is a member of an IBSS
*/
if (check_fwstate(&adapter->mlmepriv, WIFI_AP_STATE) == _FALSE)
aid = 0;
sta_info.aid = aid;
/* "Feedback Type" set to 0 for SU */
sta_info.feedback_type = 0;
/* "Nc Index" reserved if the Feedback Type field indicates SU */
sta_info.nc_index = 0;
_rtw_memcpy(pframe + 17, (u8 *)&sta_info, 2);
attrib->pktlen = 19;
attrib->last_txcmdsz = attrib->pktlen;
dump_mgntframe(adapter, pmgntframe);
return _TRUE;
}
static u8 _send_vht_mu_ndpa_packet(PADAPTER adapter, enum channel_width bw)
{
/* General */
struct xmit_priv *pxmitpriv;
struct mlme_ext_priv *pmlmeext;
struct xmit_frame *pmgntframe;
/* Beamforming */
struct beamforming_info *info;
struct sounding_info *sounding;
struct beamformee_entry *bfee;
struct ndpa_sta_info sta_info;
/* MISC */
struct pkt_attrib *attrib;
struct rtw_ieee80211_hdr *pwlanhdr;
enum MGN_RATE txrate;
u8 *pframe;
u8 *ra = NULL;
u16 duration = 0;
u8 sequence = 0, aSifsTime = 0;
u8 i;
RTW_INFO("+%s\n", __FUNCTION__);
pxmitpriv = &adapter->xmitpriv;
pmlmeext = &adapter->mlmeextpriv;
info = GET_BEAMFORM_INFO(adapter);
sounding = &info->sounding_info;
txrate = MGN_VHT2SS_MCS0;
/*
* Fill the first MU BFee entry (STA1) MAC addr to destination address then
* HW will change A1 to broadcast addr.
* 2015.05.28. Suggested by SD1 Chunchu.
*/
bfee = &info->bfee_entry[sounding->mu_sounding_list[0]];
ra = bfee->mac_addr;
pmgntframe = alloc_mgtxmitframe(pxmitpriv);
if (!pmgntframe) {
RTW_ERR("%s: alloc mgnt frame fail!\n", __FUNCTION__);
return _FALSE;
}
/* update attribute */
attrib = &pmgntframe->attrib;
update_mgntframe_attrib(adapter, attrib);
/*attrib->type = WIFI_MGT_TYPE;*/ /* set in update_mgntframe_attrib() */
attrib->subtype = WIFI_NDPA;
attrib->bwmode = bw;
/*attrib->qsel = QSLT_MGNT;*/ /* set in update_mgntframe_attrib() */
attrib->rate = (u8)txrate;
/* Set TxBFPktType of Tx desc to unicast type if there is only one MU STA for HW design */
if (info->sounding_info.candidate_mu_bfee_cnt > 1)
attrib->bf_pkt_type = 1;
else
attrib->bf_pkt_type = 0;
_rtw_memset(pmgntframe->buf_addr, 0, TXDESC_OFFSET + WLANHDR_OFFSET);
pframe = pmgntframe->buf_addr + TXDESC_OFFSET;
pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
/* Frame control */
pwlanhdr->frame_ctl = 0;
set_frame_sub_type(pframe, attrib->subtype);
/* Duration */
if (is_supported_5g(pmlmeext->cur_wireless_mode) || is_supported_ht(pmlmeext->cur_wireless_mode))
aSifsTime = 16;
else
aSifsTime = 10;
duration = 2 * aSifsTime + 44;
if (bw == CHANNEL_WIDTH_80)
duration += 40;
else if (bw == CHANNEL_WIDTH_40)
duration += 87;
else
duration += 180;
set_duration(pframe, duration);
/* RA */
_rtw_memcpy(pwlanhdr->addr1, ra, ETH_ALEN);
/* TA */
_rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(adapter), ETH_ALEN);
/* Sounding Sequence, bit0~1 is reserved */
sequence = info->sounding_sequence << 2;
if (info->sounding_sequence >= 0x3f)
info->sounding_sequence = 0;
else
info->sounding_sequence++;
_rtw_memcpy(pframe + 16, &sequence, 1);
attrib->pktlen = 17;
/*
* Construct STA info. for multiple STAs
* STA Info1, ..., STA Info n
*/
for (i = 0; i < sounding->candidate_mu_bfee_cnt; i++) {
bfee = &info->bfee_entry[sounding->mu_sounding_list[i]];
sta_info.aid = bfee->aid;
sta_info.feedback_type = 1; /* 1'b1: MU */
sta_info.nc_index = 0;
_rtw_memcpy(pframe + attrib->pktlen, (u8 *)&sta_info, 2);
attrib->pktlen += 2;
}
attrib->last_txcmdsz = attrib->pktlen;
dump_mgntframe(adapter, pmgntframe);
return _TRUE;
}
static u8 _send_bf_report_poll(PADAPTER adapter, u8 *ra, u8 bFinalPoll)
{
/* General */
struct xmit_priv *pxmitpriv;
struct xmit_frame *pmgntframe;
/* MISC */
struct pkt_attrib *attrib;
struct rtw_ieee80211_hdr *pwlanhdr;
u8 *pframe;
RTW_INFO("+%s: Send to " MAC_FMT "\n", __FUNCTION__, MAC_ARG(ra));
pxmitpriv = &adapter->xmitpriv;
pmgntframe = alloc_mgtxmitframe(pxmitpriv);
if (!pmgntframe) {
RTW_ERR("%s: alloc mgnt frame fail!\n", __FUNCTION__);
return _FALSE;
}
/* update attribute */
attrib = &pmgntframe->attrib;
update_mgntframe_attrib(adapter, attrib);
/*attrib->type = WIFI_MGT_TYPE;*/ /* set in update_mgntframe_attrib() */
attrib->subtype = WIFI_BF_REPORT_POLL;
attrib->bwmode = CHANNEL_WIDTH_20;
/*attrib->qsel = QSLT_MGNT;*/ /* set in update_mgntframe_attrib() */
attrib->rate = MGN_6M;
if (bFinalPoll)
attrib->bf_pkt_type = 3;
else
attrib->bf_pkt_type = 2;
_rtw_memset(pmgntframe->buf_addr, 0, TXDESC_OFFSET + WLANHDR_OFFSET);
pframe = pmgntframe->buf_addr + TXDESC_OFFSET;
pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
/* Frame control */
pwlanhdr->frame_ctl = 0;
set_frame_sub_type(pframe, attrib->subtype);
/* Duration */
set_duration(pframe, 100);
/* RA */
_rtw_memcpy(pwlanhdr->addr1, ra, ETH_ALEN);
/* TA */
_rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(adapter), ETH_ALEN);
/* Feedback Segment Retransmission Bitmap */
pframe[16] = 0xFF;
attrib->pktlen = 17;
attrib->last_txcmdsz = attrib->pktlen;
dump_mgntframe(adapter, pmgntframe);
return _TRUE;
}
static void _sounding_update_min_period(PADAPTER adapter, u16 period, u8 leave)
{
struct beamforming_info *info;
struct beamformee_entry *bfee;
u8 i = 0;
u16 min_val = 0xFFFF;
info = GET_BEAMFORM_INFO(adapter);
if (_TRUE == leave) {
/*
* When a BFee left,
* we need to find the latest min sounding period
* from the remaining BFees
*/
for (i = 0; i < MAX_BEAMFORMEE_ENTRY_NUM; i++) {
bfee = &info->bfee_entry[i];
if ((bfee->used == _TRUE)
&& (bfee->sound_period < min_val))
min_val = bfee->sound_period;
}
if (min_val == 0xFFFF)
info->sounding_info.min_sounding_period = 0;
else
info->sounding_info.min_sounding_period = min_val;
} else {
if ((info->sounding_info.min_sounding_period == 0)
|| (period < info->sounding_info.min_sounding_period))
info->sounding_info.min_sounding_period = period;
}
}
static void _sounding_init(struct sounding_info *sounding)
{
_rtw_memset(sounding->su_sounding_list, 0xFF, MAX_NUM_BEAMFORMEE_SU);
_rtw_memset(sounding->mu_sounding_list, 0xFF, MAX_NUM_BEAMFORMEE_MU);
sounding->state = SOUNDING_STATE_NONE;
sounding->su_bfee_curidx = 0xFF;
sounding->candidate_mu_bfee_cnt = 0;
sounding->min_sounding_period = 0;
sounding->sound_remain_cnt_per_period = 0;
}
static void _sounding_reset_vars(PADAPTER adapter)
{
struct beamforming_info *info;
struct sounding_info *sounding;
u8 idx;
info = GET_BEAMFORM_INFO(adapter);
sounding = &info->sounding_info;
_rtw_memset(sounding->su_sounding_list, 0xFF, MAX_NUM_BEAMFORMEE_SU);
_rtw_memset(sounding->mu_sounding_list, 0xFF, MAX_NUM_BEAMFORMEE_MU);
sounding->su_bfee_curidx = 0xFF;
sounding->candidate_mu_bfee_cnt = 0;
/* Clear bSound flag for the new period */
for (idx = 0; idx < MAX_BEAMFORMEE_ENTRY_NUM; idx++) {
if ((info->bfee_entry[idx].used == _TRUE)
&& (info->bfee_entry[idx].sounding == _TRUE)) {
info->bfee_entry[idx].sounding = _FALSE;
info->bfee_entry[idx].bCandidateSoundingPeer = _FALSE;
}
}
}
/*
* Return
* 0 Prepare sounding list OK
* -1 Fail to prepare sounding list, because no beamformee need to souding
* -2 Fail to prepare sounding list, because beamformee state not ready
*
*/
static int _sounding_get_list(PADAPTER adapter)
{
struct beamforming_info *info;
struct sounding_info *sounding;
struct beamformee_entry *bfee;
u8 i, mu_idx = 0, su_idx = 0, not_ready = 0;
int ret = 0;
info = GET_BEAMFORM_INFO(adapter);
sounding = &info->sounding_info;
/* Add MU BFee list first because MU priority is higher than SU */
for (i = 0; i < MAX_BEAMFORMEE_ENTRY_NUM; i++) {
bfee = &info->bfee_entry[i];
if (bfee->used == _FALSE)
continue;
if (bfee->state != BEAMFORM_ENTRY_HW_STATE_ADDED) {
RTW_ERR("%s: Invalid BFee idx(%d) Hw state=%d\n", __FUNCTION__, i, bfee->state);
not_ready++;
continue;
}
/*
* Decrease BFee's SoundCnt per period
* If the remain count is 0,
* then it can be sounded at this time
*/
if (bfee->SoundCnt) {
bfee->SoundCnt--;
if (bfee->SoundCnt)
continue;
}
/*
* <tynli_Note>
* If the STA supports MU BFee capability then we add it to MUSoundingList directly
* because we can only sound one STA by unicast NDPA with MU cap enabled to get correct channel info.
* Suggested by BB team Luke Lee. 2015.11.25.
*/
if (bfee->cap & BEAMFORMEE_CAP_VHT_MU) {
/* MU BFee */
if (mu_idx >= MAX_NUM_BEAMFORMEE_MU) {
RTW_ERR("%s: Too much MU bfee entry(Limit:%d)\n", __FUNCTION__, MAX_NUM_BEAMFORMEE_MU);
continue;
}
if (bfee->bApplySounding == _TRUE) {
bfee->bCandidateSoundingPeer = _TRUE;
bfee->SoundCnt = GetInitSoundCnt(bfee->sound_period, sounding->min_sounding_period);
sounding->mu_sounding_list[mu_idx] = i;
mu_idx++;
}
} else if (bfee->cap & (BEAMFORMEE_CAP_VHT_SU|BEAMFORMEE_CAP_HT_EXPLICIT)) {
/* SU BFee (HT/VHT) */
if (su_idx >= MAX_NUM_BEAMFORMEE_SU) {
RTW_ERR("%s: Too much SU bfee entry(Limit:%d)\n", __FUNCTION__, MAX_NUM_BEAMFORMEE_SU);
continue;
}
if (bfee->bDeleteSounding == _TRUE) {
sounding->su_sounding_list[su_idx] = i;
su_idx++;
} else if ((bfee->bApplySounding == _TRUE)
&& (bfee->bSuspendSUCap == _FALSE)) {
bfee->bCandidateSoundingPeer = _TRUE;
bfee->SoundCnt = GetInitSoundCnt(bfee->sound_period, sounding->min_sounding_period);
sounding->su_sounding_list[su_idx] = i;
su_idx++;
}
}
}
sounding->candidate_mu_bfee_cnt = mu_idx;
if (su_idx + mu_idx == 0) {
ret = -1;
if (not_ready)
ret = -2;
}
RTW_INFO("-%s: There are %d SU and %d MU BFees in this sounding period\n", __FUNCTION__, su_idx, mu_idx);
return ret;
}
static void _sounding_handler(PADAPTER adapter)
{
struct beamforming_info *info;
struct sounding_info *sounding;
struct beamformee_entry *bfee;
u8 su_idx, i;
u32 timeout_period = 0;
u8 set_timer = _FALSE;
int ret = 0;
static u16 wait_cnt = 0;
info = GET_BEAMFORM_INFO(adapter);
sounding = &info->sounding_info;
RTW_DBG("+%s: state=%d\n", __FUNCTION__, sounding->state);
if ((sounding->state != SOUNDING_STATE_INIT)
&& (sounding->state != SOUNDING_STATE_SU_SOUNDDOWN)
&& (sounding->state != SOUNDING_STATE_MU_SOUNDDOWN)
&& (sounding->state != SOUNDING_STATE_SOUNDING_TIMEOUT)) {
RTW_WARN("%s: Invalid State(%d) and return!\n", __FUNCTION__, sounding->state);
return;
}
if (sounding->state == SOUNDING_STATE_INIT) {
RTW_INFO("%s: Sounding start\n", __FUNCTION__);
/* Init Var */
_sounding_reset_vars(adapter);
/* Get the sounding list of this sounding period */
ret = _sounding_get_list(adapter);
if (ret == -1) {
wait_cnt = 0;
sounding->state = SOUNDING_STATE_NONE;
RTW_ERR("%s: No BFees found, set to SOUNDING_STATE_NONE\n", __FUNCTION__);
info->sounding_running--;
return;
}
if (ret == -2) {
RTW_WARN("%s: Temporarily cann't find BFee to sounding\n", __FUNCTION__);
if (wait_cnt < 5) {
wait_cnt++;
} else {
wait_cnt = 0;
sounding->state = SOUNDING_STATE_NONE;
RTW_ERR("%s: Wait changing state timeout!! Set to SOUNDING_STATE_NONE\n", __FUNCTION__);
}
info->sounding_running--;
return;
}
if (ret != 0) {
wait_cnt = 0;
RTW_ERR("%s: Unkown state(%d)!\n", __FUNCTION__, ret);
info->sounding_running--;
return;
}
wait_cnt = 0;
if (check_fwstate(&adapter->mlmepriv, WIFI_UNDER_SURVEY) == _TRUE) {
RTW_INFO("%s: Sounding abort! scanning APs...\n", __FUNCTION__);
info->sounding_running--;
return;
}
rtw_ps_deny(adapter, PS_DENY_BEAMFORMING);
LeaveAllPowerSaveModeDirect(adapter);
}
/* Get non-sound SU BFee index */
for (i = 0; i < MAX_NUM_BEAMFORMEE_SU; i++) {
su_idx = sounding->su_sounding_list[i];
if (su_idx >= MAX_BEAMFORMEE_ENTRY_NUM)
continue;
bfee = &info->bfee_entry[su_idx];
if (_FALSE == bfee->sounding)
break;
}
if (i < MAX_NUM_BEAMFORMEE_SU) {
sounding->su_bfee_curidx = su_idx;
/* Set to sounding start state */
sounding->state = SOUNDING_STATE_SU_START;
RTW_DBG("%s: Set to SOUNDING_STATE_SU_START\n", __FUNCTION__);
bfee->sounding = _TRUE;
/* Reset sounding timeout flag for the new sounding */
bfee->bSoundingTimeout = _FALSE;
if (_TRUE == bfee->bDeleteSounding) {
u8 res = _FALSE;
rtw_bf_cmd(adapter, BEAMFORMING_CTRL_END_PERIOD, &res, 1, 0);
return;
}
/* Start SU sounding */
if (bfee->cap & BEAMFORMEE_CAP_VHT_SU)
_send_vht_ndpa_packet(adapter, bfee->mac_addr, bfee->aid, bfee->sound_bw);
else if (bfee->cap & BEAMFORMEE_CAP_HT_EXPLICIT)
_send_ht_ndpa_packet(adapter, bfee->mac_addr, bfee->sound_bw);
/* Set sounding timeout timer */
_set_timer(&info->sounding_timeout_timer, SU_SOUNDING_TIMEOUT);
return;
}
if (sounding->candidate_mu_bfee_cnt > 0) {
/*
* If there is no SU BFee then find MU BFee and perform MU sounding
*
* <tynli_note> Need to check the MU starting condition. 2015.12.15.
*/
sounding->state = SOUNDING_STATE_MU_START;
RTW_DBG("%s: Set to SOUNDING_STATE_MU_START\n", __FUNCTION__);
/* Update MU BFee info */
for (i = 0; i < sounding->candidate_mu_bfee_cnt; i++) {
bfee = &info->bfee_entry[sounding->mu_sounding_list[i]];
bfee->sounding = _TRUE;
}
/* Send MU NDPA */
bfee = &info->bfee_entry[sounding->mu_sounding_list[0]];
_send_vht_mu_ndpa_packet(adapter, bfee->sound_bw);
/* Send BF report poll if more than 1 MU STA */
for (i = 1; i < sounding->candidate_mu_bfee_cnt; i++) {
bfee = &info->bfee_entry[sounding->mu_sounding_list[i]];
if (i == (sounding->candidate_mu_bfee_cnt - 1))/* The last STA*/
_send_bf_report_poll(adapter, bfee->mac_addr, _TRUE);
else
_send_bf_report_poll(adapter, bfee->mac_addr, _FALSE);
}
sounding->candidate_mu_bfee_cnt = 0;
/* Set sounding timeout timer */
_set_timer(&info->sounding_timeout_timer, MU_SOUNDING_TIMEOUT);
return;
}
info->sounding_running--;
sounding->state = SOUNDING_STATE_INIT;
RTW_INFO("%s: Sounding finished!\n", __FUNCTION__);
rtw_ps_deny_cancel(adapter, PS_DENY_BEAMFORMING);
}
static void _sounding_force_stop(PADAPTER adapter)
{
struct beamforming_info *info;
struct sounding_info *sounding;
info = GET_BEAMFORM_INFO(adapter);
sounding = &info->sounding_info;
if ((sounding->state == SOUNDING_STATE_SU_START)
|| (sounding->state == SOUNDING_STATE_MU_START)) {
u8 res = _FALSE;
_cancel_timer_ex(&info->sounding_timeout_timer);
rtw_bf_cmd(adapter, BEAMFORMING_CTRL_END_PERIOD, &res, 1, 1);
return;
}
info->sounding_running--;
sounding->state = SOUNDING_STATE_INIT;
RTW_INFO("%s: Sounding finished!\n", __FUNCTION__);
rtw_ps_deny_cancel(adapter, PS_DENY_BEAMFORMING);
}
static void _sounding_timer_handler(void *FunctionContext)
{
PADAPTER adapter;
struct beamforming_info *info;
struct sounding_info *sounding;
static u8 delay = 0;
RTW_DBG("+%s\n", __FUNCTION__);
adapter = (PADAPTER)FunctionContext;
info = GET_BEAMFORM_INFO(adapter);
sounding = &info->sounding_info;
if (SOUNDING_STATE_NONE == sounding->state) {
RTW_INFO("%s: Stop!\n", __FUNCTION__);
if (info->sounding_running)
RTW_WARN("%s: souding_running=%d when thread stop!\n",
__FUNCTION__, info->sounding_running);
return;
}
_set_timer(&info->sounding_timer, sounding->min_sounding_period);
if (!info->sounding_running) {
if (SOUNDING_STATE_INIT != sounding->state) {
RTW_WARN("%s: state(%d) != SOUNDING_STATE_INIT!!\n", __FUNCTION__, sounding->state);
sounding->state = SOUNDING_STATE_INIT;
}
delay = 0;
info->sounding_running++;
rtw_bf_cmd(adapter, BEAMFORMING_CTRL_START_PERIOD, NULL, 0, 1);
} else {
if (delay != 0xFF)
delay++;
RTW_WARN("%s: souding is still processing...(state:%d, running:%d, delay:%d)\n",
__FUNCTION__, sounding->state, info->sounding_running, delay);
if (delay > 3) {
RTW_WARN("%s: Stop sounding!!\n", __FUNCTION__);
_sounding_force_stop(adapter);
}
}
}
static void _sounding_timeout_timer_handler(void *FunctionContext)
{
PADAPTER adapter;
struct beamforming_info *info;
struct sounding_info *sounding;