forked from morrownr/88x2bu-20210702
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtw_rm.c
2825 lines (2332 loc) · 67 KB
/
rtw_rm.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.
*
*****************************************************************************/
#include <drv_types.h>
#include <hal_data.h>
#ifdef CONFIG_RTW_80211K
#include "rtw_rm_fsm.h"
#include "rtw_rm_util.h"
#endif
#define pstr(s) s+strlen(s)
#ifndef MIN
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#endif
u8 rm_post_event_hdl(_adapter *padapter, u8 *pbuf)
{
#ifdef CONFIG_RTW_80211K
struct rm_event *pev = (struct rm_event *)pbuf;
_rm_post_event(padapter, pev->rmid, pev->evid);
rm_handler(padapter, pev);
#endif
return H2C_SUCCESS;
}
#ifdef CONFIG_RTW_80211K
struct cmd_meas_type_ {
u8 id;
char *name;
};
char *rm_type_req_name(u8 meas_type) {
switch (meas_type) {
case basic_req:
return "basic_req";
case cca_req:
return "cca_req";
case rpi_histo_req:
return "rpi_histo_req";
case ch_load_req:
return "ch_load_req";
case noise_histo_req:
return "noise_histo_req";
case bcn_req:
return "bcn_req";
case frame_req:
return "frame_req";
case sta_statis_req:
return "sta_statis_req";
}
return "unknown_req";
};
char *rm_type_rep_name(u8 meas_type) {
switch (meas_type) {
case basic_rep:
return "basic_rep";
case cca_rep:
return "cca_rep";
case rpi_histo_rep:
return "rpi_histo_rep";
case ch_load_rep:
return "ch_load_rep";
case noise_histo_rep:
return "noise_histo_rep";
case bcn_rep:
return "bcn_rep";
case frame_rep:
return "frame_rep";
case sta_statis_rep:
return "sta_statis_rep";
}
return "unknown_rep";
};
char *rm_en_cap_name(enum rm_cap_en en)
{
switch (en) {
case RM_LINK_MEAS_CAP_EN:
return "RM_LINK_MEAS_CAP_EN";
case RM_NB_REP_CAP_EN:
return "RM_NB_REP_CAP_EN";
case RM_PARAL_MEAS_CAP_EN:
return "RM_PARAL_MEAS_CAP_EN";
case RM_REPEAT_MEAS_CAP_EN:
return "RM_REPEAT_MEAS_CAP_EN";
case RM_BCN_PASSIVE_MEAS_CAP_EN:
return "RM_BCN_PASSIVE_MEAS_CAP_EN";
case RM_BCN_ACTIVE_MEAS_CAP_EN:
return "RM_BCN_ACTIVE_MEAS_CAP_EN";
case RM_BCN_TABLE_MEAS_CAP_EN:
return "RM_BCN_TABLE_MEAS_CAP_EN";
case RM_BCN_MEAS_REP_COND_CAP_EN:
return "RM_BCN_MEAS_REP_COND_CAP_EN";
case RM_FRAME_MEAS_CAP_EN:
return "RM_FRAME_MEAS_CAP_EN";
case RM_CH_LOAD_CAP_EN:
return "RM_CH_LOAD_CAP_EN";
case RM_NOISE_HISTO_CAP_EN:
return "RM_NOISE_HISTO_CAP_EN";
case RM_STATIS_MEAS_CAP_EN:
return "RM_STATIS_MEAS_CAP_EN";
case RM_LCI_MEAS_CAP_EN:
return "RM_LCI_MEAS_CAP_EN";
case RM_LCI_AMIMUTH_CAP_EN:
return "RM_LCI_AMIMUTH_CAP_EN";
case RM_TRANS_STREAM_CAT_MEAS_CAP_EN:
return "RM_TRANS_STREAM_CAT_MEAS_CAP_EN";
case RM_TRIG_TRANS_STREAM_CAT_MEAS_CAP_EN:
return "RM_TRIG_TRANS_STREAM_CAT_MEAS_CAP_EN";
case RM_AP_CH_REP_CAP_EN:
return "RM_AP_CH_REP_CAP_EN";
case RM_RM_MIB_CAP_EN:
return "RM_RM_MIB_CAP_EN";
case RM_OP_CH_MAX_MEAS_DUR0:
return "RM_OP_CH_MAX_MEAS_DUR0";
case RM_OP_CH_MAX_MEAS_DUR1:
return "RM_OP_CH_MAX_MEAS_DUR1";
case RM_OP_CH_MAX_MEAS_DUR2:
return "RM_OP_CH_MAX_MEAS_DUR2";
case RM_NONOP_CH_MAX_MEAS_DUR0:
return "RM_NONOP_CH_MAX_MEAS_DUR0";
case RM_NONOP_CH_MAX_MEAS_DUR1:
return "RM_NONOP_CH_MAX_MEAS_DUR1";
case RM_NONOP_CH_MAX_MEAS_DUR2:
return "RM_NONOP_CH_MAX_MEAS_DUR2";
case RM_MEAS_PILOT_CAP0:
return "RM_MEAS_PILOT_CAP0"; /* 24-26 */
case RM_MEAS_PILOT_CAP1:
return "RM_MEAS_PILOT_CAP1";
case RM_MEAS_PILOT_CAP2:
return "RM_MEAS_PILOT_CAP2";
case RM_MEAS_PILOT_TRANS_INFO_CAP_EN:
return "RM_MEAS_PILOT_TRANS_INFO_CAP_EN";
case RM_NB_REP_TSF_OFFSET_CAP_EN:
return "RM_NB_REP_TSF_OFFSET_CAP_EN";
case RM_RCPI_MEAS_CAP_EN:
return "RM_RCPI_MEAS_CAP_EN"; /* 29 */
case RM_RSNI_MEAS_CAP_EN:
return "RM_RSNI_MEAS_CAP_EN";
case RM_BSS_AVG_ACCESS_DELAY_CAP_EN:
return "RM_BSS_AVG_ACCESS_DELAY_CAP_EN";
case RM_AVALB_ADMIS_CAPACITY_CAP_EN:
return "RM_AVALB_ADMIS_CAPACITY_CAP_EN";
case RM_ANT_CAP_EN:
return "RM_ANT_CAP_EN";
case RM_RSVD:
case RM_MAX:
default:
break;
}
return "unknown";
}
int rm_en_cap_chk_and_set(struct rm_obj *prm, enum rm_cap_en en)
{
int idx;
u8 cap;
if (en >= RM_MAX)
return _FALSE;
idx = en / 8;
cap = prm->psta->padapter->rmpriv.rm_en_cap_def[idx];
if (!(cap & BIT(en - (idx*8)))) {
RTW_INFO("RM: %s incapable\n",rm_en_cap_name(en));
rm_set_rep_mode(prm, MEAS_REP_MOD_INCAP);
return _FALSE;
}
return _SUCCESS;
}
/* for caller outside rm */
u8 rm_add_nb_req(_adapter *padapter, struct sta_info *psta)
{
struct rm_obj *prm;
prm = rm_alloc_rmobj(padapter);
if (prm == NULL) {
RTW_ERR("RM: unable to alloc rm obj for requeset\n");
return _FALSE;
}
prm->psta = psta;
prm->q.category = RTW_WLAN_CATEGORY_RADIO_MEAS;
prm->q.diag_token = rm_gen_dialog_token(padapter);
prm->q.m_token = rm_gen_meas_token(padapter);
prm->rmid = rm_gen_rmid(padapter, prm, RM_MASTER);
prm->q.action_code = RM_ACT_NB_REP_REQ;
#if 0
if (pmac) { /* find sta_info according to bssid */
pmac += 4; /* skip mac= */
if (hwaddr_parse(pmac, bssid) == NULL) {
sprintf(pstr(s), "Err: \nincorrect mac format\n");
return _FAIL;
}
psta = rm_get_sta(padapter, 0xff, bssid);
}
#endif
/* enquee rmobj */
rm_enqueue_rmobj(padapter, prm, _FALSE);
RTW_INFO("RM: rmid=%x add req to " MAC_FMT "\n",
prm->rmid, MAC_ARG(psta->cmn.mac_addr));
return _SUCCESS;
}
static u8 *build_wlan_hdr(_adapter *padapter, struct xmit_frame *pmgntframe,
struct sta_info *psta, u16 frame_type)
{
u8 *pframe;
u16 *fctrl;
struct pkt_attrib *pattr;
struct rtw_ieee80211_hdr *pwlanhdr;
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
/* update attribute */
pattr = &pmgntframe->attrib;
update_mgntframe_attrib(padapter, pattr);
_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;
_rtw_memcpy(pwlanhdr->addr1, psta->cmn.mac_addr, ETH_ALEN);
_rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
_rtw_memcpy(pwlanhdr->addr3,
get_my_bssid(&(pmlmeinfo->network)),ETH_ALEN);
RTW_INFO("RM: dst = " MAC_FMT "\n", MAC_ARG(pwlanhdr->addr1));
SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
pmlmeext->mgnt_seq++;
SetFragNum(pframe, 0);
set_frame_sub_type(pframe, WIFI_ACTION);
pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
pattr->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
return pframe;
}
void rm_set_rep_mode(struct rm_obj *prm, u8 mode)
{
RTW_INFO("RM: rmid=%x set %s\n",
prm->rmid,
mode|MEAS_REP_MOD_INCAP?"INCAP":
mode|MEAS_REP_MOD_REFUSE?"REFUSE":
mode|MEAS_REP_MOD_LATE?"LATE":"");
prm->p.m_mode |= mode;
}
int issue_null_reply(struct rm_obj *prm)
{
int len=0, my_len;
u8 *pframe, m_mode;
_adapter *padapter = prm->psta->padapter;
struct pkt_attrib *pattr;
struct xmit_frame *pmgntframe;
struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
m_mode = prm->p.m_mode;
if (m_mode || prm->p.rpt == 0) {
RTW_INFO("RM: rmid=%x reply (%s repeat=%d)\n",
prm->rmid,
m_mode&MEAS_REP_MOD_INCAP?"INCAP":
m_mode&MEAS_REP_MOD_REFUSE?"REFUSE":
m_mode&MEAS_REP_MOD_LATE?"LATE":"no content",
prm->p.rpt);
}
switch (prm->p.action_code) {
case RM_ACT_RADIO_MEAS_REQ:
len = 8;
break;
case RM_ACT_NB_REP_REQ:
len = 3;
break;
case RM_ACT_LINK_MEAS_REQ:
len = 3;
break;
default:
break;
}
if (len==0)
return _FALSE;
pmgntframe = alloc_mgtxmitframe(pxmitpriv);
if (pmgntframe == NULL) {
RTW_ERR("RM: %s alloc xmit_frame fail\n",__func__);
return _FALSE;
}
pattr = &pmgntframe->attrib;
pframe = build_wlan_hdr(padapter, pmgntframe, prm->psta, WIFI_ACTION);
pframe = rtw_set_fixed_ie(pframe, 3, &prm->p.category, &pattr->pktlen);
my_len = 0;
if (len>5) {
prm->p.len = len - 3 - 2;
pframe = rtw_set_fixed_ie(pframe, len - 3,
&prm->p.e_id, &my_len);
}
pattr->pktlen += my_len;
pattr->last_txcmdsz = pattr->pktlen;
dump_mgntframe(padapter, pmgntframe);
return _SUCCESS;
}
int ready_for_scan(struct rm_obj *prm)
{
_adapter *padapter = prm->psta->padapter;
u8 ssc_chk;
if (!rtw_is_adapter_up(padapter))
return _FALSE;
ssc_chk = rtw_sitesurvey_condition_check(padapter, _FALSE);
if (ssc_chk == SS_ALLOW)
return _SUCCESS;
return _FALSE;
}
int rm_sitesurvey(struct rm_obj *prm)
{
int meas_ch_amount=0;
u8 op_class=0, val8;
struct rtw_ieee80211_channel *pch_set;
struct sitesurvey_parm parm;
RTW_INFO("RM: rmid=%x %s\n",prm->rmid, __func__);
pch_set = &prm->q.ch_set[0];
_rtw_memset(pch_set, 0,
sizeof(struct rtw_ieee80211_channel) * RTW_CHANNEL_SCAN_AMOUNT);
op_class = prm->q.op_class;
if (prm->q.ch_num == 0) {
/* ch_num=0 : scan all ch in operating class */
meas_ch_amount = rm_get_ch_set(pch_set,
op_class, prm->q.ch_num);
} else if (prm->q.ch_num == 255) {
/* 802.11 p.1066 */
/* ch_num=255 : If the Channel Number is 255 and includes
* AP Channel Report subelements
*/
meas_ch_amount = rm_get_ch_set_from_bcn_req_opt(pch_set, &prm->q.opt.bcn);
} else
meas_ch_amount = rm_get_ch_set(pch_set, op_class, prm->q.ch_num);
/* get means channel */
prm->q.ch_set_ch_amount = meas_ch_amount;
#if (RM_MORE_DBG_MSG)
RTW_INFO("survey (%d) chaannels\n", meas_ch_amount);
#endif
_rtw_memset(&parm, 0, sizeof(struct sitesurvey_parm));
_rtw_memcpy(parm.ch, pch_set,
sizeof(struct rtw_ieee80211_channel) *
MIN(meas_ch_amount, RTW_CHANNEL_SCAN_AMOUNT));
_rtw_memcpy(&parm.ssid[0], &prm->q.opt.bcn.ssid, IW_ESSID_MAX_SIZE);
parm.ssid_num = 1;
parm.scan_mode = prm->q.m_mode;
parm.ch_num = meas_ch_amount;
parm.igi = 0;
parm.token = prm->rmid;
parm.duration = prm->q.meas_dur;
/* parm.bw = BW_20M; */
rtw_sitesurvey_cmd(prm->psta->padapter, &parm);
return _SUCCESS;
}
static int rm_parse_ch_load_s_elem(struct rm_obj *prm, u8 *pbody, int req_len)
{
u8 *popt_id;
int i, p=0; /* position */
int len = req_len;
prm->q.opt_s_elem_len = len;
#if (RM_MORE_DBG_MSG)
RTW_INFO("RM: opt_s_elem_len=%d\n", len);
#endif
while (len) {
switch (pbody[p]) {
case ch_load_rep_info:
/* check RM_EN */
rm_en_cap_chk_and_set(prm, RM_CH_LOAD_CAP_EN);
_rtw_memcpy(&(prm->q.opt.clm.rep_cond),
&pbody[p+2], sizeof(prm->q.opt.clm.rep_cond));
RTW_INFO("RM: ch_load_rep_info=%u:%u\n",
prm->q.opt.clm.rep_cond.cond,
prm->q.opt.clm.rep_cond.threshold);
break;
default:
break;
}
len = len - (int)pbody[p+1] - 2;
p = p + (int)pbody[p+1] + 2;
#if (RM_MORE_DBG_MSG)
RTW_INFO("RM: opt_s_elem_len=%d\n",len);
#endif
}
return _SUCCESS;
}
static int rm_parse_noise_histo_s_elem(struct rm_obj *prm,
u8 *pbody, int req_len)
{
u8 *popt_id;
int i, p=0; /* position */
int len = req_len;
prm->q.opt_s_elem_len = len;
#if (RM_MORE_DBG_MSG)
RTW_INFO("RM: opt_s_elem_len=%d\n", len);
#endif
while (len) {
switch (pbody[p]) {
case noise_histo_rep_info:
/* check RM_EN */
rm_en_cap_chk_and_set(prm, RM_NOISE_HISTO_CAP_EN);
_rtw_memcpy(&(prm->q.opt.nhm.rep_cond),
&pbody[p+2], sizeof(prm->q.opt.nhm.rep_cond));
RTW_INFO("RM: noise_histo_rep_info=%u:%u\n",
prm->q.opt.nhm.rep_cond.cond,
prm->q.opt.nhm.rep_cond.threshold);
break;
default:
break;
}
len = len - (int)pbody[p+1] - 2;
p = p + (int)pbody[p+1] + 2;
#if (RM_MORE_DBG_MSG)
RTW_INFO("RM: opt_s_elem_len=%d\n",len);
#endif
}
return _SUCCESS;
}
static int rm_parse_bcn_req_s_elem(struct rm_obj *prm, u8 *pbody, int req_len)
{
u8 *popt_id;
int i, p=0; /* position */
int len = req_len;
int ap_ch_rpt_idx = 0;
struct _RT_OPERATING_CLASS *op;
/* opt length,2:pbody[0]+ pbody[1] */
/* first opt id : pbody[18] */
prm->q.opt_s_elem_len = len;
#if (RM_MORE_DBG_MSG)
RTW_INFO("RM: opt_s_elem_len=%d\n", len);
#endif
popt_id = prm->q.opt.bcn.opt_id;
while (len && prm->q.opt.bcn.opt_id_num < BCN_REQ_OPT_MAX_NUM) {
switch (pbody[p]) {
case bcn_req_ssid:
RTW_INFO("bcn_req_ssid\n");
#if (DBG_BCN_REQ_WILDCARD)
RTW_INFO("DBG set ssid to WILDCARD\n");
#else
#if (DBG_BCN_REQ_SSID)
RTW_INFO("DBG set ssid to %s\n",DBG_BCN_REQ_SSID_NAME);
i = strlen(DBG_BCN_REQ_SSID_NAME);
prm->q.opt.bcn.ssid.SsidLength = i;
_rtw_memcpy(&(prm->q.opt.bcn.ssid.Ssid),
DBG_BCN_REQ_SSID_NAME, i);
#else /* original */
prm->q.opt.bcn.ssid.SsidLength = pbody[p+1];
_rtw_memcpy(&(prm->q.opt.bcn.ssid.Ssid),
&pbody[p+2], pbody[p+1]);
#endif
#endif
RTW_INFO("RM: bcn_req_ssid=%s\n",
prm->q.opt.bcn.ssid.Ssid);
popt_id[prm->q.opt.bcn.opt_id_num++] = pbody[p];
break;
case bcn_req_rep_info:
/* check RM_EN */
rm_en_cap_chk_and_set(prm, RM_BCN_MEAS_REP_COND_CAP_EN);
_rtw_memcpy(&(prm->q.opt.bcn.rep_cond),
&pbody[p+2], sizeof(prm->q.opt.bcn.rep_cond));
RTW_INFO("bcn_req_rep_info=%u:%u\n",
prm->q.opt.bcn.rep_cond.cond,
prm->q.opt.bcn.rep_cond.threshold);
/*popt_id[prm->q.opt.bcn.opt_id_num++] = pbody[p];*/
break;
case bcn_req_rep_detail:
#if DBG_BCN_REQ_DETAIL
prm->q.opt.bcn.rep_detail = 2; /* all IE in beacon */
#else
prm->q.opt.bcn.rep_detail = pbody[p+2];
#endif
popt_id[prm->q.opt.bcn.opt_id_num++] = pbody[p];
#if (RM_MORE_DBG_MSG)
RTW_INFO("RM: report_detail=%d\n",
prm->q.opt.bcn.rep_detail);
#endif
break;
case bcn_req_req:
RTW_INFO("RM: bcn_req_req\n");
prm->q.opt.bcn.req_start = rtw_malloc(pbody[p+1]);
if (prm->q.opt.bcn.req_start == NULL) {
RTW_ERR("RM: req_start malloc fail!!\n");
break;
}
for (i = 0; i < pbody[p+1]; i++)
*((prm->q.opt.bcn.req_start)+i) =
pbody[p+2+i];
prm->q.opt.bcn.req_len = pbody[p+1];
popt_id[prm->q.opt.bcn.opt_id_num++] = pbody[p];
break;
case bcn_req_ap_ch_rep:
#if (RM_MORE_DBG_MSG)
RTW_INFO("RM: bcn_req_ap_ch_rep\n");
#endif
if (ap_ch_rpt_idx > BCN_REQ_OPT_AP_CH_RPT_MAX_NUM) {
RTW_ERR("RM: bcn_req_ap_ch_rep over size\n");
break;
}
popt_id[prm->q.opt.bcn.opt_id_num++] = pbody[p];
/* get channel list
* EID:len:op-class:ch-list
*/
op = rtw_malloc(sizeof (*op));
op->global_op_class = pbody[p + 2];
i = pbody[p + 1] - 1; /* ch list len; (-1) is op class */
#if (RM_MORE_DBG_MSG)
RTW_INFO("%d op class %d has %d ch\n",
ap_ch_rpt_idx,op->global_op_class,i);
#endif
op->Len = i;
memcpy(op->Channel, &pbody[p + 3],
MIN(i, MAX_CH_NUM_IN_OP_CLASS));
prm->q.opt.bcn.ap_ch_rpt[ap_ch_rpt_idx++] = op;
prm->q.opt.bcn.ap_ch_rpt_num = ap_ch_rpt_idx;
break;
default:
break;
}
len = len - (int)pbody[p+1] - 2;
p = p + (int)pbody[p+1] + 2;
#if (RM_MORE_DBG_MSG)
RTW_INFO("RM: opt_s_elem_len=%d\n",len);
#endif
}
return _SUCCESS;
}
static int rm_parse_meas_req(struct rm_obj *prm, u8 *pbody)
{
int p; /* position */
int req_len;
req_len = (int)pbody[1];
p = 5;
prm->q.op_class = pbody[p++];
prm->q.ch_num = pbody[p++];
prm->q.rand_intvl = le16_to_cpu(*(u16*)(&pbody[p]));
p+=2;
prm->q.meas_dur = le16_to_cpu(*(u16*)(&pbody[p]));
p+=2;
if (prm->q.m_type == bcn_req) {
/*
* 0: passive
* 1: active
* 2: bcn_table
*/
prm->q.m_mode = pbody[p++];
/* BSSID */
_rtw_memcpy(&(prm->q.bssid), &pbody[p], 6);
p+=6;
/*
* default, used when Reporting detail subelement
* is not included in Beacon Request
*/
prm->q.opt.bcn.rep_detail = 2;
}
if (req_len-(p-2) <= 0) /* without sub-element */
return _SUCCESS;
switch (prm->q.m_type) {
case bcn_req:
rm_parse_bcn_req_s_elem(prm, &pbody[p], req_len-(p-2));
break;
case ch_load_req:
rm_parse_ch_load_s_elem(prm, &pbody[p], req_len-(p-2));
break;
case noise_histo_req:
rm_parse_noise_histo_s_elem(prm, &pbody[p], req_len-(p-2));
break;
default:
break;
}
return _SUCCESS;
}
/* receive measurement request */
int rm_recv_radio_mens_req(_adapter *padapter,
union recv_frame *precv_frame, struct sta_info *psta)
{
struct rm_obj *prm;
struct rm_priv *prmpriv = &padapter->rmpriv;
u8 *pdiag_body = (u8 *)(precv_frame->u.hdr.rx_data +
sizeof(struct rtw_ieee80211_hdr_3addr));
u8 *pmeas_body = &pdiag_body[5];
u8 rmid, update = 0;
#if 0
/* search existing rm_obj */
rmid = psta->cmn.aid << 16
| pdiag_body[2] << 8
| RM_SLAVE;
prm = rm_get_rmobj(padapter, rmid);
if (prm) {
RTW_INFO("RM: Found an exist meas rmid=%u\n", rmid);
update = 1;
} else
#endif
prm = rm_alloc_rmobj(padapter);
if (prm == NULL) {
RTW_ERR("RM: unable to alloc rm obj for requeset\n");
return _FALSE;
}
prm->psta = psta;
prm->q.diag_token = pdiag_body[2];
prm->q.rpt = le16_to_cpu(*(u16*)(&pdiag_body[3]));
/* Figure 8-104 Measurement Requested format */
prm->q.e_id = pmeas_body[0];
prm->q.m_token = pmeas_body[2];
prm->q.m_mode = pmeas_body[3];
prm->q.m_type = pmeas_body[4];
prm->rmid = rm_gen_rmid(padapter, prm, RM_SLAVE);
RTW_INFO("RM: rmid=%x, bssid " MAC_FMT "\n", prm->rmid,
MAC_ARG(prm->psta->cmn.mac_addr));
#if (RM_MORE_DBG_MSG)
RTW_INFO("RM: element_id = %d\n", prm->q.e_id);
RTW_INFO("RM: length = %d\n", (int)pmeas_body[1]);
RTW_INFO("RM: meas_token = %d\n", prm->q.m_token);
RTW_INFO("RM: meas_mode = %d\n", prm->q.m_mode);
RTW_INFO("RM: meas_type = %d\n", prm->q.m_type);
#endif
if (prm->q.e_id != _MEAS_REQ_IE_) /* 38 */
return _FALSE;
switch (prm->q.m_type) {
case bcn_req:
RTW_INFO("RM: recv beacon_request\n");
switch (prm->q.m_mode) {
case bcn_req_passive:
rm_en_cap_chk_and_set(prm, RM_BCN_PASSIVE_MEAS_CAP_EN);
break;
case bcn_req_active:
rm_en_cap_chk_and_set(prm, RM_BCN_ACTIVE_MEAS_CAP_EN);
break;
case bcn_req_bcn_table:
rm_en_cap_chk_and_set(prm, RM_BCN_TABLE_MEAS_CAP_EN);
break;
default:
rm_set_rep_mode(prm, MEAS_REP_MOD_INCAP);
break;
}
break;
case ch_load_req:
RTW_INFO("RM: recv ch_load_request\n");
rm_en_cap_chk_and_set(prm, RM_CH_LOAD_CAP_EN);
break;
case noise_histo_req:
RTW_INFO("RM: recv noise_histogram_request\n");
rm_en_cap_chk_and_set(prm, RM_NOISE_HISTO_CAP_EN);
break;
default:
RTW_INFO("RM: recv unknown request type 0x%02x\n",
prm->q.m_type);
rm_set_rep_mode(prm, MEAS_REP_MOD_INCAP);
goto done;
}
rm_parse_meas_req(prm, pmeas_body);
done:
if (!update)
rm_enqueue_rmobj(padapter, prm, _FALSE);
return _SUCCESS;
}
/* receive measurement report */
int rm_recv_radio_mens_rep(_adapter *padapter,
union recv_frame *precv_frame, struct sta_info *psta)
{
int len, ret = _FALSE;
struct rm_obj *prm;
u32 rmid;
u8 *pdiag_body = (u8 *)(precv_frame->u.hdr.rx_data +
sizeof(struct rtw_ieee80211_hdr_3addr));
u8 *pmeas_body = &pdiag_body[3];
rmid = psta->cmn.aid << 16
| pdiag_body[2] << 8
| RM_MASTER;
prm = rm_get_rmobj(padapter, rmid);
if (prm == NULL) {
/* not belong to us, report to upper */
rtw_cfg80211_rx_rrm_action(psta->padapter, precv_frame);
return _TRUE;
}
prm->p.action_code = pdiag_body[1];
prm->p.diag_token = pdiag_body[2];
/* Figure 8-140 Measuremnt Report format */
prm->p.e_id = pmeas_body[0];
prm->p.m_token = pmeas_body[2];
prm->p.m_mode = pmeas_body[3];
prm->p.m_type = pmeas_body[4];
RTW_INFO("RM: rmid=%x, bssid " MAC_FMT "\n", prm->rmid,
MAC_ARG(prm->psta->cmn.mac_addr));
#if (RM_MORE_DBG_MSG)
RTW_INFO("RM: element_id = %d\n", prm->p.e_id);
RTW_INFO("RM: length = %d\n", (int)pmeas_body[1]);
RTW_INFO("RM: meas_token = %d\n", prm->p.m_token);
RTW_INFO("RM: meas_mode = %d\n", prm->p.m_mode);
RTW_INFO("RM: meas_type = %d\n", prm->p.m_type);
#endif
if (prm->p.e_id != _MEAS_RSP_IE_) /* 39 */
return _FALSE;
RTW_INFO("RM: recv %s\n", rm_type_rep_name(prm->p.m_type));
rm_post_event(padapter, prm->rmid, RM_EV_recv_rep);
/* report to upper via ioctl */
if ((prm->from_ioctl == true) &&
prm->q.m_type == bcn_req) {
len = pmeas_body[1] + 2; /* 2 : EID(1B) length(1B) */
indicate_beacon_report(prm->psta->cmn.mac_addr,
1, len, pmeas_body);
}
return ret;
}
/* receive link measurement request */
int rm_recv_link_mens_req(_adapter *padapter,
union recv_frame *precv_frame, struct sta_info *psta)
{
struct rm_obj *prm;
struct rm_priv *prmpriv = &padapter->rmpriv;
u8 *pdiag_body = (u8 *)(precv_frame->u.hdr.rx_data +
sizeof(struct rtw_ieee80211_hdr_3addr));
u8 *pmeas_body = &pdiag_body[3];
u8 rmid, update = 0;
int i;
prm = rm_alloc_rmobj(padapter);
if (prm == NULL) {
RTW_ERR("RM: unable to alloc rm obj for requeset\n");
return _FALSE;
}
prm->psta = psta;
prm->q.action_code = pdiag_body[1];
prm->q.diag_token = pdiag_body[2];
prm->q.tx_pwr_used = pmeas_body[0];
prm->q.tx_pwr_max = pmeas_body[1];
prm->q.rx_pwr = precv_frame->u.hdr.attrib.phy_info.rx_power;
prm->q.rx_rate = hw_rate_to_m_rate(precv_frame->u.hdr.attrib.data_rate);
prm->q.rx_bw = precv_frame->u.hdr.attrib.bw;
prm->q.rx_rsni = rm_get_frame_rsni(prm, precv_frame);
prm->rmid = rm_gen_rmid(padapter, prm, RM_SLAVE);
RTW_INFO("RM: rmid=%x, bssid" MAC_FMT " rx_pwr=%ddBm, rate=%s\n",
prm->rmid, MAC_ARG(prm->psta->cmn.mac_addr), prm->q.rx_pwr,
MGN_RATE_STR(prm->q.rx_rate));
#if (RM_MORE_DBG_MSG)
RTW_INFO("RM: tx_pwr_used =%d dBm\n", prm->q.tx_pwr_used);
RTW_INFO("RM: tx_pwr_max =%d dBm\n", prm->q.tx_pwr_max);
#endif
if (!update)
rm_enqueue_rmobj(padapter, prm, _FALSE);
return _SUCCESS;
}
/* receive link measurement report */
int rm_recv_link_mens_rep(_adapter *padapter,
union recv_frame *precv_frame, struct sta_info *psta)
{
int ret = _FALSE;
struct rm_obj *prm;
u32 rmid;
u8 *pdiag_body = (u8 *)(precv_frame->u.hdr.rx_data +
sizeof(struct rtw_ieee80211_hdr_3addr));
u8 *pmeas_body = pdiag_body + 3;
s8 val;
rmid = psta->cmn.aid << 16
| pdiag_body[2] << 8
| RM_MASTER;
prm = rm_get_rmobj(padapter, rmid);
if (prm == NULL) {
/* not belong to us, report to upper */
rtw_cfg80211_rx_rrm_action(psta->padapter, precv_frame);
return _TRUE;
}
RTW_INFO("RM: rmid=%x, bssid " MAC_FMT "\n", prm->rmid,
MAC_ARG(prm->psta->cmn.mac_addr));
prm->p.action_code = pdiag_body[1];
prm->p.diag_token = pdiag_body[2];
#if (RM_MORE_DBG_MSG)
RTW_INFO("RM: action_code = %d\n", prm->p.action_code);
RTW_INFO("RM: diag_token = %d\n", prm->p.diag_token);
RTW_INFO("RM: xmit_power = %d dBm\n", pmeas_body[2]);
RTW_INFO("RM: link_margin = %d dBm\n", pmeas_body[3]);
RTW_INFO("RM: xmit_ant = %d\n", pmeas_body[4]);
RTW_INFO("RM: recv_ant = %d\n", pmeas_body[5]);
RTW_INFO("RM: RCPI = %d\n", pmeas_body[6]);
RTW_INFO("RM: RSNI = %d\n", pmeas_body[7]);
#endif
RTW_INFO("RM: recv link meas report ...\n");
ret = rm_post_event(padapter, prm->rmid, RM_EV_recv_rep);
return ret;
}
int rm_radio_mens_nb_rep(_adapter *padapter,
union recv_frame *precv_frame, struct sta_info *psta)
{
u8 *pdiag_body = (u8 *)(precv_frame->u.hdr.rx_data +
sizeof(struct rtw_ieee80211_hdr_3addr));
u8 *pmeas_body = &pdiag_body[3];
u32 len = precv_frame->u.hdr.len;
u32 rmid;
struct rm_obj *prm;
rmid = psta->cmn.aid << 16
| pdiag_body[2] << 8
| RM_MASTER;
prm = rm_get_rmobj(padapter, rmid);
if (prm == NULL) {
/* not belong to us, report to upper */
rtw_cfg80211_rx_rrm_action(psta->padapter, precv_frame);
return _TRUE;
}
prm->p.action_code = pdiag_body[1];
prm->p.diag_token = pdiag_body[2];
prm->p.e_id = pmeas_body[0];
RTW_INFO("RM: rmid=%x, bssid " MAC_FMT "\n", prm->rmid,
MAC_ARG(prm->psta->cmn.mac_addr));
#if (RM_MORE_DBG_MSG)
RTW_INFO("RM: element_id = %d\n", prm->p.e_id);
RTW_INFO("RM: length = %d\n", (int)pmeas_body[1]);
#endif
rm_post_event(padapter, prm->rmid, RM_EV_recv_rep);
#ifdef CONFIG_LAYER2_ROAMING
if (rtw_wnm_btm_candidates_survey(padapter
,(pdiag_body + 3)
,(len - sizeof(struct rtw_ieee80211_hdr_3addr))
,_FALSE) == _FAIL)
return _FALSE;
#endif
rtw_cfg80211_rx_rrm_action(padapter, precv_frame);
return _TRUE;
}
unsigned int rm_on_action(_adapter *padapter, union recv_frame *precv_frame)
{
u32 ret = _FAIL;
u8 *pframe = NULL;
u8 *pframe_body = NULL;
u8 action_code = 0;
u8 diag_token = 0;
struct rtw_ieee80211_hdr_3addr *whdr;
struct sta_info *psta;
pframe = precv_frame->u.hdr.rx_data;
/* check RA matches or not */
if (!_rtw_memcmp(adapter_mac_addr(padapter),
GetAddr1Ptr(pframe), ETH_ALEN))