forked from initdc/eswin_6600u
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecrnx_msg_rx.c
executable file
·1404 lines (1178 loc) · 48.7 KB
/
ecrnx_msg_rx.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
/**
****************************************************************************************
*
* @file ecrnx_msg_rx.c
*
* @brief RX function definitions
*
* Copyright (C) ESWIN 2015-2020
*
****************************************************************************************
*/
#include "ecrnx_defs.h"
#include "ecrnx_prof.h"
#include "ecrnx_tx.h"
#ifdef CONFIG_ECRNX_BFMER
#include "ecrnx_bfmer.h"
#endif //(CONFIG_ECRNX_BFMER)
#include "ecrnx_debugfs.h"
#include "ecrnx_msg_tx.h"
#include "ecrnx_tdls.h"
#include "ecrnx_events.h"
#include "ecrnx_compat.h"
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0)
#include <linux/time.h>
#endif
#if defined(CONFIG_ECRNX_DEBUGFS_CUSTOM)
#include "ecrnx_debugfs_func.h"
#endif
static int ecrnx_freq_to_idx(struct ecrnx_hw *ecrnx_hw, int freq)
{
struct ieee80211_supported_band *sband;
int band, ch, idx = 0;
#ifdef CONFIG_ECRNX_5G
for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; band++) {
#else
for (band = NL80211_BAND_2GHZ; band <= NL80211_BAND_2GHZ; band++) {
#endif
sband = ecrnx_hw->wiphy->bands[band];
if (!sband) {
continue;
}
for (ch = 0; ch < sband->n_channels; ch++, idx++) {
if (sband->channels[ch].center_freq == freq) {
goto exit;
}
}
}
ecrnx_printk_err("--!!!!!!!!error freq-----%d\n", freq);
//BUG_ON(1);
exit:
// Channel has been found, return the index
return idx;
}
/***************************************************************************
* Messages from MM task
**************************************************************************/
static inline int ecrnx_rx_chan_pre_switch_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
struct ecrnx_vif *ecrnx_vif;
int chan_idx = ((struct mm_channel_pre_switch_ind *)msg->param)->chan_index;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
REG_SW_SET_PROFILING_CHAN(ecrnx_hw, SW_PROF_CHAN_CTXT_PSWTCH_BIT);
list_for_each_entry(ecrnx_vif, &ecrnx_hw->vifs, list) {
if (ecrnx_vif->up && ecrnx_vif->ch_index == chan_idx) {
ecrnx_txq_vif_stop(ecrnx_vif, ECRNX_TXQ_STOP_CHAN, ecrnx_hw);
}
}
REG_SW_CLEAR_PROFILING_CHAN(ecrnx_hw, SW_PROF_CHAN_CTXT_PSWTCH_BIT);
return 0;
}
static inline int ecrnx_rx_chan_switch_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
struct ecrnx_vif *ecrnx_vif;
int chan_idx = ((struct mm_channel_switch_ind *)msg->param)->chan_index;
bool roc_req = ((struct mm_channel_switch_ind *)msg->param)->roc;
bool roc_tdls = ((struct mm_channel_switch_ind *)msg->param)->roc_tdls;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
REG_SW_SET_PROFILING_CHAN(ecrnx_hw, SW_PROF_CHAN_CTXT_SWTCH_BIT);
if (roc_tdls) {
u8 vif_index = ((struct mm_channel_switch_ind *)msg->param)->vif_index;
list_for_each_entry(ecrnx_vif, &ecrnx_hw->vifs, list) {
if (ecrnx_vif->vif_index == vif_index) {
ecrnx_vif->roc_tdls = true;
ecrnx_txq_tdls_sta_start(ecrnx_vif, ECRNX_TXQ_STOP_CHAN, ecrnx_hw);
}
}
} else if (!roc_req) {
list_for_each_entry(ecrnx_vif, &ecrnx_hw->vifs, list) {
if (ecrnx_vif->up && ecrnx_vif->ch_index == chan_idx) {
ecrnx_txq_vif_start(ecrnx_vif, ECRNX_TXQ_STOP_CHAN, ecrnx_hw);
}
}
} else {
/* Retrieve the allocated RoC element */
struct ecrnx_roc *roc = ecrnx_hw->roc;
if (roc && roc->vif) {
/* Get VIF on which RoC has been started */
ecrnx_vif = roc->vif;
/* For debug purpose (use ftrace kernel option) */
trace_switch_roc(ecrnx_vif->vif_index);
if (!roc->internal) {
/* If mgmt_roc is true, remain on channel has been started by ourself */
/* Inform the host that we have switch on the indicated off-channel */
cfg80211_ready_on_channel(&ecrnx_vif->wdev, (u64)(ecrnx_hw->roc_cookie),
roc->chan, roc->duration, GFP_ATOMIC);
}
/* Keep in mind that we have switched on the channel */
roc->on_chan = true;
}
// Enable traffic on OFF channel queue
ecrnx_txq_offchan_start(ecrnx_hw);
#if defined(CONFIG_ECRNX_P2P)
if (roc && roc->internal) {
ecrnx_hw->p2p_listen.rxdatas = 1;
wake_up(&ecrnx_hw->p2p_listen.rxdataq);
}
#endif
}
ecrnx_hw->cur_chanctx = chan_idx;
ecrnx_radar_detection_enable_on_cur_channel(ecrnx_hw);
REG_SW_CLEAR_PROFILING_CHAN(ecrnx_hw, SW_PROF_CHAN_CTXT_SWTCH_BIT);
return 0;
}
static inline int ecrnx_rx_tdls_chan_switch_cfm(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
return 0;
}
static inline int ecrnx_rx_tdls_chan_switch_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
// Enable traffic on OFF channel queue
ecrnx_txq_offchan_start(ecrnx_hw);
return 0;
}
static inline int ecrnx_rx_tdls_chan_switch_base_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
struct ecrnx_vif *ecrnx_vif;
u8 vif_index = ((struct tdls_chan_switch_base_ind *)msg->param)->vif_index;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
list_for_each_entry(ecrnx_vif, &ecrnx_hw->vifs, list) {
if (ecrnx_vif->vif_index == vif_index) {
ecrnx_vif->roc_tdls = false;
ecrnx_txq_tdls_sta_stop(ecrnx_vif, ECRNX_TXQ_STOP_CHAN, ecrnx_hw);
}
}
return 0;
}
static inline int ecrnx_rx_tdls_peer_ps_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
struct ecrnx_vif *ecrnx_vif;
u8 vif_index = ((struct tdls_peer_ps_ind *)msg->param)->vif_index;
bool ps_on = ((struct tdls_peer_ps_ind *)msg->param)->ps_on;
list_for_each_entry(ecrnx_vif, &ecrnx_hw->vifs, list) {
if (ecrnx_vif->vif_index == vif_index) {
ecrnx_vif->sta.tdls_sta->tdls.ps_on = ps_on;
// Update PS status for the TDLS station
ecrnx_ps_bh_enable(ecrnx_hw, ecrnx_vif->sta.tdls_sta, ps_on);
}
}
return 0;
}
static inline int ecrnx_rx_remain_on_channel_exp_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
if(!ecrnx_hw->roc || !ecrnx_hw->roc->chan){
ecrnx_printk_err("error!!!:ecrnx_hw->roc or !ecrnx_hw->roc->chan is null \n");
return 0;
}
/* Retrieve the allocated RoC element */
struct ecrnx_roc *roc = ecrnx_hw->roc;
/* Get VIF on which RoC has been started */
struct ecrnx_vif *ecrnx_vif = roc->vif;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
/* For debug purpose (use ftrace kernel option) */
trace_roc_exp(ecrnx_vif->vif_index);
/* If mgmt_roc is true, remain on channel has been started by ourself */
/* If RoC has been cancelled before we switched on channel, do not call cfg80211 */
if (!roc->internal && roc->on_chan) {
/* Inform the host that off-channel period has expired */
cfg80211_remain_on_channel_expired(&ecrnx_vif->wdev, (u64)(ecrnx_hw->roc_cookie),
roc->chan, GFP_ATOMIC);
}
/* De-init offchannel TX queue */
ecrnx_txq_offchan_deinit(ecrnx_vif);
/* Increase the cookie counter cannot be zero */
ecrnx_hw->roc_cookie++;
if (ecrnx_hw->roc_cookie == 0)
ecrnx_hw->roc_cookie = 1;
#if CONFIG_ECRNX_P2P
ecrnx_hw->p2p_listen.listen_started = 0;
#endif
/* Free the allocated RoC element */
kfree(roc);
ecrnx_hw->roc = NULL;
#if defined(CONFIG_ECRNX_P2P)
wake_up(&ecrnx_hw->p2p_listen.rxdataq);
#endif
return 0;
}
static inline int ecrnx_rx_p2p_vif_ps_change_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
int vif_idx = ((struct mm_p2p_vif_ps_change_ind *)msg->param)->vif_index;
int ps_state = ((struct mm_p2p_vif_ps_change_ind *)msg->param)->ps_state;
struct ecrnx_vif *vif_entry;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
vif_entry = ecrnx_hw->vif_table[vif_idx];
if (vif_entry) {
goto found_vif;
}
goto exit;
found_vif:
if (ps_state == MM_PS_MODE_OFF) {
// Start TX queues for provided VIF
ecrnx_txq_vif_start(vif_entry, ECRNX_TXQ_STOP_VIF_PS, ecrnx_hw);
}
else {
// Stop TX queues for provided VIF
ecrnx_txq_vif_stop(vif_entry, ECRNX_TXQ_STOP_VIF_PS, ecrnx_hw);
}
exit:
return 0;
}
static inline int ecrnx_rx_channel_survey_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
struct mm_channel_survey_ind *ind = (struct mm_channel_survey_ind *)msg->param;
// Get the channel index
int idx = ecrnx_freq_to_idx(ecrnx_hw, ind->freq);
// Get the survey
struct ecrnx_survey_info *ecrnx_survey;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
if (idx > ARRAY_SIZE(ecrnx_hw->survey))
return 0;
ecrnx_survey = &ecrnx_hw->survey[idx];
// Store the received parameters
ecrnx_survey->chan_time_ms = ind->chan_time_ms;
ecrnx_survey->chan_time_busy_ms = ind->chan_time_busy_ms;
ecrnx_survey->noise_dbm = ind->noise_dbm;
ecrnx_survey->filled = (SURVEY_INFO_TIME |
SURVEY_INFO_TIME_BUSY);
if (ind->noise_dbm != 0) {
ecrnx_survey->filled |= SURVEY_INFO_NOISE_DBM;
}
#if defined(CONFIG_ECRNX_DEBUGFS_CUSTOM)
ecrnx_debugfs_noise_of_survey_info_update(ecrnx_hw, ecrnx_survey, idx);
#endif
return 0;
}
static inline int ecrnx_rx_p2p_noa_upd_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
return 0;
}
static inline int ecrnx_rx_rssi_status_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
struct mm_rssi_status_ind *ind = (struct mm_rssi_status_ind *)msg->param;
int vif_idx = ind->vif_index;
bool rssi_status = ind->rssi_status;
struct ecrnx_vif *vif_entry;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
vif_entry = ecrnx_hw->vif_table[vif_idx];
if (vif_entry) {
ecrnx_cfg80211_cqm_rssi_notify(vif_entry->ndev,
rssi_status ? NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW :
NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
ind->rssi, GFP_ATOMIC);
}
return 0;
}
static inline int ecrnx_rx_pktloss_notify_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
struct mm_pktloss_ind *ind = (struct mm_pktloss_ind *)msg->param;
struct ecrnx_vif *vif_entry;
int vif_idx = ind->vif_index;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
vif_entry = ecrnx_hw->vif_table[vif_idx];
if (vif_entry) {
cfg80211_cqm_pktloss_notify(vif_entry->ndev, (const u8 *)ind->mac_addr.array,
ind->num_packets, GFP_ATOMIC);
}
return 0;
}
static inline int ecrnx_rx_csa_counter_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
struct mm_csa_counter_ind *ind = (struct mm_csa_counter_ind *)msg->param;
struct ecrnx_vif *vif;
bool found = false;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
// Look for VIF entry
list_for_each_entry(vif, &ecrnx_hw->vifs, list) {
if (vif->vif_index == ind->vif_index) {
found=true;
break;
}
}
if (found) {
if (vif->ap.csa)
vif->ap.csa->count = ind->csa_count;
else
netdev_err(vif->ndev, "CSA counter update but no active CSA");
}
return 0;
}
static inline int ecrnx_rx_csa_finish_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
struct mm_csa_finish_ind *ind = (struct mm_csa_finish_ind *)msg->param;
struct ecrnx_vif *vif;
bool found = false;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
// Look for VIF entry
list_for_each_entry(vif, &ecrnx_hw->vifs, list) {
if (vif->vif_index == ind->vif_index) {
found=true;
break;
}
}
if (found) {
if (ECRNX_VIF_TYPE(vif) == NL80211_IFTYPE_AP ||
ECRNX_VIF_TYPE(vif) == NL80211_IFTYPE_P2P_GO) {
if (vif->ap.csa) {
vif->ap.csa->status = ind->status;
vif->ap.csa->ch_idx = ind->chan_idx;
schedule_work(&vif->ap.csa->work);
} else
netdev_err(vif->ndev, "CSA finish indication but no active CSA");
} else {
if (ind->status == 0) {
ecrnx_chanctx_unlink(vif);
ecrnx_chanctx_link(vif, ind->chan_idx, NULL);
if (ecrnx_hw->cur_chanctx == ind->chan_idx) {
ecrnx_radar_detection_enable_on_cur_channel(ecrnx_hw);
ecrnx_txq_vif_start(vif, ECRNX_TXQ_STOP_CHAN, ecrnx_hw);
} else
ecrnx_txq_vif_stop(vif, ECRNX_TXQ_STOP_CHAN, ecrnx_hw);
}
}
}
return 0;
}
static inline int ecrnx_rx_csa_traffic_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
struct mm_csa_traffic_ind *ind = (struct mm_csa_traffic_ind *)msg->param;
struct ecrnx_vif *vif;
bool found = false;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
// Look for VIF entry
list_for_each_entry(vif, &ecrnx_hw->vifs, list) {
if (vif->vif_index == ind->vif_index) {
found=true;
break;
}
}
if (found) {
if (ind->enable)
ecrnx_txq_vif_start(vif, ECRNX_TXQ_STOP_CSA, ecrnx_hw);
else
ecrnx_txq_vif_stop(vif, ECRNX_TXQ_STOP_CSA, ecrnx_hw);
}
return 0;
}
static inline int ecrnx_rx_ps_change_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
struct mm_ps_change_ind *ind = (struct mm_ps_change_ind *)msg->param;
struct ecrnx_sta *sta = &ecrnx_hw->sta_table[ind->sta_idx];
if (ind->sta_idx >= (NX_REMOTE_STA_MAX + NX_VIRT_DEV_MAX)) {
wiphy_err(ecrnx_hw->wiphy, "Invalid sta index reported by fw %d\n",
ind->sta_idx);
return 1;
}
netdev_dbg(ecrnx_hw->vif_table[sta->vif_idx]->ndev,
"Sta %d, change PS mode to %s", sta->sta_idx,
ind->ps_state ? "ON" : "OFF");
ecrnx_printk_msg("Sta:0x%p, sta_idx:%d, sta->valid:%d, sta_mac:%pM, change PS mode to: %s \n",sta, sta->sta_idx, sta->valid, sta->mac_addr, ind->ps_state ? "ON" : "OFF");
if (sta->valid) {
ecrnx_ps_bh_enable(ecrnx_hw, sta, ind->ps_state);
} else if (test_bit(ECRNX_DEV_ADDING_STA, &ecrnx_hw->flags)) {
sta->ps.active = ind->ps_state ? true : false;
} else {
netdev_err(ecrnx_hw->vif_table[sta->vif_idx]->ndev,
"Ignore PS mode change on invalid sta\n");
}
return 0;
}
static inline int ecrnx_rx_traffic_req_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
struct mm_traffic_req_ind *ind = (struct mm_traffic_req_ind *)msg->param;
struct ecrnx_sta *sta = &ecrnx_hw->sta_table[ind->sta_idx];
ecrnx_printk_msg("%s-%d:Sta:0x%p, sta_idx:%d, sta->valid:%d, sta_mac:%pM \n",__func__, __LINE__, sta, ind->sta_idx, sta->valid, sta->mac_addr);
netdev_dbg(ecrnx_hw->vif_table[sta->vif_idx]->ndev,
"Sta %d, asked for %d pkt", sta->sta_idx, ind->pkt_cnt);
ecrnx_ps_bh_traffic_req(ecrnx_hw, sta, ind->pkt_cnt,
ind->uapsd ? UAPSD_ID : LEGACY_PS_ID);
return 0;
}
/***************************************************************************
* Messages from SCANU task
**************************************************************************/
#ifdef CONFIG_ECRNX_FULLMAC
static inline int ecrnx_scanu_cancel_cfm(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
struct scanu_cancel_cfm *cfm = (struct scanu_cancel_cfm *)msg;
bool abort = false;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)
struct cfg80211_scan_info info = {
.aborted = abort,
};
#endif
ecrnx_printk_always("%s: cfm status:%d, scan_request:0x%p \n", __func__, cfm->status, ecrnx_hw->scan_request);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)
cfg80211_scan_done(ecrnx_hw->scan_request, &info);
#else
cfg80211_scan_done(ecrnx_hw->scan_request, false);
#endif
ecrnx_hw->scan_request = NULL;
return 0;
}
static inline int ecrnx_rx_scanu_start_cfm(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
struct scanu_start_cfm* cfm = (struct scanu_start_cfm*)msg->param;
u8_l abort_status;
ecrnx_printk_always("%s: receive scanu cfm, status:%d \n", __func__, cfm->status);
abort_status = cfm->status?true:false;
spin_lock_bh(&ecrnx_hw->scan_req_lock);
if (ecrnx_hw->scan_request) {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)
struct cfg80211_scan_info info = {
.aborted = abort_status,
};
ecrnx_printk_always("%s: cfm status:%d, scan_request:0x%p \n", __func__, cfm->status, ecrnx_hw->scan_request);
cfg80211_scan_done(ecrnx_hw->scan_request, &info);
#else
cfg80211_scan_done(ecrnx_hw->scan_request, abort_status);
#endif
}
ecrnx_hw->scan_request = NULL;
spin_unlock_bh(&ecrnx_hw->scan_req_lock);
return 0;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0)
u64_l getBootTime(void)
{
struct timespec64 ts;
u64_l bootTime = 0;
ts = ktime_to_timespec64(ktime_get_boottime());
bootTime = ts.tv_sec;
bootTime *= 1000000;
bootTime += ts.tv_nsec / 1000;
return bootTime;
}
#endif
#ifdef CONFIG_WIRELESS_EXT
static inline int ecrnx_ieee80211_mgmt_to_network(struct ecrnx_hw *ecrnx_hw, struct cfg80211_bss *bss)
{
struct wlan_network *new_network, *entry, *tmp;
const struct cfg80211_bss_ies *ies;
const u8 *ssid_elm = NULL, *ht_elm = NULL, *he_elm = NULL, *ie_wpa = NULL, *ie_wpa2 = NULL;
const u8 *ie_p2p = NULL;
u8 ie_len = 0;
ies = rcu_dereference(bss->ies);
ie_p2p = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
ies->data,ies->len);
if(ie_p2p)
{
return -1;
}
new_network = kzalloc(sizeof(struct wlan_network), in_atomic()? GFP_ATOMIC:GFP_KERNEL);
if(!new_network)
{
return -2;
}
new_network->ch = ieee80211_frequency_to_channel(bss->channel->center_freq);
ether_addr_copy(new_network->bssid, bss->bssid);
ssid_elm = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len);
if (ssid_elm)
{
if (ssid_elm[1] <= IEEE80211_MAX_SSID_LEN)
{
memcpy(new_network->ssid, ssid_elm + 2, ssid_elm[1]);
new_network->ssid_len = ssid_elm[1];
}
}
new_network->rssi = bss->signal/100;
new_network->cap = cpu_to_le16(bss->capability);
ht_elm = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies->data, ies->len);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
he_elm = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies->data, ies->len);
#endif
if(ht_elm && he_elm)
{
new_network->bss_protol |= BIT(2);
}
else if(he_elm)
{
new_network->bss_protol |= BIT(3);
}
else if(ht_elm)
{
new_network->bss_protol |= BIT(0);
}
else
{
new_network->bss_protol |= BIT(1);
}
if(ht_elm)
{
new_network->ht_cap = cpu_to_le16(*(unsigned short *)(ht_elm + 2));
}
if(new_network->cap & BIT(4)) {
ie_wpa2 = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
if(ie_wpa2)
{
ie_len = ie_wpa2[1];
memcpy(new_network->rsn_ie, ie_wpa2, ie_len + 2);
}
ie_wpa = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
WLAN_OUI_TYPE_MICROSOFT_WPA,
ies->data, ies->len);
if(ie_wpa)
{
ie_len = ie_wpa[1];
memcpy(new_network->wpa_ie, ie_wpa, ie_len + 2);
}
}
INIT_LIST_HEAD(&new_network->list);
list_for_each_entry_safe(entry, tmp, &ecrnx_hw->scan_list, list) {
if(memcmp(entry->bssid, new_network->bssid, ETH_ALEN) == 0) {
list_del(&entry->list);
kfree(entry);
}
}
list_add_tail(&new_network->list, &ecrnx_hw->scan_list);
return 0;
}
#endif
static inline int ecrnx_rx_scanu_result_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
struct cfg80211_bss *bss = NULL;
struct ieee80211_channel *chan;
struct scanu_result_ind *ind = (struct scanu_result_ind *)msg->param;
struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)ind->payload;
chan = ieee80211_get_channel(ecrnx_hw->wiphy, ind->center_freq);
if (chan != NULL)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0)
if(ieee80211_is_beacon(mgmt->frame_control))
{
mgmt->u.beacon.timestamp = getBootTime();
}
if(ieee80211_is_probe_resp(mgmt->frame_control))
{
mgmt->u.probe_resp.timestamp = getBootTime();
}
#endif
bss = cfg80211_inform_bss_frame(ecrnx_hw->wiphy, chan,
mgmt,
ind->length, ind->rssi * 100, GFP_ATOMIC);
}
if (bss != NULL)
{
#ifdef CONFIG_WIRELESS_EXT
ecrnx_ieee80211_mgmt_to_network(ecrnx_hw, bss);
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)
cfg80211_put_bss(ecrnx_hw->wiphy, bss);
#else
cfg80211_put_bss(bss);
#endif
}
//ecrnx_printk_scan("%s:bssid:%pM, signal:%d, band:%d, freq:%d, freq_offset:%d \n", __func__, bss->bssid, bss->signal, bss->channel->band, bss->channel->center_freq, bss->channel->freq_offset);
#if defined(CONFIG_ECRNX_DEBUGFS_CUSTOM)
ecrnx_debugfs_survey_info_update(ecrnx_hw, bss);
#endif
return 0;
}
#endif /* CONFIG_ECRNX_FULLMAC */
/***************************************************************************
* Messages from ME task
**************************************************************************/
static inline int ecrnx_rx_me_tkip_mic_failure_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
struct me_tkip_mic_failure_ind *ind = (struct me_tkip_mic_failure_ind *)msg->param;
struct ecrnx_vif *ecrnx_vif = ecrnx_hw->vif_table[ind->vif_idx];
struct net_device *dev = ecrnx_vif->ndev;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
cfg80211_michael_mic_failure(dev, (u8 *)&ind->addr, (ind->ga?NL80211_KEYTYPE_GROUP:
NL80211_KEYTYPE_PAIRWISE), ind->keyid,
(u8 *)&ind->tsc, GFP_ATOMIC);
return 0;
}
static inline int ecrnx_rx_me_tx_credits_update_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
struct me_tx_credits_update_ind *ind = (struct me_tx_credits_update_ind *)msg->param;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
ecrnx_txq_credit_update(ecrnx_hw, ind->sta_idx, ind->tid, ind->credits);
return 0;
}
/***************************************************************************
* Messages from SM task
**************************************************************************/
static inline int ecrnx_rx_sm_connect_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
struct sm_connect_ind *ind = (struct sm_connect_ind *)msg->param;
struct ecrnx_vif *ecrnx_vif = ecrnx_hw->vif_table[ind->vif_idx];
struct net_device *dev = ecrnx_vif->ndev;
const u8 *req_ie, *rsp_ie;
const u8 *extcap_ie;
const struct ieee_types_extcap *extcap;
struct mac_rateset *rateset;
u8 i = 0;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
spin_lock_bh(&ecrnx_hw->connect_req_lock);
/* Retrieve IE addresses and lengths */
req_ie = (const u8 *)ind->assoc_ie_buf;
rsp_ie = req_ie + ind->assoc_req_ie_len;
// Fill-in the AP information
if (ind->status_code == 0)
{
struct ecrnx_sta *sta = &ecrnx_hw->sta_table[ind->ap_idx];
rateset = &sta->rate_set;
u8 txq_status;
struct ieee80211_channel *chan;
struct cfg80211_chan_def chandef;
sta->valid = true;
memset(&sta->rx_pn, 0, TID_MAX * sizeof(uint64_t));
memset(&ecrnx_vif->rx_pn, 0, TID_MAX * sizeof(uint64_t));
memset(rateset->array, 0, MAC_RATESET_LEN);
rateset->length = *(u8 *)(req_ie + ind->assoc_req_ie_len + 1);
memcpy(rateset->array, (u8 *)(req_ie + ind->assoc_req_ie_len + 2), rateset->length);
sta->sta_idx = ind->ap_idx;
sta->ch_idx = ind->ch_idx;
sta->vif_idx = ind->vif_idx;
sta->vlan_idx = sta->vif_idx;
sta->qos = ind->qos;
sta->bss_cap = ind->bss_cap;
sta->acm = ind->acm;
sta->ps.active = false;
sta->aid = ind->aid;
sta->band = ind->chan.band;
sta->width = ind->chan.type;
sta->center_freq = ind->chan.prim20_freq;
sta->center_freq1 = ind->chan.center1_freq;
sta->center_freq2 = ind->chan.center2_freq;
ecrnx_vif->sta.ap = sta;
ecrnx_vif->generation++;
chan = ieee80211_get_channel(ecrnx_hw->wiphy, ind->chan.prim20_freq);
cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
if (!ecrnx_hw->mod_params->ht_on)
chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
else
chandef.width = chnl2bw[ind->chan.type];
chandef.center_freq1 = ind->chan.center1_freq;
chandef.center_freq2 = ind->chan.center2_freq;
ecrnx_chanctx_link(ecrnx_vif, ind->ch_idx, &chandef);
memcpy(sta->mac_addr, ind->bssid.array, ETH_ALEN);
if (ind->ch_idx == ecrnx_hw->cur_chanctx) {
txq_status = 0;
} else {
txq_status = ECRNX_TXQ_STOP_CHAN;
}
memcpy(sta->ac_param, ind->ac_param, sizeof(sta->ac_param));
ecrnx_txq_sta_init(ecrnx_hw, sta, txq_status);
ecrnx_rx_reord_sta_init(ecrnx_hw, ecrnx_hw->vif_table[sta->vif_idx], sta->sta_idx);
ecrnx_dbgfs_register_sta(ecrnx_hw, sta);
ecrnx_printk_always("ecrnx_rx_sm_connect_ind, mac[%02x:%02x:%02x:%02x:%02x:%02x], status_code:%d \n", \
sta->mac_addr[0], sta->mac_addr[1], sta->mac_addr[2], sta->mac_addr[3], sta->mac_addr[4], sta->mac_addr[5], ind->status_code);
ecrnx_txq_tdls_vif_init(ecrnx_vif);
ecrnx_mu_group_sta_init(sta, NULL);
/* Look for TDLS Channel Switch Prohibited flag in the Extended Capability
* Information Element*/
extcap_ie = cfg80211_find_ie(WLAN_EID_EXT_CAPABILITY, rsp_ie, ind->assoc_rsp_ie_len);
if (extcap_ie && extcap_ie[1] >= 5) {
extcap = (void *)(extcap_ie);
ecrnx_vif->tdls_chsw_prohibited = extcap->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED;
}
#ifdef CONFIG_ECRNX_BFMER
/* If Beamformer feature is activated, check if features can be used
* with the new peer device
*/
if (ecrnx_hw->mod_params->bfmer) {
const u8 *vht_capa_ie;
const struct ieee80211_vht_cap *vht_cap;
do {
/* Look for VHT Capability Information Element */
vht_capa_ie = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, rsp_ie,
ind->assoc_rsp_ie_len);
/* Stop here if peer device does not support VHT */
if (!vht_capa_ie) {
break;
}
vht_cap = (const struct ieee80211_vht_cap *)(vht_capa_ie + 2);
/* Send MM_BFMER_ENABLE_REQ message if needed */
ecrnx_send_bfmer_enable(ecrnx_hw, sta, vht_cap);
} while (0);
}
#endif //(CONFIG_ECRNX_BFMER)
#ifdef CONFIG_ECRNX_MON_DATA
// If there are 1 sta and 1 monitor interface active at the same time then
// monitor interface channel context is always the same as the STA interface.
// This doesn't work with 2 STA interfaces but we don't want to support it.
if (ecrnx_hw->monitor_vif != ECRNX_INVALID_VIF) {
struct ecrnx_vif *ecrnx_mon_vif = ecrnx_hw->vif_table[ecrnx_hw->monitor_vif];
ecrnx_chanctx_unlink(ecrnx_mon_vif);
ecrnx_chanctx_link(ecrnx_mon_vif, ind->ch_idx, NULL);
}
#endif
}
if (ind->roamed) {
struct cfg80211_roam_info info;
memset(&info, 0, sizeof(info));
if (ecrnx_vif->ch_index < NX_CHAN_CTXT_CNT)
info.channel = ecrnx_hw->chanctx_table[ecrnx_vif->ch_index].chan_def.chan;
info.bssid = (const u8 *)ind->bssid.array;
info.req_ie = req_ie;
info.req_ie_len = ind->assoc_req_ie_len;
info.resp_ie = rsp_ie;
info.resp_ie_len = ind->assoc_rsp_ie_len;
cfg80211_roamed(dev, &info, GFP_ATOMIC);
} else {
cfg80211_connect_result(dev, (const u8 *)ind->bssid.array, req_ie,
ind->assoc_req_ie_len, rsp_ie,
ind->assoc_rsp_ie_len, ind->status_code,
GFP_ATOMIC);
}
netif_tx_start_all_queues(dev);
netif_carrier_on(dev);
spin_unlock_bh(&ecrnx_hw->connect_req_lock);
return 0;
}
static inline int ecrnx_rx_sm_disconnect_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
struct sm_disconnect_ind *ind = (struct sm_disconnect_ind *)msg->param;
struct ecrnx_vif *ecrnx_vif = ecrnx_hw->vif_table[ind->vif_idx];
struct net_device *dev;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
if (!ecrnx_vif) {
ecrnx_printk_warn("disconnect ind, but vif null\n");
return 0;
}
dev = ecrnx_vif->ndev;
ecrnx_printk_always("%s:dev:%p, vif_up:%d, reason_code:%d, local %d\n", __func__, dev, ecrnx_vif->up, ind->reason_code,
ecrnx_vif->local_disconn);
/* if vif is not up, ecrnx_close has already been called */
if ((ecrnx_vif->up)) {
if (!ind->reassoc && ecrnx_vif->local_disconn == 0) {
cfg80211_disconnected(dev, ind->reason_code, NULL, 0,
(ind->reason_code <= 1), GFP_ATOMIC);
if (ecrnx_vif->sta.ft_assoc_ies) {
kfree(ecrnx_vif->sta.ft_assoc_ies);
ecrnx_vif->sta.ft_assoc_ies = NULL;
ecrnx_vif->sta.ft_assoc_ies_len = 0;
}
}
netif_tx_stop_all_queues(dev);
netif_carrier_off(dev);
}
ecrnx_vif->local_disconn = 0;
if (ecrnx_vif->sta.ap && ecrnx_vif->sta.ap->valid)
{
ecrnx_dbgfs_unregister_sta(ecrnx_hw, ecrnx_vif->sta.ap);
#ifdef CONFIG_ECRNX_BFMER
/* Disable Beamformer if supported */
ecrnx_bfmer_report_del(ecrnx_hw, ecrnx_vif->sta.ap);
#endif //(CONFIG_ECRNX_BFMER)
ecrnx_txq_sta_deinit(ecrnx_hw, ecrnx_vif->sta.ap);
ecrnx_rx_reord_sta_deinit(ecrnx_hw, ecrnx_vif->sta.ap->sta_idx, true);
ecrnx_vif->sta.ap->valid = false;
ecrnx_vif->sta.ap = NULL;
}
ecrnx_txq_tdls_vif_deinit(ecrnx_vif);
//ecrnx_dbgfs_unregister_sta(ecrnx_hw, ecrnx_vif->sta.ap);
ecrnx_vif->generation++;
ecrnx_external_auth_disable(ecrnx_vif);
ecrnx_chanctx_unlink(ecrnx_vif);
return 0;
}
static inline int ecrnx_rx_sm_external_auth_required_ind(struct ecrnx_hw *ecrnx_hw,
struct ecrnx_cmd *cmd,
struct ipc_e2a_msg *msg)
{
struct sm_external_auth_required_ind *ind =
(struct sm_external_auth_required_ind *)msg->param;
struct ecrnx_vif *ecrnx_vif = ecrnx_hw->vif_table[ind->vif_idx];
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 17, 0)
struct net_device *dev = ecrnx_vif->ndev;
struct cfg80211_external_auth_params params;
ecrnx_printk_msg(ECRNX_FN_ENTRY_STR);
params.action = NL80211_EXTERNAL_AUTH_START;
memcpy(params.bssid, ind->bssid.array, ETH_ALEN);
params.ssid.ssid_len = ind->ssid.length;
memcpy(params.ssid.ssid, ind->ssid.array,
min_t(size_t, ind->ssid.length, sizeof(params.ssid.ssid)));
params.key_mgmt_suite = ind->akm;
if ((ind->vif_idx > NX_VIRT_DEV_MAX) || !ecrnx_vif->up ||