forked from Icenowy/xradio
-
Notifications
You must be signed in to change notification settings - Fork 50
/
sta.c
2233 lines (1928 loc) · 64.6 KB
/
sta.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
/*
* STA APIs for XRadio drivers
*
* Copyright (c) 2013, XRadio
* Author: XRadio
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/vmalloc.h>
#include <linux/sched.h>
#include <linux/firmware.h>
#include <linux/if_arp.h>
#include <linux/ipv6.h>
#include <linux/icmpv6.h>
#include <net/ndisc.h>
#include "xradio.h"
#include "sta.h"
#include "ap.h"
#include "keys.h"
#include "fwio.h"
#include "bh.h"
#include "wsm.h"
#ifdef ROAM_OFFLOAD
#include <net/netlink.h>
#endif /*ROAM_OFFLOAD*/
#include "net/mac80211.h"
#ifdef TES_P2P_0002_ROC_RESTART
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0))
#include <linux/ktime.h>
#else
#include <linux/time.h>
#endif
#endif
#define WEP_ENCRYPT_HDR_SIZE 4
#define WEP_ENCRYPT_TAIL_SIZE 4
#define WPA_ENCRYPT_HDR_SIZE 8
#define WPA_ENCRYPT_TAIL_SIZE 12
#define WPA2_ENCRYPT_HDR_SIZE 8
#define WPA2_ENCRYPT_TAIL_SIZE 8
#define WAPI_ENCRYPT_HDR_SIZE 18
#define WAPI_ENCRYPT_TAIL_SIZE 16
#define MAX_ARP_REPLY_TEMPLATE_SIZE 120
static inline void __xradio_free_event_queue(struct list_head *list)
{
while (!list_empty(list)) {
struct xradio_wsm_event *event =
list_first_entry(list, struct xradio_wsm_event,link);
list_del(&event->link);
kfree(event);
}
}
static inline void __xradio_bf_configure(struct xradio_vif *priv)
{
priv->bf_table.numOfIEs = __cpu_to_le32(3);
priv->bf_table.entry[0].ieId = WLAN_EID_VENDOR_SPECIFIC;
priv->bf_table.entry[0].actionFlags =
WSM_BEACON_FILTER_IE_HAS_CHANGED |
WSM_BEACON_FILTER_IE_NO_LONGER_PRESENT |
WSM_BEACON_FILTER_IE_HAS_APPEARED;
priv->bf_table.entry[0].oui[0] = 0x50;
priv->bf_table.entry[0].oui[1] = 0x6F;
priv->bf_table.entry[0].oui[2] = 0x9A;
priv->bf_table.entry[1].ieId = WLAN_EID_ERP_INFO;
priv->bf_table.entry[1].actionFlags =
WSM_BEACON_FILTER_IE_HAS_CHANGED |
WSM_BEACON_FILTER_IE_NO_LONGER_PRESENT |
WSM_BEACON_FILTER_IE_HAS_APPEARED;
priv->bf_table.entry[2].ieId = WLAN_EID_HT_OPERATION;
priv->bf_table.entry[2].actionFlags =
WSM_BEACON_FILTER_IE_HAS_CHANGED |
WSM_BEACON_FILTER_IE_NO_LONGER_PRESENT |
WSM_BEACON_FILTER_IE_HAS_APPEARED;
priv->bf_control.enabled = WSM_BEACON_FILTER_ENABLE;
}
/* ******************************************************************** */
/* STA API */
int xradio_start(struct ieee80211_hw *dev)
{
struct xradio_common *hw_priv = dev->priv;
int ret = 0;
if (wait_event_interruptible_timeout(hw_priv->wsm_startup_done,
hw_priv->driver_ready, 3*HZ) <= 0) {
wiphy_err(dev->wiphy, "driver is not ready!\n");
return -ETIMEDOUT;
}
mutex_lock(&hw_priv->conf_mutex);
memcpy(hw_priv->mac_addr, dev->wiphy->perm_addr, ETH_ALEN);
hw_priv->softled_state = 0;
ret = xradio_setup_mac(hw_priv);
if (WARN_ON(ret)) {
wiphy_err(dev->wiphy, "xradio_setup_mac failed(%d)\n", ret);
goto out;
}
out:
mutex_unlock(&hw_priv->conf_mutex);
return ret;
}
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 11, 0))
void xradio_stop(struct ieee80211_hw *dev, bool suspend)
#else
void xradio_stop(struct ieee80211_hw *dev)
#endif
{
struct xradio_common *hw_priv = dev->priv;
struct xradio_vif *priv = NULL;
LIST_HEAD(list);
int i;
wsm_lock_tx(hw_priv);
while (down_trylock(&hw_priv->scan.lock)) {
/* Scan is in progress. Force it to stop. */
hw_priv->scan.req = NULL;
schedule();
}
up(&hw_priv->scan.lock);
cancel_delayed_work_sync(&hw_priv->scan.probe_work);
cancel_delayed_work_sync(&hw_priv->scan.timeout);
flush_workqueue(hw_priv->workqueue);
del_timer_sync(&hw_priv->ba_timer);
mutex_lock(&hw_priv->conf_mutex);
hw_priv->softled_state = 0;
/* xradio_set_leds(hw_priv); */
spin_lock(&hw_priv->event_queue_lock);
list_splice_init(&hw_priv->event_queue, &list);
spin_unlock(&hw_priv->event_queue_lock);
__xradio_free_event_queue(&list);
for (i = 0; i < 4; i++)
xradio_queue_clear(&hw_priv->tx_queue[i], XRWL_ALL_IFS);
/* HACK! */
if (atomic_xchg(&hw_priv->tx_lock, 1) != 1)
wiphy_debug(dev->wiphy, "TX is force-unlocked due to stop request.\n");
xradio_for_each_vif(hw_priv, priv, i) {
if (!priv)
continue;
priv->mode = NL80211_IFTYPE_UNSPECIFIED;
priv->listening = false;
priv->delayed_link_loss = 0;
priv->join_status = XRADIO_JOIN_STATUS_PASSIVE;
cancel_delayed_work_sync(&priv->join_timeout);
cancel_delayed_work_sync(&priv->bss_loss_work);
cancel_delayed_work_sync(&priv->connection_loss_work);
cancel_delayed_work_sync(&priv->link_id_gc_work);
del_timer_sync(&priv->mcast_timeout);
}
wsm_unlock_tx(hw_priv);
mutex_unlock(&hw_priv->conf_mutex);
}
int xradio_add_interface(struct ieee80211_hw *dev,
struct ieee80211_vif *vif)
{
int ret;
struct xradio_common *hw_priv = dev->priv;
struct xradio_vif *priv;
struct xradio_vif **drv_priv = (void *)vif->drv_priv;
int i;
if (atomic_read(&hw_priv->num_vifs) >= XRWL_MAX_VIFS)
return -EOPNOTSUPP;
if (wait_event_interruptible_timeout(hw_priv->wsm_startup_done,
hw_priv->driver_ready, 3*HZ) <= 0) {
wiphy_err(dev->wiphy, "driver is not ready!\n");
return -ETIMEDOUT;
}
/* fix the problem that when connected,then deauth */
vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
priv = xrwl_get_vif_from_ieee80211(vif);
atomic_set(&priv->enabled, 0);
*drv_priv = priv;
/* __le32 auto_calibration_mode = __cpu_to_le32(1); */
mutex_lock(&hw_priv->conf_mutex);
priv->mode = vif->type;
spin_lock(&hw_priv->vif_list_lock);
if (atomic_read(&hw_priv->num_vifs) < XRWL_MAX_VIFS) {
for (i = 0; i < XRWL_MAX_VIFS; i++)
if (!memcmp(vif->addr, hw_priv->addresses[i].addr, ETH_ALEN))
break;
if (i == XRWL_MAX_VIFS) {
spin_unlock(&hw_priv->vif_list_lock);
mutex_unlock(&hw_priv->conf_mutex);
return -EINVAL;
}
priv->if_id = i;
hw_priv->if_id_slot |= BIT(priv->if_id);
priv->hw_priv = hw_priv;
priv->hw = dev;
priv->vif = vif;
hw_priv->vif_list[priv->if_id] = vif;
atomic_inc(&hw_priv->num_vifs);
} else {
spin_unlock(&hw_priv->vif_list_lock);
mutex_unlock(&hw_priv->conf_mutex);
return -EOPNOTSUPP;
}
spin_unlock(&hw_priv->vif_list_lock);
/* TODO:COMBO :Check if MAC address matches the one expected by FW */
memcpy(hw_priv->mac_addr, vif->addr, ETH_ALEN);
/* Enable auto-calibration */
/* Exception in subsequent channel switch; disabled.
WARN_ON(wsm_write_mib(hw_priv, WSM_MIB_ID_SET_AUTO_CALIBRATION_MODE,
&auto_calibration_mode, sizeof(auto_calibration_mode)));
*/
wiphy_debug(dev->wiphy, "Interface ID:%d of type:%d added\n", priv->if_id, priv->mode);
mutex_unlock(&hw_priv->conf_mutex);
xradio_vif_setup(priv);
ret = WARN_ON(xradio_setup_mac_pvif(priv));
return ret;
}
void xradio_remove_interface(struct ieee80211_hw *dev,
struct ieee80211_vif *vif)
{
struct xradio_common *hw_priv = dev->priv;
struct xradio_vif *priv = xrwl_get_vif_from_ieee80211(vif);
struct wsm_reset reset = {
.reset_statistics = true,
};
int i;
bool is_htcapie = false;
struct xradio_vif *tmp_priv;
wiphy_warn(dev->wiphy, "!!! vif_id=%d\n", priv->if_id);
atomic_set(&priv->enabled, 0);
down(&hw_priv->scan.lock);
if(priv->join_status == XRADIO_JOIN_STATUS_STA){
if (atomic_xchg(&priv->delayed_unjoin, 0)) {
wsm_unlock_tx(hw_priv);
wiphy_err(dev->wiphy, "delayed_unjoin exist!\n");
}
cancel_work_sync(&priv->unjoin_work);
wsm_lock_tx(hw_priv);
xradio_unjoin_work(&priv->unjoin_work);
}
mutex_lock(&hw_priv->conf_mutex);
xradio_tx_queues_lock(hw_priv);
wsm_lock_tx(hw_priv);
switch (priv->join_status) {
case XRADIO_JOIN_STATUS_AP:
for (i = 0; priv->link_id_map; ++i) {
if (priv->link_id_map & BIT(i)) {
xrwl_unmap_link(priv, i);
priv->link_id_map &= ~BIT(i);
}
}
memset(priv->link_id_db, 0,
sizeof(priv->link_id_db));
priv->sta_asleep_mask = 0;
priv->enable_beacon = false;
priv->tx_multicast = false;
priv->aid0_bit_set = false;
priv->buffered_multicasts = false;
priv->pspoll_mask = 0;
reset.link_id = 0;
wsm_reset(hw_priv, &reset, priv->if_id);
WARN_ON(wsm_set_operational_mode(hw_priv, &defaultoperationalmode, priv->if_id));
xradio_for_each_vif(hw_priv, tmp_priv, i) {
if (!tmp_priv)
continue;
if ((tmp_priv->join_status == XRADIO_JOIN_STATUS_STA) && tmp_priv->htcap)
is_htcapie = true;
}
if (is_htcapie) {
hw_priv->vif0_throttle = XRWL_HOST_VIF0_11N_THROTTLE;
hw_priv->vif1_throttle = XRWL_HOST_VIF1_11N_THROTTLE;
sta_printk(XRADIO_DBG_NIY, "AP REMOVE HTCAP 11N %d\n",hw_priv->vif0_throttle);
} else {
hw_priv->vif0_throttle = XRWL_HOST_VIF0_11BG_THROTTLE;
hw_priv->vif1_throttle = XRWL_HOST_VIF1_11BG_THROTTLE;
sta_printk(XRADIO_DBG_NIY, "AP REMOVE 11BG %d\n",hw_priv->vif0_throttle);
}
break;
case XRADIO_JOIN_STATUS_MONITOR:
xradio_disable_listening(priv);
break;
default:
break;
}
/* TODO:COMBO: Change Queue Module */
__xradio_flush(hw_priv, false, priv->if_id);
cancel_delayed_work_sync(&priv->bss_loss_work);
cancel_delayed_work_sync(&priv->connection_loss_work);
cancel_delayed_work_sync(&priv->link_id_gc_work);
cancel_delayed_work_sync(&priv->join_timeout);
cancel_delayed_work_sync(&priv->set_cts_work);
cancel_delayed_work_sync(&priv->pending_offchanneltx_work);
del_timer_sync(&priv->mcast_timeout);
/* TODO:COMBO: May be reset of these variables "delayed_link_loss and
* join_status to default can be removed as dev_priv will be freed by
* mac80211 */
priv->delayed_link_loss = 0;
priv->join_status = XRADIO_JOIN_STATUS_PASSIVE;
wsm_unlock_tx(hw_priv);
if ((priv->if_id ==1) && (priv->mode == NL80211_IFTYPE_AP
|| priv->mode == NL80211_IFTYPE_P2P_GO)) {
hw_priv->is_go_thru_go_neg = false;
}
spin_lock(&hw_priv->vif_list_lock);
spin_lock(&priv->vif_lock);
hw_priv->vif_list[priv->if_id] = NULL;
hw_priv->if_id_slot &= (~BIT(priv->if_id));
atomic_dec(&hw_priv->num_vifs);
if (atomic_read(&hw_priv->num_vifs) == 0) {
xradio_free_keys(hw_priv);
memset(hw_priv->mac_addr, 0, ETH_ALEN);
}
spin_unlock(&priv->vif_lock);
spin_unlock(&hw_priv->vif_list_lock);
priv->listening = false;
xradio_tx_queues_unlock(hw_priv);
mutex_unlock(&hw_priv->conf_mutex);
if (atomic_read(&hw_priv->num_vifs) == 0)
flush_workqueue(hw_priv->workqueue);
memset(priv, 0, sizeof(struct xradio_vif));
up(&hw_priv->scan.lock);
}
int xradio_change_interface(struct ieee80211_hw *dev,
struct ieee80211_vif *vif,
enum nl80211_iftype new_type,
bool p2p)
{
int ret = 0;
wiphy_debug(dev->wiphy, "changing interface type; new type=%d(%d), p2p=%d(%d)\n",
new_type, vif->type, p2p, vif->p2p);
if (new_type != vif->type || vif->p2p != p2p) {
xradio_remove_interface(dev, vif);
vif->type = new_type;
vif->p2p = p2p;
ret = xradio_add_interface(dev, vif);
}
return ret;
}
int xradio_config(struct ieee80211_hw *dev, u32 changed)
{
int ret = 0;
struct xradio_common *hw_priv = dev->priv;
struct ieee80211_conf *conf = &dev->conf;
/* TODO:COMBO: adjust to multi vif interface
* IEEE80211_CONF_CHANGE_IDLE is still handled per xradio_vif*/
int if_id = 0;
struct xradio_vif *priv;
if (changed &
(IEEE80211_CONF_CHANGE_MONITOR|IEEE80211_CONF_CHANGE_IDLE)) {
/* TBD: It looks like it's transparent
* there's a monitor interface present -- use this
* to determine for example whether to calculate
* timestamps for packets or not, do not use instead
* of filter flags! */
wiphy_debug(dev->wiphy, "ignore IEEE80211_CONF_CHANGE_MONITOR (%d)"
"IEEE80211_CONF_CHANGE_IDLE (%d)\n",
(changed & IEEE80211_CONF_CHANGE_MONITOR) ? 1 : 0,
(changed & IEEE80211_CONF_CHANGE_IDLE) ? 1 : 0);
return ret;
}
down(&hw_priv->scan.lock);
mutex_lock(&hw_priv->conf_mutex);
priv = __xrwl_hwpriv_to_vifpriv(hw_priv, hw_priv->scan.if_id);
/* TODO: IEEE80211_CONF_CHANGE_QOS */
/* TODO:COMBO:Change when support is available mac80211*/
if (changed & IEEE80211_CONF_CHANGE_POWER) {
/*hw_priv->output_power = conf->power_level;*/
hw_priv->output_power = 20;
wiphy_debug(dev->wiphy, "Config Tx power=%d, but real=%d\n",
conf->power_level, hw_priv->output_power);
WARN_ON(wsm_set_output_power(hw_priv, hw_priv->output_power * 10, if_id));
}
if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) &&
(hw_priv->channel != conf->chandef.chan)) {
/* Switch Channel commented for CC Mode */
struct ieee80211_channel *ch = conf->chandef.chan;
wiphy_debug(dev->wiphy, "Freq %d (wsm ch: %d).\n",
ch->center_freq, ch->hw_value);
/* Earlier there was a call to __xradio_flush().
Removed as deemed unnecessary */
hw_priv->channel = ch;
hw_priv->channel_changed = 1;
}
mutex_unlock(&hw_priv->conf_mutex);
up(&hw_priv->scan.lock);
return ret;
}
void xradio_update_filtering(struct xradio_vif *priv)
{
int ret;
bool bssid_filtering = !priv->rx_filter.bssid;
struct xradio_common *hw_priv = xrwl_vifpriv_to_hwpriv(priv);
static struct wsm_beacon_filter_control bf_disabled = {
.enabled = 0,
.bcn_count = 1,
};
bool ap_mode = 0;
static struct wsm_beacon_filter_table bf_table_auto = {
.numOfIEs = __cpu_to_le32(2),
.entry[0].ieId = WLAN_EID_VENDOR_SPECIFIC,
.entry[0].actionFlags = WSM_BEACON_FILTER_IE_HAS_CHANGED |
WSM_BEACON_FILTER_IE_NO_LONGER_PRESENT |
WSM_BEACON_FILTER_IE_HAS_APPEARED,
.entry[0].oui[0] = 0x50,
.entry[0].oui[1] = 0x6F,
.entry[0].oui[2] = 0x9A,
.entry[1].ieId = WLAN_EID_HT_OPERATION,
.entry[1].actionFlags = WSM_BEACON_FILTER_IE_HAS_CHANGED |
WSM_BEACON_FILTER_IE_NO_LONGER_PRESENT |
WSM_BEACON_FILTER_IE_HAS_APPEARED,
};
static struct wsm_beacon_filter_control bf_auto = {
.enabled = WSM_BEACON_FILTER_ENABLE |
WSM_BEACON_FILTER_AUTO_ERP,
.bcn_count = 1,
};
bf_auto.bcn_count = priv->bf_control.bcn_count;
if (priv->join_status == XRADIO_JOIN_STATUS_PASSIVE)
return;
else if (priv->join_status == XRADIO_JOIN_STATUS_MONITOR)
bssid_filtering = false;
if (priv->vif && (priv->vif->type == NL80211_IFTYPE_AP))
ap_mode = true;
/*
* When acting as p2p client being connected to p2p GO, in order to
* receive frames from a different p2p device, turn off bssid filter.
*
* WARNING: FW dependency!
* This can only be used with FW WSM371 and its successors.
* In that FW version even with bssid filter turned off,
* device will block most of the unwanted frames.
*/
if (priv->vif && priv->vif->p2p)
bssid_filtering = false;
ret = wsm_set_rx_filter(hw_priv, &priv->rx_filter, priv->if_id);
if (!ret && !ap_mode) {
if (priv->vif) {
if (priv->vif->p2p || NL80211_IFTYPE_STATION != priv->vif->type)
ret = wsm_set_beacon_filter_table(hw_priv, &priv->bf_table, priv->if_id);
else
ret = wsm_set_beacon_filter_table(hw_priv, &bf_table_auto, priv->if_id);
} else
WARN_ON(1);
}
if (!ret && !ap_mode) {
if (priv->disable_beacon_filter)
ret = wsm_beacon_filter_control(hw_priv, &bf_disabled, priv->if_id);
else {
if (priv->vif) {
if (priv->vif->p2p || NL80211_IFTYPE_STATION != priv->vif->type)
ret = wsm_beacon_filter_control(hw_priv, &priv->bf_control,
priv->if_id);
else
ret = wsm_beacon_filter_control(hw_priv, &bf_auto, priv->if_id);
} else
WARN_ON(1);
}
}
if (!ret)
ret = wsm_set_bssid_filtering(hw_priv, bssid_filtering, priv->if_id);
#if 0
if (!ret) {
ret = wsm_set_multicast_filter(hw_priv, &priv->multicast_filter, priv->if_id);
}
#endif
if (ret)
wiphy_debug(priv->hw_priv->hw->wiphy, "Update filtering failed: %d.\n", ret);
return;
}
void xradio_update_filtering_work(struct work_struct *work)
{
struct xradio_vif *priv =
container_of(work, struct xradio_vif,
update_filtering_work);
xradio_update_filtering(priv);
}
void xradio_set_beacon_wakeup_period_work(struct work_struct *work)
{
struct xradio_vif *priv =
container_of(work, struct xradio_vif, set_beacon_wakeup_period_work);
#ifdef XRADIO_USE_LONG_DTIM_PERIOD
{
int join_dtim_period_extend;
if (priv->join_dtim_period <= 3) {
join_dtim_period_extend = priv->join_dtim_period * 3;
} else if (priv->join_dtim_period <= 5) {
join_dtim_period_extend = priv->join_dtim_period * 2;
} else {
join_dtim_period_extend = priv->join_dtim_period;
}
WARN_ON(wsm_set_beacon_wakeup_period(priv->hw_priv, join_dtim_period_extend, 0, priv->if_id));
}
#else
WARN_ON(wsm_set_beacon_wakeup_period(priv->hw_priv, priv->join_dtim_period, 0, priv->if_id));
#endif
}
u64 xradio_prepare_multicast(struct ieee80211_hw *hw,
struct netdev_hw_addr_list *mc_list)
{
struct xradio_common *hw_priv = hw->priv;
struct xradio_vif *priv = NULL;
static u8 broadcast_ipv6[ETH_ALEN] = {
0x33, 0x33, 0x00, 0x00, 0x00, 0x01
};
static u8 broadcast_ipv4[ETH_ALEN] = {
0x01, 0x00, 0x5e, 0x00, 0x00, 0x01
};
int i= 0;
xradio_for_each_vif(hw_priv,priv,i) {
struct netdev_hw_addr *ha = NULL;
int count = 0;
if ((!priv))
continue;
/* Disable multicast filtering */
priv->has_multicast_subscription = false;
memset(&priv->multicast_filter, 0x00, sizeof(priv->multicast_filter));
if (netdev_hw_addr_list_count(mc_list) > WSM_MAX_GRP_ADDRTABLE_ENTRIES)
return 0;
/* Enable if requested */
netdev_hw_addr_list_for_each(ha, mc_list) {
sta_printk(XRADIO_DBG_MSG, "multicast: %pM\n", ha->addr);
memcpy(&priv->multicast_filter.macAddress[count], ha->addr, ETH_ALEN);
if (memcmp(ha->addr, broadcast_ipv4, ETH_ALEN) &&
memcmp(ha->addr, broadcast_ipv6, ETH_ALEN))
priv->has_multicast_subscription = true;
count++;
}
if (count) {
priv->multicast_filter.enable = __cpu_to_le32(1);
priv->multicast_filter.numOfAddresses = __cpu_to_le32(count);
}
}
return netdev_hw_addr_list_count(mc_list);
}
void xradio_configure_filter(struct ieee80211_hw *hw,
unsigned int changed_flags,
unsigned int *total_flags,
u64 multicast)
{
struct xradio_common *hw_priv = hw->priv;
struct xradio_vif *priv = NULL;
int i = 0;
/* delete umac warning */
if (hw_priv->vif_list[0] == NULL && hw_priv->vif_list[1] == NULL)
*total_flags &= ~(1<<31);
xradio_for_each_vif(hw_priv, priv, i) {
if(NULL == priv)
continue;
#if 0
bool listening = !!(*total_flags &
(FIF_PROMISC_IN_BSS |
FIF_OTHER_BSS |
FIF_BCN_PRBRESP_PROMISC |
FIF_PROBE_REQ));
#endif
*total_flags &= FIF_OTHER_BSS |
FIF_FCSFAIL |
FIF_BCN_PRBRESP_PROMISC |
FIF_PROBE_REQ;
down(&hw_priv->scan.lock);
mutex_lock(&hw_priv->conf_mutex);
priv->rx_filter.promiscuous = 0;
priv->rx_filter.bssid = (*total_flags &
(FIF_OTHER_BSS | FIF_PROBE_REQ)) ? 1 : 0;
priv->rx_filter.fcs = (*total_flags & FIF_FCSFAIL) ? 1 : 0;
priv->bf_control.bcn_count = (*total_flags &
(FIF_BCN_PRBRESP_PROMISC |
FIF_PROBE_REQ)) ? 1 : 0;
/*add for handle ap FIF_PROBE_REQ message,*/
priv->rx_filter.promiscuous = 0;
priv->rx_filter.fcs = 0;
if(NL80211_IFTYPE_AP == priv->vif->type){
priv->bf_control.bcn_count = 1;
priv->rx_filter.bssid = 1;
}else{
priv->bf_control.bcn_count = 0;
priv->rx_filter.bssid = 0;
}
#if 0
if (priv->listening ^ listening) {
priv->listening = listening;
wsm_lock_tx(hw_priv);
xradio_update_listening(priv, listening);
wsm_unlock_tx(hw_priv);
}
#endif
xradio_update_filtering(priv);
mutex_unlock(&hw_priv->conf_mutex);
up(&hw_priv->scan.lock);
}
}
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 0, 0))
int xradio_conf_tx(struct ieee80211_hw *dev, struct ieee80211_vif *vif,
unsigned int link_id, u16 queue,
const struct ieee80211_tx_queue_params *params)
#else
int xradio_conf_tx(struct ieee80211_hw *dev, struct ieee80211_vif *vif,
u16 queue, const struct ieee80211_tx_queue_params *params)
#endif
{
struct xradio_common *hw_priv = dev->priv;
struct xradio_vif *priv = xrwl_get_vif_from_ieee80211(vif);
int ret = 0;
/* To prevent re-applying PM request OID again and again*/
bool old_uapsdFlags;
wiphy_debug(dev->wiphy, "vif %d, configuring tx\n", priv->if_id);
if (WARN_ON(!priv))
return -EOPNOTSUPP;
mutex_lock(&hw_priv->conf_mutex);
if (queue < dev->queues) {
old_uapsdFlags = priv->uapsd_info.uapsdFlags;
WSM_TX_QUEUE_SET(&priv->tx_queue_params, queue, 0, 0, 0);
ret = wsm_set_tx_queue_params(hw_priv,
&priv->tx_queue_params.params[queue],
queue, priv->if_id);
if (ret) {
wiphy_err(dev->wiphy, "wsm_set_tx_queue_params failed!\n");
ret = -EINVAL;
goto out;
}
WSM_EDCA_SET(&priv->edca, queue, params->aifs,
params->cw_min, params->cw_max,
params->txop, 0xc8, params->uapsd);
/* sta role is not support the uapsd */
if (priv->mode == NL80211_IFTYPE_STATION ||
priv->mode == NL80211_IFTYPE_P2P_CLIENT)
priv->edca.params[queue].uapsdEnable = 0;
ret = wsm_set_edca_params(hw_priv, &priv->edca, priv->if_id);
if (ret) {
wiphy_err(dev->wiphy, "wsm_set_edca_params failed!\n");
ret = -EINVAL;
goto out;
}
if (priv->mode == NL80211_IFTYPE_STATION) {
ret = xradio_set_uapsd_param(priv, &priv->edca);
if (!ret && priv->setbssparams_done &&
(priv->join_status == XRADIO_JOIN_STATUS_STA) &&
(old_uapsdFlags != priv->uapsd_info.uapsdFlags))
xradio_set_pm(priv, &priv->powersave_mode);
}
} else {
wiphy_err(dev->wiphy, "queue is to large!\n");
ret = -EINVAL;
}
out:
mutex_unlock(&hw_priv->conf_mutex);
return ret;
}
int xradio_get_stats(struct ieee80211_hw *dev,
struct ieee80211_low_level_stats *stats)
{
struct xradio_common *hw_priv = dev->priv;
memcpy(stats, &hw_priv->stats, sizeof(*stats));
return 0;
}
/*
int xradio_get_tx_stats(struct ieee80211_hw *dev,
struct ieee80211_tx_queue_stats *stats)
{
int i;
struct xradio_common *priv = dev->priv;
for (i = 0; i < dev->queues; ++i)
xradio_queue_get_stats(&priv->tx_queue[i], &stats[i]);
return 0;
}
*/
int xradio_set_pm(struct xradio_vif *priv, const struct wsm_set_pm *arg)
{
struct wsm_set_pm pm = *arg;
if (priv->uapsd_info.uapsdFlags != 0)
pm.pmMode &= ~WSM_PSM_FAST_PS_FLAG;
if (memcmp(&pm, &priv->firmware_ps_mode, sizeof(struct wsm_set_pm))) {
priv->firmware_ps_mode = pm;
return wsm_set_pm(priv->hw_priv, &pm, priv->if_id);
} else {
return 0;
}
}
void xradio_wep_key_work(struct work_struct *work)
{
struct xradio_vif *priv = container_of(work, struct xradio_vif , wep_key_work);
struct xradio_common *hw_priv = xrwl_vifpriv_to_hwpriv(priv);
u8 queueId = xradio_queue_get_queue_id(hw_priv->pending_frame_id);
struct xradio_queue *queue = &hw_priv->tx_queue[queueId];
__le32 wep_default_key_id = __cpu_to_le32(priv->wep_default_key_id);
BUG_ON(queueId >= 4);
sta_printk(XRADIO_DBG_MSG, "Setting default WEP key: %d\n",
priv->wep_default_key_id);
wsm_flush_tx(hw_priv);
WARN_ON(wsm_write_mib(hw_priv, WSM_MIB_ID_DOT11_WEP_DEFAULT_KEY_ID,
&wep_default_key_id, sizeof(wep_default_key_id),
priv->if_id));
xradio_queue_requeue(queue, hw_priv->pending_frame_id, true);
wsm_unlock_tx(hw_priv);
}
int xradio_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
{
struct xradio_common *hw_priv = hw->priv;
int ret = 0;
__le32 val32;
struct xradio_vif *priv = NULL;
int i =0;
int if_id;
xradio_for_each_vif(hw_priv,priv,i) {
if (!priv)
continue;
if_id = priv->if_id;
if (value != (u32) -1)
val32 = __cpu_to_le32(value);
else
val32 = 0; /* disabled */
/* mutex_lock(&priv->conf_mutex); */
ret = WARN_ON(wsm_write_mib(hw_priv, WSM_MIB_ID_DOT11_RTS_THRESHOLD,
&val32, sizeof(val32), if_id));
/* mutex_unlock(&priv->conf_mutex); */
}
return ret;
}
/* TODO: COMBO: Flush only a particular interface specific parts */
int __xradio_flush(struct xradio_common *hw_priv, bool drop, int if_id)
{
int i, ret;
struct xradio_vif *priv =
__xrwl_hwpriv_to_vifpriv(hw_priv, if_id);
for (;;) {
/* TODO: correct flush handling is required when dev_stop.
* Temporary workaround: 2s
*/
if (drop) {
for (i = 0; i < 4; ++i)
xradio_queue_clear(&hw_priv->tx_queue[i],if_id);
} else if(!hw_priv->bh_error){
ret = wait_event_timeout(
hw_priv->tx_queue_stats.wait_link_id_empty,
xradio_queue_stats_is_empty(&hw_priv->tx_queue_stats, -1, if_id),
2 * HZ);
} else { //add by yangfh, don't wait when bh error
sta_printk(XRADIO_DBG_ERROR, " %s:bh_error occur.\n", __func__);
ret = -1;
break;
}
if (!drop && unlikely(ret <= 0)) {
sta_printk(XRADIO_DBG_ERROR, " %s: timeout...\n", __func__);
ret = -ETIMEDOUT;
break;
} else {
ret = 0;
}
wsm_vif_lock_tx(priv);
if (unlikely(!xradio_queue_stats_is_empty(&hw_priv->tx_queue_stats,
-1, if_id))) {
/* Highly unlekely: WSM requeued frames. */
wsm_unlock_tx(hw_priv);
continue;
}
wsm_unlock_tx(hw_priv);
break;
}
return ret;
}
void xradio_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u32 queues, bool drop)
{
//struct xradio_vif *priv = NULL;
struct xradio_common *hw_priv = hw->priv;
int i = 0;
struct xradio_vif *priv = xrwl_get_vif_from_ieee80211(vif);
/*TODO:COMBO: reenable this part of code when flush callback
* is implemented per vif */
/*switch (hw_priv->mode) {
case NL80211_IFTYPE_MONITOR:
drop = true;
break;
case NL80211_IFTYPE_AP:
if (!hw_priv->enable_beacon)
drop = true;
break;
}*/
//if (!(hw_priv->if_id_slot & BIT(priv->if_id)))
// return;
xradio_for_each_vif(hw_priv, priv, i) {
if(NULL == priv)
continue;
if ((hw_priv->if_id_slot & BIT(priv->if_id)))
__xradio_flush(hw_priv, drop, priv->if_id);
}
return;
}
int xradio_remain_on_channel(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_channel *chan,
int duration, enum ieee80211_roc_type type)
{
int ret = 0;
struct xradio_common *hw_priv = hw->priv;
struct xradio_vif *priv = NULL;
int i = 0;
int if_id;
#ifdef TES_P2P_0002_ROC_RESTART
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0))
struct timespec64 TES_P2P_0002_tmval;
#else
struct timeval TES_P2P_0002_tmval;
#endif
#endif
#ifdef TES_P2P_0002_ROC_RESTART
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0))
ktime_get_real_ts64(&TES_P2P_0002_tmval);
TES_P2P_0002_roc_usec = (s32)TES_P2P_0002_tmval.tv_nsec/1000;
#else
do_gettimeofday(&TES_P2P_0002_tmval);
TES_P2P_0002_roc_usec = (s32)TES_P2P_0002_tmval.tv_usec;
#endif
TES_P2P_0002_roc_dur = (s32)duration;
TES_P2P_0002_roc_sec = (s32)TES_P2P_0002_tmval.tv_sec;
#endif
down(&hw_priv->scan.lock);
mutex_lock(&hw_priv->conf_mutex);
xradio_for_each_vif(hw_priv, priv, i) {
if(NULL == priv)
continue;
if_id = priv->if_id;
#ifdef ROC_DEBUG
sta_printk(XRADIO_DBG_WARN, "ROC IN %d ch %d\n",
priv->if_id, chan->hw_value);
#endif
/* default only p2p interface if_id can remain on */
if((priv->if_id == 0) || (priv->if_id == 1))
continue;
hw_priv->roc_if_id = priv->if_id;
ret = WARN_ON(__xradio_flush(hw_priv, false, if_id));
xradio_enable_listening(priv, chan);
if (!ret) {
atomic_set(&hw_priv->remain_on_channel, 1);
queue_delayed_work(hw_priv->workqueue, &hw_priv->rem_chan_timeout,
duration * HZ / 1000);
priv->join_status = XRADIO_JOIN_STATUS_MONITOR;
ieee80211_ready_on_channel(hw);
} else {
hw_priv->roc_if_id = -1;
up(&hw_priv->scan.lock);
}
#ifdef ROC_DEBUG
sta_printk(XRADIO_DBG_WARN, "ROC OUT %d\n", priv->if_id);
#endif
}
/* set the channel to supplied ieee80211_channel pointer, if it
is not set. This is to remove the crash while sending a probe res
in listen state. Later channel will updated on
IEEE80211_CONF_CHANGE_CHANNEL event*/
if(!hw_priv->channel) {
hw_priv->channel = chan;
}
mutex_unlock(&hw_priv->conf_mutex);
return ret;
}
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0))
int xradio_cancel_remain_on_channel(struct ieee80211_hw *hw,
struct ieee80211_vif *vif)
#else
int xradio_cancel_remain_on_channel(struct ieee80211_hw *hw)
#endif
{
struct xradio_common *hw_priv = hw->priv;
sta_printk(XRADIO_DBG_NIY, "Cancel remain on channel\n");
#ifdef TES_P2P_0002_ROC_RESTART
if (TES_P2P_0002_state == TES_P2P_0002_STATE_GET_PKTID) {
TES_P2P_0002_state = TES_P2P_0002_STATE_IDLE;
sta_printk(XRADIO_DBG_WARN, "[ROC_RESTART_STATE_IDLE][Cancel ROC]\n");
}
#endif
if (atomic_read(&hw_priv->remain_on_channel))
cancel_delayed_work_sync(&hw_priv->rem_chan_timeout);