-
Notifications
You must be signed in to change notification settings - Fork 5
/
virtio_mac80211.c
1896 lines (1576 loc) · 53.6 KB
/
virtio_mac80211.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
/*
* IEEE 802.11 virtio frontend driver
* A modified mac80211_hwsim, to work as virtio frontend driver
* in short, virtio_mac80211 = mac80211_hwsim + virtio_net
*
* 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.
*/
/*
* function naming: <virtwifi> virtio specific & <vwlan> mac80211 specific
*/
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/ethtool.h>
#include <linux/module.h>
#include <linux/virtio.h>
#include <linux/virtio_net.h>
#include <linux/bpf.h>
#include <linux/bpf_trace.h>
#include <linux/scatterlist.h>
#include <linux/if_vlan.h>
#include <linux/slab.h>
#include <linux/cpu.h>
#include <linux/average.h>
#include <net/route.h>
#include <linux/list.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <net/dst.h>
#include <net/xfrm.h>
#include <net/mac80211.h>
#include <net/ieee80211_radiotap.h>
#include <linux/if_arp.h>
#include <linux/rtnetlink.h>
#include <linux/platform_device.h>
#include <linux/debugfs.h>
#include <linux/module.h>
#include <linux/ktime.h>
#include <net/genetlink.h>
#include <net/net_namespace.h>
#include <net/netns/generic.h>
#include "virtio_mac80211.h"
//#define MAC80211_RTAP_SUPPORT /* TODO radiotap monitor dev support */
#define DEBUG_ALL /* debug enable */
#define VIRTIO_ID_MAC80211 10 /* virtio mac802.11 */
#define VIRTWIFI_RADIOS_MAX 1 /* max radios per vwlan */
#define VIRTWIFI_CHANNELS_MAX 1 /* max channels per radios */
#define VIRTWIFI_MAX_QUEUE_PAIR 1 /* single rx-tx queue for now */
#define WARN_QUEUE 100
#define MAX_QUEUE 200
#define DEFAULT_VIRTQUEUE 0
//TODO: make all module params as virtio config
//only one radio per virtio-wlan device
#if 0
static int radios = 1;
module_param(radios, int, 0444);
MODULE_PARM_DESC(radios, "Number of simulated radios");
static int channels = 1;
module_param(channels, int, 0444);
MODULE_PARM_DESC(channels, "Number of concurrent channels");
#endif
static bool paged_rx = false;
module_param(paged_rx, bool, 0644);
MODULE_PARM_DESC(paged_rx, "Use paged SKBs for RX instead of linear ones");
static bool rctbl = false;
module_param(rctbl, bool, 0444);
MODULE_PARM_DESC(rctbl, "Handle rate control table");
static bool support_p2p_device = false;
module_param(support_p2p_device, bool, 0444);
MODULE_PARM_DESC(support_p2p_device, "Support P2P-Device interface type");
#define VIRTNET_DRIVER_VERSION "1.0.0"
#define CHAN2G(_freq) { \
.band = NL80211_BAND_2GHZ, \
.center_freq = (_freq), \
.hw_value = (_freq), \
.max_power = 20, \
}
#define CHAN5G(_freq) { \
.band = NL80211_BAND_5GHZ, \
.center_freq = (_freq), \
.hw_value = (_freq), \
.max_power = 20, \
}
static const struct ieee80211_channel vwlan_channels_2ghz[] = {
CHAN2G(2412), /* Channel 1 */
CHAN2G(2417), /* Channel 2 */
CHAN2G(2422), /* Channel 3 */
CHAN2G(2427), /* Channel 4 */
CHAN2G(2432), /* Channel 5 */
CHAN2G(2437), /* Channel 6 */
CHAN2G(2442), /* Channel 7 */
CHAN2G(2447), /* Channel 8 */
CHAN2G(2452), /* Channel 9 */
CHAN2G(2457), /* Channel 10 */
CHAN2G(2462), /* Channel 11 */
CHAN2G(2467), /* Channel 12 */
CHAN2G(2472), /* Channel 13 */
CHAN2G(2484), /* Channel 14 */
};
static const struct ieee80211_channel vwlan_channels_5ghz[] = {
CHAN5G(5180), /* Channel 36 */
CHAN5G(5200), /* Channel 40 */
CHAN5G(5220), /* Channel 44 */
CHAN5G(5240), /* Channel 48 */
CHAN5G(5260), /* Channel 52 */
CHAN5G(5280), /* Channel 56 */
CHAN5G(5300), /* Channel 60 */
CHAN5G(5320), /* Channel 64 */
CHAN5G(5500), /* Channel 100 */
CHAN5G(5520), /* Channel 104 */
CHAN5G(5540), /* Channel 108 */
CHAN5G(5560), /* Channel 112 */
CHAN5G(5580), /* Channel 116 */
CHAN5G(5600), /* Channel 120 */
CHAN5G(5620), /* Channel 124 */
CHAN5G(5640), /* Channel 128 */
CHAN5G(5660), /* Channel 132 */
CHAN5G(5680), /* Channel 136 */
CHAN5G(5700), /* Channel 140 */
CHAN5G(5745), /* Channel 149 */
CHAN5G(5765), /* Channel 153 */
CHAN5G(5785), /* Channel 157 */
CHAN5G(5805), /* Channel 161 */
CHAN5G(5825), /* Channel 165 */
CHAN5G(5845), /* Channel 169 */
};
static const struct ieee80211_rate vwlan_rates[] = {
{ .bitrate = 10 },
{ .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
{ .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
{ .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
{ .bitrate = 60 },
{ .bitrate = 90 },
{ .bitrate = 120 },
{ .bitrate = 180 },
{ .bitrate = 240 },
{ .bitrate = 360 },
{ .bitrate = 480 },
{ .bitrate = 540 }
};
struct vwlan_chanctx_priv {
u32 magic;
};
struct vwlan_priv_data;
#define HWSIM_CHANCTX_MAGIC 0x6d53774a
struct vwlan_vif_priv {
u32 magic;
u8 bssid[ETH_ALEN];
bool assoc;
bool bcn_en;
u16 aid;
struct vwlan_priv_data *priv;
/* beaconing */
struct delayed_work beacon_work;
bool enable_beacon;
};
#define HWSIM_VIF_MAGIC 0x69537748
struct vwlan_sta_priv {
u32 magic;
};
#define HWSIM_STA_MAGIC 0x6d537749
/* Internal representation of a send virtqueue
* @vq: Virtqueue associated with this send _queue
* @sg: TX: fragments + linear part + virtio header
* @name: Name of the send queue: output.$index
*/
struct send_queue {
struct virtqueue *vq;
struct scatterlist sg[MAX_SKB_FRAGS + 2];
char name[40];
//struct napi_struct napi; //TODO unused
};
/* Internal representation of a receive virtqueue
* @vq: Virtqueue associated with this receive_queue
* @pages: Chain pages by the private ptr.
* @ewma_pkt_len: Average packet length for mergeable receive buffers.
* @alloc_frag: Page frag for packet buffer allocation.
* @sg: RX: fragments + linear part + virtio header
* @min_buf_len: Min single buffer size for mergeable buffers case.
* @name: Name of this receive queue: input.$index
*/
struct receive_queue {
struct virtqueue *vq;
struct page *pages;
struct page_frag alloc_frag;
struct scatterlist sg[MAX_SKB_FRAGS + 2];
unsigned int min_buf_len;
char name[40];
};
//mac80211_hwsim_data
struct vwlan_priv_data {
struct ieee80211_hw *hw;
struct device *dev;
struct ieee80211_supported_band bands[NUM_NL80211_BANDS];
struct ieee80211_channel channels_2ghz[ARRAY_SIZE(vwlan_channels_2ghz)];
struct ieee80211_channel channels_5ghz[ARRAY_SIZE(vwlan_channels_5ghz)];
struct ieee80211_rate rates[ARRAY_SIZE(vwlan_rates)];
struct ieee80211_iface_combination if_combination;
struct mac_address addresses[2];
int channels, idx;
bool use_chanctx;
bool destroy_on_close;
struct work_struct destroy_work;
u32 portid;
char alpha2[2];
const struct ieee80211_regdomain *regd;
#if 0
struct ieee80211_channel *tmp_chan;
struct ieee80211_channel *roc_chan;
u32 roc_duration;
struct delayed_work roc_start;
struct delayed_work roc_done;
struct delayed_work hw_scan;
#endif
struct cfg80211_scan_request *hw_scan_request;
struct ieee80211_vif *hw_scan_vif;
int scan_chan_idx;
u8 scan_addr[ETH_ALEN];
struct {
struct ieee80211_channel *channel;
unsigned long next_start, start, end;
} survey_data[ARRAY_SIZE(vwlan_channels_2ghz) +
ARRAY_SIZE(vwlan_channels_5ghz)];
struct ieee80211_channel *channel;
u64 beacon_int /* beacon interval in us */;
unsigned int rx_filter;
bool started, idle, scanning;
struct mutex mutex;
struct tasklet_hrtimer beacon_timer;
enum ps_mode {
PS_DISABLED, PS_ENABLED, PS_AUTO_POLL, PS_MANUAL_POLL
} ps;
bool ps_poll_pending;
struct dentry *debugfs;
uintptr_t pending_cookie;
struct sk_buff_head pending; /* packets pending */
/*
* Only radios in the same group can communicate together (the
* channel has to match too). Each bit represents a group. A
* radio can be in more than one group.
*/
u64 group;
/* group shared by radios created in the same netns */
int netgroup;
/* wmediumd portid responsible for netgroup of this radio */
u32 wmediumd;
/* difference between this hw's clock and the real clock, in usecs */
s64 tsf_offset;
s64 bcn_delta;
/* absolute beacon transmission time. Used to cover up "tx" delay. */
u64 abs_bcn_ts;
};
/*
* virtwifi_info: virtio specific MAC802.11 (TODO: cleanup unused)
* @max_queue_pairs: Max # of queue pairs supported by the device
* @curr_queue_pairs: # of queue pairs currently used by the driver
* @xdp_queue_pairs: # of XDP queue pairs currently used by the driver
* @big_packets
* @mergeable_rx_bufs: Host will merge rx buffers for big packets
* @has_cvq: Has control virtqueue
* @any_header_sg: Host can handle any s/g split between our header and packet data
* @hdr_len: Packet virtio header size
* @refill: Work struct for refilling if we run low on memory.
* @config_work: Work struct for config space updates
* @affinity_hint_set: Does the affinity hint is set for virtqueues?
* @node/node_dead: CPU hotplug instances for online & dead
* @duplex/speed: Ethtool settings
*/
struct virtwifi_info {
struct list_head list; //vwlan list
struct vwlan_priv_data priv;
struct { //virtio specific
struct virtio_device *vdev;
struct virtqueue *cvq;
struct send_queue *sq;
struct receive_queue *rq;
u16 max_queue_pairs;
u16 curr_queue_pairs;
u16 xdp_queue_pairs;
bool big_packets;
bool mergeable_rx_bufs;
bool has_cvq;
bool any_header_sg;
u8 hdr_len;
struct delayed_work refill;
struct work_struct config_work;
bool affinity_hint_set;
struct control_buf *ctrl;
unsigned long guest_offloads;
};
//TODO: CPU hot-plug related, to cleanup
struct hlist_node node;
struct hlist_node node_dead;
struct {
/* Stats */
u64 tx_pkts;
u64 rx_pkts;
u64 tx_bytes;
u64 rx_bytes;
u64 tx_dropped;
u64 rx_dropped;
u64 tx_failed;
};
u8 duplex; //for ethtool
u32 speed;
unsigned int status;
};
//TODO: mesh_point | ADHOC | p2p_client
static const struct ieee80211_iface_limit vwlan_mac80211_limits[] = {
{ .max = 1, .types = BIT(NL80211_IFTYPE_STATION), },
{ .max = 1, .types = BIT(NL80211_IFTYPE_AP), },
};
static const struct ieee80211_iface_combination vwlan_mac80211_comb[] = {
{
.limits = vwlan_mac80211_limits,
.n_limits = ARRAY_SIZE(vwlan_mac80211_limits),
.max_interfaces = 2,
.num_different_channels = 1,
/* .beacon_int_infra_match = true, */
.radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
BIT(NL80211_CHAN_WIDTH_20) |
BIT(NL80211_CHAN_WIDTH_40) |
BIT(NL80211_CHAN_WIDTH_80) |
BIT(NL80211_CHAN_WIDTH_160),
},
};
/* global */
static spinlock_t vwlan_radio_lock;
static int vwlan_radio_idx = 0;
static LIST_HEAD(vwlan_radios);
#define VWLAN_NAME "vwlan%d"
#ifdef MAC80211_RTAP_SUPPORT
//radiotap monitoring interface support (ref. mac80211_hwsim) */
static struct net_device *hwsim_mon;
#endif //MAC80211_RTAP_SUPPORT
//------------------ieee80211_ops impl-----------------------
#if 0
static void __vwlan_roc_start(struct work_struct *work)
{
struct vwlan_priv_data *data =
container_of(work, struct vwlan_priv_data, roc_start.work);
mutex_lock(&data->mutex);
wiphy_dbg(data->hw->wiphy, "ROC begins\n");
data->tmp_chan = data->roc_chan;
ieee80211_ready_on_channel(data->hw);
ieee80211_queue_delayed_work(data->hw, &data->roc_done,
msecs_to_jiffies(data->roc_duration));
mutex_unlock(&data->mutex);
}
static void __vwlan_roc_done(struct work_struct *work)
{
struct vwlan_priv_data *data =
container_of(work, struct vwlan_priv_data, roc_done.work);
mutex_lock(&data->mutex);
ieee80211_remain_on_channel_expired(data->hw);
data->tmp_chan = NULL;
mutex_unlock(&data->mutex);
wiphy_dbg(data->hw->wiphy, "ROC expired\n");
}
static void __vwlan_scan_work(struct work_struct *work)
{
struct vwlan_priv_data *data =
container_of(work, struct vwlan_priv_data, hw_scan.work);
struct cfg80211_scan_request *req = data->hw_scan_request;
int dwell, i;
mutex_lock(&data->mutex);
if (data->scan_chan_idx >= req->n_channels) {
struct cfg80211_scan_info info = {
.aborted = false,
};
wiphy_dbg(hwsim->hw->wiphy, "scan complete\n");
ieee80211_scan_completed(data->hw, &info);
data->hw_scan_request = NULL;
data->hw_scan_vif = NULL;
data->tmp_chan = NULL;
mutex_unlock(&data->mutex);
return;
}
wiphy_dbg(data->hw->wiphy, "hw scan %d MHz\n",
req->channels[data->scan_chan_idx]->center_freq);
data->tmp_chan = req->channels[data->scan_chan_idx];
if (data->tmp_chan->flags & (IEEE80211_CHAN_NO_IR |
IEEE80211_CHAN_RADAR) ||
!req->n_ssids) {
dwell = 120;
} else {
dwell = 30;
/* send probes */
for (i = 0; i < req->n_ssids; i++) {
struct sk_buff *probe;
struct ieee80211_mgmt *mgmt;
probe = ieee80211_probereq_get(data->hw,
data->scan_addr,
req->ssids[i].ssid,
req->ssids[i].ssid_len,
req->ie_len);
if (!probe)
continue;
mgmt = (struct ieee80211_mgmt *) probe->data;
memcpy(mgmt->da, req->bssid, ETH_ALEN);
memcpy(mgmt->bssid, req->bssid, ETH_ALEN);
if (req->ie_len)
skb_put_data(probe, req->ie, req->ie_len);
local_bh_disable();
mac80211_hwsim_tx_frame(data->hw, probe,
data->tmp_chan); //TODO
local_bh_enable();
}
}
ieee80211_queue_delayed_work(data->hw, &data->hw_scan,
msecs_to_jiffies(dwell));
data->survey_data[data->scan_chan_idx].channel = data->tmp_chan;
data->survey_data[data->scan_chan_idx].start = jiffies;
data->survey_data[data->scan_chan_idx].end =
jiffies + msecs_to_jiffies(dwell);
data->scan_chan_idx++;
mutex_unlock(&data->mutex);
}
#endif
static int __vwlan_mac80211_tx_internal(struct virtwifi_info *info,
struct ieee80211_tx_control *control,
struct send_queue *sq,
struct sk_buff *skb)
{
int num_sg;
pr_info("XXXXX __vwlan_mac80211_tx_internal: onward to virtqueue!!\n");
sg_init_table(sq->sg, (skb_shinfo(skb)->nr_frags + 2)); //XXX not sure why "+ 2"
num_sg = skb_to_sgvec(skb, sq->sg, 0, skb->len);
if (unlikely(num_sg < 0))
return num_sg;
//add it to send queue, virtqueue_kick()
return virtqueue_add_outbuf(sq->vq, sq->sg, num_sg, skb, GFP_ATOMIC);
}
static void __free_old_xmit_skbs(struct virtwifi_info *, struct send_queue *); //TODO recheck
static void __vwlan_mac80211_tx(struct ieee80211_hw *hw,
struct ieee80211_tx_control *control,
struct sk_buff *skb)
{
struct virtwifi_info *info = (struct virtwifi_info *) hw->priv;
struct vwlan_priv_data *data = &(info->priv);
struct send_queue *sq = &(info->sq[DEFAULT_VIRTQUEUE]);
struct ieee80211_tx_info *txi = IEEE80211_SKB_CB(skb);
//struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
//struct ieee80211_chanctx_conf *chanctx_conf;
struct ieee80211_channel *channel = NULL;
int err;
//bool ack;
if (WARN_ON(skb->len < 10)) {
/* Should not happen; just a sanity check for addr1 use */
ieee80211_free_txskb(hw, skb);
return;
}
pr_info("XXXXX __vwlan_mac80211_tx: more packet? %s\n", skb->xmit_more ? "yes" : "no");
//__free_old_xmit_skbs(info, sq); //clearing used packets in tx callback
//TODO: need to use refcnt to implement packet burst like xmit_more
//if (!skb->xmit_more) //xmit_more bit does not seems to working for wireless
virtqueue_enable_cb_delayed(sq->vq);
if (!data->use_chanctx) //currently no support for use_chanctx
channel = data->channel;
if (WARN(!channel, "TX w/o channel - queue = %d\n", txi->hw_queue)) {
//virtqueue_disable_cb(sq->vq);
ieee80211_free_txskb(hw, skb);
return;
}
if (data->idle /*&& !data->tmp_chan*/) {
wiphy_dbg(hw->wiphy, "Trying to TX when idle - reject\n");
//virtqueue_disable_cb(sq->vq);
ieee80211_free_txskb(hw, skb);
return;
}
if (txi->control.vif)
pr_info("TODO vif\n");
if (control && control->sta)
pr_info("TODO sta\n");
if (ieee80211_hw_check(hw, SUPPORTS_RC_TABLE))
ieee80211_get_tx_rates(txi->control.vif, control->sta, skb,
txi->control.rates,
ARRAY_SIZE(txi->control.rates));
//skb_tx_timestamp(skb);
//TODO check is_probe_resp()
#ifdef MAC80211_RTAP_SUPPORT
//call monitor_rx()
#endif
//TODO tx stat update here or at free_tx_skbs()
err = __vwlan_mac80211_tx_internal(info, control, sq, skb);
if (unlikely(err)) {
pr_err("%s Unexpected TX queue failure: %d\n", __func__, err);
info->tx_dropped++;
dev_kfree_skb_any(skb);
return;
}
ieee80211_tx_info_clear_status(txi);
/* frame was transmitted at most favorable rate at first attempt */
txi->control.rates[0].count = 1;
txi->control.rates[1].idx = -1;
if (!(txi->flags & IEEE80211_TX_CTL_NO_ACK)/* && ack*/)
txi->flags |= IEEE80211_TX_STAT_ACK;
ieee80211_tx_status_irqsafe(hw, skb); //XXX is it needed to report back status?
pr_info("XXXXX %s: kick send queue!!\n", __func__);
//TODO check if running out of space, stop queue if needed
virtqueue_kick(sq->vq);
}
static bool try_fill_recv(struct virtwifi_info *, struct receive_queue *, gfp_t);
static int __vwlan_mac80211_start(struct ieee80211_hw *hw)
{
struct virtwifi_info *info = (struct virtwifi_info *) hw->priv;
struct send_queue *sq = &info->sq[DEFAULT_VIRTQUEUE];
struct receive_queue *rq = &info->rq[DEFAULT_VIRTQUEUE];
wiphy_dbg(hw->wiphy, "%s\n", __func__);
//TODO may be add MAC here
if (!try_fill_recv(info, rq, GFP_ATOMIC))
schedule_delayed_work(&info->refill, 0);
//normally register rx/tx intr here
if (!virtqueue_enable_cb_delayed(sq->vq))
return -EINVAL;
if (!virtqueue_enable_cb_delayed(rq->vq))
goto err_disable_sq;
info->priv.started = true;
pr_info("%s: vwlan started\n", __func__);
return 0;
err_disable_sq:
virtqueue_disable_cb(sq->vq);
return -EINVAL;
}
static void __vwlan_mac80211_stop(struct ieee80211_hw *hw)
{
struct virtwifi_info *info = (struct virtwifi_info *) hw->priv;
struct send_queue *sq = &info->sq[DEFAULT_VIRTQUEUE];
struct receive_queue *rq = &info->rq[DEFAULT_VIRTQUEUE];
info->priv.started = false;
virtqueue_disable_cb(sq->vq);
virtqueue_disable_cb(rq->vq);
wiphy_dbg(hw->wiphy, "%s\n", __func__);
}
static void __vwlan_beacon_work(struct work_struct *);
static int __vwlan_mac80211_add_interface(struct ieee80211_hw *hw,
struct ieee80211_vif *vif)
{
struct virtwifi_info *info = (struct virtwifi_info *) hw->priv;
struct vwlan_vif_priv *vif_priv;
wiphy_dbg(hw->wiphy, "%s (type=%d mac_addr=%pM)\n",
__func__, ieee80211_vif_type_p2p(vif),
vif->addr);
//hwsim_set_magic(vif);
vif->cab_queue = 0;
vif->hw_queue[IEEE80211_AC_VO] = 0;
vif->hw_queue[IEEE80211_AC_VI] = 1;
vif->hw_queue[IEEE80211_AC_BE] = 2;
vif->hw_queue[IEEE80211_AC_BK] = 3;
vif_priv = (struct vwlan_vif_priv *) vif->drv_priv;
vif_priv->priv = &(info->priv);
INIT_DELAYED_WORK(&vif_priv->beacon_work, __vwlan_beacon_work);
vif_priv->enable_beacon = false;
pr_info("%s (type=%d mac_addr=%pM)\n", __func__,
ieee80211_vif_type_p2p(vif), vif->addr);
return 0;
}
static int __vwlan_mac80211_change_interface(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
enum nl80211_iftype newtype,
bool newp2p)
{
#if 0
newtype = ieee80211_iftype_p2p(newtype, newp2p);
wiphy_dbg(hw->wiphy,
"%s (old type=%d, new type=%d, mac_addr=%pM)\n",
__func__, ieee80211_vif_type_p2p(vif),
newtype, vif->addr);
//hwsim_check_magic(vif);
#endif
pr_info("%s mac_addr=%pM\n", __func__, vif->addr);
/*
* interface may change from non-AP to AP in
* which case this needs to be set up again
*/
vif->cab_queue = 0;
return 0;
}
static void __vwlan_mac80211_remove_interface(struct ieee80211_hw *hw,
struct ieee80211_vif *vif)
{
struct vwlan_vif_priv *vif_priv = (struct vwlan_vif_priv *) vif->drv_priv;
wiphy_dbg(hw->wiphy, "%s (type=%d mac_addr=%pM)\n",
__func__, ieee80211_vif_type_p2p(vif),
vif->addr);
//hwsim_check_magic(vif);
//hwsim_clear_magic(vif);
vif_priv->priv->started = false;
pr_info("%s (type=%d mac_addr=%pM)\n", __func__,
ieee80211_vif_type_p2p(vif), vif->addr);
}
static const char * const vwlan_chanwidths[] = {
[NL80211_CHAN_WIDTH_20_NOHT] = "noht",
[NL80211_CHAN_WIDTH_20] = "ht20",
[NL80211_CHAN_WIDTH_40] = "ht40",
[NL80211_CHAN_WIDTH_80] = "vht80",
[NL80211_CHAN_WIDTH_80P80] = "vht80p80",
[NL80211_CHAN_WIDTH_160] = "vht160",
};
static int __vwlan_mac80211_config(struct ieee80211_hw *hw, u32 changed)
{
struct virtwifi_info *info = (struct virtwifi_info *) hw->priv;
struct vwlan_priv_data *data = &(info->priv);
struct ieee80211_conf *conf = &(hw->conf);
static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = {
[IEEE80211_SMPS_AUTOMATIC] = "auto",
[IEEE80211_SMPS_OFF] = "off",
[IEEE80211_SMPS_STATIC] = "static",
[IEEE80211_SMPS_DYNAMIC] = "dynamic",
};
int idx;
if (conf->chandef.chan)
wiphy_dbg(hw->wiphy,
"%s (freq=%d(%d - %d)/%s idle=%d ps=%d smps=%s)\n",
__func__,
conf->chandef.chan->center_freq,
conf->chandef.center_freq1,
conf->chandef.center_freq2,
vwlan_chanwidths[conf->chandef.width],
!!(conf->flags & IEEE80211_CONF_IDLE),
!!(conf->flags & IEEE80211_CONF_PS),
smps_modes[conf->smps_mode]);
else
wiphy_dbg(hw->wiphy,
"%s (freq=0 idle=%d ps=%d smps=%s)\n",
__func__,
!!(conf->flags & IEEE80211_CONF_IDLE),
!!(conf->flags & IEEE80211_CONF_PS),
smps_modes[conf->smps_mode]);
data->idle = !!(conf->flags & IEEE80211_CONF_IDLE);
mutex_lock(&data->mutex);
if (data->scanning && conf->chandef.chan) {
/* only valid as .sw_scan_start/complete APIs
* are implemented
*/
for (idx = 0; idx < ARRAY_SIZE(data->survey_data); idx++) {
if (data->survey_data[idx].channel == data->channel) {
data->survey_data[idx].start =
data->survey_data[idx].next_start;
data->survey_data[idx].end = jiffies;
break;
}
}
data->channel = conf->chandef.chan;
for (idx = 0; idx < ARRAY_SIZE(data->survey_data); idx++) {
if (data->survey_data[idx].channel &&
data->survey_data[idx].channel != data->channel)
continue;
data->survey_data[idx].channel = data->channel;
data->survey_data[idx].next_start = jiffies;
break;
}
} else {
data->channel = conf->chandef.chan;
}
mutex_unlock(&data->mutex);
return 0;
}
static void __vwlan_mac80211_configure_filter(struct ieee80211_hw *hw,
unsigned int changed_flags,
unsigned int *total_flags,u64 multicast)
{
struct virtwifi_info *info = (struct virtwifi_info *) hw->priv;
struct vwlan_priv_data *data = &(info->priv);
wiphy_dbg(hw->wiphy, "%s\n", __func__);
data->rx_filter = 0;
if (*total_flags & FIF_ALLMULTI)
data->rx_filter |= FIF_ALLMULTI;
*total_flags = data->rx_filter;
pr_info("%s XXXX not sure what to configure\n", __func__);
}
static void __vwlan_mac80211_bss_info_changed(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_bss_conf *info,
u32 changed)
{
struct vwlan_vif_priv *vif_priv = (struct vwlan_vif_priv *) vif->drv_priv;
struct vwlan_priv_data *data = vif_priv->priv;
//hwsim_check_magic(vif);
wiphy_dbg(hw->wiphy, "%s(changed=0x%x vif->addr=%pM)\n",
__func__, changed, vif->addr);
if (changed & BSS_CHANGED_BSSID) {
wiphy_dbg(hw->wiphy, "%s: BSSID changed: %pM\n",
__func__, info->bssid);
memcpy(vif_priv->bssid, info->bssid, ETH_ALEN);
}
if (changed & BSS_CHANGED_ASSOC) {
wiphy_dbg(hw->wiphy, " ASSOC: assoc=%d aid=%d\n",
info->assoc, info->aid);
vif_priv->assoc = info->assoc;
vif_priv->aid = info->aid;
}
if (changed & BSS_CHANGED_BEACON_ENABLED) {
wiphy_dbg(hw->wiphy, " BCN EN: %d (BI=%u)\n",
info->enable_beacon, info->beacon_int);
if (data->started) {
vif_priv->bcn_en = info->enable_beacon; //redundant
vif_priv->enable_beacon = info->enable_beacon;
}
}
if (changed & (BSS_CHANGED_BEACON_ENABLED | BSS_CHANGED_BEACON)) {
cancel_delayed_work_sync(&vif_priv->beacon_work);
if (vif_priv->enable_beacon)
schedule_work(&vif_priv->beacon_work.work);
}
if (changed & BSS_CHANGED_ERP_CTS_PROT) {
wiphy_dbg(hw->wiphy, " ERP_CTS_PROT: %d\n",
info->use_cts_prot);
}
if (changed & BSS_CHANGED_ERP_PREAMBLE) {
wiphy_dbg(hw->wiphy, " ERP_PREAMBLE: %d\n",
info->use_short_preamble);
}
if (changed & BSS_CHANGED_ERP_SLOT) {
wiphy_dbg(hw->wiphy, " ERP_SLOT: %d\n", info->use_short_slot);
}
if (changed & BSS_CHANGED_HT) {
wiphy_dbg(hw->wiphy, " HT: op_mode=0x%x\n",
info->ht_operation_mode);
}
if (changed & BSS_CHANGED_BASIC_RATES) {
wiphy_dbg(hw->wiphy, " BASIC_RATES: 0x%llx\n",
(unsigned long long) info->basic_rates);
}
if (changed & BSS_CHANGED_TXPOWER)
wiphy_dbg(hw->wiphy, " TX Power: %d dBm\n", info->txpower);
}
static int __vwlan_mac80211_sta_add(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta)
{
pr_info("sta_add: addr %pM\n", sta->addr);
//hwsim_check_magic(vif);
//hwsim_set_sta_magic(sta);
return 0;
}
static int __vwlan_mac80211_sta_remove(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta)
{
pr_info("sta_remove: addr %pM\n", sta->addr);
//hwsim_check_magic(vif);
//hwsim_clear_sta_magic(sta);
return 0;
}
static void __vwlan_mac80211_sta_notify(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
enum sta_notify_cmd cmd,
struct ieee80211_sta *sta)
{
pr_info("sta_notify: addr %pM\n", sta->addr);
//hwsim_check_magic(vif);
switch (cmd) {
case STA_NOTIFY_SLEEP:
case STA_NOTIFY_AWAKE:
/* TODO: make good use of these flags */
pr_info("sta_notify: %pM sleep/awake\n", sta->addr);
break;
default:
WARN(1, "Invalid sta notify: %d\n", cmd);
break;
}
}
static int __vwlan_mac80211_set_tim(struct ieee80211_hw *hw,
struct ieee80211_sta *sta,
bool set)
{
pr_info("sta_tim: addr %pM???\n", sta->addr);
//hwsim_check_sta_magic(sta);
return 0;
}
static int __vwlan_mac80211_conf_tx(
struct ieee80211_hw *hw,
struct ieee80211_vif *vif, u16 queue,
const struct ieee80211_tx_queue_params *params)
{
wiphy_dbg(hw->wiphy,
"%s (queue=%d txop=%d cw_min=%d cw_max=%d aifs=%d)\n",
__func__, queue,
params->txop, params->cw_min,
params->cw_max, params->aifs);
return 0;
}
static int __vwlan_mac80211_get_survey(struct ieee80211_hw *hw, int idx,
struct survey_info *survey)
{
struct virtwifi_info *info = (struct virtwifi_info *) hw->priv;
struct vwlan_priv_data *data = &(info->priv);
if (idx < 0 || idx >= ARRAY_SIZE(data->survey_data))
return -ENOENT;
mutex_lock(&data->mutex);
survey->channel = data->survey_data[idx].channel;
if (!survey->channel) {
mutex_unlock(&data->mutex);
return -ENOENT;
}
/*
* Magically conjured dummy values --- this is only ok for simulated hardware.
*
* A real driver which cannot determine real values noise MUST NOT
* report any, especially not a magically conjured ones :-)
*/
survey->filled = SURVEY_INFO_NOISE_DBM |
SURVEY_INFO_TIME |
SURVEY_INFO_TIME_BUSY;
survey->noise = -92;
survey->time =
jiffies_to_msecs(data->survey_data[idx].end -
data->survey_data[idx].start);
/* report 12.5% of channel time is used */
survey->time_busy = survey->time/8;
mutex_unlock(&data->mutex);
return 0;
}
#if 0
static int __vwlan_mac80211_ampdu_action(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_ampdu_params *params)
{
struct ieee80211_sta *sta = params->sta;
enum ieee80211_ampdu_mlme_action action = params->action;
u16 tid = params->tid;
switch (action) {
case IEEE80211_AMPDU_TX_START:
ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
break;
case IEEE80211_AMPDU_TX_STOP_CONT:
case IEEE80211_AMPDU_TX_STOP_FLUSH:
case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
break;
case IEEE80211_AMPDU_TX_OPERATIONAL:
break;