2
* Copyright 2002-2005, Instant802 Networks, Inc.
3
* Copyright 2005-2006, Devicescape Software, Inc.
4
* Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 2 as
8
* published by the Free Software Foundation.
11
#include <net/mac80211.h>
12
#include <net/ieee80211_radiotap.h>
13
#include <linux/module.h>
14
#include <linux/init.h>
15
#include <linux/netdevice.h>
16
#include <linux/types.h>
17
#include <linux/slab.h>
18
#include <linux/skbuff.h>
19
#include <linux/etherdevice.h>
20
#include <linux/if_arp.h>
21
#include <linux/wireless.h>
22
#include <linux/rtnetlink.h>
23
#include <net/iw_handler.h>
24
#include <linux/compiler.h>
25
#include <linux/bitmap.h>
26
#include <net/cfg80211.h>
27
#include <asm/unaligned.h>
29
#include "ieee80211_common.h"
30
#include "ieee80211_i.h"
31
#include "ieee80211_rate.h"
37
#include "ieee80211_led.h"
38
#include "ieee80211_cfg.h"
40
#include "debugfs_netdev.h"
41
#include "debugfs_key.h"
43
/* privid for wiphys to determine whether they belong to us or not */
44
void *mac80211_wiphy_privid = &mac80211_wiphy_privid;
46
/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
47
/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
48
static const unsigned char rfc1042_header[] =
49
{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
51
/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
52
static const unsigned char bridge_tunnel_header[] =
53
{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
55
/* No encapsulation header if EtherType < 0x600 (=length) */
56
static const unsigned char eapol_header[] =
57
{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x88, 0x8e };
61
* For seeing transmitted packets on monitor interfaces
62
* we have a radiotap header too.
64
struct iwlwifi_ieee80211_tx_status_rtap_hdr {
65
struct ieee80211_radiotap_header hdr;
68
} __attribute__ ((packed));
71
static inline void ieee80211_include_sequence(struct ieee80211_sub_if_data *sdata,
72
struct ieee80211_hdr *hdr)
74
/* Set the sequence number for this frame. */
75
hdr->seq_ctrl = cpu_to_le16(sdata->sequence);
77
/* Increase the sequence number. */
78
sdata->sequence = (sdata->sequence + 0x10) & IEEE80211_SCTL_SEQ;
81
struct ieee80211_key_conf *
82
ieee80211_key_data2conf(struct ieee80211_local *local,
83
const struct ieee80211_key *data)
85
struct ieee80211_key_conf *conf;
87
conf = kmalloc(sizeof(*conf) + data->keylen, GFP_ATOMIC);
91
conf->hw_key_idx = data->hw_key_idx;
92
conf->alg = data->alg;
93
conf->keylen = data->keylen;
95
if (data->force_sw_encrypt)
96
conf->flags |= IEEE80211_KEY_FORCE_SW_ENCRYPT;
97
conf->keyidx = data->keyidx;
98
if (data->default_tx_key)
99
conf->flags |= IEEE80211_KEY_DEFAULT_TX_KEY;
100
if (local->default_wep_only)
101
conf->flags |= IEEE80211_KEY_DEFAULT_WEP_ONLY;
102
memcpy(conf->key, data->key, data->keylen);
107
struct ieee80211_key *ieee80211_key_alloc(struct ieee80211_sub_if_data *sdata,
108
int idx, size_t key_len, gfp_t flags)
110
struct ieee80211_key *key;
112
key = kzalloc(sizeof(struct ieee80211_key) + key_len, flags);
115
kref_init(&key->kref);
119
static void ieee80211_key_release(struct kref *kref)
121
struct ieee80211_key *key;
123
key = container_of(kref, struct ieee80211_key, kref);
124
if (key->alg == ALG_CCMP)
125
ieee80211_aes_key_free(key->u.ccmp.tfm);
126
ieee80211_debugfs_key_remove(key);
130
void ieee80211_key_free(struct ieee80211_key *key)
133
kref_put(&key->kref, ieee80211_key_release);
136
static int rate_list_match(const int *rate_list, int rate)
143
for (i = 0; rate_list[i] >= 0; i++)
144
if (rate_list[i] == rate)
151
void ieee80211_prepare_rates(struct ieee80211_local *local,
152
struct ieee80211_hw_mode *mode)
156
for (i = 0; i < mode->num_rates; i++) {
157
struct ieee80211_rate *rate = &mode->rates[i];
159
rate->flags &= ~(IEEE80211_RATE_SUPPORTED |
160
IEEE80211_RATE_BASIC);
162
if (local->supp_rates[mode->mode]) {
163
if (!rate_list_match(local->supp_rates[mode->mode],
168
rate->flags |= IEEE80211_RATE_SUPPORTED;
170
/* Use configured basic rate set if it is available. If not,
171
* use defaults that are sane for most cases. */
172
if (local->basic_rates[mode->mode]) {
173
if (rate_list_match(local->basic_rates[mode->mode],
175
rate->flags |= IEEE80211_RATE_BASIC;
176
} else switch (mode->mode) {
177
case MODE_IEEE80211A:
178
if (rate->rate == 60 || rate->rate == 120 ||
180
rate->flags |= IEEE80211_RATE_BASIC;
182
case MODE_IEEE80211B:
183
if (rate->rate == 10 || rate->rate == 20)
184
rate->flags |= IEEE80211_RATE_BASIC;
186
case MODE_ATHEROS_TURBO:
187
if (rate->rate == 120 || rate->rate == 240 ||
189
rate->flags |= IEEE80211_RATE_BASIC;
191
case MODE_IEEE80211G:
192
if (rate->rate == 10 || rate->rate == 20 ||
193
rate->rate == 55 || rate->rate == 110)
194
rate->flags |= IEEE80211_RATE_BASIC;
198
/* Set ERP and MANDATORY flags based on phymode */
199
switch (mode->mode) {
200
case MODE_IEEE80211A:
201
if (rate->rate == 60 || rate->rate == 120 ||
203
rate->flags |= IEEE80211_RATE_MANDATORY;
205
case MODE_IEEE80211B:
206
if (rate->rate == 10)
207
rate->flags |= IEEE80211_RATE_MANDATORY;
209
case MODE_ATHEROS_TURBO:
211
case MODE_IEEE80211G:
212
if (rate->rate == 10 || rate->rate == 20 ||
213
rate->rate == 55 || rate->rate == 110 ||
214
rate->rate == 60 || rate->rate == 120 ||
216
rate->flags |= IEEE80211_RATE_MANDATORY;
219
if (ieee80211_is_erp_rate(mode->mode, rate->rate))
220
rate->flags |= IEEE80211_RATE_ERP;
225
static void ieee80211_key_threshold_notify(struct net_device *dev,
226
struct ieee80211_key *key,
227
struct sta_info *sta)
229
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
231
struct ieee80211_msg_key_notification *msg;
233
/* if no one will get it anyway, don't even allocate it.
234
* unlikely because this is only relevant for APs
235
* where the device must be open... */
236
if (unlikely(!local->apdev))
239
skb = dev_alloc_skb(sizeof(struct ieee80211_frame_info) +
240
sizeof(struct ieee80211_msg_key_notification));
244
skb_reserve(skb, sizeof(struct ieee80211_frame_info));
245
msg = (struct ieee80211_msg_key_notification *)
246
skb_put(skb, sizeof(struct ieee80211_msg_key_notification));
247
msg->tx_rx_count = key->tx_rx_count;
248
memcpy(msg->ifname, dev->name, IFNAMSIZ);
250
memcpy(msg->addr, sta->addr, ETH_ALEN);
252
memset(msg->addr, 0xff, ETH_ALEN);
254
key->tx_rx_count = 0;
256
ieee80211_rx_mgmt(local, skb, NULL,
257
ieee80211_msg_key_threshold_notification);
261
static u8 * ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
266
fc = le16_to_cpu(hdr->frame_control);
268
switch (fc & IEEE80211_FCTL_FTYPE) {
269
case IEEE80211_FTYPE_DATA:
270
switch (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
271
case IEEE80211_FCTL_TODS:
273
case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
275
case IEEE80211_FCTL_FROMDS:
281
case IEEE80211_FTYPE_MGMT:
283
case IEEE80211_FTYPE_CTL:
284
if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)
286
else if ((fc & IEEE80211_FCTL_STYPE) ==
287
IEEE80211_STYPE_BACK_REQ) {
289
case IEEE80211_IF_TYPE_STA:
291
case IEEE80211_IF_TYPE_AP:
303
int iwlwifi_ieee80211_get_hdrlen(u16 fc)
307
switch (fc & IEEE80211_FCTL_FTYPE) {
308
case IEEE80211_FTYPE_DATA:
309
if ((fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))
310
hdrlen = 30; /* Addr4 */
312
* The QoS Control field is two bytes and its presence is
313
* indicated by the IEEE80211_STYPE_QOS_DATA bit. Add 2 to
314
* hdrlen if that bit is set.
315
* This works by masking out the bit and shifting it to
316
* bit position 1 so the result has the value 0 or 2.
318
hdrlen += (fc & IEEE80211_STYPE_QOS_DATA)
319
>> (ilog2(IEEE80211_STYPE_QOS_DATA)-1);
321
case IEEE80211_FTYPE_CTL:
323
* ACK and CTS are 10 bytes, all others 16. To see how
324
* to get this condition consider
325
* subtype mask: 0b0000000011110000 (0x00F0)
326
* ACK subtype: 0b0000000011010000 (0x00D0)
327
* CTS subtype: 0b0000000011000000 (0x00C0)
328
* bits that matter: ^^^ (0x00E0)
329
* value of those: 0b0000000011000000 (0x00C0)
331
if ((fc & 0xE0) == 0xC0)
340
EXPORT_SYMBOL(iwlwifi_ieee80211_get_hdrlen);
342
int iwlwifi_iwlwifi_ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
344
const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *) skb->data;
347
if (unlikely(skb->len < 10))
349
hdrlen = iwlwifi_ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control));
350
if (unlikely(hdrlen > skb->len))
354
EXPORT_SYMBOL(iwlwifi_iwlwifi_ieee80211_get_hdrlen_from_skb);
356
static int ieee80211_get_radiotap_len(struct sk_buff *skb)
358
struct ieee80211_radiotap_header *hdr =
359
(struct ieee80211_radiotap_header *) skb->data;
361
return le16_to_cpu(hdr->it_len);
364
#ifdef CONFIG_MAC80211_LOWTX_FRAME_DUMP
365
static void ieee80211_dump_frame(const char *ifname, const char *title,
366
const struct sk_buff *skb)
368
const struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
372
printk(KERN_DEBUG "%s: %s (len=%d)", ifname, title, skb->len);
378
fc = le16_to_cpu(hdr->frame_control);
379
hdrlen = iwlwifi_ieee80211_get_hdrlen(fc);
380
if (hdrlen > skb->len)
383
printk(" FC=0x%04x DUR=0x%04x",
384
fc, le16_to_cpu(hdr->duration_id));
386
printk(" A1=" MAC_FMT, MAC_ARG(hdr->addr1));
388
printk(" A2=" MAC_FMT, MAC_ARG(hdr->addr2));
390
printk(" A3=" MAC_FMT, MAC_ARG(hdr->addr3));
392
printk(" A4=" MAC_FMT, MAC_ARG(hdr->addr4));
395
#else /* CONFIG_MAC80211_LOWTX_FRAME_DUMP */
396
static inline void ieee80211_dump_frame(const char *ifname, const char *title,
400
#endif /* CONFIG_MAC80211_LOWTX_FRAME_DUMP */
403
static int ieee80211_is_eapol(const struct sk_buff *skb)
405
const struct ieee80211_hdr *hdr;
409
if (unlikely(skb->len < 10))
412
hdr = (const struct ieee80211_hdr *) skb->data;
413
fc = le16_to_cpu(hdr->frame_control);
415
if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
418
hdrlen = iwlwifi_ieee80211_get_hdrlen(fc);
420
if (unlikely(skb->len >= hdrlen + sizeof(eapol_header) &&
421
memcmp(skb->data + hdrlen, eapol_header,
422
sizeof(eapol_header)) == 0))
429
static ieee80211_txrx_result
430
ieee80211_tx_h_rate_ctrl(struct ieee80211_txrx_data *tx)
432
struct rate_control_extra extra;
434
memset(&extra, 0, sizeof(extra));
435
extra.mode = tx->u.tx.mode;
436
extra.mgmt_data = tx->sdata &&
437
tx->sdata->type == IEEE80211_IF_TYPE_MGMT;
438
extra.ethertype = tx->ethertype;
440
tx->u.tx.rate = rate_control_get_rate(tx->local, tx->dev, tx->skb,
442
if (unlikely(extra.probe != NULL)) {
443
tx->u.tx.control->flags |= IEEE80211_TXCTL_RATE_CTRL_PROBE;
444
tx->u.tx.probe_last_frag = 1;
445
tx->u.tx.control->alt_retry_rate = tx->u.tx.rate->val;
446
tx->u.tx.rate = extra.probe;
448
tx->u.tx.control->alt_retry_rate = -1;
452
if (tx->u.tx.mode->mode == MODE_IEEE80211G &&
453
tx->sdata->use_protection && tx->fragmented &&
455
tx->u.tx.last_frag_rate = tx->u.tx.rate;
456
tx->u.tx.probe_last_frag = extra.probe ? 1 : 0;
458
tx->u.tx.rate = extra.nonerp;
459
tx->u.tx.control->rate = extra.nonerp;
460
tx->u.tx.control->flags &= ~IEEE80211_TXCTL_RATE_CTRL_PROBE;
462
tx->u.tx.last_frag_rate = tx->u.tx.rate;
463
tx->u.tx.control->rate = tx->u.tx.rate;
465
tx->u.tx.control->tx_rate = tx->u.tx.rate->val;
466
if ((tx->u.tx.rate->flags & IEEE80211_RATE_PREAMBLE2) &&
467
tx->local->short_preamble &&
468
(!tx->sta || (tx->sta->flags & WLAN_STA_SHORT_PREAMBLE))) {
469
tx->u.tx.short_preamble = 1;
470
tx->u.tx.control->tx_rate = tx->u.tx.rate->val2;
473
/* only data unicast frame */
474
if ((tx->u.tx.rate) && tx->skb && tx->sdata && tx->u.tx.unicast &&
475
(tx->sdata->type == IEEE80211_IF_TYPE_STA ||
476
tx->sdata->type == IEEE80211_IF_TYPE_IBSS )&& !extra.mgmt_data) {
477
struct ieee80211_hdr *hdr;
480
hdr = (struct ieee80211_hdr *) tx->skb->data;
481
fc = le16_to_cpu(hdr->frame_control);
483
if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
484
tx->sdata->u.sta.last_rate = tx->u.tx.rate->rate *
488
return TXRX_CONTINUE;
492
static ieee80211_txrx_result
493
ieee80211_tx_h_select_key(struct ieee80211_txrx_data *tx)
496
tx->u.tx.control->key_idx = tx->sta->key_idx_compression;
498
tx->u.tx.control->key_idx = HW_KEY_IDX_INVALID;
500
if (unlikely(tx->u.tx.control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT))
502
else if (tx->sta && tx->sta->key)
503
tx->key = tx->sta->key;
504
else if (tx->sdata->default_key)
505
tx->key = tx->sdata->default_key;
506
else if (tx->sdata->drop_unencrypted &&
507
!(tx->sdata->eapol && ieee80211_is_eapol(tx->skb))) {
508
I802_DEBUG_INC(tx->local->tx_handlers_drop_unencrypted);
514
tx->key->tx_rx_count++;
515
if (unlikely(tx->local->key_tx_rx_threshold &&
516
tx->key->tx_rx_count >
517
tx->local->key_tx_rx_threshold)) {
518
ieee80211_key_threshold_notify(tx->dev, tx->key,
523
return TXRX_CONTINUE;
527
static ieee80211_txrx_result
528
ieee80211_tx_h_fragment(struct ieee80211_txrx_data *tx)
530
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
531
size_t hdrlen, per_fragm, num_fragm, payload_len, left;
532
struct sk_buff **frags, *first, *frag;
536
int frag_threshold = tx->local->fragmentation_threshold;
539
return TXRX_CONTINUE;
543
hdrlen = iwlwifi_ieee80211_get_hdrlen(tx->fc);
544
payload_len = first->len - hdrlen;
545
per_fragm = frag_threshold - hdrlen - FCS_LEN;
546
num_fragm = (payload_len + per_fragm - 1) / per_fragm;
548
frags = kzalloc(num_fragm * sizeof(struct sk_buff *), GFP_ATOMIC);
552
hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREFRAGS);
553
seq = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ;
554
pos = first->data + hdrlen + per_fragm;
555
left = payload_len - per_fragm;
556
for (i = 0; i < num_fragm - 1; i++) {
557
struct ieee80211_hdr *fhdr;
563
/* reserve enough extra head and tail room for possible
566
dev_alloc_skb(tx->local->tx_headroom +
568
IEEE80211_ENCRYPT_HEADROOM +
569
IEEE80211_ENCRYPT_TAILROOM);
572
/* Make sure that all fragments use the same priority so
573
* that they end up using the same TX queue */
574
frag->priority = first->priority;
575
skb_reserve(frag, tx->local->tx_headroom +
576
IEEE80211_ENCRYPT_HEADROOM);
577
fhdr = (struct ieee80211_hdr *) skb_put(frag, hdrlen);
578
memcpy(fhdr, first->data, hdrlen);
579
if (i == num_fragm - 2)
580
fhdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREFRAGS);
581
fhdr->seq_ctrl = cpu_to_le16(seq | ((i + 1) & IEEE80211_SCTL_FRAG));
582
copylen = left > per_fragm ? per_fragm : left;
583
memcpy(skb_put(frag, copylen), pos, copylen);
588
skb_trim(first, hdrlen + per_fragm);
590
tx->u.tx.num_extra_frag = num_fragm - 1;
591
tx->u.tx.extra_frag = frags;
593
return TXRX_CONTINUE;
596
printk(KERN_DEBUG "%s: failed to fragment frame\n", tx->dev->name);
598
for (i = 0; i < num_fragm - 1; i++)
600
dev_kfree_skb(frags[i]);
603
I802_DEBUG_INC(tx->local->tx_handlers_drop_fragment);
608
static int wep_encrypt_skb(struct ieee80211_txrx_data *tx, struct sk_buff *skb)
610
if (tx->key->force_sw_encrypt) {
611
if (ieee80211_wep_encrypt(tx->local, skb, tx->key))
614
tx->u.tx.control->key_idx = tx->key->hw_key_idx;
615
if (tx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) {
616
if (ieee80211_wep_add_iv(tx->local, skb, tx->key) ==
625
void ieee80211_tx_set_iswep(struct ieee80211_txrx_data *tx)
627
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
629
hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
630
if (tx->u.tx.extra_frag) {
631
struct ieee80211_hdr *fhdr;
633
for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
634
fhdr = (struct ieee80211_hdr *)
635
tx->u.tx.extra_frag[i]->data;
636
fhdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
642
static ieee80211_txrx_result
643
ieee80211_tx_h_wep_encrypt(struct ieee80211_txrx_data *tx)
645
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
648
fc = le16_to_cpu(hdr->frame_control);
650
if (!tx->key || tx->key->alg != ALG_WEP ||
651
((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
652
((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
653
(fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)))
654
return TXRX_CONTINUE;
656
tx->u.tx.control->iv_len = WEP_IV_LEN;
657
tx->u.tx.control->icv_len = WEP_ICV_LEN;
658
ieee80211_tx_set_iswep(tx);
660
if (wep_encrypt_skb(tx, tx->skb) < 0) {
661
I802_DEBUG_INC(tx->local->tx_handlers_drop_wep);
665
if (tx->u.tx.extra_frag) {
667
for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
668
if (wep_encrypt_skb(tx, tx->u.tx.extra_frag[i]) < 0) {
669
I802_DEBUG_INC(tx->local->
670
tx_handlers_drop_wep);
676
return TXRX_CONTINUE;
680
static int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
681
int rate, int erp, int short_preamble)
685
/* calculate duration (in microseconds, rounded up to next higher
686
* integer if it includes a fractional microsecond) to send frame of
687
* len bytes (does not include FCS) at the given rate. Duration will
690
* rate is in 100 kbps, so divident is multiplied by 10 in the
691
* DIV_ROUND_UP() operations.
694
if (local->hw.conf.phymode == MODE_IEEE80211A || erp ||
695
local->hw.conf.phymode == MODE_ATHEROS_TURBO) {
699
* N_DBPS = DATARATE x 4
700
* N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
701
* (16 = SIGNAL time, 6 = tail bits)
702
* TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
705
* 802.11a - 17.5.2: aSIFSTime = 16 usec
706
* 802.11g - 19.8.4: aSIFSTime = 10 usec +
707
* signal ext = 6 usec
709
/* FIX: Atheros Turbo may have different (shorter) duration? */
710
dur = 16; /* SIFS + signal ext */
711
dur += 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */
712
dur += 4; /* 17.3.2.3: T_SIGNAL = 4 usec */
713
dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10,
714
4 * rate); /* T_SYM x N_SYM */
717
* 802.11b or 802.11g with 802.11b compatibility:
718
* 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
719
* Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
721
* 802.11 (DS): 15.3.3, 802.11b: 18.3.4
722
* aSIFSTime = 10 usec
723
* aPreambleLength = 144 usec or 72 usec with short preamble
724
* aPLCPHeaderLength = 48 usec or 24 usec with short preamble
726
dur = 10; /* aSIFSTime = 10 usec */
727
dur += short_preamble ? (72 + 24) : (144 + 48);
729
dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate);
736
/* Exported duration function for driver use */
737
__le16 iwlwifi_ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
738
size_t frame_len, int rate)
740
struct ieee80211_local *local = hw_to_local(hw);
744
erp = ieee80211_is_erp_rate(hw->conf.phymode, rate);
745
dur = ieee80211_frame_duration(local, frame_len, rate,
746
erp, local->short_preamble);
748
return cpu_to_le16(dur);
750
EXPORT_SYMBOL(iwlwifi_ieee80211_generic_frame_duration);
753
static u16 ieee80211_duration(struct ieee80211_txrx_data *tx, int group_addr,
756
int rate, mrate, erp, dur, i;
757
struct ieee80211_rate *txrate = tx->u.tx.rate;
758
struct ieee80211_local *local = tx->local;
759
struct ieee80211_hw_mode *mode = tx->u.tx.mode;
761
erp = txrate->flags & IEEE80211_RATE_ERP;
764
* data and mgmt (except PS Poll):
765
* - during CFP: 32768
766
* - during contention period:
767
* if addr1 is group address: 0
768
* if more fragments = 0 and addr1 is individual address: time to
769
* transmit one ACK plus SIFS
770
* if more fragments = 1 and addr1 is individual address: time to
771
* transmit next fragment plus 2 x ACK plus 3 x SIFS
774
* - control response frame (CTS or ACK) shall be transmitted using the
775
* same rate as the immediately previous frame in the frame exchange
776
* sequence, if this rate belongs to the PHY mandatory rates, or else
777
* at the highest possible rate belonging to the PHY rates in the
781
if ((tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) {
782
/* TODO: These control frames are not currently sent by
783
* 80211.o, but should they be implemented, this function
784
* needs to be updated to support duration field calculation.
786
* RTS: time needed to transmit pending data/mgmt frame plus
787
* one CTS frame plus one ACK frame plus 3 x SIFS
788
* CTS: duration of immediately previous RTS minus time
789
* required to transmit CTS and its SIFS
790
* ACK: 0 if immediately previous directed data/mgmt had
791
* more=0, with more=1 duration in ACK frame is duration
792
* from previous frame minus time needed to transmit ACK
794
* PS Poll: BIT(15) | BIT(14) | aid
800
if (0 /* FIX: data/mgmt during CFP */)
803
if (group_addr) /* Group address as the destination - no ACK */
806
/* Individual destination address:
807
* IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes)
808
* CTS and ACK frames shall be transmitted using the highest rate in
809
* basic rate set that is less than or equal to the rate of the
810
* immediately previous frame and that is using the same modulation
811
* (CCK or OFDM). If no basic rate set matches with these requirements,
812
* the highest mandatory rate of the PHY that is less than or equal to
813
* the rate of the previous frame is used.
814
* Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps
817
mrate = 10; /* use 1 Mbps if everything fails */
818
for (i = 0; i < mode->num_rates; i++) {
819
struct ieee80211_rate *r = &mode->rates[i];
820
if (r->rate > txrate->rate)
823
if (IEEE80211_RATE_MODULATION(txrate->flags) !=
824
IEEE80211_RATE_MODULATION(r->flags))
827
if (r->flags & IEEE80211_RATE_BASIC)
829
else if (r->flags & IEEE80211_RATE_MANDATORY)
833
/* No matching basic rate found; use highest suitable mandatory
838
/* Time needed to transmit ACK
839
* (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
840
* to closest integer */
842
dur = ieee80211_frame_duration(local, 10, rate, erp,
843
local->short_preamble);
846
/* Frame is fragmented: duration increases with time needed to
847
* transmit next fragment plus ACK and 2 x SIFS. */
848
dur *= 2; /* ACK + SIFS */
850
dur += ieee80211_frame_duration(local, next_frag_len,
852
local->short_preamble);
859
static ieee80211_txrx_result
860
ieee80211_tx_h_misc(struct ieee80211_txrx_data *tx)
862
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
864
struct ieee80211_tx_control *control = tx->u.tx.control;
865
struct ieee80211_hw_mode *mode = tx->u.tx.mode;
867
if (!is_multicast_ether_addr(hdr->addr1)) {
868
if (tx->skb->len + FCS_LEN > tx->local->rts_threshold &&
869
tx->local->rts_threshold < IEEE80211_MAX_RTS_THRESHOLD) {
870
control->flags |= IEEE80211_TXCTL_USE_RTS_CTS;
871
control->retry_limit =
872
tx->local->long_retry_limit;
874
control->retry_limit =
875
tx->local->short_retry_limit;
878
control->retry_limit = 1;
881
if (tx->fragmented) {
882
/* Do not use multiple retry rates when sending fragmented
884
* TODO: The last fragment could still use multiple retry
886
control->alt_retry_rate = -1;
889
/* Use CTS protection for unicast frames sent using extended rates if
890
* there are associated non-ERP stations and RTS/CTS is not configured
892
if (mode->mode == MODE_IEEE80211G &&
893
(tx->u.tx.rate->flags & IEEE80211_RATE_ERP) &&
894
tx->u.tx.unicast && tx->sdata->use_protection &&
895
!(control->flags & IEEE80211_TXCTL_USE_RTS_CTS))
896
control->flags |= IEEE80211_TXCTL_USE_CTS_PROTECT;
898
/* Setup duration field for the first fragment of the frame. Duration
899
* for remaining fragments will be updated when they are being sent
900
* to low-level driver in ieee80211_tx(). */
901
dur = ieee80211_duration(tx, is_multicast_ether_addr(hdr->addr1),
902
tx->fragmented ? tx->u.tx.extra_frag[0]->len :
904
hdr->duration_id = cpu_to_le16(dur);
906
if ((control->flags & IEEE80211_TXCTL_USE_RTS_CTS) ||
907
(control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) {
908
struct ieee80211_rate *rate;
910
/* Do not use multiple retry rates when using RTS/CTS */
911
control->alt_retry_rate = -1;
913
/* Use min(data rate, max base rate) as CTS/RTS rate */
914
rate = tx->u.tx.rate;
915
while (rate > mode->rates &&
916
!(rate->flags & IEEE80211_RATE_BASIC))
919
control->rts_cts_rate = rate->val;
920
control->rts_rate = rate;
924
tx->sta->tx_packets++;
925
tx->sta->tx_fragments++;
926
tx->sta->tx_bytes += tx->skb->len;
927
if (tx->u.tx.extra_frag) {
929
tx->sta->tx_fragments += tx->u.tx.num_extra_frag;
930
for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
932
tx->u.tx.extra_frag[i]->len;
937
return TXRX_CONTINUE;
941
static ieee80211_txrx_result
942
ieee80211_tx_h_check_assoc(struct ieee80211_txrx_data *tx)
944
#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
945
struct sk_buff *skb = tx->skb;
946
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
947
#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
950
if (unlikely(tx->local->sta_sw_scanning != 0) &&
951
((tx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
952
(tx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PROBE_REQ))
955
if (tx->u.tx.ps_buffered)
956
return TXRX_CONTINUE;
958
sta_flags = tx->sta ? tx->sta->flags : 0;
960
if (likely(tx->u.tx.unicast)) {
961
if (unlikely(!(sta_flags & WLAN_STA_ASSOC) &&
962
tx->sdata->type != IEEE80211_IF_TYPE_IBSS &&
963
(tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) {
964
#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
965
printk(KERN_DEBUG "%s: dropped data frame to not "
966
"associated station " MAC_FMT "\n",
967
tx->dev->name, MAC_ARG(hdr->addr1));
968
#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
969
I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
973
if (unlikely((tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
974
tx->local->num_sta == 0 &&
975
!tx->local->allow_broadcast_always &&
976
tx->sdata->type != IEEE80211_IF_TYPE_IBSS)) {
978
* No associated STAs - no need to send multicast
983
return TXRX_CONTINUE;
986
if (unlikely(!tx->u.tx.mgmt_interface && tx->sdata->ieee802_1x &&
987
!(sta_flags & WLAN_STA_AUTHORIZED))) {
988
#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
989
printk(KERN_DEBUG "%s: dropped frame to " MAC_FMT
990
" (unauthorized port)\n", tx->dev->name,
991
MAC_ARG(hdr->addr1));
993
I802_DEBUG_INC(tx->local->tx_handlers_drop_unauth_port);
997
return TXRX_CONTINUE;
1000
static ieee80211_txrx_result
1001
ieee80211_tx_h_sequence(struct ieee80211_txrx_data *tx)
1003
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
1005
if (iwlwifi_ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control)) >= 24)
1006
ieee80211_include_sequence(tx->sdata, hdr);
1008
return TXRX_CONTINUE;
1011
/* This function is called whenever the AP is about to exceed the maximum limit
1012
* of buffered frames for power saving STAs. This situation should not really
1013
* happen often during normal operation, so dropping the oldest buffered packet
1014
* from each queue should be OK to make some room for new frames. */
1015
static void purge_old_ps_buffers(struct ieee80211_local *local)
1017
int total = 0, purged = 0;
1018
struct sk_buff *skb;
1019
struct ieee80211_sub_if_data *sdata;
1020
struct sta_info *sta;
1022
read_lock(&local->sub_if_lock);
1023
list_for_each_entry(sdata, &local->sub_if_list, list) {
1024
struct ieee80211_if_ap *ap;
1025
if (sdata->dev == local->mdev ||
1026
sdata->type != IEEE80211_IF_TYPE_AP)
1029
skb = skb_dequeue(&ap->ps_bc_buf);
1034
total += skb_queue_len(&ap->ps_bc_buf);
1036
read_unlock(&local->sub_if_lock);
1038
spin_lock_bh(&local->sta_lock);
1039
list_for_each_entry(sta, &local->sta_list, list) {
1040
skb = skb_dequeue(&sta->ps_tx_buf);
1045
total += skb_queue_len(&sta->ps_tx_buf);
1047
spin_unlock_bh(&local->sta_lock);
1049
local->total_ps_buffered = total;
1050
printk(KERN_DEBUG "%s: PS buffers full - purged %d frames\n",
1051
local->mdev->name, purged);
1055
static inline ieee80211_txrx_result
1056
ieee80211_tx_h_multicast_ps_buf(struct ieee80211_txrx_data *tx)
1058
/* broadcast/multicast frame */
1059
/* If any of the associated stations is in power save mode,
1060
* the frame is buffered to be sent after DTIM beacon frame */
1061
if ((tx->local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING) &&
1062
tx->sdata->type != IEEE80211_IF_TYPE_WDS &&
1063
tx->sdata->bss && atomic_read(&tx->sdata->bss->num_sta_ps) &&
1064
!(tx->fc & IEEE80211_FCTL_ORDER)) {
1065
if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
1066
purge_old_ps_buffers(tx->local);
1067
if (skb_queue_len(&tx->sdata->bss->ps_bc_buf) >=
1069
if (net_ratelimit()) {
1070
printk(KERN_DEBUG "%s: BC TX buffer full - "
1071
"dropping the oldest frame\n",
1074
dev_kfree_skb(skb_dequeue(&tx->sdata->bss->ps_bc_buf));
1076
tx->local->total_ps_buffered++;
1077
skb_queue_tail(&tx->sdata->bss->ps_bc_buf, tx->skb);
1081
return TXRX_CONTINUE;
1085
static inline ieee80211_txrx_result
1086
ieee80211_tx_h_unicast_ps_buf(struct ieee80211_txrx_data *tx)
1088
struct sta_info *sta = tx->sta;
1090
if (unlikely(!sta ||
1091
((tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT &&
1092
(tx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP)))
1093
return TXRX_CONTINUE;
1095
if (unlikely((sta->flags & WLAN_STA_PS) && !sta->pspoll)) {
1096
struct ieee80211_tx_packet_data *pkt_data;
1097
#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
1098
printk(KERN_DEBUG "STA " MAC_FMT " aid %d: PS buffer (entries "
1100
MAC_ARG(sta->addr), sta->aid,
1101
skb_queue_len(&sta->ps_tx_buf));
1102
#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1103
sta->flags |= WLAN_STA_TIM;
1104
if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
1105
purge_old_ps_buffers(tx->local);
1106
if (skb_queue_len(&sta->ps_tx_buf) >= STA_MAX_TX_BUFFER) {
1107
struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf);
1108
if (net_ratelimit()) {
1109
printk(KERN_DEBUG "%s: STA " MAC_FMT " TX "
1110
"buffer full - dropping oldest frame\n",
1111
tx->dev->name, MAC_ARG(sta->addr));
1115
tx->local->total_ps_buffered++;
1116
/* Queue frame to be sent after STA sends an PS Poll frame */
1117
if (skb_queue_empty(&sta->ps_tx_buf)) {
1118
if (tx->local->ops->set_tim)
1119
tx->local->ops->set_tim(local_to_hw(tx->local),
1122
bss_tim_set(tx->local, tx->sdata->bss, sta->aid);
1124
pkt_data = (struct ieee80211_tx_packet_data *)tx->skb->cb;
1125
pkt_data->jiffies = jiffies;
1126
skb_queue_tail(&sta->ps_tx_buf, tx->skb);
1129
#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
1130
else if (unlikely(sta->flags & WLAN_STA_PS)) {
1131
printk(KERN_DEBUG "%s: STA " MAC_FMT " in PS mode, but pspoll "
1132
"set -> send frame\n", tx->dev->name,
1133
MAC_ARG(sta->addr));
1135
#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1138
return TXRX_CONTINUE;
1142
static ieee80211_txrx_result
1143
ieee80211_tx_h_ps_buf(struct ieee80211_txrx_data *tx)
1145
if (unlikely(tx->u.tx.ps_buffered))
1146
return TXRX_CONTINUE;
1148
if (tx->u.tx.unicast)
1149
return ieee80211_tx_h_unicast_ps_buf(tx);
1151
return ieee80211_tx_h_multicast_ps_buf(tx);
1156
* deal with packet injection down monitor interface
1157
* with Radiotap Header -- only called for monitor mode interface
1160
static ieee80211_txrx_result
1161
__ieee80211_parse_tx_radiotap(
1162
struct ieee80211_txrx_data *tx,
1163
struct sk_buff *skb, struct ieee80211_tx_control *control)
1166
* this is the moment to interpret and discard the radiotap header that
1167
* must be at the start of the packet injected in Monitor mode
1169
* Need to take some care with endian-ness since radiotap
1170
* args are little-endian
1173
struct ieee80211_radiotap_iterator iterator;
1174
struct ieee80211_radiotap_header *rthdr =
1175
(struct ieee80211_radiotap_header *) skb->data;
1176
struct ieee80211_hw_mode *mode = tx->local->hw.conf.mode;
1177
int ret = iwlwifi_ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len);
1180
* default control situation for all injected packets
1181
* FIXME: this does not suit all usage cases, expand to allow control
1184
control->retry_limit = 1; /* no retry */
1185
control->key_idx = -1; /* no encryption key */
1186
control->flags &= ~(IEEE80211_TXCTL_USE_RTS_CTS |
1187
IEEE80211_TXCTL_USE_CTS_PROTECT);
1188
control->flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT |
1189
IEEE80211_TXCTL_NO_ACK;
1190
control->antenna_sel_tx = 0; /* default to default antenna */
1193
* for every radiotap entry that is present
1194
* (iwlwifi_ieee80211_radiotap_iterator_next returns -ENOENT when no more
1195
* entries present, or -EINVAL on error)
1201
ret = iwlwifi_ieee80211_radiotap_iterator_next(&iterator);
1206
/* see if this argument is something we can use */
1207
switch (iterator.this_arg_index) {
1209
* You must take care when dereferencing iterator.this_arg
1210
* for multibyte types... the pointer is not aligned. Use
1211
* get_unaligned((type *)iterator.this_arg) to dereference
1212
* iterator.this_arg for type "type" safely on all arches.
1214
case IEEE80211_RADIOTAP_RATE:
1216
* radiotap rate u8 is in 500kbps units eg, 0x02=1Mbps
1217
* ieee80211 rate int is in 100kbps units eg, 0x0a=1Mbps
1219
target_rate = (*iterator.this_arg) * 5;
1220
for (i = 0; i < mode->num_rates; i++) {
1221
struct ieee80211_rate *r = &mode->rates[i];
1223
if (r->rate > target_rate)
1228
if (r->flags & IEEE80211_RATE_PREAMBLE2)
1229
control->tx_rate = r->val2;
1231
control->tx_rate = r->val;
1233
/* end on exact match */
1234
if (r->rate == target_rate)
1235
i = mode->num_rates;
1239
case IEEE80211_RADIOTAP_ANTENNA:
1241
* radiotap uses 0 for 1st ant, mac80211 is 1 for
1244
control->antenna_sel_tx = (*iterator.this_arg) + 1;
1247
case IEEE80211_RADIOTAP_DBM_TX_POWER:
1248
control->power_level = *iterator.this_arg;
1251
case IEEE80211_RADIOTAP_FLAGS:
1252
if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) {
1254
* this indicates that the skb we have been
1255
* handed has the 32-bit FCS CRC at the end...
1256
* we should react to that by snipping it off
1257
* because it will be recomputed and added
1260
if (skb->len < (iterator.max_length + FCS_LEN))
1263
skb_trim(skb, skb->len - FCS_LEN);
1272
if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */
1276
* remove the radiotap header
1277
* iterator->max_length was sanity-checked against
1278
* skb->len by iterator init
1280
skb_pull(skb, iterator.max_length);
1282
return TXRX_CONTINUE;
1286
static ieee80211_txrx_result inline
1287
__ieee80211_tx_prepare(struct ieee80211_txrx_data *tx,
1288
struct sk_buff *skb,
1289
struct net_device *dev,
1290
struct ieee80211_tx_control *control)
1292
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1293
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1294
struct ieee80211_sub_if_data *sdata;
1295
ieee80211_txrx_result res = TXRX_CONTINUE;
1299
memset(tx, 0, sizeof(*tx));
1301
tx->dev = dev; /* use original interface */
1303
tx->sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1304
tx->sta = iwlwifi_sta_info_get(local, hdr->addr1);
1305
tx->fc = le16_to_cpu(hdr->frame_control);
1308
* set defaults for things that can be set by
1309
* injected radiotap headers
1311
control->power_level = local->hw.conf.power_level;
1312
control->antenna_sel_tx = local->hw.conf.antenna_sel_tx;
1313
if (local->sta_antenna_sel != STA_ANTENNA_SEL_AUTO && tx->sta)
1314
control->antenna_sel_tx = tx->sta->antenna_sel_tx;
1316
/* process and remove the injection radiotap header */
1317
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1318
if (unlikely(sdata->type == IEEE80211_IF_TYPE_MNTR)) {
1319
if (__ieee80211_parse_tx_radiotap(tx, skb, control) ==
1324
* we removed the radiotap header after this point,
1325
* we filled control with what we could use
1326
* set to the actual ieee header now
1328
hdr = (struct ieee80211_hdr *) skb->data;
1329
res = TXRX_QUEUED; /* indication it was monitor packet */
1332
tx->u.tx.control = control;
1333
tx->u.tx.unicast = !is_multicast_ether_addr(hdr->addr1);
1334
if (is_multicast_ether_addr(hdr->addr1))
1335
control->flags |= IEEE80211_TXCTL_NO_ACK;
1337
control->flags &= ~IEEE80211_TXCTL_NO_ACK;
1338
tx->fragmented = local->fragmentation_threshold <
1339
IEEE80211_MAX_FRAG_THRESHOLD && tx->u.tx.unicast &&
1340
skb->len + FCS_LEN > local->fragmentation_threshold &&
1341
(!local->ops->set_frag_threshold);
1343
control->flags |= IEEE80211_TXCTL_CLEAR_DST_MASK;
1344
else if (tx->sta->clear_dst_mask) {
1345
control->flags |= IEEE80211_TXCTL_CLEAR_DST_MASK;
1346
tx->sta->clear_dst_mask = 0;
1348
hdrlen = iwlwifi_ieee80211_get_hdrlen(tx->fc);
1349
if (skb->len > hdrlen + sizeof(rfc1042_header) + 2) {
1350
u8 *pos = &skb->data[hdrlen + sizeof(rfc1042_header)];
1351
tx->ethertype = (pos[0] << 8) | pos[1];
1353
control->flags |= IEEE80211_TXCTL_FIRST_FRAGMENT;
1358
static int inline is_ieee80211_device(struct net_device *dev,
1359
struct net_device *master)
1361
return (wdev_priv(dev->ieee80211_ptr) ==
1362
wdev_priv(master->ieee80211_ptr));
1365
/* Device in tx->dev has a reference added; use dev_put(tx->dev) when
1366
* finished with it. */
1367
static int inline ieee80211_tx_prepare(struct ieee80211_txrx_data *tx,
1368
struct sk_buff *skb,
1369
struct net_device *mdev,
1370
struct ieee80211_tx_control *control)
1372
struct ieee80211_tx_packet_data *pkt_data;
1373
struct net_device *dev;
1375
pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
1376
dev = dev_get_by_index(&init_net, pkt_data->ifindex);
1377
if (unlikely(dev && !is_ieee80211_device(dev, mdev))) {
1383
__ieee80211_tx_prepare(tx, skb, dev, control);
1387
static inline int __ieee80211_queue_stopped(const struct ieee80211_local *local,
1390
return test_bit(IEEE80211_LINK_STATE_XOFF, &local->state[queue]);
1393
static inline int __ieee80211_queue_pending(const struct ieee80211_local *local,
1396
return test_bit(IEEE80211_LINK_STATE_PENDING, &local->state[queue]);
1399
#define IEEE80211_TX_OK 0
1400
#define IEEE80211_TX_AGAIN 1
1401
#define IEEE80211_TX_FRAG_AGAIN 2
1403
static int __ieee80211_tx(struct ieee80211_local *local, struct sk_buff *skb,
1404
struct ieee80211_txrx_data *tx)
1406
struct ieee80211_tx_control *control = tx->u.tx.control;
1409
if (!ieee80211_qdisc_installed(local->mdev) &&
1410
__ieee80211_queue_stopped(local, 0)) {
1411
netif_stop_queue(local->mdev);
1412
return IEEE80211_TX_AGAIN;
1415
ieee80211_dump_frame(local->mdev->name, "TX to low-level driver", skb);
1416
ret = local->ops->tx(local_to_hw(local), skb, control);
1418
return IEEE80211_TX_AGAIN;
1419
local->mdev->trans_start = jiffies;
1420
ieee80211_led_tx(local, 1);
1422
if (tx->u.tx.extra_frag) {
1423
control->flags &= ~(IEEE80211_TXCTL_USE_RTS_CTS |
1424
IEEE80211_TXCTL_USE_CTS_PROTECT |
1425
IEEE80211_TXCTL_CLEAR_DST_MASK |
1426
IEEE80211_TXCTL_FIRST_FRAGMENT);
1427
for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
1428
if (!tx->u.tx.extra_frag[i])
1430
if (__ieee80211_queue_stopped(local, control->queue))
1431
return IEEE80211_TX_FRAG_AGAIN;
1432
if (i == tx->u.tx.num_extra_frag) {
1433
control->tx_rate = tx->u.tx.last_frag_hwrate;
1434
control->rate = tx->u.tx.last_frag_rate;
1435
if (tx->u.tx.probe_last_frag)
1437
IEEE80211_TXCTL_RATE_CTRL_PROBE;
1440
~IEEE80211_TXCTL_RATE_CTRL_PROBE;
1443
ieee80211_dump_frame(local->mdev->name,
1444
"TX to low-level driver",
1445
tx->u.tx.extra_frag[i]);
1446
ret = local->ops->tx(local_to_hw(local),
1447
tx->u.tx.extra_frag[i],
1450
return IEEE80211_TX_FRAG_AGAIN;
1451
local->mdev->trans_start = jiffies;
1452
ieee80211_led_tx(local, 1);
1453
tx->u.tx.extra_frag[i] = NULL;
1455
kfree(tx->u.tx.extra_frag);
1456
tx->u.tx.extra_frag = NULL;
1458
return IEEE80211_TX_OK;
1461
static int ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
1462
struct ieee80211_tx_control *control, int mgmt)
1464
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1465
struct sta_info *sta;
1466
ieee80211_tx_handler *handler;
1467
struct ieee80211_txrx_data tx;
1468
ieee80211_txrx_result res = TXRX_DROP, res_prepare;
1471
WARN_ON(__ieee80211_queue_pending(local, control->queue));
1473
if (unlikely(skb->len < 10)) {
1478
res_prepare = __ieee80211_tx_prepare(&tx, skb, dev, control);
1480
if (res_prepare == TXRX_DROP) {
1486
tx.u.tx.mgmt_interface = mgmt;
1487
tx.u.tx.mode = local->hw.conf.mode;
1489
if (res_prepare == TXRX_QUEUED) { /* if it was an injected packet */
1490
res = TXRX_CONTINUE;
1492
for (handler = local->tx_handlers; *handler != NULL;
1494
res = (*handler)(&tx);
1495
if (res != TXRX_CONTINUE)
1500
skb = tx.skb; /* handlers are allowed to change skb */
1503
iwlwifi_sta_info_put(sta);
1505
if (unlikely(res == TXRX_DROP)) {
1506
I802_DEBUG_INC(local->tx_handlers_drop);
1510
if (unlikely(res == TXRX_QUEUED)) {
1511
I802_DEBUG_INC(local->tx_handlers_queued);
1515
if (tx.u.tx.extra_frag) {
1516
for (i = 0; i < tx.u.tx.num_extra_frag; i++) {
1518
struct ieee80211_hdr *hdr =
1519
(struct ieee80211_hdr *)
1520
tx.u.tx.extra_frag[i]->data;
1522
if (i + 1 < tx.u.tx.num_extra_frag) {
1523
next_len = tx.u.tx.extra_frag[i + 1]->len;
1526
tx.u.tx.rate = tx.u.tx.last_frag_rate;
1527
tx.u.tx.last_frag_hwrate = tx.u.tx.rate->val;
1529
dur = ieee80211_duration(&tx, 0, next_len);
1530
hdr->duration_id = cpu_to_le16(dur);
1535
ret = __ieee80211_tx(local, skb, &tx);
1537
struct ieee80211_tx_stored_packet *store =
1538
&local->pending_packet[control->queue];
1540
if (ret == IEEE80211_TX_FRAG_AGAIN)
1542
set_bit(IEEE80211_LINK_STATE_PENDING,
1543
&local->state[control->queue]);
1545
/* When the driver gets out of buffers during sending of
1546
* fragments and calls iwlwifi_ieee80211_stop_queue, there is
1547
* a small window between IEEE80211_LINK_STATE_XOFF and
1548
* IEEE80211_LINK_STATE_PENDING flags are set. If a buffer
1549
* gets available in that window (i.e. driver calls
1550
* iwlwifi_ieee80211_wake_queue), we would end up with ieee80211_tx
1551
* called with IEEE80211_LINK_STATE_PENDING. Prevent this by
1552
* continuing transmitting here when that situation is
1553
* possible to have happened. */
1554
if (!__ieee80211_queue_stopped(local, control->queue)) {
1555
clear_bit(IEEE80211_LINK_STATE_PENDING,
1556
&local->state[control->queue]);
1559
memcpy(&store->control, control,
1560
sizeof(struct ieee80211_tx_control));
1562
store->extra_frag = tx.u.tx.extra_frag;
1563
store->num_extra_frag = tx.u.tx.num_extra_frag;
1564
store->last_frag_hwrate = tx.u.tx.last_frag_hwrate;
1565
store->last_frag_rate = tx.u.tx.last_frag_rate;
1566
store->last_frag_rate_ctrl_probe = tx.u.tx.probe_last_frag;
1573
for (i = 0; i < tx.u.tx.num_extra_frag; i++)
1574
if (tx.u.tx.extra_frag[i])
1575
dev_kfree_skb(tx.u.tx.extra_frag[i]);
1576
kfree(tx.u.tx.extra_frag);
1580
static void ieee80211_tx_pending(unsigned long data)
1582
struct ieee80211_local *local = (struct ieee80211_local *)data;
1583
struct net_device *dev = local->mdev;
1584
struct ieee80211_tx_stored_packet *store;
1585
struct ieee80211_txrx_data tx;
1586
int i, ret, reschedule = 0;
1588
netif_tx_lock_bh(dev);
1589
for (i = 0; i < local->hw.queues; i++) {
1590
if (__ieee80211_queue_stopped(local, i))
1592
if (!__ieee80211_queue_pending(local, i)) {
1596
store = &local->pending_packet[i];
1597
tx.u.tx.control = &store->control;
1598
tx.u.tx.extra_frag = store->extra_frag;
1599
tx.u.tx.num_extra_frag = store->num_extra_frag;
1600
tx.u.tx.last_frag_hwrate = store->last_frag_hwrate;
1601
tx.u.tx.last_frag_rate = store->last_frag_rate;
1602
tx.u.tx.probe_last_frag = store->last_frag_rate_ctrl_probe;
1603
ret = __ieee80211_tx(local, store->skb, &tx);
1605
if (ret == IEEE80211_TX_FRAG_AGAIN)
1608
clear_bit(IEEE80211_LINK_STATE_PENDING,
1613
netif_tx_unlock_bh(dev);
1615
if (!ieee80211_qdisc_installed(dev)) {
1616
if (!__ieee80211_queue_stopped(local, 0))
1617
netif_wake_queue(dev);
1619
netif_schedule(dev);
1623
static void ieee80211_clear_tx_pending(struct ieee80211_local *local)
1626
struct ieee80211_tx_stored_packet *store;
1628
for (i = 0; i < local->hw.queues; i++) {
1629
if (!__ieee80211_queue_pending(local, i))
1631
store = &local->pending_packet[i];
1632
kfree_skb(store->skb);
1633
for (j = 0; j < store->num_extra_frag; j++)
1634
kfree_skb(store->extra_frag[j]);
1635
kfree(store->extra_frag);
1636
clear_bit(IEEE80211_LINK_STATE_PENDING, &local->state[i]);
1640
static int ieee80211_master_start_xmit(struct sk_buff *skb,
1641
struct net_device *dev)
1643
struct ieee80211_tx_control control;
1644
struct ieee80211_tx_packet_data *pkt_data;
1645
struct net_device *odev = NULL;
1646
struct ieee80211_sub_if_data *osdata;
1651
* copy control out of the skb so other people can use skb->cb
1653
pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
1654
memset(&control, 0, sizeof(struct ieee80211_tx_control));
1656
if (pkt_data->ifindex)
1657
odev = dev_get_by_index(&init_net, pkt_data->ifindex);
1658
if (unlikely(odev && !is_ieee80211_device(odev, dev))) {
1662
if (unlikely(!odev)) {
1663
#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1664
printk(KERN_DEBUG "%s: Discarded packet with nonexistent "
1665
"originating device\n", dev->name);
1670
osdata = IEEE80211_DEV_TO_SUB_IF(odev);
1672
headroom = osdata->local->tx_headroom + IEEE80211_ENCRYPT_HEADROOM;
1673
if (skb_headroom(skb) < headroom) {
1674
if (pskb_expand_head(skb, headroom, 0, GFP_ATOMIC)) {
1681
control.ifindex = odev->ifindex;
1682
control.type = osdata->type;
1683
if (pkt_data->req_tx_status)
1684
control.flags |= IEEE80211_TXCTL_REQ_TX_STATUS;
1685
if (pkt_data->do_not_encrypt)
1686
control.flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT;
1687
if (pkt_data->requeue)
1688
control.flags |= IEEE80211_TXCTL_REQUEUE;
1689
if (pkt_data->ht_queue)
1690
control.flags |= IEEE80211_TXCTL_HT_MPDU_AGG;
1692
control.queue = pkt_data->queue;
1694
ret = ieee80211_tx(odev, skb, &control,
1695
control.type == IEEE80211_IF_TYPE_MGMT);
1702
int ieee80211_monitor_start_xmit(struct sk_buff *skb,
1703
struct net_device *dev)
1705
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1706
struct ieee80211_tx_packet_data *pkt_data;
1707
struct ieee80211_radiotap_header *prthdr =
1708
(struct ieee80211_radiotap_header *)skb->data;
1712
* there must be a radiotap header at the
1713
* start in this case
1715
if (unlikely(prthdr->it_version)) {
1716
/* only version 0 is supported */
1718
return NETDEV_TX_OK;
1721
skb->dev = local->mdev;
1723
pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
1724
memset(pkt_data, 0, sizeof(*pkt_data));
1725
pkt_data->ifindex = dev->ifindex;
1726
pkt_data->mgmt_iface = 0;
1727
pkt_data->do_not_encrypt = 1;
1729
/* above needed because we set skb device to master */
1732
* fix up the pointers accounting for the radiotap
1733
* header still being in there. We are being given
1734
* a precooked IEEE80211 header so no need for
1737
len = le16_to_cpu(get_unaligned(&prthdr->it_len));
1738
skb_set_mac_header(skb, len);
1739
skb_set_network_header(skb, len + sizeof(struct ieee80211_hdr));
1740
skb_set_transport_header(skb, len + sizeof(struct ieee80211_hdr));
1743
* pass the radiotap header up to
1744
* the next stage intact
1746
dev_queue_xmit(skb);
1748
return NETDEV_TX_OK;
1753
* ieee80211_subif_start_xmit - netif start_xmit function for Ethernet-type
1754
* subinterfaces (wlan#, WDS, and VLAN interfaces)
1755
* @skb: packet to be sent
1756
* @dev: incoming interface
1758
* Returns: 0 on success (and frees skb in this case) or 1 on failure (skb will
1759
* not be freed, and caller is responsible for either retrying later or freeing
1762
* This function takes in an Ethernet header and encapsulates it with suitable
1763
* IEEE 802.11 header based on which interface the packet is coming in. The
1764
* encapsulated packet will then be passed to master interface, wlan#.11, for
1765
* transmission (through low-level driver).
1767
int ieee80211_subif_start_xmit(struct sk_buff *skb,
1768
struct net_device *dev)
1770
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1771
struct ieee80211_tx_packet_data *pkt_data;
1772
struct ieee80211_sub_if_data *sdata;
1773
int ret = 1, head_need;
1774
u16 ethertype, hdrlen, fc;
1775
struct ieee80211_hdr hdr;
1776
const u8 *encaps_data;
1777
int encaps_len, skip_header_bytes;
1778
int nh_pos, h_pos, no_encrypt = 0;
1779
struct sta_info *sta;
1781
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1782
if (unlikely(skb->len < ETH_HLEN)) {
1783
printk(KERN_DEBUG "%s: short skb (len=%d)\n",
1784
dev->name, skb->len);
1789
nh_pos = skb_network_header(skb) - skb->data;
1790
h_pos = skb_transport_header(skb) - skb->data;
1792
/* convert Ethernet header to proper 802.11 header (based on
1793
* operation mode) */
1794
ethertype = (skb->data[12] << 8) | skb->data[13];
1795
/* TODO: handling for 802.1x authorized/unauthorized port */
1796
fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA;
1798
if (likely(sdata->type == IEEE80211_IF_TYPE_AP ||
1799
sdata->type == IEEE80211_IF_TYPE_VLAN)) {
1800
fc |= IEEE80211_FCTL_FROMDS;
1802
memcpy(hdr.addr1, skb->data, ETH_ALEN);
1803
memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN);
1804
memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
1806
} else if (sdata->type == IEEE80211_IF_TYPE_WDS) {
1807
fc |= IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS;
1809
memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN);
1810
memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN);
1811
memcpy(hdr.addr3, skb->data, ETH_ALEN);
1812
memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
1814
} else if (sdata->type == IEEE80211_IF_TYPE_STA) {
1815
if (dls_link_status(local, skb->data) == DLS_STATUS_OK) {
1817
memcpy(hdr.addr1, skb->data, ETH_ALEN);
1818
memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
1819
memcpy(hdr.addr3, sdata->u.sta.bssid, ETH_ALEN);
1821
fc |= IEEE80211_FCTL_TODS;
1823
memcpy(hdr.addr1, sdata->u.sta.bssid, ETH_ALEN);
1824
memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
1825
memcpy(hdr.addr3, skb->data, ETH_ALEN);
1828
} else if (sdata->type == IEEE80211_IF_TYPE_IBSS) {
1830
memcpy(hdr.addr1, skb->data, ETH_ALEN);
1831
memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
1832
memcpy(hdr.addr3, sdata->u.sta.bssid, ETH_ALEN);
1839
/* receiver is QoS enabled, use a QoS type frame */
1840
sta = iwlwifi_sta_info_get(local, hdr.addr1);
1842
if (sta->flags & WLAN_STA_WME) {
1843
fc |= IEEE80211_STYPE_QOS_DATA;
1846
iwlwifi_sta_info_put(sta);
1849
hdr.frame_control = cpu_to_le16(fc);
1850
hdr.duration_id = 0;
1853
skip_header_bytes = ETH_HLEN;
1854
if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
1855
encaps_data = bridge_tunnel_header;
1856
encaps_len = sizeof(bridge_tunnel_header);
1857
skip_header_bytes -= 2;
1858
} else if (ethertype >= 0x600) {
1859
encaps_data = rfc1042_header;
1860
encaps_len = sizeof(rfc1042_header);
1861
skip_header_bytes -= 2;
1867
skb_pull(skb, skip_header_bytes);
1868
nh_pos -= skip_header_bytes;
1869
h_pos -= skip_header_bytes;
1871
/* TODO: implement support for fragments so that there is no need to
1872
* reallocate and copy payload; it might be enough to support one
1873
* extra fragment that would be copied in the beginning of the frame
1874
* data.. anyway, it would be nice to include this into skb structure
1877
* There are few options for this:
1878
* use skb->cb as an extra space for 802.11 header
1879
* allocate new buffer if not enough headroom
1880
* make sure that there is enough headroom in every skb by increasing
1881
* build in headroom in __dev_alloc_skb() (linux/skbuff.h) and
1882
* alloc_skb() (net/core/skbuff.c)
1884
head_need = hdrlen + encaps_len + local->tx_headroom;
1885
head_need -= skb_headroom(skb);
1887
/* We are going to modify skb data, so make a copy of it if happens to
1888
* be cloned. This could happen, e.g., with Linux bridge code passing
1889
* us broadcast frames. */
1891
if (head_need > 0 || skb_cloned(skb)) {
1893
printk(KERN_DEBUG "%s: need to reallocate buffer for %d bytes "
1894
"of headroom\n", dev->name, head_need);
1897
if (skb_cloned(skb))
1898
I802_DEBUG_INC(local->tx_expand_skb_head_cloned);
1900
I802_DEBUG_INC(local->tx_expand_skb_head);
1901
/* Since we have to reallocate the buffer, make sure that there
1902
* is enough room for possible WEP IV/ICV and TKIP (8 bytes
1903
* before payload and 12 after). */
1904
if (pskb_expand_head(skb, (head_need > 0 ? head_need + 8 : 8),
1906
printk(KERN_DEBUG "%s: failed to reallocate TX buffer"
1913
memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
1914
nh_pos += encaps_len;
1915
h_pos += encaps_len;
1917
memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
1921
pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
1922
memset(pkt_data, 0, sizeof(struct ieee80211_tx_packet_data));
1923
pkt_data->ifindex = dev->ifindex;
1924
pkt_data->mgmt_iface = (sdata->type == IEEE80211_IF_TYPE_MGMT);
1925
pkt_data->do_not_encrypt = no_encrypt;
1927
skb->dev = local->mdev;
1928
sdata->stats.tx_packets++;
1929
sdata->stats.tx_bytes += skb->len;
1931
/* Update skb pointers to various headers since this modified frame
1932
* is going to go through Linux networking code that may potentially
1933
* need things like pointer to IP header. */
1934
skb_set_mac_header(skb, 0);
1935
skb_set_network_header(skb, nh_pos);
1936
skb_set_transport_header(skb, h_pos);
1938
dev->trans_start = jiffies;
1939
dev_queue_xmit(skb);
1952
* This is the transmit routine for the 802.11 type interfaces
1953
* called by upper layers of the linux networking
1954
* stack when it has a frame to transmit
1957
ieee80211_mgmt_start_xmit(struct sk_buff *skb, struct net_device *dev)
1959
struct ieee80211_sub_if_data *sdata;
1960
struct ieee80211_tx_packet_data *pkt_data;
1961
struct ieee80211_hdr *hdr;
1964
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1966
if (skb->len < 10) {
1971
if (skb_headroom(skb) < sdata->local->tx_headroom) {
1972
if (pskb_expand_head(skb, sdata->local->tx_headroom,
1979
hdr = (struct ieee80211_hdr *) skb->data;
1980
fc = le16_to_cpu(hdr->frame_control);
1982
pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
1983
memset(pkt_data, 0, sizeof(struct ieee80211_tx_packet_data));
1984
pkt_data->ifindex = sdata->dev->ifindex;
1985
pkt_data->mgmt_iface = (sdata->type == IEEE80211_IF_TYPE_MGMT);
1987
skb->priority = 20; /* use hardcoded priority for mgmt TX queue */
1988
skb->dev = sdata->local->mdev;
1991
* We're using the protocol field of the the frame control header
1992
* to request TX callback for hostapd. BIT(1) is checked.
1994
if ((fc & BIT(1)) == BIT(1)) {
1995
pkt_data->req_tx_status = 1;
1997
hdr->frame_control = cpu_to_le16(fc);
2000
pkt_data->do_not_encrypt = !(fc & IEEE80211_FCTL_PROTECTED);
2002
sdata->stats.tx_packets++;
2003
sdata->stats.tx_bytes += skb->len;
2005
dev_queue_xmit(skb);
2011
static void ieee80211_beacon_add_tim(struct ieee80211_local *local,
2012
struct ieee80211_if_ap *bss,
2013
struct sk_buff *skb)
2017
int i, have_bits = 0, n1, n2;
2019
/* Generate bitmap for TIM only if there are any STAs in power save
2021
spin_lock_bh(&local->sta_lock);
2022
if (atomic_read(&bss->num_sta_ps) > 0)
2023
/* in the hope that this is faster than
2024
* checking byte-for-byte */
2025
have_bits = !bitmap_empty((unsigned long*)bss->tim,
2026
IEEE80211_MAX_AID+1);
2028
if (bss->dtim_count == 0)
2029
bss->dtim_count = bss->dtim_period - 1;
2033
tim = pos = (u8 *) skb_put(skb, 6);
2034
*pos++ = WLAN_EID_TIM;
2036
*pos++ = bss->dtim_count;
2037
*pos++ = bss->dtim_period;
2039
if (bss->dtim_count == 0 && !skb_queue_empty(&bss->ps_bc_buf))
2043
/* Find largest even number N1 so that bits numbered 1 through
2044
* (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
2045
* (N2 + 1) x 8 through 2007 are 0. */
2047
for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) {
2054
for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) {
2061
/* Bitmap control */
2063
/* Part Virt Bitmap */
2064
memcpy(pos, bss->tim + n1, n2 - n1 + 1);
2066
tim[1] = n2 - n1 + 4;
2067
skb_put(skb, n2 - n1);
2069
*pos++ = aid0; /* Bitmap control */
2070
*pos++ = 0; /* Part Virt Bitmap */
2072
spin_unlock_bh(&local->sta_lock);
2076
struct sk_buff * iwlwifi_ieee80211_beacon_get(struct ieee80211_hw *hw, int if_id,
2077
struct ieee80211_tx_control *control)
2079
struct ieee80211_local *local = hw_to_local(hw);
2080
struct sk_buff *skb;
2081
struct net_device *bdev;
2082
struct ieee80211_sub_if_data *sdata = NULL;
2083
struct ieee80211_if_ap *ap = NULL;
2084
struct ieee80211_rate *rate;
2085
struct rate_control_extra extra;
2086
u8 *b_head, *b_tail;
2089
bdev = dev_get_by_index(&init_net, if_id);
2091
sdata = IEEE80211_DEV_TO_SUB_IF(bdev);
2096
if (!ap || sdata->type != IEEE80211_IF_TYPE_AP ||
2098
#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2099
if (net_ratelimit())
2100
printk(KERN_DEBUG "no beacon data avail for idx=%d "
2101
"(%s)\n", if_id, bdev ? bdev->name : "N/A");
2102
#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
2106
/* Assume we are generating the normal beacon locally */
2107
b_head = ap->beacon_head;
2108
b_tail = ap->beacon_tail;
2109
bh_len = ap->beacon_head_len;
2110
bt_len = ap->beacon_tail_len;
2112
skb = dev_alloc_skb(local->tx_headroom +
2113
bh_len + bt_len + 256 /* maximum TIM len */);
2117
skb_reserve(skb, local->tx_headroom);
2118
memcpy(skb_put(skb, bh_len), b_head, bh_len);
2120
ieee80211_include_sequence(sdata, (struct ieee80211_hdr *)skb->data);
2122
ieee80211_beacon_add_tim(local, ap, skb);
2125
memcpy(skb_put(skb, bt_len), b_tail, bt_len);
2129
memset(&extra, 0, sizeof(extra));
2130
extra.mode = local->oper_hw_mode;
2132
rate = rate_control_get_rate(local, local->mdev, skb, &extra);
2134
if (net_ratelimit()) {
2135
printk(KERN_DEBUG "%s: iwlwifi_ieee80211_beacon_get: no rate "
2136
"found\n", local->mdev->name);
2142
control->tx_rate = (local->short_preamble &&
2143
(rate->flags & IEEE80211_RATE_PREAMBLE2)) ?
2144
rate->val2 : rate->val;
2145
control->antenna_sel_tx = local->hw.conf.antenna_sel_tx;
2146
control->power_level = local->hw.conf.power_level;
2147
control->flags |= IEEE80211_TXCTL_NO_ACK;
2148
control->retry_limit = 1;
2149
control->flags |= IEEE80211_TXCTL_CLEAR_DST_MASK;
2155
EXPORT_SYMBOL(iwlwifi_ieee80211_beacon_get);
2157
__le16 iwlwifi_ieee80211_rts_duration(struct ieee80211_hw *hw,
2159
const struct ieee80211_tx_control *frame_txctl)
2161
struct ieee80211_local *local = hw_to_local(hw);
2162
struct ieee80211_rate *rate;
2163
int short_preamble = local->short_preamble;
2167
rate = frame_txctl->rts_rate;
2168
erp = !!(rate->flags & IEEE80211_RATE_ERP);
2171
dur = ieee80211_frame_duration(local, 10, rate->rate,
2172
erp, short_preamble);
2173
/* Data frame duration */
2174
dur += ieee80211_frame_duration(local, frame_len, rate->rate,
2175
erp, short_preamble);
2177
dur += ieee80211_frame_duration(local, 10, rate->rate,
2178
erp, short_preamble);
2180
return cpu_to_le16(dur);
2182
EXPORT_SYMBOL(iwlwifi_ieee80211_rts_duration);
2185
__le16 iwlwifi_ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
2187
const struct ieee80211_tx_control *frame_txctl)
2189
struct ieee80211_local *local = hw_to_local(hw);
2190
struct ieee80211_rate *rate;
2191
int short_preamble = local->short_preamble;
2195
rate = frame_txctl->rts_rate;
2196
erp = !!(rate->flags & IEEE80211_RATE_ERP);
2198
/* Data frame duration */
2199
dur = ieee80211_frame_duration(local, frame_len, rate->rate,
2200
erp, short_preamble);
2201
if (!(frame_txctl->flags & IEEE80211_TXCTL_NO_ACK)) {
2203
dur += ieee80211_frame_duration(local, 10, rate->rate,
2204
erp, short_preamble);
2207
return cpu_to_le16(dur);
2209
EXPORT_SYMBOL(iwlwifi_ieee80211_ctstoself_duration);
2211
void iwlwifi_ieee80211_rts_get(struct ieee80211_hw *hw,
2212
const void *frame, size_t frame_len,
2213
const struct ieee80211_tx_control *frame_txctl,
2214
struct ieee80211_rts *rts)
2216
const struct ieee80211_hdr *hdr = frame;
2219
fctl = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS;
2220
rts->frame_control = cpu_to_le16(fctl);
2221
rts->duration = iwlwifi_ieee80211_rts_duration(hw, frame_len, frame_txctl);
2222
memcpy(rts->ra, hdr->addr1, sizeof(rts->ra));
2223
memcpy(rts->ta, hdr->addr2, sizeof(rts->ta));
2225
EXPORT_SYMBOL(iwlwifi_ieee80211_rts_get);
2227
void iwlwifi_ieee80211_ctstoself_get(struct ieee80211_hw *hw,
2228
const void *frame, size_t frame_len,
2229
const struct ieee80211_tx_control *frame_txctl,
2230
struct ieee80211_cts *cts)
2232
const struct ieee80211_hdr *hdr = frame;
2235
fctl = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS;
2236
cts->frame_control = cpu_to_le16(fctl);
2237
cts->duration = iwlwifi_ieee80211_ctstoself_duration(hw, frame_len, frame_txctl);
2238
memcpy(cts->ra, hdr->addr1, sizeof(cts->ra));
2240
EXPORT_SYMBOL(iwlwifi_ieee80211_ctstoself_get);
2243
iwlwifi_ieee80211_get_buffered_bc(struct ieee80211_hw *hw, int if_id,
2244
struct ieee80211_tx_control *control)
2246
struct ieee80211_local *local = hw_to_local(hw);
2247
struct sk_buff *skb;
2248
struct sta_info *sta;
2249
ieee80211_tx_handler *handler;
2250
struct ieee80211_txrx_data tx;
2251
ieee80211_txrx_result res = TXRX_DROP;
2252
struct net_device *bdev;
2253
struct ieee80211_sub_if_data *sdata;
2254
struct ieee80211_if_ap *bss = NULL;
2256
bdev = dev_get_by_index(&init_net, if_id);
2258
sdata = IEEE80211_DEV_TO_SUB_IF(bdev);
2262
if (!bss || sdata->type != IEEE80211_IF_TYPE_AP || !bss->beacon_head)
2265
if (bss->dtim_count != 0)
2266
return NULL; /* send buffered bc/mc only after DTIM beacon */
2267
memset(control, 0, sizeof(*control));
2269
skb = skb_dequeue(&bss->ps_bc_buf);
2272
local->total_ps_buffered--;
2274
if (!skb_queue_empty(&bss->ps_bc_buf) && skb->len >= 2) {
2275
struct ieee80211_hdr *hdr =
2276
(struct ieee80211_hdr *) skb->data;
2277
/* more buffered multicast/broadcast frames ==> set
2278
* MoreData flag in IEEE 802.11 header to inform PS
2280
hdr->frame_control |=
2281
cpu_to_le16(IEEE80211_FCTL_MOREDATA);
2284
if (ieee80211_tx_prepare(&tx, skb, local->mdev, control) == 0)
2286
dev_kfree_skb_any(skb);
2289
tx.u.tx.ps_buffered = 1;
2291
for (handler = local->tx_handlers; *handler != NULL; handler++) {
2292
res = (*handler)(&tx);
2293
if (res == TXRX_DROP || res == TXRX_QUEUED)
2297
skb = tx.skb; /* handlers are allowed to change skb */
2299
if (res == TXRX_DROP) {
2300
I802_DEBUG_INC(local->tx_handlers_drop);
2303
} else if (res == TXRX_QUEUED) {
2304
I802_DEBUG_INC(local->tx_handlers_queued);
2309
iwlwifi_sta_info_put(sta);
2313
EXPORT_SYMBOL(iwlwifi_ieee80211_get_buffered_bc);
2315
static int __ieee80211_if_config(struct net_device *dev,
2316
struct sk_buff *beacon,
2317
struct ieee80211_tx_control *control)
2319
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2320
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2321
struct ieee80211_if_conf conf;
2322
static u8 scan_bssid[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2324
if (!local->ops->config_interface || !netif_running(dev))
2327
memset(&conf, 0, sizeof(conf));
2328
conf.type = sdata->type;
2329
if (sdata->type == IEEE80211_IF_TYPE_STA ||
2330
sdata->type == IEEE80211_IF_TYPE_IBSS) {
2331
if (local->sta_hw_scanning)
2332
conf.bssid = scan_bssid;
2334
conf.bssid = sdata->u.sta.bssid;
2335
conf.ssid = sdata->u.sta.ssid;
2336
conf.ssid_len = sdata->u.sta.ssid_len;
2337
conf.generic_elem = sdata->u.sta.extra_ie;
2338
conf.generic_elem_len = sdata->u.sta.extra_ie_len;
2339
} else if (sdata->type == IEEE80211_IF_TYPE_AP) {
2340
conf.ssid = sdata->u.ap.ssid;
2341
conf.ssid_len = sdata->u.ap.ssid_len;
2342
conf.generic_elem = sdata->u.ap.generic_elem;
2343
conf.generic_elem_len = sdata->u.ap.generic_elem_len;
2344
conf.beacon = beacon;
2345
conf.beacon_control = control;
2347
return local->ops->config_interface(local_to_hw(local),
2348
dev->ifindex, &conf);
2351
int ieee80211_if_config(struct net_device *dev)
2353
return __ieee80211_if_config(dev, NULL, NULL);
2356
int ieee80211_if_config_beacon(struct net_device *dev)
2358
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2359
struct ieee80211_tx_control control;
2360
struct sk_buff *skb;
2362
if (!(local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE))
2364
skb = iwlwifi_ieee80211_beacon_get(local_to_hw(local), dev->ifindex, &control);
2367
return __ieee80211_if_config(dev, skb, &control);
2370
int ieee80211_hw_config(struct ieee80211_local *local)
2372
struct ieee80211_hw_mode *mode;
2373
struct ieee80211_channel *chan;
2376
if (local->sta_sw_scanning) {
2377
chan = local->scan_channel;
2378
mode = local->scan_hw_mode;
2380
chan = local->oper_channel;
2381
mode = local->oper_hw_mode;
2384
local->hw.conf.channel = chan->chan;
2385
local->hw.conf.channel_val = chan->val;
2386
local->hw.conf.power_level =
2387
(local->user_txpow < chan->power_level) ?
2388
local->user_txpow : chan->power_level;
2389
local->hw.conf.freq = chan->freq;
2390
local->hw.conf.phymode = mode->mode;
2391
local->hw.conf.antenna_max = chan->antenna_max;
2392
local->hw.conf.chan = chan;
2393
local->hw.conf.mode = mode;
2395
#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2396
printk(KERN_DEBUG "HW CONFIG: channel=%d freq=%d "
2397
"phymode=%d\n", local->hw.conf.channel, local->hw.conf.freq,
2398
local->hw.conf.phymode);
2399
#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
2401
if (local->ops->config)
2402
ret = local->ops->config(local_to_hw(local), &local->hw.conf);
2408
static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
2410
/* FIX: what would be proper limits for MTU?
2411
* This interface uses 802.3 frames. */
2412
if (new_mtu < 256 || new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6) {
2413
printk(KERN_WARNING "%s: invalid MTU %d\n",
2414
dev->name, new_mtu);
2418
#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2419
printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu);
2420
#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
2426
static int ieee80211_change_mtu_apdev(struct net_device *dev, int new_mtu)
2428
/* FIX: what would be proper limits for MTU?
2429
* This interface uses 802.11 frames. */
2430
if (new_mtu < 256 || new_mtu > IEEE80211_MAX_DATA_LEN) {
2431
printk(KERN_WARNING "%s: invalid MTU %d\n",
2432
dev->name, new_mtu);
2436
#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2437
printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu);
2438
#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
2443
enum netif_tx_lock_class {
2448
static inline void netif_tx_lock_nested(struct net_device *dev, int subclass)
2450
spin_lock_nested(&dev->_xmit_lock, subclass);
2451
dev->xmit_lock_owner = smp_processor_id();
2454
static void ieee80211_set_multicast_list(struct net_device *dev)
2456
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2457
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2458
unsigned short flags;
2460
netif_tx_lock_nested(local->mdev, TX_LOCK_MASTER);
2461
if (((dev->flags & IFF_ALLMULTI) != 0) ^ (sdata->allmulti != 0)) {
2462
if (sdata->allmulti) {
2463
sdata->allmulti = 0;
2464
local->iff_allmultis--;
2466
sdata->allmulti = 1;
2467
local->iff_allmultis++;
2470
if (((dev->flags & IFF_PROMISC) != 0) ^ (sdata->promisc != 0)) {
2471
if (sdata->promisc) {
2473
local->iff_promiscs--;
2476
local->iff_promiscs++;
2479
if (dev->mc_count != sdata->mc_count) {
2480
local->mc_count = local->mc_count - sdata->mc_count +
2482
sdata->mc_count = dev->mc_count;
2484
if (local->ops->set_multicast_list) {
2485
flags = local->mdev->flags;
2486
if (local->iff_allmultis)
2487
flags |= IFF_ALLMULTI;
2488
if (local->iff_promiscs)
2489
flags |= IFF_PROMISC;
2490
read_lock(&local->sub_if_lock);
2491
local->ops->set_multicast_list(local_to_hw(local), flags,
2493
read_unlock(&local->sub_if_lock);
2495
netif_tx_unlock(local->mdev);
2498
struct dev_mc_list *iwlwifi_ieee80211_get_mc_list_item(struct ieee80211_hw *hw,
2499
struct dev_mc_list *prev,
2502
struct ieee80211_local *local = hw_to_local(hw);
2503
struct ieee80211_sub_if_data *sdata = *ptr;
2504
struct dev_mc_list *mc;
2510
if (!prev || !prev->next) {
2512
sdata = list_entry(sdata->list.next,
2513
struct ieee80211_sub_if_data, list);
2515
sdata = list_entry(local->sub_if_list.next,
2516
struct ieee80211_sub_if_data, list);
2517
if (&sdata->list != &local->sub_if_list)
2518
mc = sdata->dev->mc_list;
2527
EXPORT_SYMBOL(iwlwifi_ieee80211_get_mc_list_item);
2529
static struct net_device_stats *ieee80211_get_stats(struct net_device *dev)
2531
struct ieee80211_sub_if_data *sdata;
2532
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2533
return &(sdata->stats);
2536
static void ieee80211_if_shutdown(struct net_device *dev)
2538
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2539
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2542
switch (sdata->type) {
2543
case IEEE80211_IF_TYPE_STA:
2544
case IEEE80211_IF_TYPE_IBSS:
2545
sdata->u.sta.state = IEEE80211_DISABLED;
2546
del_timer_sync(&sdata->u.sta.timer);
2547
del_timer_sync(&sdata->u.sta.admit_timer);
2548
skb_queue_purge(&sdata->u.sta.skb_queue);
2549
if (!local->ops->hw_scan &&
2550
local->scan_dev == sdata->dev) {
2551
local->sta_sw_scanning = 0;
2552
cancel_delayed_work(&local->scan_work);
2554
flush_workqueue(local->hw.workqueue);
2556
kfree(sdata->u.sta.extra_ie);
2557
sdata->u.sta.extra_ie = NULL;
2562
static inline int identical_mac_addr_allowed(int type1, int type2)
2564
return (type1 == IEEE80211_IF_TYPE_MNTR ||
2565
type2 == IEEE80211_IF_TYPE_MNTR ||
2566
(type1 == IEEE80211_IF_TYPE_AP &&
2567
type2 == IEEE80211_IF_TYPE_WDS) ||
2568
(type1 == IEEE80211_IF_TYPE_WDS &&
2569
(type2 == IEEE80211_IF_TYPE_WDS ||
2570
type2 == IEEE80211_IF_TYPE_AP)) ||
2571
(type1 == IEEE80211_IF_TYPE_AP &&
2572
type2 == IEEE80211_IF_TYPE_VLAN) ||
2573
(type1 == IEEE80211_IF_TYPE_VLAN &&
2574
(type2 == IEEE80211_IF_TYPE_AP ||
2575
type2 == IEEE80211_IF_TYPE_VLAN)));
2578
static int ieee80211_master_open(struct net_device *dev)
2580
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2581
struct ieee80211_sub_if_data *sdata;
2582
int res = -EOPNOTSUPP;
2584
read_lock(&local->sub_if_lock);
2585
list_for_each_entry(sdata, &local->sub_if_list, list) {
2586
if (sdata->dev != dev && netif_running(sdata->dev)) {
2591
read_unlock(&local->sub_if_lock);
2595
static int ieee80211_master_stop(struct net_device *dev)
2597
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2598
struct ieee80211_sub_if_data *sdata;
2600
read_lock(&local->sub_if_lock);
2601
list_for_each_entry(sdata, &local->sub_if_list, list)
2602
if (sdata->dev != dev && netif_running(sdata->dev))
2603
dev_close(sdata->dev);
2604
read_unlock(&local->sub_if_lock);
2609
static int ieee80211_mgmt_open(struct net_device *dev)
2611
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2613
if (!netif_running(local->mdev))
2618
static int ieee80211_mgmt_stop(struct net_device *dev)
2623
/* Check if running monitor interfaces should go to a "soft monitor" mode
2624
* and switch them if necessary. */
2625
static inline void ieee80211_start_soft_monitor(struct ieee80211_local *local)
2627
struct ieee80211_if_init_conf conf;
2629
if (local->open_count && local->open_count == local->monitors &&
2630
!(local->hw.flags & IEEE80211_HW_MONITOR_DURING_OPER) &&
2631
local->ops->remove_interface) {
2633
conf.type = IEEE80211_IF_TYPE_MNTR;
2634
conf.mac_addr = NULL;
2635
local->ops->remove_interface(local_to_hw(local), &conf);
2639
/* Check if running monitor interfaces should go to a "hard monitor" mode
2640
* and switch them if necessary. */
2641
static void ieee80211_start_hard_monitor(struct ieee80211_local *local)
2643
struct ieee80211_if_init_conf conf;
2645
if (local->open_count && local->open_count == local->monitors &&
2646
!(local->hw.flags & IEEE80211_HW_MONITOR_DURING_OPER)) {
2648
conf.type = IEEE80211_IF_TYPE_MNTR;
2649
conf.mac_addr = NULL;
2650
local->ops->add_interface(local_to_hw(local), &conf);
2654
static int ieee80211_open(struct net_device *dev)
2656
struct ieee80211_sub_if_data *sdata, *nsdata;
2657
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2658
struct ieee80211_if_init_conf conf;
2661
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2662
read_lock(&local->sub_if_lock);
2663
list_for_each_entry(nsdata, &local->sub_if_list, list) {
2664
struct net_device *ndev = nsdata->dev;
2666
if (ndev != dev && ndev != local->mdev && netif_running(ndev) &&
2667
compare_ether_addr(dev->dev_addr, ndev->dev_addr) == 0 &&
2668
!identical_mac_addr_allowed(sdata->type, nsdata->type)) {
2669
read_unlock(&local->sub_if_lock);
2673
read_unlock(&local->sub_if_lock);
2675
if (sdata->type == IEEE80211_IF_TYPE_WDS &&
2676
is_zero_ether_addr(sdata->u.wds.remote_addr))
2679
if (sdata->type == IEEE80211_IF_TYPE_MNTR && local->open_count &&
2680
!(local->hw.flags & IEEE80211_HW_MONITOR_DURING_OPER)) {
2681
/* run the interface in a "soft monitor" mode */
2683
local->open_count++;
2684
local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
2687
ieee80211_start_soft_monitor(local);
2689
conf.if_id = dev->ifindex;
2690
conf.type = sdata->type;
2691
conf.mac_addr = dev->dev_addr;
2692
res = local->ops->add_interface(local_to_hw(local), &conf);
2694
if (sdata->type == IEEE80211_IF_TYPE_MNTR)
2695
ieee80211_start_hard_monitor(local);
2699
if (local->open_count == 0) {
2701
if (local->ops->open)
2702
res = local->ops->open(local_to_hw(local));
2704
res = dev_open(local->mdev);
2706
if (local->ops->stop)
2707
local->ops->stop(local_to_hw(local));
2709
res = ieee80211_hw_config(local);
2710
if (res && local->ops->stop)
2711
local->ops->stop(local_to_hw(local));
2712
else if (!res && local->apdev)
2713
dev_open(local->apdev);
2717
if (local->ops->remove_interface)
2718
local->ops->remove_interface(local_to_hw(local),
2722
/* enable tasklets only if all callbacks return correctly */
2723
tasklet_enable(&local->tx_pending_tasklet);
2724
tasklet_enable(&local->tasklet);
2726
local->open_count++;
2728
if (sdata->type == IEEE80211_IF_TYPE_MNTR) {
2730
local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
2732
ieee80211_if_config(dev);
2734
if (sdata->type == IEEE80211_IF_TYPE_STA &&
2735
!local->user_space_mlme)
2736
netif_carrier_off(dev);
2738
netif_carrier_on(dev);
2740
netif_start_queue(dev);
2745
static int ieee80211_stop(struct net_device *dev)
2747
struct ieee80211_sub_if_data *sdata;
2748
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2750
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2752
if (sdata->type == IEEE80211_IF_TYPE_MNTR &&
2753
local->open_count > 1 &&
2754
!(local->hw.flags & IEEE80211_HW_MONITOR_DURING_OPER)) {
2755
/* remove "soft monitor" interface */
2756
local->open_count--;
2758
if (!local->monitors)
2759
local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
2763
netif_stop_queue(dev);
2764
ieee80211_if_shutdown(dev);
2766
if (sdata->type == IEEE80211_IF_TYPE_MNTR) {
2768
if (!local->monitors)
2769
local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
2772
local->open_count--;
2773
if (local->open_count == 0) {
2774
if (netif_running(local->mdev))
2775
dev_close(local->mdev);
2777
dev_close(local->apdev);
2778
if (local->ops->stop)
2779
local->ops->stop(local_to_hw(local));
2780
tasklet_disable(&local->tx_pending_tasklet);
2781
tasklet_disable(&local->tasklet);
2783
if (local->ops->remove_interface) {
2784
struct ieee80211_if_init_conf conf;
2786
conf.if_id = dev->ifindex;
2787
conf.type = sdata->type;
2788
conf.mac_addr = dev->dev_addr;
2789
local->ops->remove_interface(local_to_hw(local), &conf);
2792
ieee80211_start_hard_monitor(local);
2798
static int header_parse_80211(const struct sk_buff *skb, unsigned char *haddr)
2800
memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
2804
static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
2806
return compare_ether_addr(raddr, addr) == 0 ||
2807
is_broadcast_ether_addr(raddr);
2811
inline static unsigned int calc_pad_len(unsigned int len)
2813
return ((4 - len) & 0x3);
2816
static ieee80211_txrx_result
2817
ieee80211_rx_h_data_agg(struct ieee80211_txrx_data *rx)
2819
struct net_device *dev = rx->dev;
2820
struct ieee80211_local *local = rx->local;
2821
u16 fc, hdrlen, ethertype;
2823
struct sk_buff *skb = rx->skb, *skb2, *frame = NULL;
2824
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2825
const struct ethhdr* eth;
2829
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
2833
if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA))
2834
return TXRX_CONTINUE;
2836
if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
2839
if (!rx->u.rx.is_agg_frame)
2840
return TXRX_CONTINUE;
2842
hdrlen = iwlwifi_ieee80211_get_hdrlen(fc);
2844
switch (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
2845
case IEEE80211_FCTL_TODS:
2847
if (unlikely(sdata->type != IEEE80211_IF_TYPE_AP &&
2848
sdata->type != IEEE80211_IF_TYPE_VLAN)) {
2849
printk(KERN_DEBUG "%s: dropped ToDS frame (BSSID="
2850
MAC_FMT " SA=" MAC_FMT " DA=" MAC_FMT ")\n",
2851
dev->name, MAC_ARG(hdr->addr1),
2852
MAC_ARG(hdr->addr2), MAC_ARG(hdr->addr3));
2856
case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
2858
if (unlikely(sdata->type != IEEE80211_IF_TYPE_WDS)) {
2859
printk(KERN_DEBUG "%s: dropped FromDS&ToDS frame (RA="
2860
MAC_FMT " TA=" MAC_FMT " DA=" MAC_FMT " SA="
2862
rx->dev->name, MAC_ARG(hdr->addr1),
2863
MAC_ARG(hdr->addr2), MAC_ARG(hdr->addr3),
2864
MAC_ARG(hdr->addr4));
2868
case IEEE80211_FCTL_FROMDS:
2870
if (sdata->type != IEEE80211_IF_TYPE_STA)
2875
if (sdata->type != IEEE80211_IF_TYPE_IBSS) {
2876
if (net_ratelimit()) {
2877
printk(KERN_DEBUG "%s: dropped IBSS frame (DA="
2878
MAC_FMT " SA=" MAC_FMT " BSSID=" MAC_FMT
2880
dev->name, MAC_ARG(hdr->addr1),
2881
MAC_ARG(hdr->addr2),
2882
MAC_ARG(hdr->addr3));
2889
if (unlikely((skb->len - hdrlen) < 8)) {
2890
if (net_ratelimit())
2891
printk(KERN_DEBUG "%s: RX too short data frame "
2892
"payload\n", dev->name);
2896
eth = (struct ethhdr *) skb_pull(skb, hdrlen);
2898
payload = skb->data;
2899
ethertype = (payload[6] << 8) | payload[7];
2901
if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
2902
ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
2903
compare_ether_addr(payload,
2904
bridge_tunnel_header) == 0))
2905
eth = (struct ethhdr *) skb_pull(skb, 8);
2911
while (skb != frame) {
2913
__be16 len = eth->h_proto;
2914
unsigned int subframe_len = sizeof(struct ethhdr) + ntohs(len);
2916
remaining = skb->len;
2917
memcpy(dst, eth->h_dest, ETH_ALEN);
2918
memcpy(src, eth->h_source, ETH_ALEN);
2920
padding = calc_pad_len(subframe_len);
2921
/* the last MSDU has no padding */
2922
if (subframe_len > remaining) {
2923
printk(KERN_DEBUG "%s: wrong buffer size", dev->name);
2927
skb_pull(skb, sizeof(struct ethhdr));
2928
/* if last subframe reuse skb */
2929
if (remaining <= subframe_len + padding)
2932
frame = dev_alloc_skb(local->hw.extra_tx_headroom +
2938
skb_reserve(frame, local->hw.extra_tx_headroom +
2939
sizeof(struct ethhdr));
2940
memcpy(skb_put(frame, ntohs(len)), skb->data,
2943
eth = (struct ethhdr *) skb_pull(skb, ntohs(len) +
2946
printk(KERN_DEBUG "%s: wrong buffer size ",
2948
dev_kfree_skb(frame);
2954
payload = frame->data;
2955
ethertype = (payload[6] << 8) | payload[7];
2957
if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
2958
ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
2959
compare_ether_addr(payload,
2960
bridge_tunnel_header) == 0)) {
2961
/* remove RFC1042 or Bridge-Tunnel
2962
* encapsulation and replace EtherType */
2964
memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
2965
memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
2967
memcpy(skb_push(frame, sizeof(__be16)), &len,
2969
memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
2970
memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
2972
sdata->stats.rx_packets++;
2973
sdata->stats.rx_bytes += frame->len;
2975
if (local->bridge_packets &&
2976
(sdata->type == IEEE80211_IF_TYPE_AP ||
2977
sdata->type == IEEE80211_IF_TYPE_VLAN) &&
2978
rx->u.rx.ra_match) {
2979
if (is_multicast_ether_addr(frame->data)) {
2980
/* send multicast frames both to higher layers
2981
* in local net stack and back to the wireless
2983
skb2 = skb_copy(frame, GFP_ATOMIC);
2985
printk(KERN_DEBUG "%s: failed to clone"
2986
" multicast frame\n", dev->name);
2988
struct sta_info *dsta;
2990
dsta = iwlwifi_sta_info_get(local, frame->data);
2991
if (dsta && !dsta->dev)
2992
printk(KERN_DEBUG "Station with null "
2993
"dev structure!\n");
2994
else if (dsta && dsta->dev == dev) {
2995
/* Destination station is associated
2996
*to this AP, so send the frame
2997
* directly to it and do not pass
2998
* the frame to local net stack.
3004
iwlwifi_sta_info_put(dsta);
3008
/* deliver to local stack */
3009
skb_set_network_header(frame, 0);
3010
frame->protocol = eth_type_trans(frame, dev);
3011
frame->priority = skb->priority;
3016
/* send to wireless media */
3017
skb2->protocol = __constant_htons(ETH_P_802_3);
3018
skb_set_network_header(skb2, 0);
3019
skb_set_mac_header(skb2, 0);
3020
skb2->priority = skb->priority;
3022
dev_queue_xmit(skb2);
3029
static ieee80211_txrx_result
3030
ieee80211_rx_h_data(struct ieee80211_txrx_data *rx)
3032
struct net_device *dev = rx->dev;
3033
struct ieee80211_local *local = rx->local;
3034
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
3035
u16 fc, hdrlen, ethertype;
3039
struct sk_buff *skb = rx->skb, *skb2;
3040
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3043
if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA))
3044
return TXRX_CONTINUE;
3046
if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
3049
hdrlen = iwlwifi_ieee80211_get_hdrlen(fc);
3051
/* convert IEEE 802.11 header + possible LLC headers into Ethernet
3053
* IEEE 802.11 address fields:
3054
* ToDS FromDS Addr1 Addr2 Addr3 Addr4
3055
* 0 0 DA SA BSSID n/a
3056
* 0 1 DA BSSID SA n/a
3057
* 1 0 BSSID SA DA n/a
3061
switch (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
3062
case IEEE80211_FCTL_TODS:
3064
memcpy(dst, hdr->addr3, ETH_ALEN);
3065
memcpy(src, hdr->addr2, ETH_ALEN);
3067
if (unlikely(sdata->type != IEEE80211_IF_TYPE_AP &&
3068
sdata->type != IEEE80211_IF_TYPE_VLAN)) {
3069
printk(KERN_DEBUG "%s: dropped ToDS frame (BSSID="
3070
MAC_FMT " SA=" MAC_FMT " DA=" MAC_FMT ")\n",
3071
dev->name, MAC_ARG(hdr->addr1),
3072
MAC_ARG(hdr->addr2), MAC_ARG(hdr->addr3));
3076
case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
3078
memcpy(dst, hdr->addr3, ETH_ALEN);
3079
memcpy(src, hdr->addr4, ETH_ALEN);
3081
if (unlikely(sdata->type != IEEE80211_IF_TYPE_WDS)) {
3082
printk(KERN_DEBUG "%s: dropped FromDS&ToDS frame (RA="
3083
MAC_FMT " TA=" MAC_FMT " DA=" MAC_FMT " SA="
3085
rx->dev->name, MAC_ARG(hdr->addr1),
3086
MAC_ARG(hdr->addr2), MAC_ARG(hdr->addr3),
3087
MAC_ARG(hdr->addr4));
3091
case IEEE80211_FCTL_FROMDS:
3093
memcpy(dst, hdr->addr1, ETH_ALEN);
3094
memcpy(src, hdr->addr3, ETH_ALEN);
3096
if (sdata->type != IEEE80211_IF_TYPE_STA ||
3097
(is_multicast_ether_addr(dst) &&
3098
!compare_ether_addr(src, dev->dev_addr)))
3103
memcpy(dst, hdr->addr1, ETH_ALEN);
3104
memcpy(src, hdr->addr2, ETH_ALEN);
3106
if (sdata->type != IEEE80211_IF_TYPE_IBSS) {
3107
if (net_ratelimit()) {
3108
printk(KERN_DEBUG "%s: dropped IBSS frame (DA="
3109
MAC_FMT " SA=" MAC_FMT " BSSID=" MAC_FMT
3111
dev->name, MAC_ARG(hdr->addr1),
3112
MAC_ARG(hdr->addr2),
3113
MAC_ARG(hdr->addr3));
3120
payload = skb->data + hdrlen;
3122
if (unlikely(skb->len - hdrlen < 8)) {
3123
if (net_ratelimit()) {
3124
printk(KERN_DEBUG "%s: RX too short data frame "
3125
"payload\n", dev->name);
3130
ethertype = (payload[6] << 8) | payload[7];
3132
if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
3133
ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
3134
compare_ether_addr(payload, bridge_tunnel_header) == 0)) {
3135
/* remove RFC1042 or Bridge-Tunnel encapsulation and
3136
* replace EtherType */
3137
skb_pull(skb, hdrlen + 6);
3138
memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
3139
memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
3141
struct ethhdr *ehdr;
3143
skb_pull(skb, hdrlen);
3144
len = htons(skb->len);
3145
ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
3146
memcpy(ehdr->h_dest, dst, ETH_ALEN);
3147
memcpy(ehdr->h_source, src, ETH_ALEN);
3148
ehdr->h_proto = len;
3154
sdata->stats.rx_packets++;
3155
sdata->stats.rx_bytes += skb->len;
3157
if (local->bridge_packets && (sdata->type == IEEE80211_IF_TYPE_AP
3158
|| sdata->type == IEEE80211_IF_TYPE_VLAN) && rx->u.rx.ra_match) {
3159
if (is_multicast_ether_addr(skb->data)) {
3160
/* send multicast frames both to higher layers in
3161
* local net stack and back to the wireless media */
3162
skb2 = skb_copy(skb, GFP_ATOMIC);
3164
printk(KERN_DEBUG "%s: failed to clone "
3165
"multicast frame\n", dev->name);
3167
struct sta_info *dsta;
3168
dsta = iwlwifi_sta_info_get(local, skb->data);
3169
if (dsta && !dsta->dev) {
3170
printk(KERN_DEBUG "Station with null dev "
3172
} else if (dsta && dsta->dev == dev) {
3173
/* Destination station is associated to this
3174
* AP, so send the frame directly to it and
3175
* do not pass the frame to local net stack.
3181
iwlwifi_sta_info_put(dsta);
3186
/* deliver to local stack */
3187
skb->protocol = eth_type_trans(skb, dev);
3188
memset(skb->cb, 0, sizeof(skb->cb));
3193
/* send to wireless media */
3194
skb2->protocol = __constant_htons(ETH_P_802_3);
3195
skb_set_network_header(skb2, 0);
3196
skb_set_mac_header(skb2, 0);
3197
dev_queue_xmit(skb2);
3204
static struct ieee80211_rate *
3205
ieee80211_get_rate(struct ieee80211_local *local, int phymode, int hw_rate)
3207
struct ieee80211_hw_mode *mode;
3210
list_for_each_entry(mode, &local->modes_list, list) {
3211
if (mode->mode != phymode)
3213
for (r = 0; r < mode->num_rates; r++) {
3214
struct ieee80211_rate *rate = &mode->rates[r];
3215
if (rate->val == hw_rate ||
3216
(rate->flags & IEEE80211_RATE_PREAMBLE2 &&
3217
rate->val2 == hw_rate))
3226
ieee80211_fill_frame_info(struct ieee80211_local *local,
3227
struct ieee80211_frame_info *fi,
3228
struct ieee80211_rx_status *status)
3232
struct ieee80211_rate *rate;
3234
jiffies_to_timespec(jiffies, &ts);
3235
fi->hosttime = cpu_to_be64((u64) ts.tv_sec * 1000000 +
3237
fi->mactime = cpu_to_be64(status->mactime);
3238
switch (status->phymode) {
3239
case MODE_IEEE80211A:
3240
fi->phytype = htonl(ieee80211_phytype_ofdm_dot11_a);
3242
case MODE_IEEE80211B:
3243
fi->phytype = htonl(ieee80211_phytype_dsss_dot11_b);
3245
case MODE_IEEE80211G:
3246
fi->phytype = htonl(ieee80211_phytype_pbcc_dot11_g);
3248
case MODE_ATHEROS_TURBO:
3250
htonl(ieee80211_phytype_dsss_dot11_turbo);
3253
fi->phytype = htonl(0xAAAAAAAA);
3256
fi->channel = htonl(status->channel);
3257
rate = ieee80211_get_rate(local, status->phymode,
3260
fi->datarate = htonl(rate->rate);
3261
if (rate->flags & IEEE80211_RATE_PREAMBLE2) {
3262
if (status->rate == rate->val)
3263
fi->preamble = htonl(2); /* long */
3264
else if (status->rate == rate->val2)
3265
fi->preamble = htonl(1); /* short */
3267
fi->preamble = htonl(0);
3269
fi->datarate = htonl(0);
3270
fi->preamble = htonl(0);
3273
fi->antenna = htonl(status->antenna);
3274
fi->priority = htonl(0xffffffff); /* no clue */
3275
fi->ssi_type = htonl(ieee80211_ssi_raw);
3276
fi->ssi_signal = htonl(status->ssi);
3277
fi->ssi_noise = 0x00000000;
3280
/* clear everything because we really don't know.
3281
* the msg_type field isn't present on monitor frames
3282
* so we don't know whether it will be present or not,
3283
* but it's ok to not clear it since it'll be assigned
3285
memset(fi, 0, sizeof(*fi) - sizeof(fi->msg_type));
3287
fi->ssi_type = htonl(ieee80211_ssi_none);
3289
fi->version = htonl(IEEE80211_FI_VERSION);
3290
fi->length = cpu_to_be32(sizeof(*fi) - sizeof(fi->msg_type));
3293
/* this routine is actually not just for this, but also
3294
* for pushing fake 'management' frames into userspace.
3295
* it shall be replaced by a netlink-based system. */
3297
ieee80211_rx_mgmt(struct ieee80211_local *local, struct sk_buff *skb,
3298
struct ieee80211_rx_status *status, u32 msg_type)
3300
struct ieee80211_frame_info *fi;
3301
const size_t hlen = sizeof(struct ieee80211_frame_info);
3302
struct ieee80211_sub_if_data *sdata;
3304
skb->dev = local->apdev;
3306
sdata = IEEE80211_DEV_TO_SUB_IF(local->apdev);
3308
if (skb_headroom(skb) < hlen) {
3309
I802_DEBUG_INC(local->rx_expand_skb_head);
3310
if (pskb_expand_head(skb, hlen, 0, GFP_ATOMIC)) {
3316
fi = (struct ieee80211_frame_info *) skb_push(skb, hlen);
3318
ieee80211_fill_frame_info(local, fi, status);
3319
fi->msg_type = htonl(msg_type);
3321
sdata->stats.rx_packets++;
3322
sdata->stats.rx_bytes += skb->len;
3324
skb_set_mac_header(skb, 0);
3325
skb->ip_summed = CHECKSUM_UNNECESSARY;
3326
skb->pkt_type = PACKET_OTHERHOST;
3327
skb->protocol = htons(ETH_P_802_2);
3328
memset(skb->cb, 0, sizeof(skb->cb));
3333
ieee80211_rx_monitor(struct net_device *dev, struct sk_buff *skb,
3334
struct ieee80211_rx_status *status)
3336
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3337
struct ieee80211_sub_if_data *sdata;
3338
struct ieee80211_rate *rate;
3339
struct ieee80211_rtap_hdr {
3340
struct ieee80211_radiotap_header hdr;
3346
} __attribute__ ((packed)) *rthdr;
3350
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3352
if (status->flag & RX_FLAG_RADIOTAP)
3355
if (skb_headroom(skb) < sizeof(*rthdr)) {
3356
I802_DEBUG_INC(local->rx_expand_skb_head);
3357
if (pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC)) {
3363
rthdr = (struct ieee80211_rtap_hdr *) skb_push(skb, sizeof(*rthdr));
3364
memset(rthdr, 0, sizeof(*rthdr));
3365
rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
3366
rthdr->hdr.it_present =
3367
cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
3368
(1 << IEEE80211_RADIOTAP_RATE) |
3369
(1 << IEEE80211_RADIOTAP_CHANNEL) |
3370
(1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL));
3371
rthdr->flags = local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS ?
3372
IEEE80211_RADIOTAP_F_FCS : 0;
3373
rate = ieee80211_get_rate(local, status->phymode, status->rate);
3375
rthdr->rate = rate->rate / 5;
3376
rthdr->chan_freq = cpu_to_le16(status->freq);
3378
status->phymode == MODE_IEEE80211A ?
3379
cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ) :
3380
cpu_to_le16(IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ);
3381
rthdr->antsignal = status->ssi;
3384
sdata->stats.rx_packets++;
3385
sdata->stats.rx_bytes += skb->len;
3387
skb_set_mac_header(skb, 0);
3388
skb->ip_summed = CHECKSUM_UNNECESSARY;
3389
skb->pkt_type = PACKET_OTHERHOST;
3390
skb->protocol = htons(ETH_P_802_2);
3391
memset(skb->cb, 0, sizeof(skb->cb));
3395
int iwlwifi_ieee80211_radar_status(struct ieee80211_hw *hw, int channel,
3396
int radar, int radar_type)
3398
struct sk_buff *skb;
3399
struct ieee80211_radar_info *msg;
3400
struct ieee80211_local *local = hw_to_local(hw);
3405
skb = dev_alloc_skb(sizeof(struct ieee80211_frame_info) +
3406
sizeof(struct ieee80211_radar_info));
3410
skb_reserve(skb, sizeof(struct ieee80211_frame_info));
3412
msg = (struct ieee80211_radar_info *)
3413
skb_put(skb, sizeof(struct ieee80211_radar_info));
3414
msg->channel = channel;
3416
msg->radar_type = radar_type;
3418
ieee80211_rx_mgmt(local, skb, NULL, ieee80211_msg_radar);
3421
EXPORT_SYMBOL(iwlwifi_ieee80211_radar_status);
3424
static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta)
3426
struct ieee80211_sub_if_data *sdata;
3427
sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
3430
atomic_inc(&sdata->bss->num_sta_ps);
3431
sta->flags |= WLAN_STA_PS;
3433
#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
3434
printk(KERN_DEBUG "%s: STA " MAC_FMT " aid %d enters power "
3435
"save mode\n", dev->name, MAC_ARG(sta->addr), sta->aid);
3436
#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
3440
static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
3442
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3443
struct sk_buff *skb;
3445
struct ieee80211_sub_if_data *sdata;
3446
struct ieee80211_tx_packet_data *pkt_data;
3448
sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
3450
atomic_dec(&sdata->bss->num_sta_ps);
3451
sta->flags &= ~(WLAN_STA_PS | WLAN_STA_TIM);
3453
if (!skb_queue_empty(&sta->ps_tx_buf)) {
3454
if (local->ops->set_tim)
3455
local->ops->set_tim(local_to_hw(local), sta->aid, 0);
3457
bss_tim_clear(local, sdata->bss, sta->aid);
3459
#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
3460
printk(KERN_DEBUG "%s: STA " MAC_FMT " aid %d exits power "
3461
"save mode\n", dev->name, MAC_ARG(sta->addr), sta->aid);
3462
#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
3463
/* Send all buffered frames to the station */
3464
while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
3465
pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
3467
pkt_data->requeue = 1;
3468
dev_queue_xmit(skb);
3470
while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
3471
pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
3472
local->total_ps_buffered--;
3474
#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
3475
printk(KERN_DEBUG "%s: STA " MAC_FMT " aid %d send PS frame "
3476
"since STA not sleeping anymore\n", dev->name,
3477
MAC_ARG(sta->addr), sta->aid);
3478
#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
3479
pkt_data->requeue = 1;
3480
dev_queue_xmit(skb);
3487
static ieee80211_txrx_result
3488
ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx)
3490
struct sk_buff *skb;
3491
int no_pending_pkts;
3493
if (likely(!rx->sta ||
3494
(rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL ||
3495
(rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PSPOLL ||
3496
!rx->u.rx.ra_match))
3497
return TXRX_CONTINUE;
3499
skb = skb_dequeue(&rx->sta->tx_filtered);
3501
skb = skb_dequeue(&rx->sta->ps_tx_buf);
3503
rx->local->total_ps_buffered--;
3505
no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) &&
3506
skb_queue_empty(&rx->sta->ps_tx_buf);
3509
struct ieee80211_hdr *hdr =
3510
(struct ieee80211_hdr *) skb->data;
3512
/* tell TX path to send one frame even though the STA may
3513
* still remain is PS mode after this frame exchange */
3514
rx->sta->pspoll = 1;
3516
#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
3517
printk(KERN_DEBUG "STA " MAC_FMT " aid %d: PS Poll (entries "
3519
MAC_ARG(rx->sta->addr), rx->sta->aid,
3520
skb_queue_len(&rx->sta->ps_tx_buf));
3521
#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
3523
/* Use MoreData flag to indicate whether there are more
3524
* buffered frames for this STA */
3525
if (no_pending_pkts) {
3526
hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
3527
rx->sta->flags &= ~WLAN_STA_TIM;
3529
hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
3531
dev_queue_xmit(skb);
3533
if (no_pending_pkts) {
3534
if (rx->local->ops->set_tim)
3535
rx->local->ops->set_tim(local_to_hw(rx->local),
3538
bss_tim_clear(rx->local, rx->sdata->bss, rx->sta->aid);
3540
#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
3541
} else if (!rx->u.rx.sent_ps_buffered) {
3542
printk(KERN_DEBUG "%s: STA " MAC_FMT " sent PS Poll even "
3543
"though there is no buffered frames for it\n",
3544
rx->dev->name, MAC_ARG(rx->sta->addr));
3545
#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
3549
/* Free PS Poll skb here instead of returning TXRX_DROP that would
3550
* count as an dropped frame. */
3551
dev_kfree_skb(rx->skb);
3557
static inline struct ieee80211_fragment_entry *
3558
ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
3559
unsigned int frag, unsigned int seq, int rx_queue,
3560
struct sk_buff **skb)
3562
struct ieee80211_fragment_entry *entry;
3565
idx = sdata->fragment_next;
3566
entry = &sdata->fragments[sdata->fragment_next++];
3567
if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
3568
sdata->fragment_next = 0;
3570
if (!skb_queue_empty(&entry->skb_list)) {
3571
#ifdef CONFIG_MAC80211_DEBUG
3572
struct ieee80211_hdr *hdr =
3573
(struct ieee80211_hdr *) entry->skb_list.next->data;
3574
printk(KERN_DEBUG "%s: RX reassembly removed oldest "
3575
"fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
3576
"addr1=" MAC_FMT " addr2=" MAC_FMT "\n",
3577
sdata->dev->name, idx,
3578
jiffies - entry->first_frag_time, entry->seq,
3579
entry->last_frag, MAC_ARG(hdr->addr1),
3580
MAC_ARG(hdr->addr2));
3581
#endif /* CONFIG_MAC80211_DEBUG */
3582
__skb_queue_purge(&entry->skb_list);
3585
__skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
3587
entry->first_frag_time = jiffies;
3589
entry->rx_queue = rx_queue;
3590
entry->last_frag = frag;
3592
entry->extra_len = 0;
3598
static inline struct ieee80211_fragment_entry *
3599
ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
3600
u16 fc, unsigned int frag, unsigned int seq,
3601
int rx_queue, struct ieee80211_hdr *hdr)
3603
struct ieee80211_fragment_entry *entry;
3606
idx = sdata->fragment_next;
3607
for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
3608
struct ieee80211_hdr *f_hdr;
3613
idx = IEEE80211_FRAGMENT_MAX - 1;
3615
entry = &sdata->fragments[idx];
3616
if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
3617
entry->rx_queue != rx_queue ||
3618
entry->last_frag + 1 != frag)
3621
f_hdr = (struct ieee80211_hdr *) entry->skb_list.next->data;
3622
f_fc = le16_to_cpu(f_hdr->frame_control);
3624
if ((fc & IEEE80211_FCTL_FTYPE) != (f_fc & IEEE80211_FCTL_FTYPE) ||
3625
compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 ||
3626
compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0)
3629
if (entry->first_frag_time + 2 * HZ < jiffies) {
3630
__skb_queue_purge(&entry->skb_list);
3640
static ieee80211_txrx_result
3641
ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
3643
struct ieee80211_hdr *hdr;
3645
unsigned int frag, seq;
3646
struct ieee80211_fragment_entry *entry;
3647
struct sk_buff *skb;
3649
hdr = (struct ieee80211_hdr *) rx->skb->data;
3650
sc = le16_to_cpu(hdr->seq_ctrl);
3651
frag = sc & IEEE80211_SCTL_FRAG;
3653
if (likely((!(rx->fc & IEEE80211_FCTL_MOREFRAGS) && frag == 0) ||
3654
(rx->skb)->len < 24 ||
3655
is_multicast_ether_addr(hdr->addr1))) {
3656
/* not fragmented */
3659
I802_DEBUG_INC(rx->local->rx_handlers_fragments);
3661
seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
3664
/* This is the first fragment of a new frame. */
3665
entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
3666
rx->u.rx.queue, &(rx->skb));
3667
if (rx->key && rx->key->alg == ALG_CCMP &&
3668
(rx->fc & IEEE80211_FCTL_PROTECTED)) {
3669
/* Store CCMP PN so that we can verify that the next
3670
* fragment has a sequential PN value. */
3672
memcpy(entry->last_pn,
3673
rx->key->u.ccmp.rx_pn[rx->u.rx.queue],
3679
/* This is a fragment for a frame that should already be pending in
3680
* fragment cache. Add this fragment to the end of the pending entry.
3682
entry = ieee80211_reassemble_find(rx->sdata, rx->fc, frag, seq,
3683
rx->u.rx.queue, hdr);
3685
I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
3689
/* Verify that MPDUs within one MSDU have sequential PN values.
3690
* (IEEE 802.11i, 8.3.3.4.5) */
3693
u8 pn[CCMP_PN_LEN], *rpn;
3694
if (!rx->key || rx->key->alg != ALG_CCMP)
3696
memcpy(pn, entry->last_pn, CCMP_PN_LEN);
3697
for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
3702
rpn = rx->key->u.ccmp.rx_pn[rx->u.rx.queue];
3703
if (memcmp(pn, rpn, CCMP_PN_LEN) != 0) {
3704
printk(KERN_DEBUG "%s: defrag: CCMP PN not sequential"
3705
" A2=" MAC_FMT " PN=%02x%02x%02x%02x%02x%02x "
3706
"(expected %02x%02x%02x%02x%02x%02x)\n",
3707
rx->dev->name, MAC_ARG(hdr->addr2),
3708
rpn[0], rpn[1], rpn[2], rpn[3], rpn[4], rpn[5],
3709
pn[0], pn[1], pn[2], pn[3], pn[4], pn[5]);
3712
memcpy(entry->last_pn, pn, CCMP_PN_LEN);
3715
skb_pull(rx->skb, iwlwifi_ieee80211_get_hdrlen(rx->fc));
3716
__skb_queue_tail(&entry->skb_list, rx->skb);
3717
entry->last_frag = frag;
3718
entry->extra_len += rx->skb->len;
3719
if (rx->fc & IEEE80211_FCTL_MOREFRAGS) {
3724
rx->skb = __skb_dequeue(&entry->skb_list);
3725
if (skb_tailroom(rx->skb) < entry->extra_len) {
3726
I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
3727
if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
3729
I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
3730
__skb_queue_purge(&entry->skb_list);
3734
while ((skb = __skb_dequeue(&entry->skb_list))) {
3735
memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
3739
/* Complete frame has been reassembled - process it now */
3744
rx->sta->rx_packets++;
3745
if (is_multicast_ether_addr(hdr->addr1))
3746
rx->local->dot11MulticastReceivedFrameCount++;
3748
ieee80211_led_rx(rx->local);
3749
return TXRX_CONTINUE;
3753
static ieee80211_txrx_result
3754
ieee80211_rx_h_monitor(struct ieee80211_txrx_data *rx)
3756
if (rx->sdata->type == IEEE80211_IF_TYPE_MNTR) {
3757
ieee80211_rx_monitor(rx->dev, rx->skb, rx->u.rx.status);
3761
if (rx->u.rx.status->flag & RX_FLAG_RADIOTAP)
3762
skb_pull(rx->skb, ieee80211_get_radiotap_len(rx->skb));
3764
return TXRX_CONTINUE;
3768
static ieee80211_txrx_result
3769
ieee80211_rx_h_check(struct ieee80211_txrx_data *rx)
3771
struct ieee80211_hdr *hdr;
3773
hdr = (struct ieee80211_hdr *) rx->skb->data;
3775
/* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
3776
if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) {
3777
if (unlikely(rx->fc & IEEE80211_FCTL_RETRY &&
3778
rx->sta->last_seq_ctrl[rx->u.rx.queue] ==
3780
if (rx->u.rx.ra_match) {
3781
rx->local->dot11FrameDuplicateCount++;
3782
rx->sta->num_duplicates++;
3786
rx->sta->last_seq_ctrl[rx->u.rx.queue] = hdr->seq_ctrl;
3789
if ((rx->local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) &&
3790
rx->skb->len > FCS_LEN)
3791
skb_trim(rx->skb, rx->skb->len - FCS_LEN);
3793
if (unlikely(rx->skb->len < 16)) {
3794
I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
3798
if (!rx->u.rx.ra_match)
3799
rx->skb->pkt_type = PACKET_OTHERHOST;
3800
else if (compare_ether_addr(rx->dev->dev_addr, hdr->addr1) == 0)
3801
rx->skb->pkt_type = PACKET_HOST;
3802
else if (is_multicast_ether_addr(hdr->addr1)) {
3803
if (is_broadcast_ether_addr(hdr->addr1))
3804
rx->skb->pkt_type = PACKET_BROADCAST;
3806
rx->skb->pkt_type = PACKET_MULTICAST;
3808
rx->skb->pkt_type = PACKET_OTHERHOST;
3810
/* Drop disallowed frame classes based on STA auth/assoc state;
3811
* IEEE 802.11, Chap 5.5.
3813
* 80211.o does filtering only based on association state, i.e., it
3814
* drops Class 3 frames from not associated stations. hostapd sends
3815
* deauth/disassoc frames when needed. In addition, hostapd is
3816
* responsible for filtering on both auth and assoc states.
3818
if (unlikely(((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA ||
3819
((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL &&
3820
(rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)) &&
3821
rx->sdata->type != IEEE80211_IF_TYPE_IBSS &&
3822
(!rx->sta || !(rx->sta->flags & WLAN_STA_ASSOC)))) {
3823
if ((!(rx->fc & IEEE80211_FCTL_FROMDS) &&
3824
!(rx->fc & IEEE80211_FCTL_TODS) &&
3825
(rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
3826
|| !rx->u.rx.ra_match) {
3827
/* Drop IBSS frames and frames for other hosts
3832
if (!rx->local->apdev)
3835
ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status,
3836
ieee80211_msg_sta_not_assoc);
3840
if (rx->sdata->type == IEEE80211_IF_TYPE_STA)
3845
if (rx->sta && rx->sta->key && always_sta_key) {
3846
rx->key = rx->sta->key;
3848
if (rx->sta && rx->sta->key)
3849
rx->key = rx->sta->key;
3851
rx->key = rx->sdata->default_key;
3853
if ((rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) &&
3854
rx->fc & IEEE80211_FCTL_PROTECTED) {
3855
int keyidx = ieee80211_wep_get_keyidx(rx->skb);
3857
if (keyidx >= 0 && keyidx < NUM_DEFAULT_KEYS &&
3858
(!rx->sta || !rx->sta->key || keyidx > 0))
3859
rx->key = rx->sdata->keys[keyidx];
3862
if (!rx->u.rx.ra_match)
3864
printk(KERN_DEBUG "%s: RX WEP frame with "
3865
"unknown keyidx %d (A1=" MAC_FMT " A2="
3866
MAC_FMT " A3=" MAC_FMT ")\n",
3867
rx->dev->name, keyidx,
3868
MAC_ARG(hdr->addr1),
3869
MAC_ARG(hdr->addr2),
3870
MAC_ARG(hdr->addr3));
3871
if (!rx->local->apdev)
3874
rx->local, rx->skb, rx->u.rx.status,
3875
ieee80211_msg_wep_frame_unknown_key);
3881
if (rx->fc & IEEE80211_FCTL_PROTECTED && rx->key && rx->u.rx.ra_match) {
3882
rx->key->tx_rx_count++;
3883
if (unlikely(rx->local->key_tx_rx_threshold &&
3884
rx->key->tx_rx_count >
3885
rx->local->key_tx_rx_threshold)) {
3886
ieee80211_key_threshold_notify(rx->dev, rx->key,
3891
return TXRX_CONTINUE;
3895
static ieee80211_txrx_result
3896
ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx)
3898
struct sta_info *sta = rx->sta;
3899
struct net_device *dev = rx->dev;
3900
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
3903
return TXRX_CONTINUE;
3905
/* Update last_rx only for IBSS packets which are for the current
3906
* BSSID to avoid keeping the current IBSS network alive in cases where
3907
* other STAs are using different BSSID. */
3908
if (rx->sdata->type == IEEE80211_IF_TYPE_IBSS) {
3909
u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,IEEE80211_IF_TYPE_IBSS);
3910
if (compare_ether_addr(bssid, rx->sdata->u.sta.bssid) == 0)
3911
sta->last_rx = jiffies;
3913
if (!is_multicast_ether_addr(hdr->addr1) ||
3914
rx->sdata->type == IEEE80211_IF_TYPE_STA) {
3915
/* Update last_rx only for unicast frames in order to prevent
3916
* the Probe Request frames (the only broadcast frames from a
3917
* STA in infrastructure mode) from keeping a connection alive.
3919
sta->last_rx = jiffies;
3922
if (!rx->u.rx.ra_match)
3923
return TXRX_CONTINUE;
3925
sta->rx_fragments++;
3926
sta->rx_bytes += rx->skb->len;
3928
/* Low pass filter: 15/16 current avg + new.
3929
* Accumulated values here are 16x values sent from driver. */
3930
sta->accum_rssi = sta->accum_rssi - (sta->accum_rssi >> 4) +
3931
rx->u.rx.status->ssi;
3932
sta->accum_signal = sta->accum_signal - (sta->accum_signal >> 4) +
3933
rx->u.rx.status->signal;
3934
sta->accum_noise = sta->accum_noise - (sta->accum_noise >> 4) +
3935
rx->u.rx.status->noise;
3937
/* Quantize the averages (divide by 16) */
3938
sta->last_rssi = sta->accum_rssi >> 4;
3939
sta->last_signal = sta->accum_signal >> 4;
3940
sta->last_noise = sta->accum_noise >> 4;
3942
if (!(rx->fc & IEEE80211_FCTL_MOREFRAGS)) {
3943
/* Change STA power saving mode only in the end of a frame
3944
* exchange sequence */
3945
if ((sta->flags & WLAN_STA_PS) && !(rx->fc & IEEE80211_FCTL_PM))
3946
rx->u.rx.sent_ps_buffered += ap_sta_ps_end(dev, sta);
3947
else if (!(sta->flags & WLAN_STA_PS) &&
3948
(rx->fc & IEEE80211_FCTL_PM))
3949
ap_sta_ps_start(dev, sta);
3952
/* Drop data::nullfunc frames silently, since they are used only to
3953
* control station power saving mode. */
3954
if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
3955
(rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_NULLFUNC) {
3956
I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
3957
/* Update counter and free packet here to avoid counting this
3958
* as a dropped packed. */
3960
dev_kfree_skb(rx->skb);
3964
return TXRX_CONTINUE;
3965
} /* ieee80211_rx_h_sta_process */
3968
static ieee80211_txrx_result
3969
ieee80211_rx_h_wep_weak_iv_detection(struct ieee80211_txrx_data *rx)
3971
if (!rx->sta || !(rx->fc & IEEE80211_FCTL_PROTECTED) ||
3972
(rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
3973
!rx->key || rx->key->alg != ALG_WEP || !rx->u.rx.ra_match)
3974
return TXRX_CONTINUE;
3976
/* Check for weak IVs, if hwaccel did not remove IV from the frame */
3977
if ((rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) ||
3978
rx->key->force_sw_encrypt) {
3979
u8 *iv = ieee80211_wep_is_weak_iv(rx->skb, rx->key);
3981
rx->sta->wep_weak_iv_count++;
3985
return TXRX_CONTINUE;
3989
static ieee80211_txrx_result
3990
ieee80211_rx_h_wep_decrypt(struct ieee80211_txrx_data *rx)
3992
/* If the device handles decryption totally, skip this test */
3993
if (rx->local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP)
3994
return TXRX_CONTINUE;
3996
if ((rx->key && rx->key->alg != ALG_WEP) ||
3997
!(rx->fc & IEEE80211_FCTL_PROTECTED) ||
3998
((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
3999
((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
4000
(rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)))
4001
return TXRX_CONTINUE;
4004
printk(KERN_DEBUG "%s: RX WEP frame, but no key set\n",
4009
if (!(rx->u.rx.status->flag & RX_FLAG_DECRYPTED) ||
4010
rx->key->force_sw_encrypt) {
4011
if (ieee80211_wep_decrypt(rx->local, rx->skb, rx->key)) {
4012
printk(KERN_DEBUG "%s: RX WEP frame, decrypt "
4013
"failed\n", rx->dev->name);
4016
} else if (rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) {
4017
ieee80211_wep_remove_iv(rx->local, rx->skb, rx->key);
4019
skb_trim(rx->skb, rx->skb->len - 4);
4022
return TXRX_CONTINUE;
4026
static ieee80211_txrx_result
4027
ieee80211_rx_h_802_1x_pae(struct ieee80211_txrx_data *rx)
4029
if (rx->sdata->eapol && ieee80211_is_eapol(rx->skb) &&
4030
rx->sdata->type != IEEE80211_IF_TYPE_STA && rx->u.rx.ra_match) {
4031
/* Pass both encrypted and unencrypted EAPOL frames to user
4032
* space for processing. */
4033
if (!rx->local->apdev)
4035
ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status,
4036
ieee80211_msg_normal);
4040
if (unlikely(rx->sdata->ieee802_1x &&
4041
(rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
4042
(rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC &&
4043
(!rx->sta || !(rx->sta->flags & WLAN_STA_AUTHORIZED)) &&
4044
!ieee80211_is_eapol(rx->skb))) {
4045
#ifdef CONFIG_MAC80211_DEBUG
4046
struct ieee80211_hdr *hdr =
4047
(struct ieee80211_hdr *) rx->skb->data;
4048
printk(KERN_DEBUG "%s: dropped frame from " MAC_FMT
4049
" (unauthorized port)\n", rx->dev->name,
4050
MAC_ARG(hdr->addr2));
4051
#endif /* CONFIG_MAC80211_DEBUG */
4055
return TXRX_CONTINUE;
4059
static ieee80211_txrx_result
4060
ieee80211_rx_h_drop_unencrypted(struct ieee80211_txrx_data *rx)
4062
/* If the device handles decryption totally, skip this test */
4063
if (rx->local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP)
4064
return TXRX_CONTINUE;
4066
/* Drop unencrypted frames if key is set. */
4067
if (unlikely(!(rx->fc & IEEE80211_FCTL_PROTECTED) &&
4068
(rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
4069
(rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC &&
4070
(rx->key || rx->sdata->drop_unencrypted) &&
4071
(rx->sdata->eapol == 0 ||
4072
!ieee80211_is_eapol(rx->skb)))) {
4073
printk(KERN_DEBUG "%s: RX non-WEP frame, but expected "
4074
"encryption\n", rx->dev->name);
4077
return TXRX_CONTINUE;
4080
static ieee80211_txrx_result
4081
ieee80211_rx_h_ctrl(struct ieee80211_txrx_data *rx)
4083
struct ieee80211_local *local = rx->local;
4084
struct ieee80211_hw *hw = &local->hw;
4085
struct sk_buff *skb = rx->skb;
4086
struct ieee80211_bar *bar = (struct ieee80211_bar *) skb->data;
4087
struct tid_ht_agg_info_rx *tid_rx_info;
4091
if (likely((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL))
4092
return TXRX_CONTINUE;
4094
if ((rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BACK_REQ) {
4096
return TXRX_CONTINUE;
4097
tid = le16_to_cpu(bar->control) >> 12;
4098
tid_rx_info = &(rx->sta->ht_ba_mlme.tid_agg_info_rx[tid]);
4099
if (tid_rx_info->state != HT_AGG_STATE_OPERATIONAL)
4100
return TXRX_CONTINUE;
4102
start_seq_num = le16_to_cpu(bar->start_seq_num) >> 4;
4104
/* reset session timer */
4105
if (tid_rx_info->timeout) {
4106
unsigned long expires = jiffies +
4107
(tid_rx_info->timeout / 1000) * HZ;
4108
mod_timer(&tid_rx_info->session_timer,expires);
4111
/* manage reordering buffer according to requested sequence number */
4112
ieee80211_sta_manage_reorder_buf(hw,rx,tid_rx_info,NULL,
4118
return TXRX_CONTINUE;
4121
static ieee80211_txrx_result
4122
ieee80211_rx_h_mgmt(struct ieee80211_txrx_data *rx)
4124
struct ieee80211_sub_if_data *sdata;
4125
struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
4127
if (!rx->u.rx.ra_match)
4130
sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
4131
if ((sdata->type == IEEE80211_IF_TYPE_STA ||
4132
sdata->type == IEEE80211_IF_TYPE_IBSS) &&
4133
!rx->local->user_space_mlme) {
4134
ieee80211_sta_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status);
4135
} else if ((sdata->type == IEEE80211_IF_TYPE_AP) &&
4136
((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
4137
((rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ACTION) &&
4138
(mgmt->u.action.category == WLAN_CATEGORY_BACK)){
4139
/* 11n is not implemented yet in hostapd,so process in mac80211 */
4140
ieee80211_rx_mgmt_action(rx->dev,NULL,mgmt,rx->skb->len);
4142
/* Management frames are sent to hostapd for processing */
4143
if (!rx->local->apdev)
4145
ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status,
4146
ieee80211_msg_normal);
4152
static ieee80211_txrx_result
4153
ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data *rx)
4155
struct ieee80211_local *local = rx->local;
4156
struct sk_buff *skb = rx->skb;
4158
if (unlikely(local->sta_hw_scanning != 0))
4159
return ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status);
4161
if (unlikely(local->sta_sw_scanning != 0)) {
4162
/* drop all the other packets during a software scan anyway */
4163
if (ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status)
4169
if (unlikely(rx->u.rx.in_scan)) {
4170
/* scanning finished during invoking of handlers */
4171
I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
4175
return TXRX_CONTINUE;
4179
static void ieee80211_rx_michael_mic_report(struct net_device *dev,
4180
struct ieee80211_hdr *hdr,
4181
struct sta_info *sta,
4182
struct ieee80211_txrx_data *rx)
4186
hdrlen = iwlwifi_iwlwifi_ieee80211_get_hdrlen_from_skb(rx->skb);
4187
if (rx->skb->len >= hdrlen + 4)
4188
keyidx = rx->skb->data[hdrlen + 3] >> 6;
4192
/* TODO: verify that this is not triggered by fragmented
4193
* frames (hw does not verify MIC for them). */
4194
printk(KERN_DEBUG "%s: TKIP hwaccel reported Michael MIC "
4195
"failure from " MAC_FMT " to " MAC_FMT " keyidx=%d\n",
4196
dev->name, MAC_ARG(hdr->addr2), MAC_ARG(hdr->addr1), keyidx);
4199
/* Some hardware versions seem to generate incorrect
4200
* Michael MIC reports; ignore them to avoid triggering
4201
* countermeasures. */
4202
printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
4203
"error for unknown address " MAC_FMT "\n",
4204
dev->name, MAC_ARG(hdr->addr2));
4208
if (!(rx->fc & IEEE80211_FCTL_PROTECTED)) {
4209
printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
4210
"error for a frame with no ISWEP flag (src "
4211
MAC_FMT ")\n", dev->name, MAC_ARG(hdr->addr2));
4215
if ((rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) &&
4216
rx->sdata->type == IEEE80211_IF_TYPE_AP) {
4217
keyidx = ieee80211_wep_get_keyidx(rx->skb);
4218
/* AP with Pairwise keys support should never receive Michael
4219
* MIC errors for non-zero keyidx because these are reserved
4220
* for group keys and only the AP is sending real multicast
4223
printk(KERN_DEBUG "%s: ignored Michael MIC error for "
4224
"a frame with non-zero keyidx (%d) (src " MAC_FMT
4225
")\n", dev->name, keyidx, MAC_ARG(hdr->addr2));
4230
if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
4231
((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
4232
(rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)) {
4233
printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
4234
"error for a frame that cannot be encrypted "
4235
"(fc=0x%04x) (src " MAC_FMT ")\n",
4236
dev->name, rx->fc, MAC_ARG(hdr->addr2));
4241
union iwreq_data wrqu;
4242
char *buf = kmalloc(128, GFP_ATOMIC);
4246
/* TODO: needed parameters: count, key type, TSC */
4247
sprintf(buf, "MLME-MICHAELMICFAILURE.indication("
4248
"keyid=%d %scast addr=" MAC_FMT ")",
4249
keyidx, hdr->addr1[0] & 0x01 ? "broad" : "uni",
4250
MAC_ARG(hdr->addr2));
4251
memset(&wrqu, 0, sizeof(wrqu));
4252
wrqu.data.length = strlen(buf);
4253
wireless_send_event(rx->dev, IWEVCUSTOM, &wrqu, buf);
4257
/* TODO: consider verifying the MIC error report with software
4258
* implementation if we get too many spurious reports from the
4260
if (!rx->local->apdev)
4262
ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status,
4263
ieee80211_msg_michael_mic_failure);
4267
dev_kfree_skb(rx->skb);
4271
static inline ieee80211_txrx_result __ieee80211_invoke_rx_handlers(
4272
struct ieee80211_local *local,
4273
ieee80211_rx_handler *handlers,
4274
struct ieee80211_txrx_data *rx,
4275
struct sta_info *sta)
4277
ieee80211_rx_handler *handler;
4278
ieee80211_txrx_result res = TXRX_DROP;
4280
for (handler = handlers; *handler != NULL; handler++) {
4281
res = (*handler)(rx);
4282
if (res != TXRX_CONTINUE) {
4283
if (res == TXRX_DROP) {
4284
I802_DEBUG_INC(local->rx_handlers_drop);
4288
if (res == TXRX_QUEUED)
4289
I802_DEBUG_INC(local->rx_handlers_queued);
4294
if (res == TXRX_DROP) {
4295
dev_kfree_skb(rx->skb);
4300
static inline void ieee80211_invoke_rx_handlers(struct ieee80211_local *local,
4301
ieee80211_rx_handler *handlers,
4302
struct ieee80211_txrx_data *rx,
4303
struct sta_info *sta)
4305
if (__ieee80211_invoke_rx_handlers(local, handlers, rx, sta) ==
4307
dev_kfree_skb(rx->skb);
4311
* This is the receive path handler. It is called by a low level driver when an
4312
* 802.11 MPDU is received from the hardware.
4314
void iwlwifi___ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
4315
struct ieee80211_rx_status *status)
4317
struct ieee80211_local *local = hw_to_local(hw);
4318
struct ieee80211_sub_if_data *sdata;
4319
struct sta_info *sta;
4320
struct ieee80211_hdr *hdr;
4321
struct ieee80211_txrx_data rx;
4324
int radiotap_len = 0;
4326
if (status->flag & RX_FLAG_RADIOTAP) {
4327
radiotap_len = ieee80211_get_radiotap_len(skb);
4328
skb_pull(skb, radiotap_len);
4331
hdr = (struct ieee80211_hdr *) skb->data;
4332
memset(&rx, 0, sizeof(rx));
4336
rx.u.rx.status = status;
4337
rx.fc = skb->len >= 2 ? le16_to_cpu(hdr->frame_control) : 0;
4338
type = rx.fc & IEEE80211_FCTL_FTYPE;
4339
if (type == IEEE80211_FTYPE_DATA || type == IEEE80211_FTYPE_MGMT)
4340
local->dot11ReceivedFragmentCount++;
4341
multicast = is_multicast_ether_addr(hdr->addr1);
4344
sta = rx.sta = iwlwifi_sta_info_get(local, hdr->addr2);
4346
sta = rx.sta = NULL;
4350
rx.sdata = IEEE80211_DEV_TO_SUB_IF(rx.dev);
4353
if ((status->flag & RX_FLAG_MMIC_ERROR)) {
4354
ieee80211_rx_michael_mic_report(local->mdev, hdr, sta, &rx);
4358
if (unlikely(local->sta_sw_scanning || local->sta_hw_scanning))
4359
rx.u.rx.in_scan = 1;
4361
if (__ieee80211_invoke_rx_handlers(local, local->rx_pre_handlers, &rx,
4362
sta) != TXRX_CONTINUE)
4366
skb_push(skb, radiotap_len);
4367
if (sta && !sta->assoc_ap && !(sta->flags & WLAN_STA_WDS) &&
4368
!local->iff_promiscs && !multicast) {
4369
rx.u.rx.ra_match = 1;
4370
ieee80211_invoke_rx_handlers(local, local->rx_handlers, &rx,
4373
struct ieee80211_sub_if_data *prev = NULL;
4374
struct sk_buff *skb_new;
4377
read_lock(&local->sub_if_lock);
4378
list_for_each_entry(sdata, &local->sub_if_list, list) {
4379
bssid = ieee80211_get_bssid(hdr,
4380
skb->len - radiotap_len,
4382
rx.u.rx.ra_match = 1;
4383
switch (sdata->type) {
4384
case IEEE80211_IF_TYPE_STA:
4387
if (!ieee80211_bssid_match(bssid,
4388
sdata->u.sta.bssid)) {
4389
if (!rx.u.rx.in_scan)
4391
rx.u.rx.ra_match = 0;
4392
} else if (!multicast &&
4393
compare_ether_addr(sdata->dev->dev_addr,
4395
if (!sdata->promisc)
4397
rx.u.rx.ra_match = 0;
4400
case IEEE80211_IF_TYPE_IBSS:
4403
if (!ieee80211_bssid_match(bssid,
4404
sdata->u.sta.bssid)) {
4405
if (!rx.u.rx.in_scan)
4407
rx.u.rx.ra_match = 0;
4408
} else if (!multicast &&
4409
compare_ether_addr(sdata->dev->dev_addr,
4411
if (!sdata->promisc)
4413
rx.u.rx.ra_match = 0;
4416
ieee80211_ibss_add_sta(sdata->dev,
4420
case IEEE80211_IF_TYPE_AP:
4422
if (compare_ether_addr(sdata->dev->dev_addr,
4425
} else if (!ieee80211_bssid_match(bssid,
4426
sdata->dev->dev_addr)) {
4427
if (!rx.u.rx.in_scan)
4429
rx.u.rx.ra_match = 0;
4431
if (sdata->dev == local->mdev &&
4433
/* do not receive anything via
4434
* master device when not scanning */
4437
case IEEE80211_IF_TYPE_WDS:
4439
(rx.fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
4441
if (compare_ether_addr(sdata->u.wds.remote_addr,
4448
skb_new = skb_copy(skb, GFP_ATOMIC);
4450
if (net_ratelimit())
4451
printk(KERN_DEBUG "%s: failed to copy "
4452
"multicast frame for %s",
4453
local->mdev->name, prev->dev->name);
4459
ieee80211_invoke_rx_handlers(local,
4469
ieee80211_invoke_rx_handlers(local, local->rx_handlers,
4473
read_unlock(&local->sub_if_lock);
4478
iwlwifi_sta_info_put(sta);
4480
EXPORT_SYMBOL(iwlwifi___ieee80211_rx);
4482
static ieee80211_txrx_result
4483
ieee80211_tx_h_load_stats(struct ieee80211_txrx_data *tx)
4485
struct ieee80211_local *local = tx->local;
4486
struct ieee80211_hw_mode *mode = tx->u.tx.mode;
4487
struct sk_buff *skb = tx->skb;
4488
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
4489
u32 load = 0, hdrtime;
4491
/* TODO: this could be part of tx_status handling, so that the number
4492
* of retries would be known; TX rate should in that case be stored
4493
* somewhere with the packet */
4495
/* Estimate total channel use caused by this frame */
4497
/* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
4498
* 1 usec = 1/8 * (1080 / 10) = 13.5 */
4500
if (mode->mode == MODE_IEEE80211A ||
4501
mode->mode == MODE_ATHEROS_TURBO ||
4502
mode->mode == MODE_ATHEROS_TURBOG ||
4503
(mode->mode == MODE_IEEE80211G &&
4504
tx->u.tx.rate->flags & IEEE80211_RATE_ERP))
4505
hdrtime = CHAN_UTIL_HDR_SHORT;
4507
hdrtime = CHAN_UTIL_HDR_LONG;
4510
if (!is_multicast_ether_addr(hdr->addr1))
4513
if (tx->u.tx.control->flags & IEEE80211_TXCTL_USE_RTS_CTS)
4514
load += 2 * hdrtime;
4515
else if (tx->u.tx.control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)
4518
load += skb->len * tx->u.tx.rate->rate_inv;
4520
if (tx->u.tx.extra_frag) {
4522
for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
4523
load += 2 * hdrtime;
4524
load += tx->u.tx.extra_frag[i]->len *
4525
tx->u.tx.rate->rate;
4529
/* Divide channel_use by 8 to avoid wrapping around the counter */
4530
load >>= CHAN_UTIL_SHIFT;
4531
local->channel_use_raw += load;
4533
tx->sta->channel_use_raw += load;
4534
tx->sdata->channel_use_raw += load;
4536
return TXRX_CONTINUE;
4540
static ieee80211_txrx_result
4541
ieee80211_rx_h_reorder_ampdu(struct ieee80211_txrx_data *rx)
4543
struct ieee80211_local *local = rx->local;
4544
struct ieee80211_hw *hw = &local->hw;
4545
struct sk_buff *skb = rx->skb;
4546
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
4547
struct tid_ht_agg_info_rx *tid_rx_info;
4552
return TXRX_CONTINUE;
4554
tid_rx_info = &(rx->sta->ht_ba_mlme.tid_agg_info_rx[rx->u.rx.queue]);
4556
/* filter the QoS data rx stream according to STA/TID
4557
* and check if this STA/TID is on aggregation */
4558
if ((tid_rx_info->state != HT_AGG_STATE_OPERATIONAL)
4559
|| ((rx->fc & 0x00CC) != (IEEE80211_STYPE_QOS_DATA |
4560
IEEE80211_FTYPE_DATA)))
4561
return TXRX_CONTINUE;
4563
/* check if this frame has already been queued and ordered */
4564
if(rx->u.rx.status->ordered == TXRX_QUEUED)
4565
return TXRX_CONTINUE;
4567
/* check if this frame has already been queued and ordered but
4568
* should be deleted */
4569
if(rx->u.rx.status->ordered == TXRX_DROP) {
4575
/* new un-ordered ampdu frame - process it */
4577
/* reset session timer */
4578
if (tid_rx_info->timeout) {
4579
unsigned long expires = jiffies + (tid_rx_info->timeout / 1000) * HZ;
4580
mod_timer(&tid_rx_info->session_timer,expires);
4583
/* if this mpdu is fragmented - terminate rx aggregation session */
4584
sc = le16_to_cpu(hdr->seq_ctrl);
4585
if (sc & IEEE80211_SCTL_FRAG) {
4586
ieee80211_sta_stop_rx_BA_session(rx->dev,rx->sta->addr,rx->u.rx.queue,
4587
0,WLAN_REASON_QSTA_REQUIRE_SETUP);
4588
return TXRX_CONTINUE;
4591
/* according to mpdu sequence number deal with reordering buffer */
4592
mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
4593
return ieee80211_sta_manage_reorder_buf(hw,rx,tid_rx_info,skb,
4598
static ieee80211_txrx_result
4599
ieee80211_rx_h_load_stats(struct ieee80211_txrx_data *rx)
4601
struct ieee80211_local *local = rx->local;
4602
struct sk_buff *skb = rx->skb;
4603
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
4604
u32 load = 0, hdrtime;
4605
struct ieee80211_rate *rate;
4606
struct ieee80211_hw_mode *mode = local->hw.conf.mode;
4609
/* Estimate total channel use caused by this frame */
4611
if (unlikely(mode->num_rates < 0) || (rx->u.rx.status->ordered != 0))
4612
return TXRX_CONTINUE;
4614
rate = &mode->rates[0];
4615
for (i = 0; i < mode->num_rates; i++) {
4616
if (mode->rates[i].val == rx->u.rx.status->rate) {
4617
rate = &mode->rates[i];
4622
/* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
4623
* 1 usec = 1/8 * (1080 / 10) = 13.5 */
4625
if (mode->mode == MODE_IEEE80211A ||
4626
mode->mode == MODE_ATHEROS_TURBO ||
4627
mode->mode == MODE_ATHEROS_TURBOG ||
4628
(mode->mode == MODE_IEEE80211G &&
4629
rate->flags & IEEE80211_RATE_ERP))
4630
hdrtime = CHAN_UTIL_HDR_SHORT;
4632
hdrtime = CHAN_UTIL_HDR_LONG;
4635
if (!is_multicast_ether_addr(hdr->addr1))
4638
load += skb->len * rate->rate_inv;
4640
/* Divide channel_use by 8 to avoid wrapping around the counter */
4641
load >>= CHAN_UTIL_SHIFT;
4642
local->channel_use_raw += load;
4644
rx->sta->channel_use_raw += load;
4645
rx->u.rx.load = load;
4647
return TXRX_CONTINUE;
4650
static ieee80211_txrx_result
4651
ieee80211_rx_h_if_stats(struct ieee80211_txrx_data *rx)
4653
rx->sdata->channel_use_raw += rx->u.rx.load;
4654
return TXRX_CONTINUE;
4657
static void ieee80211_stat_refresh(unsigned long data)
4659
struct ieee80211_local *local = (struct ieee80211_local *) data;
4660
struct sta_info *sta;
4661
struct ieee80211_sub_if_data *sdata;
4663
if (!local->stat_time)
4666
/* go through all stations */
4667
spin_lock_bh(&local->sta_lock);
4668
list_for_each_entry(sta, &local->sta_list, list) {
4669
sta->channel_use = (sta->channel_use_raw / local->stat_time) /
4671
sta->channel_use_raw = 0;
4673
spin_unlock_bh(&local->sta_lock);
4675
/* go through all subinterfaces */
4676
read_lock(&local->sub_if_lock);
4677
list_for_each_entry(sdata, &local->sub_if_list, list) {
4678
sdata->channel_use = (sdata->channel_use_raw /
4679
local->stat_time) / CHAN_UTIL_PER_10MS;
4680
sdata->channel_use_raw = 0;
4682
read_unlock(&local->sub_if_lock);
4684
/* hardware interface */
4685
local->channel_use = (local->channel_use_raw /
4686
local->stat_time) / CHAN_UTIL_PER_10MS;
4687
local->channel_use_raw = 0;
4689
local->stat_timer.expires = jiffies + HZ * local->stat_time / 100;
4690
add_timer(&local->stat_timer);
4694
/* This is a version of the rx handler that can be called from hard irq
4695
* context. Post the skb on the queue and schedule the tasklet */
4696
void iwlwifi_ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb,
4697
struct ieee80211_rx_status *status)
4699
struct ieee80211_local *local = hw_to_local(hw);
4701
BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
4703
skb->dev = local->mdev;
4704
/* copy status into skb->cb for use by tasklet */
4705
memcpy(skb->cb, status, sizeof(*status));
4706
skb->pkt_type = IEEE80211_RX_MSG;
4707
skb_queue_tail(&local->skb_queue, skb);
4708
tasklet_schedule(&local->tasklet);
4710
EXPORT_SYMBOL(iwlwifi_ieee80211_rx_irqsafe);
4712
void iwlwifi_iwlwifi_ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
4713
struct sk_buff *skb,
4714
struct iwlwifi_ieee80211_tx_status *status)
4716
struct ieee80211_local *local = hw_to_local(hw);
4717
struct iwlwifi_ieee80211_tx_status *saved;
4720
skb->dev = local->mdev;
4721
saved = kmalloc(sizeof(struct iwlwifi_ieee80211_tx_status), GFP_ATOMIC);
4722
if (unlikely(!saved)) {
4723
if (net_ratelimit())
4724
printk(KERN_WARNING "%s: Not enough memory, "
4725
"dropping tx status", skb->dev->name);
4726
/* should be dev_kfree_skb_irq, but due to this function being
4727
* named _irqsafe instead of just _irq we can't be sure that
4728
* people won't call it from non-irq contexts */
4729
dev_kfree_skb_any(skb);
4732
memcpy(saved, status, sizeof(struct iwlwifi_ieee80211_tx_status));
4733
/* copy pointer to saved status into skb->cb for use by tasklet */
4734
memcpy(skb->cb, &saved, sizeof(saved));
4736
skb->pkt_type = IEEE80211_TX_STATUS_MSG;
4737
skb_queue_tail(status->control.flags & IEEE80211_TXCTL_REQ_TX_STATUS ?
4738
&local->skb_queue : &local->skb_queue_unreliable, skb);
4739
tmp = skb_queue_len(&local->skb_queue) +
4740
skb_queue_len(&local->skb_queue_unreliable);
4741
while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
4742
(skb = skb_dequeue(&local->skb_queue_unreliable))) {
4743
memcpy(&saved, skb->cb, sizeof(saved));
4745
dev_kfree_skb_irq(skb);
4747
I802_DEBUG_INC(local->tx_status_drop);
4749
tasklet_schedule(&local->tasklet);
4751
EXPORT_SYMBOL(iwlwifi_iwlwifi_ieee80211_tx_status_irqsafe);
4753
static void ieee80211_tasklet_handler(unsigned long data)
4755
struct ieee80211_local *local = (struct ieee80211_local *) data;
4756
struct sk_buff *skb;
4757
struct ieee80211_rx_status rx_status;
4758
struct iwlwifi_ieee80211_tx_status *tx_status;
4760
while ((skb = skb_dequeue(&local->skb_queue)) ||
4761
(skb = skb_dequeue(&local->skb_queue_unreliable))) {
4762
switch (skb->pkt_type) {
4763
case IEEE80211_RX_MSG:
4764
/* status is in skb->cb */
4765
memcpy(&rx_status, skb->cb, sizeof(rx_status));
4766
/* Clear skb->type in order to not confuse kernel
4769
iwlwifi___ieee80211_rx(local_to_hw(local), skb, &rx_status);
4771
case IEEE80211_TX_STATUS_MSG:
4772
/* get pointer to saved status out of skb->cb */
4773
memcpy(&tx_status, skb->cb, sizeof(tx_status));
4775
iwlwifi_ieee80211_tx_status(local_to_hw(local),
4779
default: /* should never get here! */
4780
printk(KERN_ERR "%s: Unknown message type (%d)\n",
4781
local->mdev->name, skb->pkt_type);
4789
/* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
4790
* make a prepared TX frame (one that has been given to hw) to look like brand
4791
* new IEEE 802.11 frame that is ready to go through TX processing again.
4792
* Also, tx_packet_data in cb is restored from tx_control. */
4793
static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
4794
struct ieee80211_key *key,
4795
struct sk_buff *skb,
4796
struct ieee80211_tx_control *control)
4798
int hdrlen, iv_len, mic_len;
4799
struct ieee80211_tx_packet_data *pkt_data;
4801
pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
4802
pkt_data->ifindex = control->ifindex;
4803
pkt_data->mgmt_iface = (control->type == IEEE80211_IF_TYPE_MGMT);
4804
pkt_data->req_tx_status = !!(control->flags & IEEE80211_TXCTL_REQ_TX_STATUS);
4805
pkt_data->do_not_encrypt = !!(control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT);
4806
pkt_data->requeue = !!(control->flags & IEEE80211_TXCTL_REQUEUE);
4807
pkt_data->queue = control->queue;
4809
hdrlen = iwlwifi_iwlwifi_ieee80211_get_hdrlen_from_skb(skb);
4816
iv_len = WEP_IV_LEN;
4817
mic_len = WEP_ICV_LEN;
4820
iv_len = TKIP_IV_LEN;
4821
mic_len = TKIP_ICV_LEN;
4824
iv_len = CCMP_HDR_LEN;
4825
mic_len = CCMP_MIC_LEN;
4831
if (skb->len >= mic_len && key->force_sw_encrypt)
4832
skb_trim(skb, skb->len - mic_len);
4833
if (skb->len >= iv_len && skb->len > hdrlen) {
4834
memmove(skb->data + iv_len, skb->data, hdrlen);
4835
skb_pull(skb, iv_len);
4840
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
4841
u16 fc = le16_to_cpu(hdr->frame_control);
4842
if ((fc & 0x8C) == 0x88) /* QoS Control Field */ {
4843
fc &= ~IEEE80211_STYPE_QOS_DATA;
4844
hdr->frame_control = cpu_to_le16(fc);
4845
memmove(skb->data + 2, skb->data, hdrlen - 2);
4852
void iwlwifi_ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
4853
struct iwlwifi_ieee80211_tx_status *status)
4855
struct sk_buff *skb2;
4856
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
4857
struct ieee80211_local *local = hw_to_local(hw);
4860
struct iwlwifi_ieee80211_tx_status_rtap_hdr *rthdr;
4861
struct ieee80211_sub_if_data *sdata;
4866
"%s: iwlwifi_ieee80211_tx_status called with NULL status\n",
4872
if (status->excessive_retries) {
4873
struct sta_info *sta;
4874
sta = iwlwifi_sta_info_get(local, hdr->addr1);
4876
if (sta->flags & WLAN_STA_PS) {
4877
/* The STA is in power save mode, so assume
4878
* that this TX packet failed because of that.
4880
status->excessive_retries = 0;
4881
status->flags |= IEEE80211_TX_STATUS_TX_FILTERED;
4883
iwlwifi_sta_info_put(sta);
4887
if (status->flags & IEEE80211_TX_STATUS_TX_FILTERED) {
4888
struct sta_info *sta;
4889
sta = iwlwifi_sta_info_get(local, hdr->addr1);
4891
sta->tx_filtered_count++;
4893
/* Clear the TX filter mask for this STA when sending
4894
* the next packet. If the STA went to power save mode,
4895
* this will happen when it is waking up for the next
4897
sta->clear_dst_mask = 1;
4899
/* TODO: Is the WLAN_STA_PS flag always set here or is
4900
* the race between RX and TX status causing some
4901
* packets to be filtered out before 80211.o gets an
4902
* update for PS status? This seems to be the case, so
4903
* no changes are likely to be needed. */
4904
if (sta->flags & WLAN_STA_PS &&
4905
skb_queue_len(&sta->tx_filtered) <
4906
STA_MAX_TX_BUFFER) {
4907
ieee80211_remove_tx_extra(local, sta->key,
4910
skb_queue_tail(&sta->tx_filtered, skb);
4911
} else if (!(sta->flags & WLAN_STA_PS) &&
4912
!(status->control.flags & IEEE80211_TXCTL_REQUEUE)) {
4913
/* Software retry the packet once */
4914
status->control.flags |= IEEE80211_TXCTL_REQUEUE;
4915
ieee80211_remove_tx_extra(local, sta->key,
4918
dev_queue_xmit(skb);
4920
if (net_ratelimit()) {
4921
printk(KERN_DEBUG "%s: dropped TX "
4922
"filtered frame queue_len=%d "
4927
!!(sta->flags & WLAN_STA_PS),
4932
iwlwifi_sta_info_put(sta);
4936
/* FIXME: STUPID to call this with both local and local->mdev */
4937
rate_control_tx_status(local, local->mdev, skb, status);
4940
ieee80211_led_tx(local, 0);
4943
* Fragments are passed to low-level drivers as separate skbs, so these
4944
* are actually fragments, not frames. Update frame counters only for
4945
* the first fragment of the frame. */
4947
frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
4948
type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
4950
if (status->flags & IEEE80211_TX_STATUS_ACK) {
4952
local->dot11TransmittedFrameCount++;
4953
if (is_multicast_ether_addr(hdr->addr1))
4954
local->dot11MulticastTransmittedFrameCount++;
4955
if (status->retry_count > 0)
4956
local->dot11RetryCount++;
4957
if (status->retry_count > 1)
4958
local->dot11MultipleRetryCount++;
4961
/* This counter shall be incremented for an acknowledged MPDU
4962
* with an individual address in the address 1 field or an MPDU
4963
* with a multicast address in the address 1 field of type Data
4965
if (!is_multicast_ether_addr(hdr->addr1) ||
4966
type == IEEE80211_FTYPE_DATA ||
4967
type == IEEE80211_FTYPE_MGMT)
4968
local->dot11TransmittedFragmentCount++;
4971
local->dot11FailedCount++;
4974
msg_type = (status->flags & IEEE80211_TX_STATUS_ACK) ?
4975
ieee80211_msg_tx_callback_ack : ieee80211_msg_tx_callback_fail;
4977
/* this was a transmitted frame, but now we want to reuse it */
4980
if ((status->control.flags & IEEE80211_TXCTL_REQ_TX_STATUS) &&
4982
if (local->monitors) {
4983
skb2 = skb_clone(skb, GFP_ATOMIC);
4990
/* Send frame to hostapd */
4991
ieee80211_rx_mgmt(local, skb2, NULL, msg_type);
4997
if (!local->monitors) {
5002
/* send frame to monitor interfaces now */
5004
if (skb_headroom(skb) < sizeof(*rthdr)) {
5005
printk(KERN_ERR "iwlwifi_ieee80211_tx_status: headroom too small\n");
5010
rthdr = (struct iwlwifi_ieee80211_tx_status_rtap_hdr*)
5011
skb_push(skb, sizeof(*rthdr));
5013
memset(rthdr, 0, sizeof(*rthdr));
5014
rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
5015
rthdr->hdr.it_present =
5016
cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
5017
(1 << IEEE80211_RADIOTAP_DATA_RETRIES));
5019
if (!(status->flags & IEEE80211_TX_STATUS_ACK) &&
5020
!is_multicast_ether_addr(hdr->addr1))
5021
rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL);
5023
if ((status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS) &&
5024
(status->control.flags & IEEE80211_TXCTL_USE_CTS_PROTECT))
5025
rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS);
5026
else if (status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS)
5027
rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS);
5029
rthdr->data_retries = status->retry_count;
5031
read_lock(&local->sub_if_lock);
5032
monitors = local->monitors;
5033
list_for_each_entry(sdata, &local->sub_if_list, list) {
5035
* Using the monitors counter is possibly racy, but
5036
* if the value is wrong we simply either clone the skb
5037
* once too much or forget sending it to one monitor iface
5038
* The latter case isn't nice but fixing the race is much
5041
if (!monitors || !skb)
5044
if (sdata->type == IEEE80211_IF_TYPE_MNTR) {
5045
if (!netif_running(sdata->dev))
5049
skb2 = skb_clone(skb, GFP_KERNEL);
5052
skb->dev = sdata->dev;
5053
/* XXX: is this sufficient for BPF? */
5054
skb_set_mac_header(skb, 0);
5055
skb->ip_summed = CHECKSUM_UNNECESSARY;
5056
skb->pkt_type = PACKET_OTHERHOST;
5057
skb->protocol = htons(ETH_P_802_2);
5058
memset(skb->cb, 0, sizeof(skb->cb));
5064
read_unlock(&local->sub_if_lock);
5068
EXPORT_SYMBOL(iwlwifi_ieee80211_tx_status);
5070
/* TODO: implement register/unregister functions for adding TX/RX handlers
5071
* into ordered list */
5073
/* rx_pre handlers don't have dev and sdata fields available in
5074
* ieee80211_txrx_data */
5075
static ieee80211_rx_handler ieee80211_rx_pre_handlers[] =
5077
ieee80211_rx_h_parse_qos,
5078
ieee80211_rx_h_load_stats,
5079
ieee80211_rx_h_reorder_ampdu,
5083
static ieee80211_rx_handler ieee80211_rx_handlers[] =
5085
ieee80211_rx_h_if_stats,
5086
ieee80211_rx_h_monitor,
5087
ieee80211_rx_h_passive_scan,
5088
ieee80211_rx_h_check,
5089
ieee80211_rx_h_sta_process,
5090
ieee80211_rx_h_ccmp_decrypt,
5091
ieee80211_rx_h_tkip_decrypt,
5092
ieee80211_rx_h_wep_weak_iv_detection,
5093
ieee80211_rx_h_wep_decrypt,
5094
ieee80211_rx_h_defragment,
5095
ieee80211_rx_h_ps_poll,
5096
ieee80211_rx_h_michael_mic_verify,
5097
/* this must be after decryption - so header is counted in MPDU mic
5098
* must be before pae and data, so QOS_DATA format frames
5099
* are not passed to user space by these functions
5101
ieee80211_rx_h_remove_qos_control,
5102
ieee80211_rx_h_802_1x_pae,
5103
ieee80211_rx_h_drop_unencrypted,
5104
ieee80211_rx_h_data_agg,
5105
ieee80211_rx_h_data,
5106
ieee80211_rx_h_ctrl,
5107
ieee80211_rx_h_mgmt,
5111
static ieee80211_tx_handler ieee80211_tx_handlers[] =
5113
ieee80211_tx_h_check_assoc,
5114
ieee80211_tx_h_sequence,
5115
ieee80211_tx_h_ps_buf,
5116
ieee80211_tx_h_select_key,
5117
ieee80211_tx_h_michael_mic_add,
5118
ieee80211_tx_h_fragment,
5119
ieee80211_tx_h_tkip_encrypt,
5120
ieee80211_tx_h_ccmp_encrypt,
5121
ieee80211_tx_h_wep_encrypt,
5122
ieee80211_tx_h_rate_ctrl,
5123
ieee80211_tx_h_misc,
5124
ieee80211_tx_h_load_stats,
5129
int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr)
5131
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
5132
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5133
struct sta_info *sta;
5135
if (compare_ether_addr(remote_addr, sdata->u.wds.remote_addr) == 0)
5138
/* Create STA entry for the new peer */
5139
sta = sta_info_add(local, dev, remote_addr, GFP_KERNEL);
5142
iwlwifi_sta_info_put(sta);
5144
/* Remove STA entry for the old peer */
5145
sta = iwlwifi_sta_info_get(local, sdata->u.wds.remote_addr);
5147
iwlwifi_sta_info_put(sta);
5148
sta_info_free(sta, 0);
5150
printk(KERN_DEBUG "%s: could not find STA entry for WDS link "
5151
"peer " MAC_FMT "\n",
5152
dev->name, MAC_ARG(sdata->u.wds.remote_addr));
5155
/* Update WDS link data */
5156
memcpy(&sdata->u.wds.remote_addr, remote_addr, ETH_ALEN);
5161
static const struct header_ops ieee80211_header_ops = {
5162
.create = eth_header,
5163
.parse = header_parse_80211,
5164
.rebuild = eth_rebuild_header,
5165
.cache = eth_header_cache,
5166
.cache_update = eth_header_cache_update,
5169
/* Must not be called for mdev and apdev */
5170
void ieee80211_if_setup(struct net_device *dev)
5173
dev->hard_start_xmit = ieee80211_subif_start_xmit;
5174
dev->wireless_handlers = &ieee80211_iw_handler_def;
5175
dev->set_multicast_list = ieee80211_set_multicast_list;
5176
dev->change_mtu = ieee80211_change_mtu;
5177
dev->get_stats = ieee80211_get_stats;
5178
dev->open = ieee80211_open;
5179
dev->stop = ieee80211_stop;
5180
dev->uninit = ieee80211_if_reinit;
5181
dev->destructor = ieee80211_if_free;
5184
void ieee80211_if_mgmt_setup(struct net_device *dev)
5187
dev->hard_start_xmit = ieee80211_mgmt_start_xmit;
5188
dev->change_mtu = ieee80211_change_mtu_apdev;
5189
dev->get_stats = ieee80211_get_stats;
5190
dev->open = ieee80211_mgmt_open;
5191
dev->stop = ieee80211_mgmt_stop;
5192
dev->type = ARPHRD_IEEE80211_PRISM;
5193
dev->uninit = ieee80211_if_reinit;
5194
dev->destructor = ieee80211_if_free;
5197
int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
5200
struct rate_control_ref *ref, *old;
5203
if (local->open_count || netif_running(local->mdev) ||
5204
(local->apdev && netif_running(local->apdev)))
5207
ref = rate_control_alloc(name, local);
5209
printk(KERN_WARNING "%s: Failed to select rate control "
5210
"algorithm\n", local->mdev->name);
5214
old = local->rate_ctrl;
5215
local->rate_ctrl = ref;
5217
rate_control_put(old);
5218
sta_info_flush(local, NULL);
5221
printk(KERN_DEBUG "%s: Selected rate control "
5222
"algorithm '%s'\n", local->mdev->name,
5229
static void rate_control_deinitialize(struct ieee80211_local *local)
5231
struct rate_control_ref *ref;
5233
ref = local->rate_ctrl;
5234
local->rate_ctrl = NULL;
5235
rate_control_put(ref);
5238
struct ieee80211_hw *iwlwifi_ieee80211_alloc_hw(size_t priv_data_len,
5239
const struct ieee80211_ops *ops)
5241
struct net_device *mdev;
5242
struct ieee80211_local *local;
5243
struct ieee80211_sub_if_data *sdata;
5245
struct wiphy *wiphy;
5247
/* Ensure 32-byte alignment of our private data and hw private data.
5248
* We use the wiphy priv data for both our ieee80211_local and for
5249
* the driver's private data
5251
* In memory it'll be like this:
5253
* +-------------------------+
5255
* +-------------------------+
5256
* | struct ieee80211_local |
5257
* +-------------------------+
5258
* | driver's private data |
5259
* +-------------------------+
5262
priv_size = ((sizeof(struct ieee80211_local) +
5263
NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) +
5266
wiphy = wiphy_new(&mac80211_config_ops, priv_size);
5271
wiphy->privid = mac80211_wiphy_privid;
5273
local = wiphy_priv(wiphy);
5274
local->hw.wiphy = wiphy;
5276
local->hw.priv = (char *)local +
5277
((sizeof(struct ieee80211_local) +
5278
NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
5281
BUG_ON(!ops->config);
5282
BUG_ON(!ops->add_interface);
5285
/* for now, mdev needs sub_if_data :/ */
5286
mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
5287
"wmaster%d", ether_setup);
5293
sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
5294
mdev->ieee80211_ptr = &sdata->wdev;
5295
sdata->wdev.wiphy = wiphy;
5297
local->hw.queues = 1; /* default */
5300
local->rx_pre_handlers = ieee80211_rx_pre_handlers;
5301
local->rx_handlers = ieee80211_rx_handlers;
5302
local->tx_handlers = ieee80211_tx_handlers;
5304
local->bridge_packets = 1;
5306
local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
5307
local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
5308
local->short_retry_limit = 7;
5309
local->long_retry_limit = 4;
5310
local->hw.conf.radio_enabled = 1;
5311
local->hw.conf.power_management_enable = 0;
5313
local->enabled_modes = (unsigned int) -1;
5315
INIT_LIST_HEAD(&local->modes_list);
5317
rwlock_init(&local->sub_if_lock);
5318
INIT_LIST_HEAD(&local->sub_if_list);
5320
INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work);
5321
init_timer(&local->stat_timer);
5322
local->stat_timer.function = ieee80211_stat_refresh;
5323
local->stat_timer.data = (unsigned long) local;
5324
ieee80211_rx_bss_list_init(mdev);
5326
sta_info_init(local);
5328
mdev->hard_start_xmit = ieee80211_master_start_xmit;
5329
mdev->open = ieee80211_master_open;
5330
mdev->stop = ieee80211_master_stop;
5331
mdev->type = ARPHRD_IEEE80211;
5332
mdev->header_ops = &ieee80211_header_ops;
5334
sdata->type = 0xFFFFFFFF;
5336
sdata->local = local;
5337
sdata->u.ap.force_unicast_rateidx = -1;
5338
sdata->u.ap.max_ratectrl_rateidx = -1;
5339
ieee80211_if_sdata_init(sdata);
5340
list_add_tail(&sdata->list, &local->sub_if_list);
5342
tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
5343
(unsigned long)local);
5344
tasklet_disable(&local->tx_pending_tasklet);
5346
tasklet_init(&local->tasklet,
5347
ieee80211_tasklet_handler,
5348
(unsigned long) local);
5349
tasklet_disable(&local->tasklet);
5351
skb_queue_head_init(&local->skb_queue);
5352
skb_queue_head_init(&local->skb_queue_unreliable);
5354
return local_to_hw(local);
5356
EXPORT_SYMBOL(iwlwifi_ieee80211_alloc_hw);
5358
int iwlwifi_ieee80211_register_hw(struct ieee80211_hw *hw)
5360
struct ieee80211_local *local = hw_to_local(hw);
5364
result = wiphy_register(local->hw.wiphy);
5368
name = wiphy_dev(local->hw.wiphy)->driver->name;
5369
local->hw.workqueue = create_singlethread_workqueue(name);
5370
if (!local->hw.workqueue) {
5372
goto fail_workqueue;
5376
* The hardware needs headroom for sending the frame,
5377
* and we need some headroom for passing the frame to monitor
5378
* interfaces, but never both at the same time.
5380
local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
5381
sizeof(struct iwlwifi_ieee80211_tx_status_rtap_hdr));
5383
debugfs_hw_add(local);
5385
local->hw.conf.beacon_int = 1000;
5387
local->wstats_flags |= local->hw.max_rssi ?
5388
IW_QUAL_LEVEL_UPDATED : IW_QUAL_LEVEL_INVALID;
5389
local->wstats_flags |= local->hw.max_signal ?
5390
IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
5391
local->wstats_flags |= local->hw.max_noise ?
5392
IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
5393
if (local->hw.max_rssi < 0 || local->hw.max_noise < 0)
5394
local->wstats_flags |= IW_QUAL_DBM;
5396
local->user_txpow = IEEE80211_MAX_TXPOWER;
5397
result = sta_info_start(local);
5402
result = dev_alloc_name(local->mdev, local->mdev->name);
5406
memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
5407
SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy));
5409
result = register_netdevice(local->mdev);
5413
ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
5415
result = ieee80211_init_rate_ctrl_alg(local,
5416
hw->preferred_rate_control);
5418
printk(KERN_DEBUG "%s: Failed to initialize %s rate control "
5419
"algorithm\n", local->mdev->name,
5420
hw->preferred_rate_control ?
5421
hw->preferred_rate_control : "default");
5425
result = ieee80211_wep_init(local);
5428
printk(KERN_DEBUG "%s: Failed to initialize wep\n",
5433
ieee80211_install_qdisc(local->mdev);
5435
/* add one default STA interface */
5436
result = ieee80211_if_add(local->mdev, "wlan%d", NULL,
5437
IEEE80211_IF_TYPE_STA);
5439
printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
5442
local->reg_state = IEEE80211_DEV_REGISTERED;
5445
ieee80211_led_init(local);
5450
rate_control_deinitialize(local);
5452
ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
5453
unregister_netdevice(local->mdev);
5456
sta_info_stop(local);
5458
debugfs_hw_del(local);
5459
destroy_workqueue(local->hw.workqueue);
5461
wiphy_unregister(local->hw.wiphy);
5464
EXPORT_SYMBOL(iwlwifi_ieee80211_register_hw);
5466
int iwlwifi_iwlwifi_ieee80211_register_hwmode(struct ieee80211_hw *hw,
5467
struct ieee80211_hw_mode *mode)
5469
struct ieee80211_local *local = hw_to_local(hw);
5470
struct ieee80211_rate *rate;
5473
INIT_LIST_HEAD(&mode->list);
5474
list_add_tail(&mode->list, &local->modes_list);
5476
local->hw_modes |= (1 << mode->mode);
5477
for (i = 0; i < mode->num_rates; i++) {
5478
rate = &(mode->rates[i]);
5479
rate->rate_inv = CHAN_UTIL_RATE_LCM / rate->rate;
5481
ieee80211_prepare_rates(local, mode);
5483
if (!local->oper_hw_mode) {
5484
/* Default to this mode */
5485
local->hw.conf.phymode = mode->mode;
5486
local->oper_hw_mode = local->scan_hw_mode = mode;
5487
local->oper_channel = local->scan_channel = &mode->channels[0];
5488
local->hw.conf.mode = local->oper_hw_mode;
5489
local->hw.conf.chan = local->oper_channel;
5492
if (!(hw->flags & IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED))
5493
ieee80211_set_default_regdomain(mode);
5497
EXPORT_SYMBOL(iwlwifi_iwlwifi_ieee80211_register_hwmode);
5499
void iwlwifi_ieee80211_unregister_hw(struct ieee80211_hw *hw)
5501
struct ieee80211_local *local = hw_to_local(hw);
5502
struct ieee80211_sub_if_data *sdata, *tmp;
5503
struct list_head tmp_list;
5506
tasklet_kill(&local->tx_pending_tasklet);
5507
tasklet_kill(&local->tasklet);
5511
BUG_ON(local->reg_state != IEEE80211_DEV_REGISTERED);
5513
local->reg_state = IEEE80211_DEV_UNREGISTERED;
5515
ieee80211_if_del_mgmt(local);
5517
write_lock_bh(&local->sub_if_lock);
5518
list_replace_init(&local->sub_if_list, &tmp_list);
5519
write_unlock_bh(&local->sub_if_lock);
5521
list_for_each_entry_safe(sdata, tmp, &tmp_list, list)
5522
__ieee80211_if_del(local, sdata);
5526
if (local->stat_time)
5527
del_timer_sync(&local->stat_timer);
5529
ieee80211_rx_bss_list_deinit(local->mdev);
5530
ieee80211_clear_tx_pending(local);
5531
sta_info_stop(local);
5532
rate_control_deinitialize(local);
5533
debugfs_hw_del(local);
5535
for (i = 0; i < NUM_IEEE80211_MODES; i++) {
5536
kfree(local->supp_rates[i]);
5537
kfree(local->basic_rates[i]);
5540
if (skb_queue_len(&local->skb_queue)
5541
|| skb_queue_len(&local->skb_queue_unreliable))
5542
printk(KERN_WARNING "%s: skb_queue not empty\n",
5544
skb_queue_purge(&local->skb_queue);
5545
skb_queue_purge(&local->skb_queue_unreliable);
5547
destroy_workqueue(local->hw.workqueue);
5548
wiphy_unregister(local->hw.wiphy);
5549
ieee80211_wep_free(local);
5550
ieee80211_led_exit(local);
5552
EXPORT_SYMBOL(iwlwifi_ieee80211_unregister_hw);
5554
void iwlwifi_ieee80211_free_hw(struct ieee80211_hw *hw)
5556
struct ieee80211_local *local = hw_to_local(hw);
5558
ieee80211_if_free(local->mdev);
5559
wiphy_free(local->hw.wiphy);
5561
EXPORT_SYMBOL(iwlwifi_ieee80211_free_hw);
5563
void iwlwifi_ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
5565
struct ieee80211_local *local = hw_to_local(hw);
5567
if (test_and_clear_bit(IEEE80211_LINK_STATE_XOFF,
5568
&local->state[queue])) {
5569
if (test_bit(IEEE80211_LINK_STATE_PENDING,
5570
&local->state[queue]))
5571
tasklet_schedule(&local->tx_pending_tasklet);
5573
if (!ieee80211_qdisc_installed(local->mdev)) {
5575
netif_wake_queue(local->mdev);
5577
__netif_schedule(local->mdev);
5580
EXPORT_SYMBOL(iwlwifi_ieee80211_wake_queue);
5582
void iwlwifi_ieee80211_stop_queue(struct ieee80211_hw *hw, int queue)
5584
struct ieee80211_local *local = hw_to_local(hw);
5586
if (!ieee80211_qdisc_installed(local->mdev) && queue == 0)
5587
netif_stop_queue(local->mdev);
5588
set_bit(IEEE80211_LINK_STATE_XOFF, &local->state[queue]);
5590
EXPORT_SYMBOL(iwlwifi_ieee80211_stop_queue);
5592
void iwlwifi_ieee80211_start_queues(struct ieee80211_hw *hw)
5594
struct ieee80211_local *local = hw_to_local(hw);
5597
for (i = 0; i < local->hw.queues; i++)
5598
clear_bit(IEEE80211_LINK_STATE_XOFF, &local->state[i]);
5599
if (!ieee80211_qdisc_installed(local->mdev))
5600
netif_start_queue(local->mdev);
5602
EXPORT_SYMBOL(iwlwifi_ieee80211_start_queues);
5604
void iwlwifi_iwlwifi_ieee80211_stop_queues(struct ieee80211_hw *hw)
5608
for (i = 0; i < hw->queues; i++)
5609
iwlwifi_ieee80211_stop_queue(hw, i);
5611
EXPORT_SYMBOL(iwlwifi_iwlwifi_ieee80211_stop_queues);
5613
void iwlwifi_iwlwifi_ieee80211_wake_queues(struct ieee80211_hw *hw)
5617
for (i = 0; i < hw->queues; i++)
5618
iwlwifi_ieee80211_wake_queue(hw, i);
5620
EXPORT_SYMBOL(iwlwifi_iwlwifi_ieee80211_wake_queues);
5622
int iwlwifi_ieee80211_start_BA_session(struct ieee80211_hw *hw, u8 *da, u16 tid)
5624
struct ieee80211_local *local = hw_to_local(hw);
5625
struct sta_info *sta;
5626
struct net_device *dev;
5627
struct ieee80211_sub_if_data *sdata;
5628
u16 start_seq_num=0;
5631
if (tid >= STA_TID_NUM)
5634
printk (KERN_DEBUG "Open a BA session requested on DA " MAC_FMT " tid %d\n",MAC_ARG(da),tid);
5636
sta = iwlwifi_sta_info_get(local, da);
5640
/* check if the TID is not in aggregation flow already */
5641
spin_lock_bh(&sta->ht_ba_mlme.agg_data_lock_tx);
5642
if (sta->ht_ba_mlme.tid_agg_info_tx[tid].state == HT_AGG_STATE_IDLE)
5643
sta->ht_ba_mlme.tid_agg_info_tx[tid].state = HT_AGG_STATE_START_BA;
5645
spin_unlock_bh(&sta->ht_ba_mlme.agg_data_lock_tx);
5646
printk (KERN_DEBUG "BA request denied - aggregation is not idle on tid %d\n",tid);
5649
spin_unlock_bh(&sta->ht_ba_mlme.agg_data_lock_tx);
5651
/* create a new queue for this aggregation */
5652
rc = ieee80211_ht_agg_queue_add(local,sta,tid);
5654
/* case no queue is available to aggregation don't switch to aggregation */
5656
printk (KERN_DEBUG "BA request denied - no queue available for tid %d\n",tid);
5657
} else { /* try to move HW to aggregation */
5660
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5661
start_seq_num = sdata->sequence >> 4; /* this default value can be changed by driver */
5662
if (local->ops->ht_tx_agg_start)
5663
rc = local->ops->ht_tx_agg_start(hw,da,tid,&start_seq_num);
5665
/* remove the queue for this aggregation */
5666
ieee80211_ht_agg_queue_remove(local,sta,tid);
5669
/* case we denied aggregation go back to legacy */
5671
spin_lock_bh(&sta->ht_ba_mlme.agg_data_lock_tx);
5672
sta->ht_ba_mlme.tid_agg_info_tx[tid].state = HT_AGG_STATE_IDLE;
5673
spin_unlock_bh(&sta->ht_ba_mlme.agg_data_lock_tx);
5674
printk (KERN_DEBUG "BA request denied - HW or queue unavailable for tid %d\n",tid);
5678
/* send an addBA request */
5679
spin_lock_bh(&sta->ht_ba_mlme.agg_data_lock_tx);
5680
sta->ht_ba_mlme.tid_agg_info_tx[tid].state = HT_AGG_STATE_ADDBA_REQUESTED;
5681
sta->ht_ba_mlme.dialog_token_allocator++;
5682
sta->ht_ba_mlme.tid_agg_info_tx[tid].dialog_token = sta->ht_ba_mlme.dialog_token_allocator;
5683
sta->ht_ba_mlme.tid_agg_info_tx[tid].start_seq_num = start_seq_num;
5684
spin_unlock_bh(&sta->ht_ba_mlme.agg_data_lock_tx);
5686
ieee80211_send_addba_request(sta->dev, da, tid,
5687
sta->ht_ba_mlme.tid_agg_info_tx[tid].dialog_token,
5688
sta->ht_ba_mlme.tid_agg_info_tx[tid].start_seq_num,
5691
/* activate the timer for the recipient's addBA response */
5692
sta->ht_ba_mlme.tid_agg_info_tx[tid].addba_resp_timer.expires = jiffies + ADDBA_RESP_INTERVAL;
5693
add_timer(&sta->ht_ba_mlme.tid_agg_info_tx[tid].addba_resp_timer);
5694
printk(KERN_DEBUG "activated addBA response timer on tid %d\n",tid);
5698
iwlwifi_sta_info_put(sta);
5701
EXPORT_SYMBOL(iwlwifi_ieee80211_start_BA_session);
5703
int iwlwifi_ieee80211_stop_BA_session(struct ieee80211_hw *hw, u8 *da, u16 tid)
5705
struct ieee80211_local *local = hw_to_local(hw);
5706
struct sta_info *sta;
5709
if (tid >= STA_TID_NUM)
5712
printk (KERN_DEBUG "Stop a BA session requested on DA " MAC_FMT " tid %d\n",MAC_ARG(da),tid);
5714
sta = iwlwifi_sta_info_get(local, da);
5718
/* check if the TID is in aggregation */
5719
spin_lock_bh(&sta->ht_ba_mlme.agg_data_lock_tx);
5720
if (sta->ht_ba_mlme.tid_agg_info_tx[tid].state == HT_AGG_STATE_OPERATIONAL)
5721
sta->ht_ba_mlme.tid_agg_info_tx[tid].state = HT_AGG_STATE_INITIATOR_REQ_STOP_BA;
5723
spin_unlock_bh(&sta->ht_ba_mlme.agg_data_lock_tx);
5724
printk (KERN_DEBUG "request denied - aggregation is not opertional yet on tid %d\n",tid);
5727
spin_unlock_bh(&sta->ht_ba_mlme.agg_data_lock_tx);
5729
if (local->ops->ht_tx_agg_stop)
5730
rc = local->ops->ht_tx_agg_stop(hw,da,tid,1 /*WLAN_BACK_INITIATOR*/);
5732
/* case HW denied going back to legacy */
5734
spin_lock_bh(&sta->ht_ba_mlme.agg_data_lock_tx);
5735
sta->ht_ba_mlme.tid_agg_info_tx[tid].state = HT_AGG_STATE_OPERATIONAL;
5736
spin_unlock_bh(&sta->ht_ba_mlme.agg_data_lock_tx);
5737
printk (KERN_ERR "HW problem - can not stop aggergation for tid %d\n",tid);
5741
/* remove the queue for this aggregation */
5742
ieee80211_ht_agg_queue_remove(local,sta,tid);
5745
ieee80211_send_delba(sta->dev, da, tid, 1 /*WLAN_BACK_INITIATOR*/, WLAN_REASON_QSTA_NOT_USE);
5746
spin_lock_bh(&sta->ht_ba_mlme.agg_data_lock_tx);
5747
sta->ht_ba_mlme.tid_agg_info_tx[tid].state = HT_AGG_STATE_IDLE;
5748
spin_unlock_bh(&sta->ht_ba_mlme.agg_data_lock_tx);
5752
iwlwifi_sta_info_put(sta);
5755
EXPORT_SYMBOL(iwlwifi_ieee80211_stop_BA_session);
5757
struct net_device_stats *ieee80211_dev_stats(struct net_device *dev)
5759
struct ieee80211_sub_if_data *sdata;
5760
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5761
return &sdata->stats;
5764
static int __init ieee80211_init(void)
5766
struct sk_buff *skb;
5769
BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb));
5771
ret = ieee80211_wme_register();
5773
printk(KERN_DEBUG "ieee80211_init: failed to "
5774
"initialize WME (err=%d)\n", ret);
5778
ieee80211_debugfs_netdev_init();
5779
ieee80211_regdomain_init();
5785
static void __exit ieee80211_exit(void)
5787
ieee80211_wme_unregister();
5788
ieee80211_debugfs_netdev_exit();
5792
module_init(ieee80211_init);
5793
module_exit(ieee80211_exit);
5795
MODULE_DESCRIPTION("IEEE 802.11 subsystem");
5796
MODULE_LICENSE("GPL");