-
Notifications
You must be signed in to change notification settings - Fork 1
/
sta.c
2429 lines (2076 loc) · 64.2 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
/*
* Mac80211 STA API for ST-Ericsson CW1200 drivers
*
* Copyright (c) 2010, ST-Ericsson
* Author: Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>
*
* 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/module.h>
#include "cw1200.h"
#include "sta.h"
#include "fwio.h"
#include "bh.h"
#include "debug.h"
#ifndef ERP_INFO_BYTE_OFFSET
#define ERP_INFO_BYTE_OFFSET 2
#endif
static void cw1200_do_join(struct cw1200_common *priv);
static void cw1200_do_unjoin(struct cw1200_common *priv);
static int cw1200_upload_beacon(struct cw1200_common *priv);
static int cw1200_upload_pspoll(struct cw1200_common *priv);
static int cw1200_upload_null(struct cw1200_common *priv);
static int cw1200_upload_qosnull(struct cw1200_common *priv);
static int cw1200_start_ap(struct cw1200_common *priv);
static int cw1200_update_beaconing(struct cw1200_common *priv);
static int cw1200_enable_beaconing(struct cw1200_common *priv,
bool enable);
static void __cw1200_sta_notify(struct ieee80211_hw *dev,
struct ieee80211_vif *vif,
enum sta_notify_cmd notify_cmd,
int link_id);
static int __cw1200_flush(struct cw1200_common *priv, bool drop);
static int cw1200_setup_mac(struct cw1200_common *priv);
static inline void __cw1200_free_event_queue(struct list_head *list)
{
struct cw1200_wsm_event *event, *tmp;
list_for_each_entry_safe(event, tmp, list, link) {
list_del(&event->link);
kfree(event);
}
}
/* ******************************************************************** */
/* STA API */
int cw1200_start(struct ieee80211_hw *dev)
{
struct cw1200_common *priv = dev->priv;
int ret = 0;
cw1200_pm_stay_awake(&priv->pm_state, HZ);
mutex_lock(&priv->conf_mutex);
/* default EDCA */
WSM_EDCA_SET(&priv->edca, 0, 0x0002, 0x0003, 0x0007, 47, 0xc8, false);
WSM_EDCA_SET(&priv->edca, 1, 0x0002, 0x0007, 0x000f, 94, 0xc8, false);
WSM_EDCA_SET(&priv->edca, 2, 0x0003, 0x000f, 0x03ff, 0, 0xc8, false);
WSM_EDCA_SET(&priv->edca, 3, 0x0007, 0x000f, 0x03ff, 0, 0xc8, false);
ret = wsm_set_edca_params(priv, &priv->edca);
if (ret)
goto out;
ret = cw1200_set_uapsd_param(priv, &priv->edca);
if (ret)
goto out;
priv->setbssparams_done = false;
memcpy(priv->mac_addr, dev->wiphy->perm_addr, ETH_ALEN);
priv->mode = NL80211_IFTYPE_MONITOR;
priv->wep_default_key_id = -1;
priv->cqm_beacon_loss_count = 10;
ret = cw1200_setup_mac(priv);
out:
mutex_unlock(&priv->conf_mutex);
return ret;
}
void cw1200_stop(struct ieee80211_hw *dev)
{
struct cw1200_common *priv = dev->priv;
LIST_HEAD(list);
int i;
wsm_lock_tx(priv);
while (down_trylock(&priv->scan.lock)) {
/* Scan is in progress. Force it to stop. */
priv->scan.req = NULL;
schedule();
}
up(&priv->scan.lock);
cancel_delayed_work_sync(&priv->scan.probe_work);
cancel_delayed_work_sync(&priv->scan.timeout);
cancel_delayed_work_sync(&priv->clear_recent_scan_work);
cancel_delayed_work_sync(&priv->join_timeout);
cw1200_cqm_bssloss_sm(priv, 0, 0, 0);
cw1200_cancel_unjoin_work(priv);
cancel_delayed_work_sync(&priv->link_id_gc_work);
flush_workqueue(priv->workqueue);
del_timer_sync(&priv->mcast_timeout);
mutex_lock(&priv->conf_mutex);
priv->mode = NL80211_IFTYPE_UNSPECIFIED;
priv->listening = false;
spin_lock(&priv->event_queue_lock);
list_splice_init(&priv->event_queue, &list);
spin_unlock(&priv->event_queue_lock);
__cw1200_free_event_queue(&list);
priv->join_status = CW1200_JOIN_STATUS_PASSIVE;
priv->join_pending = false;
for (i = 0; i < 4; i++)
cw1200_queue_clear(&priv->tx_queue[i]);
mutex_unlock(&priv->conf_mutex);
tx_policy_clean(priv);
/* HACK! */
if (atomic_xchg(&priv->tx_lock, 1) != 1)
pr_debug("[STA] TX is force-unlocked due to stop request.\n");
wsm_unlock_tx(priv);
atomic_xchg(&priv->tx_lock, 0); /* for recovery to work */
}
static int cw1200_bssloss_mitigation = 1;
module_param(cw1200_bssloss_mitigation, int, 0644);
MODULE_PARM_DESC(cw1200_bssloss_mitigation, "BSS Loss mitigation. 0 == disabled, 1 == enabled (default)");
void __cw1200_cqm_bssloss_sm(struct cw1200_common *priv,
int init, int good, int bad)
{
int tx = 0;
priv->delayed_link_loss = 0;
// VLAD:
spin_unlock(&priv->bss_loss_lock);
cancel_work_sync(&priv->bss_params_work);
spin_lock(&priv->bss_loss_lock);
// VLAD:
pr_debug("[STA] CQM BSSLOSS_SM: state: %d init %d good %d bad: %d txlock: %d uj: %d\n",
priv->bss_loss_state,
init, good, bad,
atomic_read(&priv->tx_lock),
priv->delayed_unjoin);
/* If we have a pending unjoin */
if (priv->delayed_unjoin)
return;
if (init) {
queue_delayed_work(priv->workqueue,
&priv->bss_loss_work,
HZ);
priv->bss_loss_state = 0;
/* Skip the confimration procedure in P2P case */
if (!priv->vif->p2p && !atomic_read(&priv->tx_lock))
tx = 1;
} else if (good) {
// VLAD:
spin_unlock(&priv->bss_loss_lock);
cancel_delayed_work_sync(&priv->bss_loss_work);
spin_lock(&priv->bss_loss_lock);
priv->bss_loss_state = 0;
queue_work(priv->workqueue, &priv->bss_params_work);
} else if (bad) {
/* XXX Should we just keep going until we time out? */
if (priv->bss_loss_state < 3)
tx = 1;
} else {
// VLAD:
spin_unlock(&priv->bss_loss_lock);
cancel_delayed_work_sync(&priv->bss_loss_work);
spin_lock(&priv->bss_loss_lock);
priv->bss_loss_state = 0;
}
/* Bypass mitigation if it's disabled */
if (!cw1200_bssloss_mitigation)
tx = 0;
/* Spit out a NULL packet to our AP if necessary */
if (tx) {
struct sk_buff *skb;
priv->bss_loss_state++;
skb = ieee80211_nullfunc_get(priv->hw, priv->vif);
WARN_ON(!skb);
if (skb)
cw1200_tx(priv->hw, NULL, skb);
}
}
int cw1200_add_interface(struct ieee80211_hw *dev,
struct ieee80211_vif *vif)
{
int ret;
struct cw1200_common *priv = dev->priv;
/* __le32 auto_calibration_mode = __cpu_to_le32(1); */
vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
IEEE80211_VIF_SUPPORTS_CQM_RSSI;
mutex_lock(&priv->conf_mutex);
if (priv->mode != NL80211_IFTYPE_MONITOR) {
mutex_unlock(&priv->conf_mutex);
return -EOPNOTSUPP;
}
switch (vif->type) {
case NL80211_IFTYPE_STATION:
case NL80211_IFTYPE_ADHOC:
case NL80211_IFTYPE_MESH_POINT:
case NL80211_IFTYPE_AP:
priv->mode = vif->type;
break;
default:
mutex_unlock(&priv->conf_mutex);
return -EOPNOTSUPP;
}
priv->vif = vif;
memcpy(priv->mac_addr, vif->addr, ETH_ALEN);
ret = cw1200_setup_mac(priv);
/* Enable auto-calibration */
/* Exception in subsequent channel switch; disabled.
* wsm_write_mib(priv, WSM_MIB_ID_SET_AUTO_CALIBRATION_MODE,
* &auto_calibration_mode, sizeof(auto_calibration_mode));
*/
mutex_unlock(&priv->conf_mutex);
return ret;
}
void cw1200_remove_interface(struct ieee80211_hw *dev,
struct ieee80211_vif *vif)
{
struct cw1200_common *priv = dev->priv;
struct wsm_reset reset = {
.reset_statistics = true,
};
int i;
mutex_lock(&priv->conf_mutex);
switch (priv->join_status) {
case CW1200_JOIN_STATUS_JOINING:
case CW1200_JOIN_STATUS_PRE_STA:
case CW1200_JOIN_STATUS_STA:
case CW1200_JOIN_STATUS_IBSS:
wsm_lock_tx(priv);
if (queue_work(priv->workqueue, &priv->unjoin_work) <= 0)
wsm_unlock_tx(priv);
break;
case CW1200_JOIN_STATUS_AP:
for (i = 0; priv->link_id_map; ++i) {
if (priv->link_id_map & BIT(i)) {
reset.link_id = i;
wsm_reset(priv, &reset);
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(priv, &reset);
break;
case CW1200_JOIN_STATUS_MONITOR:
cw1200_update_listening(priv, false);
break;
default:
break;
}
priv->vif = NULL;
priv->mode = NL80211_IFTYPE_MONITOR;
memset(priv->mac_addr, 0, ETH_ALEN);
memset(&priv->p2p_ps_modeinfo, 0, sizeof(priv->p2p_ps_modeinfo));
cw1200_free_keys(priv);
cw1200_setup_mac(priv);
priv->listening = false;
priv->join_status = CW1200_JOIN_STATUS_PASSIVE;
if (!__cw1200_flush(priv, true))
wsm_unlock_tx(priv);
mutex_unlock(&priv->conf_mutex);
}
int cw1200_change_interface(struct ieee80211_hw *dev,
struct ieee80211_vif *vif,
enum nl80211_iftype new_type,
bool p2p)
{
int ret = 0;
pr_debug("change_interface new: %d (%d), old: %d (%d)\n", new_type,
p2p, vif->type, vif->p2p);
if (new_type != vif->type || vif->p2p != p2p) {
cw1200_remove_interface(dev, vif);
vif->type = new_type;
vif->p2p = p2p;
ret = cw1200_add_interface(dev, vif);
}
return ret;
}
int cw1200_config(struct ieee80211_hw *dev, u32 changed)
{
int ret = 0;
struct cw1200_common *priv = dev->priv;
struct ieee80211_conf *conf = &dev->conf;
pr_debug("CONFIG CHANGED: %08x\n", changed);
down(&priv->scan.lock);
mutex_lock(&priv->conf_mutex);
/* TODO: IEEE80211_CONF_CHANGE_QOS */
/* TODO: IEEE80211_CONF_CHANGE_LISTEN_INTERVAL */
if (changed & IEEE80211_CONF_CHANGE_POWER) {
priv->output_power = conf->power_level;
pr_debug("[STA] TX power: %d\n", priv->output_power);
wsm_set_output_power(priv, priv->output_power * 10);
}
if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) &&
(priv->channel != conf->chandef.chan)) {
struct ieee80211_channel *ch = conf->chandef.chan;
struct wsm_switch_channel channel = {
.channel_number = ch->hw_value,
};
pr_debug("[STA] Freq %d (wsm ch: %d).\n",
ch->center_freq, ch->hw_value);
/* __cw1200_flush() implicitly locks tx, if successful */
if (!__cw1200_flush(priv, false)) {
if (!wsm_switch_channel(priv, &channel)) {
ret = wait_event_timeout(priv->channel_switch_done,
!priv->channel_switch_in_progress,
3 * HZ);
if (ret) {
/* Already unlocks if successful */
priv->channel = ch;
ret = 0;
} else {
ret = -ETIMEDOUT;
}
} else {
/* Unlock if switch channel fails */
wsm_unlock_tx(priv);
}
}
}
if (changed & IEEE80211_CONF_CHANGE_PS) {
if (!(conf->flags & IEEE80211_CONF_PS))
priv->powersave_mode.mode = WSM_PSM_ACTIVE;
else if (conf->dynamic_ps_timeout <= 0)
priv->powersave_mode.mode = WSM_PSM_PS;
else
priv->powersave_mode.mode = WSM_PSM_FAST_PS;
/* Firmware requires that value for this 1-byte field must
* be specified in units of 500us. Values above the 128ms
* threshold are not supported.
*/
if (conf->dynamic_ps_timeout >= 0x80)
priv->powersave_mode.fast_psm_idle_period = 0xFF;
else
priv->powersave_mode.fast_psm_idle_period =
conf->dynamic_ps_timeout << 1;
if (priv->join_status == CW1200_JOIN_STATUS_STA &&
priv->bss_params.aid)
cw1200_set_pm(priv, &priv->powersave_mode);
}
if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
/* 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!
*/
}
if (changed & IEEE80211_CONF_CHANGE_IDLE) {
struct wsm_operational_mode mode = {
.power_mode = cw1200_power_mode,
.disable_more_flag_usage = true,
};
wsm_lock_tx(priv);
/* Disable p2p-dev mode forced by TX request */
if ((priv->join_status == CW1200_JOIN_STATUS_MONITOR) &&
(conf->flags & IEEE80211_CONF_IDLE) &&
!priv->listening) {
cw1200_disable_listening(priv);
priv->join_status = CW1200_JOIN_STATUS_PASSIVE;
}
wsm_set_operational_mode(priv, &mode);
wsm_unlock_tx(priv);
}
if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
pr_debug("[STA] Retry limits: %d (long), %d (short).\n",
conf->long_frame_max_tx_count,
conf->short_frame_max_tx_count);
spin_lock_bh(&priv->tx_policy_cache.lock);
priv->long_frame_max_tx_count = conf->long_frame_max_tx_count;
priv->short_frame_max_tx_count =
(conf->short_frame_max_tx_count < 0x0F) ?
conf->short_frame_max_tx_count : 0x0F;
priv->hw->max_rate_tries = priv->short_frame_max_tx_count;
spin_unlock_bh(&priv->tx_policy_cache.lock);
}
mutex_unlock(&priv->conf_mutex);
up(&priv->scan.lock);
return ret;
}
void cw1200_update_filtering(struct cw1200_common *priv)
{
int ret;
bool bssid_filtering = !priv->rx_filter.bssid;
bool is_p2p = priv->vif && priv->vif->p2p;
bool is_sta = priv->vif && NL80211_IFTYPE_STATION == priv->vif->type;
static struct wsm_beacon_filter_control bf_ctrl;
static struct wsm_mib_beacon_filter_table bf_tbl = {
.entry[0].ie_id = WLAN_EID_VENDOR_SPECIFIC,
.entry[0].flags = 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].ie_id = WLAN_EID_HT_OPERATION,
.entry[1].flags = WSM_BEACON_FILTER_IE_HAS_CHANGED |
WSM_BEACON_FILTER_IE_NO_LONGER_PRESENT |
WSM_BEACON_FILTER_IE_HAS_APPEARED,
.entry[2].ie_id = WLAN_EID_ERP_INFO,
.entry[2].flags = WSM_BEACON_FILTER_IE_HAS_CHANGED |
WSM_BEACON_FILTER_IE_NO_LONGER_PRESENT |
WSM_BEACON_FILTER_IE_HAS_APPEARED,
};
if (priv->join_status == CW1200_JOIN_STATUS_PASSIVE)
return;
else if (priv->join_status == CW1200_JOIN_STATUS_MONITOR)
bssid_filtering = false;
if (priv->disable_beacon_filter) {
bf_ctrl.enabled = 0;
bf_ctrl.bcn_count = 1;
bf_tbl.num = __cpu_to_le32(0);
} else if (is_p2p || !is_sta) {
bf_ctrl.enabled = WSM_BEACON_FILTER_ENABLE |
WSM_BEACON_FILTER_AUTO_ERP;
bf_ctrl.bcn_count = 0;
bf_tbl.num = __cpu_to_le32(2);
} else {
bf_ctrl.enabled = WSM_BEACON_FILTER_ENABLE;
bf_ctrl.bcn_count = 0;
bf_tbl.num = __cpu_to_le32(3);
}
/* 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 (is_p2p)
bssid_filtering = false;
ret = wsm_set_rx_filter(priv, &priv->rx_filter);
if (!ret)
ret = wsm_set_beacon_filter_table(priv, &bf_tbl);
if (!ret)
ret = wsm_beacon_filter_control(priv, &bf_ctrl);
if (!ret)
ret = wsm_set_bssid_filtering(priv, bssid_filtering);
if (!ret)
ret = wsm_set_multicast_filter(priv, &priv->multicast_filter);
if (ret)
wiphy_err(priv->hw->wiphy,
"Update filtering failed: %d.\n", ret);
return;
}
void cw1200_update_filtering_work(struct work_struct *work)
{
struct cw1200_common *priv =
container_of(work, struct cw1200_common,
update_filtering_work);
cw1200_update_filtering(priv);
}
void cw1200_set_beacon_wakeup_period_work(struct work_struct *work)
{
struct cw1200_common *priv =
container_of(work, struct cw1200_common,
set_beacon_wakeup_period_work);
wsm_set_beacon_wakeup_period(priv,
priv->beacon_int * priv->join_dtim_period >
MAX_BEACON_SKIP_TIME_MS ? 1 :
priv->join_dtim_period, 0);
}
u64 cw1200_prepare_multicast(struct ieee80211_hw *hw,
struct netdev_hw_addr_list *mc_list)
{
static u8 broadcast_ipv6[ETH_ALEN] = {
0x33, 0x33, 0x00, 0x00, 0x00, 0x01
};
static u8 broadcast_ipv4[ETH_ALEN] = {
0x01, 0x00, 0x5e, 0x00, 0x00, 0x01
};
struct cw1200_common *priv = hw->priv;
struct netdev_hw_addr *ha;
int count = 0;
/* 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) {
pr_debug("[STA] multicast: %pM\n", ha->addr);
memcpy(&priv->multicast_filter.macaddrs[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.num_addrs = __cpu_to_le32(count);
}
return netdev_hw_addr_list_count(mc_list);
}
void cw1200_configure_filter(struct ieee80211_hw *dev,
unsigned int changed_flags,
unsigned int *total_flags,
u64 multicast)
{
struct cw1200_common *priv = dev->priv;
bool listening = !!(*total_flags &
(FIF_PROMISC_IN_BSS |
FIF_OTHER_BSS |
FIF_BCN_PRBRESP_PROMISC |
FIF_PROBE_REQ));
*total_flags &= FIF_PROMISC_IN_BSS |
FIF_OTHER_BSS |
FIF_FCSFAIL |
FIF_BCN_PRBRESP_PROMISC |
FIF_PROBE_REQ;
down(&priv->scan.lock);
mutex_lock(&priv->conf_mutex);
priv->rx_filter.promiscuous = (*total_flags & FIF_PROMISC_IN_BSS)
? 1 : 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->disable_beacon_filter = !(*total_flags &
(FIF_BCN_PRBRESP_PROMISC |
FIF_PROMISC_IN_BSS |
FIF_PROBE_REQ));
if (priv->listening != listening) {
priv->listening = listening;
wsm_lock_tx(priv);
cw1200_update_listening(priv, listening);
wsm_unlock_tx(priv);
}
cw1200_update_filtering(priv);
mutex_unlock(&priv->conf_mutex);
up(&priv->scan.lock);
}
int cw1200_conf_tx(struct ieee80211_hw *dev, struct ieee80211_vif *vif,
u16 queue, const struct ieee80211_tx_queue_params *params)
{
struct cw1200_common *priv = dev->priv;
int ret = 0;
/* To prevent re-applying PM request OID again and again*/
bool old_uapsd_flags;
mutex_lock(&priv->conf_mutex);
if (queue < dev->queues) {
old_uapsd_flags = le16_to_cpu(priv->uapsd_info.uapsd_flags);
WSM_TX_QUEUE_SET(&priv->tx_queue_params, queue, 0, 0, 0);
ret = wsm_set_tx_queue_params(priv,
&priv->tx_queue_params.params[queue], queue);
if (ret) {
ret = -EINVAL;
goto out;
}
WSM_EDCA_SET(&priv->edca, queue, params->aifs,
params->cw_min, params->cw_max,
params->txop, 0xc8,
params->uapsd);
ret = wsm_set_edca_params(priv, &priv->edca);
if (ret) {
ret = -EINVAL;
goto out;
}
if (priv->mode == NL80211_IFTYPE_STATION) {
ret = cw1200_set_uapsd_param(priv, &priv->edca);
if (!ret && priv->setbssparams_done &&
(priv->join_status == CW1200_JOIN_STATUS_STA) &&
(old_uapsd_flags != le16_to_cpu(priv->uapsd_info.uapsd_flags)))
ret = cw1200_set_pm(priv, &priv->powersave_mode);
}
} else {
ret = -EINVAL;
}
out:
mutex_unlock(&priv->conf_mutex);
return ret;
}
int cw1200_get_stats(struct ieee80211_hw *dev,
struct ieee80211_low_level_stats *stats)
{
memset(stats, 0, sizeof(*stats));
return 0;
}
int cw1200_set_pm(struct cw1200_common *priv, const struct wsm_set_pm *arg)
{
struct wsm_set_pm pm = *arg;
if (priv->uapsd_info.uapsd_flags != 0)
pm.mode &= ~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, &pm);
} else {
return 0;
}
}
int cw1200_set_key(struct ieee80211_hw *dev, enum set_key_cmd cmd,
struct ieee80211_vif *vif, struct ieee80211_sta *sta,
struct ieee80211_key_conf *key)
{
int ret = -EOPNOTSUPP;
struct cw1200_common *priv = dev->priv;
struct ieee80211_key_seq seq;
mutex_lock(&priv->conf_mutex);
if (cmd == SET_KEY) {
u8 *peer_addr = NULL;
int pairwise = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) ?
1 : 0;
int idx = cw1200_alloc_key(priv);
struct wsm_add_key *wsm_key = &priv->keys[idx];
if (idx < 0) {
ret = -EINVAL;
goto finally;
}
if (sta)
peer_addr = sta->addr;
key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
switch (key->cipher) {
case WLAN_CIPHER_SUITE_WEP40:
case WLAN_CIPHER_SUITE_WEP104:
if (key->keylen > 16) {
cw1200_free_key(priv, idx);
ret = -EINVAL;
goto finally;
}
if (pairwise) {
wsm_key->type = WSM_KEY_TYPE_WEP_PAIRWISE;
memcpy(wsm_key->wep_pairwise.peer,
peer_addr, ETH_ALEN);
memcpy(wsm_key->wep_pairwise.keydata,
&key->key[0], key->keylen);
wsm_key->wep_pairwise.keylen = key->keylen;
} else {
wsm_key->type = WSM_KEY_TYPE_WEP_DEFAULT;
memcpy(wsm_key->wep_group.keydata,
&key->key[0], key->keylen);
wsm_key->wep_group.keylen = key->keylen;
wsm_key->wep_group.keyid = key->keyidx;
}
break;
case WLAN_CIPHER_SUITE_TKIP:
ieee80211_get_key_rx_seq(key, 0, &seq);
if (pairwise) {
wsm_key->type = WSM_KEY_TYPE_TKIP_PAIRWISE;
memcpy(wsm_key->tkip_pairwise.peer,
peer_addr, ETH_ALEN);
memcpy(wsm_key->tkip_pairwise.keydata,
&key->key[0], 16);
memcpy(wsm_key->tkip_pairwise.tx_mic_key,
&key->key[16], 8);
memcpy(wsm_key->tkip_pairwise.rx_mic_key,
&key->key[24], 8);
} else {
size_t mic_offset =
(priv->mode == NL80211_IFTYPE_AP) ?
16 : 24;
wsm_key->type = WSM_KEY_TYPE_TKIP_GROUP;
memcpy(wsm_key->tkip_group.keydata,
&key->key[0], 16);
memcpy(wsm_key->tkip_group.rx_mic_key,
&key->key[mic_offset], 8);
wsm_key->tkip_group.rx_seqnum[0] = seq.tkip.iv16 & 0xff;
wsm_key->tkip_group.rx_seqnum[1] = (seq.tkip.iv16 >> 8) & 0xff;
wsm_key->tkip_group.rx_seqnum[2] = seq.tkip.iv32 & 0xff;
wsm_key->tkip_group.rx_seqnum[3] = (seq.tkip.iv32 >> 8) & 0xff;
wsm_key->tkip_group.rx_seqnum[4] = (seq.tkip.iv32 >> 16) & 0xff;
wsm_key->tkip_group.rx_seqnum[5] = (seq.tkip.iv32 >> 24) & 0xff;
wsm_key->tkip_group.rx_seqnum[6] = 0;
wsm_key->tkip_group.rx_seqnum[7] = 0;
wsm_key->tkip_group.keyid = key->keyidx;
}
break;
case WLAN_CIPHER_SUITE_CCMP:
ieee80211_get_key_rx_seq(key, 0, &seq);
if (pairwise) {
wsm_key->type = WSM_KEY_TYPE_AES_PAIRWISE;
memcpy(wsm_key->aes_pairwise.peer,
peer_addr, ETH_ALEN);
memcpy(wsm_key->aes_pairwise.keydata,
&key->key[0], 16);
} else {
wsm_key->type = WSM_KEY_TYPE_AES_GROUP;
memcpy(wsm_key->aes_group.keydata,
&key->key[0], 16);
wsm_key->aes_group.rx_seqnum[0] = seq.ccmp.pn[5];
wsm_key->aes_group.rx_seqnum[1] = seq.ccmp.pn[4];
wsm_key->aes_group.rx_seqnum[2] = seq.ccmp.pn[3];
wsm_key->aes_group.rx_seqnum[3] = seq.ccmp.pn[2];
wsm_key->aes_group.rx_seqnum[4] = seq.ccmp.pn[1];
wsm_key->aes_group.rx_seqnum[5] = seq.ccmp.pn[0];
wsm_key->aes_group.rx_seqnum[6] = 0;
wsm_key->aes_group.rx_seqnum[7] = 0;
wsm_key->aes_group.keyid = key->keyidx;
}
break;
case WLAN_CIPHER_SUITE_SMS4:
if (pairwise) {
wsm_key->type = WSM_KEY_TYPE_WAPI_PAIRWISE;
memcpy(wsm_key->wapi_pairwise.peer,
peer_addr, ETH_ALEN);
memcpy(wsm_key->wapi_pairwise.keydata,
&key->key[0], 16);
memcpy(wsm_key->wapi_pairwise.mic_key,
&key->key[16], 16);
wsm_key->wapi_pairwise.keyid = key->keyidx;
} else {
wsm_key->type = WSM_KEY_TYPE_WAPI_GROUP;
memcpy(wsm_key->wapi_group.keydata,
&key->key[0], 16);
memcpy(wsm_key->wapi_group.mic_key,
&key->key[16], 16);
wsm_key->wapi_group.keyid = key->keyidx;
}
break;
default:
pr_warn("Unhandled key type %d\n", key->cipher);
cw1200_free_key(priv, idx);
ret = -EOPNOTSUPP;
goto finally;
}
ret = wsm_add_key(priv, wsm_key);
if (!ret)
key->hw_key_idx = idx;
else
cw1200_free_key(priv, idx);
} else if (cmd == DISABLE_KEY) {
struct wsm_remove_key wsm_key = {
.index = key->hw_key_idx,
};
if (wsm_key.index > WSM_KEY_MAX_INDEX) {
ret = -EINVAL;
goto finally;
}
cw1200_free_key(priv, wsm_key.index);
ret = wsm_remove_key(priv, &wsm_key);
} else {
pr_warn("Unhandled key command %d\n", cmd);
}
finally:
mutex_unlock(&priv->conf_mutex);
return ret;
}
void cw1200_wep_key_work(struct work_struct *work)
{
struct cw1200_common *priv =
container_of(work, struct cw1200_common, wep_key_work);
u8 queue_id = cw1200_queue_get_queue_id(priv->pending_frame_id);
struct cw1200_queue *queue = &priv->tx_queue[queue_id];
__le32 wep_default_key_id = __cpu_to_le32(
priv->wep_default_key_id);
pr_debug("[STA] Setting default WEP key: %d\n",
priv->wep_default_key_id);
wsm_lock_tx(priv);
wsm_write_mib(priv, WSM_MIB_ID_DOT11_WEP_DEFAULT_KEY_ID,
&wep_default_key_id, sizeof(wep_default_key_id));
cw1200_queue_requeue(queue, priv->pending_frame_id);
wsm_unlock_tx(priv);
}
int cw1200_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
{
int ret = 0;
__le32 val32;
struct cw1200_common *priv = hw->priv;
if (priv->mode == NL80211_IFTYPE_UNSPECIFIED)
return 0;
if (value != (u32) -1)
val32 = __cpu_to_le32(value);
else
val32 = 0; /* disabled */
if (priv->mode == NL80211_IFTYPE_UNSPECIFIED) {
/* device is down, can _not_ set threshold */
ret = -ENODEV;
goto out;
}
if (priv->rts_threshold == value)
goto out;
pr_debug("[STA] Setting RTS threshold: %d\n",
priv->rts_threshold);
/* mutex_lock(&priv->conf_mutex); */
ret = wsm_write_mib(priv, WSM_MIB_ID_DOT11_RTS_THRESHOLD,
&val32, sizeof(val32));
if (!ret)
priv->rts_threshold = value;
/* mutex_unlock(&priv->conf_mutex); */
out:
return ret;
}
/* If successful, LOCKS the TX queue! */
static int __cw1200_flush(struct cw1200_common *priv, bool drop)
{
int i, ret;
for (;;) {
/* TODO: correct flush handling is required when dev_stop.
* Temporary workaround: 2s
*/
if (drop) {
for (i = 0; i < 4; ++i)
cw1200_queue_clear(&priv->tx_queue[i]);
} else {
ret = wait_event_timeout(
priv->tx_queue_stats.wait_link_id_empty,
cw1200_queue_stats_is_empty(
&priv->tx_queue_stats, -1),
2 * HZ);
}
if (!drop && ret <= 0) {
ret = -ETIMEDOUT;
break;
} else {
ret = 0;
}
wsm_lock_tx(priv);
if (!cw1200_queue_stats_is_empty(&priv->tx_queue_stats, -1)) {
/* Highly unlikely: WSM requeued frames. */
wsm_unlock_tx(priv);
continue;
}
break;
}
return ret;
}
void cw1200_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
{
struct cw1200_common *priv = hw->priv;
switch (priv->mode) {
case NL80211_IFTYPE_MONITOR:
drop = true;
break;
case NL80211_IFTYPE_AP:
if (!priv->enable_beacon)
drop = true;
break;
}
if (!__cw1200_flush(priv, drop))
wsm_unlock_tx(priv);
return;
}
/* ******************************************************************** */
/* WSM callbacks */
void cw1200_free_event_queue(struct cw1200_common *priv)
{
LIST_HEAD(list);
spin_lock(&priv->event_queue_lock);
list_splice_init(&priv->event_queue, &list);
spin_unlock(&priv->event_queue_lock);
__cw1200_free_event_queue(&list);
}
void cw1200_event_handler(struct work_struct *work)
{
struct cw1200_common *priv =
container_of(work, struct cw1200_common, event_handler);
struct cw1200_wsm_event *event;
LIST_HEAD(list);
spin_lock(&priv->event_queue_lock);
list_splice_init(&priv->event_queue, &list);
spin_unlock(&priv->event_queue_lock);
list_for_each_entry(event, &list, link) {
switch (event->evt.id) {
case WSM_EVENT_ERROR:
pr_err("Unhandled WSM Error from LMAC\n");
break;
case WSM_EVENT_BSS_LOST:
pr_debug("[CQM] BSS lost.\n");
cw1200_cancel_unjoin_work(priv);
if (!down_trylock(&priv->scan.lock)) {
cw1200_cqm_bssloss_sm(priv, 1, 0, 0);
up(&priv->scan.lock);