SAMA5D4 Xplained Ultra Board BSP
guowenxue
2019-08-19 2e7235d10c6dbff81960282e1a1e2e798f9b8db8
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
/* ************************************************************
 * Description:
 *
 * This file is for TXBF interface mechanism
 *
 * ************************************************************ */
#include "mp_precomp.h"
#include "../phydm_precomp.h"
 
#if (BEAMFORMING_SUPPORT == 1)
#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
void
beamforming_gid_paid(
    struct _ADAPTER    *adapter,
    PRT_TCB        p_tcb
)
{
    u8        idx = 0;
    u8        RA[6] = {0};
    u8        *p_header = GET_FRAME_OF_FIRST_FRAG(adapter, p_tcb);
    HAL_DATA_TYPE            *p_hal_data = GET_HAL_DATA(adapter);
    struct PHY_DM_STRUCT                *p_dm_odm = &p_hal_data->DM_OutSrc;
    struct _RT_BEAMFORMING_INFO    *p_beam_info = &(p_dm_odm->beamforming_info);
 
    if (adapter->HardwareType < HARDWARE_TYPE_RTL8192EE)
        return;
    else if (IS_WIRELESS_MODE_N(adapter) == false)
        return;
 
#if (SUPPORT_MU_BF == 1)
    if (p_tcb->tx_bf_pkt_type == RT_BF_PKT_TYPE_BROADCAST_NDPA) { /* MU NDPA */
#else
    if (0) {
#endif
        /* Fill G_ID and P_AID */
        p_tcb->G_ID = 63;
        if (p_beam_info->first_mu_bfee_index < BEAMFORMEE_ENTRY_NUM) {
            p_tcb->P_AID = p_beam_info->beamformee_entry[p_beam_info->first_mu_bfee_index].p_aid;
            RT_DISP(FBEAM, FBEAM_FUN, ("[David]@%s End, G_ID=0x%X, P_AID=0x%X\n", __func__, p_tcb->G_ID, p_tcb->P_AID));
        }
    } else {
        GET_80211_HDR_ADDRESS1(p_header, &RA);
 
        /* VHT SU PPDU carrying one or more group addressed MPDUs or */
        /* Transmitting a VHT NDP intended for multiple recipients */
        if (MacAddr_isBcst(RA) || MacAddr_isMulticast(RA)    || p_tcb->macId == MAC_ID_STATIC_FOR_BROADCAST_MULTICAST) {
            p_tcb->G_ID = 63;
            p_tcb->P_AID = 0;
        } else if (ACTING_AS_AP(adapter)) {
            u16    AID = (u16)(MacIdGetOwnerAssociatedClientAID(adapter, p_tcb->macId) & 0x1ff);        /*AID[0:8]*/
 
            /*RT_DISP(FBEAM, FBEAM_FUN, ("@%s  p_tcb->mac_id=0x%X, AID=0x%X\n", __func__, p_tcb->mac_id, AID));*/
            p_tcb->G_ID = 63;
 
            if (AID == 0)        /*A PPDU sent by an AP to a non associated STA*/
                p_tcb->P_AID = 0;
            else {                /*Sent by an AP and addressed to a STA associated with that AP*/
                u16    BSSID = 0;
                GET_80211_HDR_ADDRESS2(p_header, &RA);
                BSSID = ((RA[5] & 0xf0) >> 4) ^ (RA[5] & 0xf);    /*BSSID[44:47] xor BSSID[40:43]*/
                p_tcb->P_AID = (AID + BSSID * 32) & 0x1ff;        /*(dec(A) + dec(B)*32) mod 512*/
            }
        } else if (ACTING_AS_IBSS(adapter)) {
            p_tcb->G_ID = 63;
            /*P_AID for infrasturcture mode; MACID for ad-hoc mode. */
            p_tcb->P_AID = p_tcb->macId;
        } else if (MgntLinkStatusQuery(adapter)) {                /*Addressed to AP*/
            p_tcb->G_ID = 0;
            GET_80211_HDR_ADDRESS1(p_header, &RA);
            p_tcb->P_AID =  RA[5];                            /*RA[39:47]*/
            p_tcb->P_AID = (p_tcb->P_AID << 1) | (RA[4] >> 7);
        } else {
            p_tcb->G_ID = 63;
            p_tcb->P_AID = 0;
        }
        /*RT_DISP(FBEAM, FBEAM_FUN, ("[David]@%s End, G_ID=0x%X, P_AID=0x%X\n", __func__, p_tcb->G_ID, p_tcb->P_AID));*/
    }
}
 
 
enum rt_status
beamforming_get_report_frame(
    struct _ADAPTER        *adapter,
    PRT_RFD            p_rfd,
    POCTET_STRING    p_pdu_os
)
{
    HAL_DATA_TYPE                *p_hal_data = GET_HAL_DATA(adapter);
    struct PHY_DM_STRUCT                    *p_dm_odm = &p_hal_data->DM_OutSrc;
    struct _RT_BEAMFORMEE_ENTRY        *p_beamform_entry = NULL;
    u8                        *p_mimo_ctrl_field, p_csi_report, p_csi_matrix;
    u8                        idx, nc, nr, CH_W;
    u16                        csi_matrix_len = 0;
 
    ACT_PKT_TYPE                pkt_type = ACT_PKT_TYPE_UNKNOWN;
 
    /* Memory comparison to see if CSI report is the same with previous one */
    p_beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(p_dm_odm, Frame_Addr2(*p_pdu_os), &idx);
 
    if (p_beamform_entry == NULL) {
        ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("beamforming_get_report_frame: Cannot find entry by addr\n"));
        return RT_STATUS_FAILURE;
    }
 
    pkt_type = PacketGetActionFrameType(p_pdu_os);
 
    /* -@ Modified by David */
    if (pkt_type == ACT_PKT_VHT_COMPRESSED_BEAMFORMING) {
        p_mimo_ctrl_field = p_pdu_os->Octet + 26;
        nc = ((*p_mimo_ctrl_field) & 0x7) + 1;
        nr = (((*p_mimo_ctrl_field) & 0x38) >> 3) + 1;
        CH_W = (((*p_mimo_ctrl_field) & 0xC0) >> 6);
        /*p_csi_matrix = p_mimo_ctrl_field + 3 + nc;*/ /* 24+(1+1+3)+2  MAC header+(Category+ActionCode+MIMOControlField) +SNR(nc=2) */
        csi_matrix_len = p_pdu_os->Length  - 26 - 3 - nc;
    } else if (pkt_type == ACT_PKT_HT_COMPRESSED_BEAMFORMING) {
        p_mimo_ctrl_field = p_pdu_os->Octet + 26;
        nc = ((*p_mimo_ctrl_field) & 0x3) + 1;
        nr = (((*p_mimo_ctrl_field) & 0xC) >> 2) + 1;
        CH_W = (((*p_mimo_ctrl_field) & 0x10) >> 4);
        /*p_csi_matrix = p_mimo_ctrl_field + 6 + nr;*/    /* 24+(1+1+6)+2  MAC header+(Category+ActionCode+MIMOControlField) +SNR(nc=2) */
        csi_matrix_len = p_pdu_os->Length  - 26 - 6 - nr;
    } else
        return RT_STATUS_SUCCESS;
 
    ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] idx=%d, pkt type=%d, nc=%d, nr=%d, CH_W=%d\n", __func__, idx, pkt_type, nc, nr, CH_W));
 
    return RT_STATUS_SUCCESS;
}
 
 
void
construct_ht_ndpa_packet(
    struct _ADAPTER        *adapter,
    u8            *RA,
    u8            *buffer,
    u32            *p_length,
    CHANNEL_WIDTH    BW
)
{
    u16                    duration = 0;
    PMGNT_INFO                p_mgnt_info = &(adapter->MgntInfo);
    OCTET_STRING            p_ndpa_frame, action_content;
    u8                    action_hdr[4] = {ACT_CAT_VENDOR, 0x00, 0xe0, 0x4c};
 
    PlatformZeroMemory(buffer, 32);
 
    SET_80211_HDR_FRAME_CONTROL(buffer, 0);
 
    SET_80211_HDR_ORDER(buffer, 1);
    SET_80211_HDR_TYPE_AND_SUBTYPE(buffer, Type_Action_No_Ack);
 
    SET_80211_HDR_ADDRESS1(buffer, RA);
    SET_80211_HDR_ADDRESS2(buffer, adapter->CurrentAddress);
    SET_80211_HDR_ADDRESS3(buffer, p_mgnt_info->Bssid);
 
    duration = 2 * a_SifsTime + 40;
 
    if (BW == CHANNEL_WIDTH_40)
        duration += 87;
    else
        duration += 180;
 
    SET_80211_HDR_DURATION(buffer, duration);
 
    /* HT control field */
    SET_HT_CTRL_CSI_STEERING(buffer + sMacHdrLng, 3);
    SET_HT_CTRL_NDP_ANNOUNCEMENT(buffer + sMacHdrLng, 1);
 
    FillOctetString(p_ndpa_frame, buffer, sMacHdrLng + sHTCLng);
 
    FillOctetString(action_content, action_hdr, 4);
    PacketAppendData(&p_ndpa_frame, action_content);
 
    *p_length = 32;
}
 
 
 
 
bool
send_fw_ht_ndpa_packet(
    void            *p_dm_void,
    u8            *RA,
    CHANNEL_WIDTH    BW
)
{
    struct PHY_DM_STRUCT                *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
    struct _ADAPTER                *adapter = p_dm_odm->adapter;
    PRT_TCB                p_tcb;
    PRT_TX_LOCAL_BUFFER    p_buf;
    bool                ret = true;
    u32                    buf_len;
    u8                    *buf_addr;
    u8                    desc_len = 0, idx = 0, ndp_tx_rate;
    struct _ADAPTER                *p_def_adapter = GetDefaultAdapter(adapter);
    struct _RT_BEAMFORMING_INFO    *p_beam_info = &p_dm_odm->beamforming_info;
    HAL_DATA_TYPE            *p_hal_data = GET_HAL_DATA(adapter);
    struct _RT_BEAMFORMEE_ENTRY    *p_beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(p_dm_odm, RA, &idx);
 
    ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] Start!\n", __func__));
 
    if (p_beamform_entry == NULL)
        return false;
 
    ndp_tx_rate = beamforming_get_htndp_tx_rate(p_dm_odm, p_beamform_entry->comp_steering_num_of_bfer);
    ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] ndp_tx_rate =%d\n", __func__, ndp_tx_rate));
    PlatformAcquireSpinLock(adapter, RT_TX_SPINLOCK);
 
    if (MgntGetFWBuffer(p_def_adapter, &p_tcb, &p_buf)) {
#if (DEV_BUS_TYPE != RT_PCI_INTERFACE)
        desc_len = adapter->HWDescHeadLength - p_hal_data->USBALLDummyLength;
#endif
        buf_addr = p_buf->Buffer.VirtualAddress + desc_len;
 
        construct_ht_ndpa_packet(
            adapter,
            RA,
            buf_addr,
            &buf_len,
            BW
        );
 
        p_tcb->PacketLength = buf_len + desc_len;
 
        p_tcb->bTxEnableSwCalcDur = true;
 
        p_tcb->BWOfPacket = BW;
 
        if (ACTING_AS_IBSS(adapter) || ACTING_AS_AP(adapter))
            p_tcb->G_ID = 63;
 
        p_tcb->P_AID = p_beamform_entry->p_aid;
        p_tcb->DataRate = ndp_tx_rate;    /*rate of NDP decide by nr*/
 
        adapter->HalFunc.CmdSendPacketHandler(adapter, p_tcb, p_buf, p_tcb->PacketLength, DESC_PACKET_TYPE_NORMAL, false);
    } else
        ret = false;
 
    PlatformReleaseSpinLock(adapter, RT_TX_SPINLOCK);
 
    if (ret)
        RT_DISP_DATA(FBEAM, FBEAM_DATA, "", p_buf->Buffer.VirtualAddress, p_tcb->PacketLength);
 
    return ret;
}
 
 
bool
send_sw_ht_ndpa_packet(
    void            *p_dm_void,
    u8            *RA,
    CHANNEL_WIDTH    BW
)
{
    struct PHY_DM_STRUCT                *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
    struct _ADAPTER                *adapter = p_dm_odm->adapter;
    PRT_TCB                    p_tcb;
    PRT_TX_LOCAL_BUFFER        p_buf;
    bool                    ret = true;
    u8                    idx = 0, ndp_tx_rate = 0;
    struct _RT_BEAMFORMING_INFO    *p_beam_info = &p_dm_odm->beamforming_info;
    struct _RT_BEAMFORMEE_ENTRY    *p_beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(p_dm_odm, RA, &idx);
 
    ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] Start!\n", __func__));
 
    ndp_tx_rate = beamforming_get_htndp_tx_rate(p_dm_odm, p_beamform_entry->comp_steering_num_of_bfer);
    ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] ndp_tx_rate =%d\n", __func__, ndp_tx_rate));
 
    PlatformAcquireSpinLock(adapter, RT_TX_SPINLOCK);
 
    if (MgntGetBuffer(adapter, &p_tcb, &p_buf)) {
        construct_ht_ndpa_packet(
            adapter,
            RA,
            p_buf->Buffer.VirtualAddress,
            &p_tcb->PacketLength,
            BW
        );
 
        p_tcb->bTxEnableSwCalcDur = true;
 
        p_tcb->BWOfPacket = BW;
 
        MgntSendPacket(adapter, p_tcb, p_buf, p_tcb->PacketLength, NORMAL_QUEUE, ndp_tx_rate);
    } else
        ret = false;
 
    PlatformReleaseSpinLock(adapter, RT_TX_SPINLOCK);
 
    if (ret)
        RT_DISP_DATA(FBEAM, FBEAM_DATA, "", p_buf->Buffer.VirtualAddress, p_tcb->PacketLength);
 
    return ret;
}
 
 
 
void
construct_vht_ndpa_packet(
    struct PHY_DM_STRUCT    *p_dm_odm,
    u8            *RA,
    u16            AID,
    u8            *buffer,
    u32            *p_length,
    CHANNEL_WIDTH    BW
)
{
    u16                    duration = 0;
    u8                    sequence = 0;
    u8                    *p_ndpa_frame = buffer;
    struct _RT_NDPA_STA_INFO        sta_info;
    struct _ADAPTER                *adapter = p_dm_odm->adapter;
    u8    idx = 0;
    struct _RT_BEAMFORMEE_ENTRY    *p_beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(p_dm_odm, RA, &idx);
    /* Frame control. */
    SET_80211_HDR_FRAME_CONTROL(p_ndpa_frame, 0);
    SET_80211_HDR_TYPE_AND_SUBTYPE(p_ndpa_frame, Type_NDPA);
 
    SET_80211_HDR_ADDRESS1(p_ndpa_frame, RA);
    SET_80211_HDR_ADDRESS2(p_ndpa_frame, p_beamform_entry->my_mac_addr);
 
    duration = 2 * a_SifsTime + 44;
 
    if (BW == CHANNEL_WIDTH_80)
        duration += 40;
    else if (BW == CHANNEL_WIDTH_40)
        duration += 87;
    else
        duration += 180;
 
    SET_80211_HDR_DURATION(p_ndpa_frame, duration);
 
    sequence = *(p_dm_odm->p_sounding_seq) << 2;
    odm_move_memory(p_dm_odm, p_ndpa_frame + 16, &sequence, 1);
 
    if (phydm_acting_determine(p_dm_odm, phydm_acting_as_ibss) || phydm_acting_determine(p_dm_odm, phydm_acting_as_ap) == false)
        AID = 0;
 
    sta_info.aid = AID;
    sta_info.feedback_type = 0;
    sta_info.nc_index = 0;
 
    odm_move_memory(p_dm_odm, p_ndpa_frame + 17, (u8 *)&sta_info, 2);
 
    *p_length = 19;
}
 
 
bool
send_fw_vht_ndpa_packet(
    void            *p_dm_void,
    u8            *RA,
    u16            AID,
    CHANNEL_WIDTH    BW
)
{
    struct PHY_DM_STRUCT                *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
    struct _ADAPTER                *adapter = p_dm_odm->adapter;
    PRT_TCB                    p_tcb;
    PRT_TX_LOCAL_BUFFER        p_buf;
    bool                    ret = true;
    u32                    buf_len;
    u8                    *buf_addr;
    u8                    desc_len = 0, idx = 0, ndp_tx_rate = 0;
    struct _ADAPTER                *p_def_adapter = GetDefaultAdapter(adapter);
    struct _RT_BEAMFORMING_INFO    *p_beam_info = &p_dm_odm->beamforming_info;
    HAL_DATA_TYPE            *p_hal_data = GET_HAL_DATA(adapter);
    struct _RT_BEAMFORMEE_ENTRY    *p_beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(p_dm_odm, RA, &idx);
 
    ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] Start!\n", __func__));
 
    if (p_beamform_entry == NULL)
        return false;
 
    ndp_tx_rate = beamforming_get_vht_ndp_tx_rate(p_dm_odm, p_beamform_entry->comp_steering_num_of_bfer);
    ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] ndp_tx_rate =%d\n", __func__, ndp_tx_rate));
 
    PlatformAcquireSpinLock(adapter, RT_TX_SPINLOCK);
 
    if (MgntGetFWBuffer(p_def_adapter, &p_tcb, &p_buf)) {
#if (DEV_BUS_TYPE != RT_PCI_INTERFACE)
        desc_len = adapter->HWDescHeadLength - p_hal_data->USBALLDummyLength;
#endif
        buf_addr = p_buf->Buffer.VirtualAddress + desc_len;
 
        construct_vht_ndpa_packet(
            p_dm_odm,
            RA,
            AID,
            buf_addr,
            &buf_len,
            BW
        );
 
        p_tcb->PacketLength = buf_len + desc_len;
 
        p_tcb->bTxEnableSwCalcDur = true;
 
        p_tcb->BWOfPacket = BW;
 
        if (phydm_acting_determine(p_dm_odm, phydm_acting_as_ibss) || phydm_acting_determine(p_dm_odm, phydm_acting_as_ap))
            p_tcb->G_ID = 63;
 
        p_tcb->P_AID = p_beamform_entry->p_aid;
        p_tcb->DataRate = ndp_tx_rate;    /*decide by nr*/
 
        adapter->HalFunc.CmdSendPacketHandler(adapter, p_tcb, p_buf, p_tcb->PacketLength, DESC_PACKET_TYPE_NORMAL, false);
    } else
        ret = false;
 
    PlatformReleaseSpinLock(adapter, RT_TX_SPINLOCK);
 
    ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] End, ret=%d\n", __func__, ret));
 
    if (ret)
        RT_DISP_DATA(FBEAM, FBEAM_DATA, "", p_buf->Buffer.VirtualAddress, p_tcb->PacketLength);
 
    return ret;
}
 
 
 
bool
send_sw_vht_ndpa_packet(
    void            *p_dm_void,
    u8            *RA,
    u16            AID,
    CHANNEL_WIDTH    BW
)
{
    struct PHY_DM_STRUCT                *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
    struct _ADAPTER                *adapter = p_dm_odm->adapter;
    PRT_TCB                    p_tcb;
    PRT_TX_LOCAL_BUFFER        p_buf;
    bool                    ret = true;
    u8                    idx = 0, ndp_tx_rate = 0;
    struct _RT_BEAMFORMING_INFO    *p_beam_info = &(p_dm_odm->beamforming_info);
    struct _RT_BEAMFORMEE_ENTRY    *p_beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(p_dm_odm, RA, &idx);
 
    ndp_tx_rate = beamforming_get_vht_ndp_tx_rate(p_dm_odm, p_beamform_entry->comp_steering_num_of_bfer);
    ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] ndp_tx_rate =%d\n", __func__, ndp_tx_rate));
 
    PlatformAcquireSpinLock(adapter, RT_TX_SPINLOCK);
 
    if (MgntGetBuffer(adapter, &p_tcb, &p_buf)) {
        construct_vht_ndpa_packet(
            p_dm_odm,
            RA,
            AID,
            p_buf->Buffer.VirtualAddress,
            &p_tcb->PacketLength,
            BW
        );
 
        p_tcb->bTxEnableSwCalcDur = true;
        p_tcb->BWOfPacket = BW;
 
        /*rate of NDP decide by nr*/
        MgntSendPacket(adapter, p_tcb, p_buf, p_tcb->PacketLength, NORMAL_QUEUE, ndp_tx_rate);
    } else
        ret = false;
 
    PlatformReleaseSpinLock(adapter, RT_TX_SPINLOCK);
 
    if (ret)
        RT_DISP_DATA(FBEAM, FBEAM_DATA, "", p_buf->Buffer.VirtualAddress, p_tcb->PacketLength);
 
    return ret;
}
 
#ifdef SUPPORT_MU_BF
#if (SUPPORT_MU_BF == 1)
/*
 * Description: On VHT GID management frame by an MU beamformee.
 *
 * 2015.05.20. Created by tynli.
 */
enum rt_status
beamforming_get_vht_gid_mgnt_frame(
    struct _ADAPTER        *adapter,
    PRT_RFD            p_rfd,
    POCTET_STRING    p_pdu_os
)
{
    HAL_DATA_TYPE    *p_hal_data = GET_HAL_DATA(adapter);
    struct PHY_DM_STRUCT        *p_dm_odm = &p_hal_data->DM_OutSrc;
    enum rt_status        rt_status = RT_STATUS_SUCCESS;
    u8            *p_buffer = NULL;
    u8            *p_raddr = NULL;
    u8            mem_status[8] = {0}, user_pos[16] = {0};
    u8            idx;
    struct _RT_BEAMFORMING_INFO    *p_beam_info = &(p_dm_odm->beamforming_info);
    struct _RT_BEAMFORMER_ENTRY    *p_beamform_entry = &p_beam_info->beamformer_entry[p_beam_info->mu_ap_index];
 
    ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] On VHT GID mgnt frame!\n", __func__));
 
    /* Check length*/
    if (p_pdu_os->length < (FRAME_OFFSET_VHT_GID_MGNT_USER_POSITION_ARRAY + 16)) {
        ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("beamforming_get_vht_gid_mgnt_frame(): Invalid length (%d)\n", p_pdu_os->length));
        return RT_STATUS_INVALID_LENGTH;
    }
 
    /* Check RA*/
    p_raddr = (u8 *)(p_pdu_os->Octet) + 4;
    if (!eq_mac_addr(p_raddr, adapter->CurrentAddress)) {
        ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("beamforming_get_vht_gid_mgnt_frame(): Drop because of RA error.\n"));
        return RT_STATUS_PKT_DROP;
    }
 
    RT_DISP_DATA(FBEAM, FBEAM_DATA, "On VHT GID Mgnt Frame ==>:\n", p_pdu_os->Octet, p_pdu_os->length);
 
    /*Parsing Membership status array*/
    p_buffer = p_pdu_os->Octet + FRAME_OFFSET_VHT_GID_MGNT_MEMBERSHIP_STATUS_ARRAY;
    for (idx = 0; idx < 8; idx++) {
        mem_status[idx] = GET_VHT_GID_MGNT_INFO_MEMBERSHIP_STATUS(p_buffer + idx);
        p_beamform_entry->gid_valid[idx] = GET_VHT_GID_MGNT_INFO_MEMBERSHIP_STATUS(p_buffer + idx);
    }
 
    RT_DISP_DATA(FBEAM, FBEAM_DATA, "mem_status: ", mem_status, 8);
 
    /* Parsing User Position array*/
    p_buffer = p_pdu_os->Octet + FRAME_OFFSET_VHT_GID_MGNT_USER_POSITION_ARRAY;
    for (idx = 0; idx < 16; idx++) {
        user_pos[idx] = GET_VHT_GID_MGNT_INFO_USER_POSITION(p_buffer + idx);
        p_beamform_entry->user_position[idx] = GET_VHT_GID_MGNT_INFO_USER_POSITION(p_buffer + idx);
    }
 
    RT_DISP_DATA(FBEAM, FBEAM_DATA, "user_pos: ", user_pos, 16);
 
    /* Group ID detail printed*/
    {
        u8    i, j;
        u8    tmp_val;
        u16    tmp_val2;
 
        for (i = 0; i < 8; i++) {
            tmp_val = mem_status[i];
            tmp_val2 = ((user_pos[i * 2 + 1] << 8) & 0xFF00) + (user_pos[i * 2] & 0xFF);
            for (j = 0; j < 8; j++) {
                if ((tmp_val >> j) & BIT(0)) {
                    ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("Use Group ID (%d), User Position (%d)\n",
                        (i * 8 + j), (tmp_val2 >> 2 * j) & 0x3));
                }
            }
        }
    }
 
    /* Indicate GID frame to IHV service. */
    {
        u8    indibuffer[24] = {0};
        u8    indioffset = 0;
 
        PlatformMoveMemory(indibuffer + indioffset, p_beamform_entry->gid_valid, 8);
        indioffset += 8;
        PlatformMoveMemory(indibuffer + indioffset, p_beamform_entry->user_position, 16);
        indioffset += 16;
 
        PlatformIndicateCustomStatus(
            adapter,
            RT_CUSTOM_EVENT_VHT_RECV_GID_MGNT_FRAME,
            RT_CUSTOM_INDI_TARGET_IHV,
            indibuffer,
            indioffset);
    }
 
    /* Config HW GID table */
    hal_com_txbf_config_gtab(p_dm_odm);
 
    return rt_status;
}
 
/*
 * Description: Construct VHT Group ID (GID) management frame.
 *
 * 2015.05.20. Created by tynli.
 */
void
construct_vht_gid_mgnt_frame(
    struct PHY_DM_STRUCT        *p_dm_odm,
    u8            *RA,
    struct _RT_BEAMFORMEE_ENTRY    *p_beamform_entry,
    u8            *buffer,
    u32            *p_length
 
)
{
    struct _RT_BEAMFORMING_INFO    *p_beam_info = &(p_dm_odm->beamforming_info);
    struct _ADAPTER                *adapter = p_beam_info->source_adapter;
    OCTET_STRING        os_ftm_frame, tmp;
 
    FillOctetString(os_ftm_frame, buffer, 0);
    *p_length = 0;
 
    ConstructMaFrameHdr(
        adapter,
        RA,
        ACT_CAT_VHT,
        ACT_VHT_GROUPID_MANAGEMENT,
        &os_ftm_frame);
 
    /* Membership status array*/
    FillOctetString(tmp, p_beamform_entry->gid_valid, 8);
    PacketAppendData(&os_ftm_frame, tmp);
 
    /* User Position array*/
    FillOctetString(tmp, p_beamform_entry->user_position, 16);
    PacketAppendData(&os_ftm_frame, tmp);
 
    *p_length = os_ftm_frame.length;
 
    RT_DISP_DATA(FBEAM, FBEAM_DATA, "construct_vht_gid_mgnt_frame():\n", buffer, *p_length);
}
 
bool
send_sw_vht_gid_mgnt_frame(
    void            *p_dm_void,
    u8            *RA,
    u8            idx
)
{
    struct PHY_DM_STRUCT                *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
    PRT_TCB                    p_tcb;
    PRT_TX_LOCAL_BUFFER        p_buf;
    bool                    ret = true;
    u8                    data_rate = 0;
    struct _RT_BEAMFORMING_INFO    *p_beam_info = &(p_dm_odm->beamforming_info);
    struct _RT_BEAMFORMEE_ENTRY    *p_beamform_entry = &p_beam_info->beamformee_entry[idx];
    struct _ADAPTER                *adapter = p_beam_info->source_adapter;
 
    ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] Start!\n", __func__));
 
    PlatformAcquireSpinLock(adapter, RT_TX_SPINLOCK);
 
    if (MgntGetBuffer(adapter, &p_tcb, &p_buf)) {
        construct_vht_gid_mgnt_frame(
            p_dm_odm,
            RA,
            p_beamform_entry,
            p_buf->Buffer.VirtualAddress,
            &p_tcb->PacketLength
        );
 
        p_tcb->bw_of_packet = CHANNEL_WIDTH_20;
        data_rate = MGN_6M;
        MgntSendPacket(adapter, p_tcb, p_buf, p_tcb->PacketLength, NORMAL_QUEUE, data_rate);
    } else
        ret = false;
 
    PlatformReleaseSpinLock(adapter, RT_TX_SPINLOCK);
 
    if (ret)
        RT_DISP_DATA(FBEAM, FBEAM_DATA, "", p_buf->Buffer.VirtualAddress, p_tcb->PacketLength);
 
    return ret;
}
 
 
/*
 * Description: Construct VHT beamforming report poll.
 *
 * 2015.05.20. Created by tynli.
 */
void
construct_vht_bf_report_poll(
    struct PHY_DM_STRUCT        *p_dm_odm,
    u8            *RA,
    u8            *buffer,
    u32            *p_length
)
{
    struct _RT_BEAMFORMING_INFO    *p_beam_info = &(p_dm_odm->beamforming_info);
    struct _ADAPTER                *adapter = p_beam_info->source_adapter;
    u8            *p_bf_rpt_poll = buffer;
 
    /* Frame control*/
    SET_80211_HDR_FRAME_CONTROL(p_bf_rpt_poll, 0);
    SET_80211_HDR_TYPE_AND_SUBTYPE(p_bf_rpt_poll, Type_Beamforming_Report_Poll);
 
    /* duration*/
    SET_80211_HDR_DURATION(p_bf_rpt_poll, 100);
 
    /* RA*/
    SET_VHT_BF_REPORT_POLL_RA(p_bf_rpt_poll, RA);
 
    /* TA*/
    SET_VHT_BF_REPORT_POLL_TA(p_bf_rpt_poll, adapter->CurrentAddress);
 
    /* Feedback Segment Retransmission Bitmap*/
    SET_VHT_BF_REPORT_POLL_FEEDBACK_SEG_RETRAN_BITMAP(p_bf_rpt_poll, 0xFF);
 
    *p_length = 17;
 
    RT_DISP_DATA(FBEAM, FBEAM_DATA, "construct_vht_bf_report_poll():\n", buffer, *p_length);
 
}
 
bool
send_sw_vht_bf_report_poll(
    void            *p_dm_void,
    u8            *RA,
    bool            is_final_poll
)
{
    struct PHY_DM_STRUCT                *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
    PRT_TCB                    p_tcb;
    PRT_TX_LOCAL_BUFFER        p_buf;
    bool                    ret = true;
    u8                    idx = 0, data_rate = 0;
    struct _RT_BEAMFORMING_INFO    *p_beam_info = &(p_dm_odm->beamforming_info);
    struct _RT_BEAMFORMEE_ENTRY    *p_beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(p_dm_odm, RA, &idx);
    struct _ADAPTER                *adapter = p_beam_info->source_adapter;
 
    ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] Start!\n", __func__));
 
    PlatformAcquireSpinLock(adapter, RT_TX_SPINLOCK);
 
    if (MgntGetBuffer(adapter, &p_tcb, &p_buf)) {
        construct_vht_bf_report_poll(
            p_dm_odm,
            RA,
            p_buf->Buffer.VirtualAddress,
            &p_tcb->PacketLength
        );
 
        p_tcb->bTxEnableSwCalcDur = true; /* <tynli_note> need?*/
        p_tcb->BWOfPacket = CHANNEL_WIDTH_20;
 
        if (is_final_poll)
            p_tcb->TxBFPktType = RT_BF_PKT_TYPE_FINAL_BF_REPORT_POLL;
        else
            p_tcb->TxBFPktType = RT_BF_PKT_TYPE_BF_REPORT_POLL;
 
        data_rate = MGN_6M;    /* Legacy OFDM rate*/
        MgntSendPacket(adapter, p_tcb, p_buf, p_tcb->PacketLength, NORMAL_QUEUE, data_rate);
    } else
        ret = false;
 
    PlatformReleaseSpinLock(adapter, RT_TX_SPINLOCK);
 
    if (ret)
        RT_DISP_DATA(FBEAM, FBEAM_DATA, "send_sw_vht_bf_report_poll():\n", p_buf->Buffer.VirtualAddress, p_tcb->PacketLength);
 
    return ret;
 
}
 
 
/*
 * Description: Construct VHT MU NDPA packet.
 *    <Note> We should combine this function with construct_vht_ndpa_packet() in the future.
 *
 * 2015.05.21. Created by tynli.
 */
void
construct_vht_mu_ndpa_packet(
    struct PHY_DM_STRUCT        *p_dm_odm,
    CHANNEL_WIDTH    BW,
    u8            *buffer,
    u32            *p_length
)
{
    struct _RT_BEAMFORMING_INFO    *p_beam_info = &(p_dm_odm->beamforming_info);
    struct _ADAPTER                *adapter = p_beam_info->source_adapter;
    u16                    duration = 0;
    u8                    sequence = 0;
    u8                    *p_ndpa_frame = buffer;
    struct _RT_NDPA_STA_INFO        sta_info;
    u8                    idx;
    u8                    dest_addr[6] = {0};
    struct _RT_BEAMFORMEE_ENTRY    *p_entry = NULL;
 
    /* 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. */
    for (idx = 0; idx < BEAMFORMEE_ENTRY_NUM; idx++) {
        p_entry = &(p_beam_info->beamformee_entry[idx]);
        if (p_entry->is_mu_sta) {
            cp_mac_addr(dest_addr, p_entry->mac_addr);
            break;
        }
    }
    if (p_entry == NULL)
        return;
 
    /* Frame control.*/
    SET_80211_HDR_FRAME_CONTROL(p_ndpa_frame, 0);
    SET_80211_HDR_TYPE_AND_SUBTYPE(p_ndpa_frame, Type_NDPA);
 
    SET_80211_HDR_ADDRESS1(p_ndpa_frame, dest_addr);
    SET_80211_HDR_ADDRESS2(p_ndpa_frame, p_entry->my_mac_addr);
 
    /*--------------------------------------------*/
    /* <Note> Need to modify "duration" to MU consideration. */
    duration = 2 * a_SifsTime + 44;
 
    if (BW == CHANNEL_WIDTH_80)
        duration += 40;
    else if (BW == CHANNEL_WIDTH_40)
        duration += 87;
    else
        duration += 180;
    /*--------------------------------------------*/
 
    SET_80211_HDR_DURATION(p_ndpa_frame, duration);
 
    sequence = *(p_dm_odm->p_sounding_seq) << 2;
    odm_move_memory(p_dm_odm, p_ndpa_frame + 16, &sequence, 1);
 
    *p_length = 17;
 
    /* Construct STA info. for multiple STAs*/
    for (idx = 0; idx < BEAMFORMEE_ENTRY_NUM; idx++) {
        p_entry = &(p_beam_info->beamformee_entry[idx]);
        if (p_entry->is_mu_sta) {
            sta_info.aid = p_entry->AID;
            sta_info.feedback_type = 1; /* 1'b1: MU*/
            sta_info.nc_index = 0;
 
            ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] Get beamformee_entry idx(%d), AID =%d\n", __func__, idx, p_entry->AID));
 
            odm_move_memory(p_dm_odm, p_ndpa_frame + (*p_length), (u8 *)&sta_info, 2);
            *p_length += 2;
        }
    }
 
}
 
bool
send_sw_vht_mu_ndpa_packet(
    void            *p_dm_void,
    CHANNEL_WIDTH    BW
)
{
    struct PHY_DM_STRUCT                *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
    PRT_TCB                    p_tcb;
    PRT_TX_LOCAL_BUFFER        p_buf;
    bool                    ret = true;
    u8                    ndp_tx_rate = 0;
    struct _RT_BEAMFORMING_INFO    *p_beam_info = &(p_dm_odm->beamforming_info);
    struct _ADAPTER                *adapter = p_beam_info->source_adapter;
 
    ndp_tx_rate = MGN_VHT2SS_MCS0;
    ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] ndp_tx_rate =%d\n", __func__, ndp_tx_rate));
 
    PlatformAcquireSpinLock(adapter, RT_TX_SPINLOCK);
 
    if (MgntGetBuffer(adapter, &p_tcb, &p_buf)) {
        construct_vht_mu_ndpa_packet(
            p_dm_odm,
            BW,
            p_buf->Buffer.VirtualAddress,
            &p_tcb->PacketLength
        );
 
        p_tcb->bTxEnableSwCalcDur = true;
        p_tcb->BWOfPacket = BW;
        p_tcb->TxBFPktType = RT_BF_PKT_TYPE_BROADCAST_NDPA;
 
        /*rate of NDP decide by nr*/
        MgntSendPacket(adapter, p_tcb, p_buf, p_tcb->PacketLength, NORMAL_QUEUE, ndp_tx_rate);
    } else
        ret = false;
 
    PlatformReleaseSpinLock(adapter, RT_TX_SPINLOCK);
 
    if (ret)
        RT_DISP_DATA(FBEAM, FBEAM_DATA, "", p_buf->Buffer.VirtualAddress, p_tcb->PacketLength);
 
    return ret;
}
 
 
void
dbg_construct_vht_mundpa_packet(
    struct PHY_DM_STRUCT        *p_dm_odm,
    CHANNEL_WIDTH    BW,
    u8            *buffer,
    u32            *p_length
)
{
    struct _RT_BEAMFORMING_INFO    *p_beam_info = &(p_dm_odm->beamforming_info);
    struct _ADAPTER                *adapter = p_beam_info->source_adapter;
    u16                    duration = 0;
    u8                    sequence = 0;
    u8                    *p_ndpa_frame = buffer;
    struct _RT_NDPA_STA_INFO        sta_info;
    u8                    idx;
    u8                    dest_addr[6] = {0};
    struct _RT_BEAMFORMEE_ENTRY    *p_entry = NULL;
 
    bool    is_STA1 = false;
 
 
    /* 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. */
    for (idx = 0; idx < BEAMFORMEE_ENTRY_NUM; idx++) {
        p_entry = &(p_beam_info->beamformee_entry[idx]);
        if (p_entry->is_mu_sta) {
            if (is_STA1 == false) {
                is_STA1 = true;
                continue;
            } else {
                cp_mac_addr(dest_addr, p_entry->mac_addr);
                break;
            }
        }
    }
 
    /* Frame control.*/
    SET_80211_HDR_FRAME_CONTROL(p_ndpa_frame, 0);
    SET_80211_HDR_TYPE_AND_SUBTYPE(p_ndpa_frame, Type_NDPA);
 
    SET_80211_HDR_ADDRESS1(p_ndpa_frame, dest_addr);
    SET_80211_HDR_ADDRESS2(p_ndpa_frame, p_dm_odm->CurrentAddress);
 
    /*--------------------------------------------*/
    /* <Note> Need to modify "duration" to MU consideration. */
    duration = 2 * a_SifsTime + 44;
 
    if (BW == CHANNEL_WIDTH_80)
        duration += 40;
    else if (BW == CHANNEL_WIDTH_40)
        duration += 87;
    else
        duration += 180;
    /*--------------------------------------------*/
 
    SET_80211_HDR_DURATION(p_ndpa_frame, duration);
 
    sequence = *(p_dm_odm->p_sounding_seq) << 2;
    odm_move_memory(p_dm_odm, p_ndpa_frame + 16, &sequence, 1);
 
    *p_length = 17;
 
    /*STA2's STA Info*/
    sta_info.aid = p_entry->aid;
    sta_info.feedback_type = 1; /* 1'b1: MU */
    sta_info.nc_index = 0;
 
    ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] Get beamformee_entry idx(%d), AID =%d\n", __func__, idx, p_entry->aid));
 
    odm_move_memory(p_dm_odm, p_ndpa_frame + (*p_length), (u8 *)&sta_info, 2);
    *p_length += 2;
 
}
 
bool
dbg_send_sw_vht_mundpa_packet(
    void            *p_dm_void,
    CHANNEL_WIDTH    BW
)
{
    struct PHY_DM_STRUCT                *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
    PRT_TCB                    p_tcb;
    PRT_TX_LOCAL_BUFFER        p_buf;
    bool                    ret = true;
    u8                    ndp_tx_rate = 0;
    struct _RT_BEAMFORMING_INFO    *p_beam_info = &(p_dm_odm->beamforming_info);
    struct _ADAPTER                *adapter = p_beam_info->source_adapter;
 
    ndp_tx_rate = MGN_VHT2SS_MCS0;
    ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] ndp_tx_rate =%d\n", __func__, ndp_tx_rate));
 
    PlatformAcquireSpinLock(adapter, RT_TX_SPINLOCK);
 
    if (MgntGetBuffer(adapter, &p_tcb, &p_buf)) {
        dbg_construct_vht_mundpa_packet(
            p_dm_odm,
            BW,
            p_buf->Buffer.VirtualAddress,
            &p_tcb->PacketLength
        );
 
        p_tcb->bTxEnableSwCalcDur = true;
        p_tcb->BWOfPacket = BW;
        p_tcb->TxBFPktType = RT_BF_PKT_TYPE_UNICAST_NDPA;
 
        /*rate of NDP decide by nr*/
        MgntSendPacket(adapter, p_tcb, p_buf, p_tcb->PacketLength, NORMAL_QUEUE, ndp_tx_rate);
    } else
        ret = false;
 
    PlatformReleaseSpinLock(adapter, RT_TX_SPINLOCK);
 
    if (ret)
        RT_DISP_DATA(FBEAM, FBEAM_DATA, "", p_buf->Buffer.VirtualAddress, p_tcb->PacketLength);
 
    return ret;
}
 
 
#endif    /*#if (SUPPORT_MU_BF == 1)*/
#endif    /*#ifdef SUPPORT_MU_BF*/
 
 
#elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
 
u32
beamforming_get_report_frame(
    void            *p_dm_void,
    union recv_frame *precv_frame
)
{
    struct PHY_DM_STRUCT                *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
    u32                    ret = _SUCCESS;
    struct _RT_BEAMFORMEE_ENTRY    *p_beamform_entry = NULL;
    u8                    *pframe = precv_frame->u.hdr.rx_data;
    u32                    frame_len = precv_frame->u.hdr.len;
    u8                    *TA;
    u8                    idx, offset;
 
 
    /*Memory comparison to see if CSI report is the same with previous one*/
    TA = get_addr2_ptr(pframe);
    p_beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(p_dm_odm, TA, &idx);
    if (p_beamform_entry->beamform_entry_cap & BEAMFORMER_CAP_VHT_SU)
        offset = 31;        /*24+(1+1+3)+2  MAC header+(Category+ActionCode+MIMOControlField)+SNR(nc=2)*/
    else if (p_beamform_entry->beamform_entry_cap & BEAMFORMER_CAP_HT_EXPLICIT)
        offset = 34;        /*24+(1+1+6)+2  MAC header+(Category+ActionCode+MIMOControlField)+SNR(nc=2)*/
    else
        return ret;
 
 
    return ret;
}
 
 
bool
send_fw_ht_ndpa_packet(
    void            *p_dm_void,
    u8            *RA,
    CHANNEL_WIDTH    BW
)
{
    struct PHY_DM_STRUCT                *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
    struct _ADAPTER                *adapter = p_dm_odm->adapter;
    struct xmit_frame        *pmgntframe;
    struct pkt_attrib        *pattrib;
    struct rtw_ieee80211_hdr    *pwlanhdr;
    struct xmit_priv        *pxmitpriv = &(adapter->xmitpriv);
    struct mlme_ext_priv    *pmlmeext = &adapter->mlmeextpriv;
    struct mlme_ext_info    *pmlmeinfo = &(pmlmeext->mlmext_info);
    u8    action_hdr[4] = {ACT_CAT_VENDOR, 0x00, 0xe0, 0x4c};
    u8    *pframe;
    u16    *fctrl;
    u16    duration = 0;
    u8    a_sifs_time = 0, ndp_tx_rate = 0, idx = 0;
    struct _RT_BEAMFORMING_INFO    *p_beam_info = &(p_dm_odm->beamforming_info);
    struct _RT_BEAMFORMEE_ENTRY    *p_beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(p_dm_odm, RA, &idx);
 
    pmgntframe = alloc_mgtxmitframe(pxmitpriv);
 
    if (pmgntframe == NULL) {
        ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("%s, alloc mgnt frame fail\n", __func__));
        return _FALSE;
    }
 
    /* update attribute */
    pattrib = &pmgntframe->attrib;
    update_mgntframe_attrib(adapter, pattrib);
 
    pattrib->qsel = QSLT_BEACON;
    ndp_tx_rate = beamforming_get_htndp_tx_rate(p_dm_odm, p_beamform_entry->comp_steering_num_of_bfer);
    ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] ndp_tx_rate =%d\n", __func__, ndp_tx_rate));
    pattrib->rate = ndp_tx_rate;
    pattrib->bwmode = BW;
    pattrib->order = 1;
    pattrib->subtype = WIFI_ACTION_NOACK;
 
    _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
 
    pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
 
    pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
 
    fctrl = &pwlanhdr->frame_ctl;
    *(fctrl) = 0;
 
    set_order_bit(pframe);
    set_frame_sub_type(pframe, WIFI_ACTION_NOACK);
 
    _rtw_memcpy(pwlanhdr->addr1, RA, ETH_ALEN);
    _rtw_memcpy(pwlanhdr->addr2, p_beamform_entry->my_mac_addr, ETH_ALEN);
    _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
 
    if (pmlmeext->cur_wireless_mode == WIRELESS_11B)
        a_sifs_time = 10;
    else
        a_sifs_time = 16;
 
    duration = 2 * a_sifs_time + 40;
 
    if (BW == CHANNEL_WIDTH_40)
        duration += 87;
    else
        duration += 180;
 
    set_duration(pframe, duration);
 
    /* HT control field */
    SET_HT_CTRL_CSI_STEERING(pframe + 24, 3);
    SET_HT_CTRL_NDP_ANNOUNCEMENT(pframe + 24, 1);
 
    _rtw_memcpy(pframe + 28, action_hdr, 4);
 
    pattrib->pktlen = 32;
 
    pattrib->last_txcmdsz = pattrib->pktlen;
 
    dump_mgntframe(adapter, pmgntframe);
 
    return _TRUE;
}
 
 
bool
send_sw_ht_ndpa_packet(
    void            *p_dm_void,
    u8            *RA,
    CHANNEL_WIDTH    BW
)
{
    struct PHY_DM_STRUCT                *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
    struct _ADAPTER                *adapter = p_dm_odm->adapter;
    struct xmit_frame        *pmgntframe;
    struct pkt_attrib        *pattrib;
    struct rtw_ieee80211_hdr    *pwlanhdr;
    struct xmit_priv        *pxmitpriv = &(adapter->xmitpriv);
    struct mlme_ext_priv    *pmlmeext = &adapter->mlmeextpriv;
    struct mlme_ext_info    *pmlmeinfo = &(pmlmeext->mlmext_info);
    u8    action_hdr[4] = {ACT_CAT_VENDOR, 0x00, 0xe0, 0x4c};
    u8    *pframe;
    u16    *fctrl;
    u16    duration = 0;
    u8    a_sifs_time = 0, ndp_tx_rate = 0, idx = 0;
    struct _RT_BEAMFORMING_INFO    *p_beam_info = &(p_dm_odm->beamforming_info);
    struct _RT_BEAMFORMEE_ENTRY    *p_beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(p_dm_odm, RA, &idx);
 
    ndp_tx_rate = beamforming_get_htndp_tx_rate(p_dm_odm, p_beamform_entry->comp_steering_num_of_bfer);
 
    pmgntframe = alloc_mgtxmitframe(pxmitpriv);
 
    if (pmgntframe == NULL) {
        ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("%s, alloc mgnt frame fail\n", __func__));
        return _FALSE;
    }
 
    /*update attribute*/
    pattrib = &pmgntframe->attrib;
    update_mgntframe_attrib(adapter, pattrib);
    pattrib->qsel = QSLT_MGNT;
    pattrib->rate = ndp_tx_rate;
    pattrib->bwmode = BW;
    pattrib->order = 1;
    pattrib->subtype = WIFI_ACTION_NOACK;
 
    _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
 
    pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
 
    pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
 
    fctrl = &pwlanhdr->frame_ctl;
    *(fctrl) = 0;
 
    set_order_bit(pframe);
    set_frame_sub_type(pframe, WIFI_ACTION_NOACK);
 
    _rtw_memcpy(pwlanhdr->addr1, RA, ETH_ALEN);
    _rtw_memcpy(pwlanhdr->addr2, p_beamform_entry->my_mac_addr, ETH_ALEN);
    _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
 
    if (pmlmeext->cur_wireless_mode == WIRELESS_11B)
        a_sifs_time = 10;
    else
        a_sifs_time = 16;
 
    duration = 2 * a_sifs_time + 40;
 
    if (BW == CHANNEL_WIDTH_40)
        duration += 87;
    else
        duration += 180;
 
    set_duration(pframe, duration);
 
    /*HT control field*/
    SET_HT_CTRL_CSI_STEERING(pframe + 24, 3);
    SET_HT_CTRL_NDP_ANNOUNCEMENT(pframe + 24, 1);
 
    _rtw_memcpy(pframe + 28, action_hdr, 4);
 
    pattrib->pktlen = 32;
 
    pattrib->last_txcmdsz = pattrib->pktlen;
 
    dump_mgntframe(adapter, pmgntframe);
 
    return _TRUE;
}
 
 
bool
send_fw_vht_ndpa_packet(
    void            *p_dm_void,
    u8            *RA,
    u16            AID,
    CHANNEL_WIDTH    BW
)
{
    struct PHY_DM_STRUCT                *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
    struct _ADAPTER                *adapter = p_dm_odm->adapter;
    struct xmit_frame        *pmgntframe;
    struct pkt_attrib        *pattrib;
    struct rtw_ieee80211_hdr    *pwlanhdr;
    struct xmit_priv        *pxmitpriv = &(adapter->xmitpriv);
    struct mlme_ext_priv    *pmlmeext = &adapter->mlmeextpriv;
    struct mlme_ext_info    *pmlmeinfo = &(pmlmeext->mlmext_info);
    struct mlme_priv        *pmlmepriv = &(adapter->mlmepriv);
    u8    *pframe;
    u16    *fctrl;
    u16    duration = 0;
    u8    sequence = 0, a_sifs_time = 0, ndp_tx_rate = 0, idx = 0;
    struct _RT_BEAMFORMING_INFO    *p_beam_info = &(p_dm_odm->beamforming_info);
    struct _RT_BEAMFORMEE_ENTRY    *p_beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(p_dm_odm, RA, &idx);
    struct _RT_NDPA_STA_INFO    sta_info;
 
    pmgntframe = alloc_mgtxmitframe(pxmitpriv);
 
    if (pmgntframe == NULL) {
        ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("%s, alloc mgnt frame fail\n", __func__));
        return _FALSE;
    }
 
    /* update attribute */
    pattrib = &pmgntframe->attrib;
    _rtw_memcpy(pattrib->ra, RA, ETH_ALEN);
    update_mgntframe_attrib(adapter, pattrib);
 
    pattrib->qsel = QSLT_BEACON;
    ndp_tx_rate = beamforming_get_vht_ndp_tx_rate(p_dm_odm, p_beamform_entry->comp_steering_num_of_bfer);
    ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] ndp_tx_rate =%d\n", __func__, ndp_tx_rate));
    pattrib->rate = ndp_tx_rate;
    pattrib->bwmode = BW;
    pattrib->subtype = WIFI_NDPA;
 
    _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
 
    pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
 
    pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
 
    fctrl = &pwlanhdr->frame_ctl;
    *(fctrl) = 0;
 
    set_frame_sub_type(pframe, WIFI_NDPA);
 
    _rtw_memcpy(pwlanhdr->addr1, RA, ETH_ALEN);
    _rtw_memcpy(pwlanhdr->addr2, p_beamform_entry->my_mac_addr, ETH_ALEN);
 
    if (is_supported_5g(pmlmeext->cur_wireless_mode) || is_supported_ht(pmlmeext->cur_wireless_mode))
        a_sifs_time = 16;
    else
        a_sifs_time = 10;
 
    duration = 2 * a_sifs_time + 44;
 
    if (BW == CHANNEL_WIDTH_80)
        duration += 40;
    else if (BW == CHANNEL_WIDTH_40)
        duration += 87;
    else
        duration += 180;
 
    set_duration(pframe, duration);
 
    sequence = p_beam_info->sounding_sequence << 2;
    if (p_beam_info->sounding_sequence >= 0x3f)
        p_beam_info->sounding_sequence = 0;
    else
        p_beam_info->sounding_sequence++;
 
    _rtw_memcpy(pframe + 16, &sequence, 1);
 
    if (((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE))
        AID = 0;
 
    sta_info.aid = AID;
    sta_info.feedback_type = 0;
    sta_info.nc_index = 0;
 
    _rtw_memcpy(pframe + 17, (u8 *)&sta_info, 2);
 
    pattrib->pktlen = 19;
 
    pattrib->last_txcmdsz = pattrib->pktlen;
 
    dump_mgntframe(adapter, pmgntframe);
 
    return _TRUE;
}
 
 
 
bool
send_sw_vht_ndpa_packet(
    void            *p_dm_void,
    u8            *RA,
    u16            AID,
    CHANNEL_WIDTH    BW
)
{
    struct PHY_DM_STRUCT                *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
    struct _ADAPTER                *adapter = p_dm_odm->adapter;
    struct xmit_frame        *pmgntframe;
    struct pkt_attrib        *pattrib;
    struct rtw_ieee80211_hdr    *pwlanhdr;
    struct xmit_priv        *pxmitpriv = &(adapter->xmitpriv);
    struct mlme_ext_priv    *pmlmeext = &adapter->mlmeextpriv;
    struct mlme_ext_info    *pmlmeinfo = &(pmlmeext->mlmext_info);
    struct mlme_priv        *pmlmepriv = &(adapter->mlmepriv);
    struct _RT_NDPA_STA_INFO    ndpa_sta_info;
    u8    ndp_tx_rate = 0, sequence = 0, a_sifs_time = 0, idx = 0;
    u8    *pframe;
    u16    *fctrl;
    u16    duration = 0;
    struct _RT_BEAMFORMING_INFO    *p_beam_info = &(p_dm_odm->beamforming_info);
    struct _RT_BEAMFORMEE_ENTRY    *p_beamform_entry = phydm_beamforming_get_bfee_entry_by_addr(p_dm_odm, RA, &idx);
 
    ndp_tx_rate = beamforming_get_vht_ndp_tx_rate(p_dm_odm, p_beamform_entry->comp_steering_num_of_bfer);
    ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] ndp_tx_rate =%d\n", __func__, ndp_tx_rate));
 
    pmgntframe = alloc_mgtxmitframe(pxmitpriv);
 
    if (pmgntframe == NULL) {
        ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("%s, alloc mgnt frame fail\n", __func__));
        return _FALSE;
    }
 
    /*update attribute*/
    pattrib = &pmgntframe->attrib;
    _rtw_memcpy(pattrib->ra, RA, ETH_ALEN);
    update_mgntframe_attrib(adapter, pattrib);
    pattrib->qsel = QSLT_MGNT;
    pattrib->rate = ndp_tx_rate;
    pattrib->bwmode = BW;
    pattrib->subtype = WIFI_NDPA;
 
    _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
 
    pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
 
    pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
 
    fctrl = &pwlanhdr->frame_ctl;
    *(fctrl) = 0;
 
    set_frame_sub_type(pframe, WIFI_NDPA);
 
    _rtw_memcpy(pwlanhdr->addr1, RA, ETH_ALEN);
    _rtw_memcpy(pwlanhdr->addr2, p_beamform_entry->my_mac_addr, ETH_ALEN);
 
    if (is_supported_5g(pmlmeext->cur_wireless_mode) || is_supported_ht(pmlmeext->cur_wireless_mode))
        a_sifs_time = 16;
    else
        a_sifs_time = 10;
 
    duration = 2 * a_sifs_time + 44;
 
    if (BW == CHANNEL_WIDTH_80)
        duration += 40;
    else if (BW == CHANNEL_WIDTH_40)
        duration += 87;
    else
        duration += 180;
 
    set_duration(pframe, duration);
 
    sequence = p_beam_info->sounding_sequence << 2;
    if (p_beam_info->sounding_sequence >= 0x3f)
        p_beam_info->sounding_sequence = 0;
    else
        p_beam_info->sounding_sequence++;
 
    _rtw_memcpy(pframe + 16, &sequence, 1);
    if (((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE))
        AID = 0;
 
    ndpa_sta_info.aid = AID;
    ndpa_sta_info.feedback_type = 0;
    ndpa_sta_info.nc_index = 0;
 
    _rtw_memcpy(pframe + 17, (u8 *)&ndpa_sta_info, 2);
 
    pattrib->pktlen = 19;
 
    pattrib->last_txcmdsz = pattrib->pktlen;
 
    dump_mgntframe(adapter, pmgntframe);
    ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] [%d]\n", __func__, __LINE__));
 
    return _TRUE;
}
 
 
#endif
 
 
void
beamforming_get_ndpa_frame(
    void            *p_dm_void,
#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
    OCTET_STRING    pdu_os
#elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
    union recv_frame *precv_frame
#endif
)
{
    struct PHY_DM_STRUCT                    *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void;
    struct _ADAPTER                    *adapter = p_dm_odm->adapter;
    u8                        *TA ;
    u8                        idx, sequence;
#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
    u8                        *p_ndpa_frame = pdu_os.Octet;
#elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
    u8                        *p_ndpa_frame = precv_frame->u.hdr.rx_data;
#endif
    struct _RT_BEAMFORMER_ENTRY        *p_beamformer_entry = NULL;        /*Modified By Jeffery @2014-10-29*/
 
 
#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
    RT_DISP_DATA(FBEAM, FBEAM_DATA, "beamforming_get_ndpa_frame\n", pdu_os.Octet, pdu_os.Length);
    if (IsCtrlNDPA(p_ndpa_frame) == false)
#elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
    if (get_frame_sub_type(p_ndpa_frame) != WIFI_NDPA)
#endif
        return;
    else if (!(p_dm_odm->support_ic_type & (ODM_RTL8812 | ODM_RTL8821))) {
        ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] not 8812 or 8821A, return\n", __func__));
        return;
    }
#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
    TA = Frame_Addr2(pdu_os);
#elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
    TA = get_addr2_ptr(p_ndpa_frame);
#endif
    /*Remove signaling TA. */
    TA[0] = TA[0] & 0xFE;
 
    p_beamformer_entry = phydm_beamforming_get_bfer_entry_by_addr(p_dm_odm, TA, &idx);        /* Modified By Jeffery @2014-10-29 */
 
    /*Break options for Clock Reset*/
    if (p_beamformer_entry == NULL)
        return;
    else if (!(p_beamformer_entry->beamform_entry_cap & BEAMFORMEE_CAP_VHT_SU))
        return;
    /*log_success: As long as 8812A receive NDPA and feedback CSI succeed once, clock reset is NO LONGER needed !2015-04-10, Jeffery*/
    /*clock_reset_times: While BFer entry always doesn't receive our CSI, clock will reset again and again.So clock_reset_times is limited to 5 times.2015-04-13, Jeffery*/
    else if ((p_beamformer_entry->log_success == 1) || (p_beamformer_entry->clock_reset_times == 5)) {
        ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] log_seq=%d, pre_log_seq=%d, log_retry_cnt=%d, log_success=%d, clock_reset_times=%d, clock reset is no longer needed.\n",
            __func__, p_beamformer_entry->log_seq, p_beamformer_entry->pre_log_seq, p_beamformer_entry->log_retry_cnt, p_beamformer_entry->log_success, p_beamformer_entry->clock_reset_times));
 
        return;
    }
 
    sequence = (p_ndpa_frame[16]) >> 2;
 
    ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] Start, sequence=%d, log_seq=%d, pre_log_seq=%d, log_retry_cnt=%d, clock_reset_times=%d, log_success=%d\n",
        __func__, sequence, p_beamformer_entry->log_seq, p_beamformer_entry->pre_log_seq, p_beamformer_entry->log_retry_cnt, p_beamformer_entry->clock_reset_times, p_beamformer_entry->log_success));
 
    if ((p_beamformer_entry->log_seq != 0) && (p_beamformer_entry->pre_log_seq != 0)) {
        /*Success condition*/
        if ((p_beamformer_entry->log_seq != sequence) && (p_beamformer_entry->pre_log_seq != p_beamformer_entry->log_seq)) {
            /* break option for clcok reset, 2015-03-30, Jeffery */
            p_beamformer_entry->log_retry_cnt = 0;
            /*As long as 8812A receive NDPA and feedback CSI succeed once, clock reset is no longer needed.*/
            /*That is, log_success is NOT needed to be reset to zero, 2015-04-13, Jeffery*/
            p_beamformer_entry->log_success = 1;
 
        } else {/*Fail condition*/
 
            if (p_beamformer_entry->log_retry_cnt == 5) {
                p_beamformer_entry->clock_reset_times++;
                p_beamformer_entry->log_retry_cnt = 0;
 
                ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] Clock Reset!!! clock_reset_times=%d\n",
                    __func__, p_beamformer_entry->clock_reset_times));
                hal_com_txbf_set(p_dm_odm, TXBF_SET_SOUNDING_CLK, NULL);
 
            } else
                p_beamformer_entry->log_retry_cnt++;
        }
    }
 
    /*Update log_seq & pre_log_seq*/
    p_beamformer_entry->pre_log_seq = p_beamformer_entry->log_seq;
    p_beamformer_entry->log_seq = sequence;
 
}
 
 
 
#endif