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>
28 #include "ieee80211_common.h"
29 #include "ieee80211_i.h"
30 #include "ieee80211_rate.h"
36 #include "ieee80211_led.h"
37 #include "ieee80211_cfg.h"
39 /* privid for wiphys to determine whether they belong to us or not */
40 void *mac80211_wiphy_privid
= &mac80211_wiphy_privid
;
42 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
43 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
44 static const unsigned char rfc1042_header
[] =
45 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
47 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
48 static const unsigned char bridge_tunnel_header
[] =
49 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
51 /* No encapsulation header if EtherType < 0x600 (=length) */
52 static const unsigned char eapol_header
[] =
53 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x88, 0x8e };
56 static inline void ieee80211_include_sequence(struct ieee80211_sub_if_data
*sdata
,
57 struct ieee80211_hdr
*hdr
)
59 /* Set the sequence number for this frame. */
60 hdr
->seq_ctrl
= cpu_to_le16(sdata
->sequence
);
62 /* Increase the sequence number. */
63 sdata
->sequence
= (sdata
->sequence
+ 0x10) & IEEE80211_SCTL_SEQ
;
66 struct ieee80211_key_conf
*
67 ieee80211_key_data2conf(struct ieee80211_local
*local
,
68 const struct ieee80211_key
*data
)
70 struct ieee80211_key_conf
*conf
;
72 conf
= kmalloc(sizeof(*conf
) + data
->keylen
, GFP_ATOMIC
);
76 conf
->hw_key_idx
= data
->hw_key_idx
;
77 conf
->alg
= data
->alg
;
78 conf
->keylen
= data
->keylen
;
80 if (data
->force_sw_encrypt
)
81 conf
->flags
|= IEEE80211_KEY_FORCE_SW_ENCRYPT
;
82 conf
->keyidx
= data
->keyidx
;
83 if (data
->default_tx_key
)
84 conf
->flags
|= IEEE80211_KEY_DEFAULT_TX_KEY
;
85 if (local
->default_wep_only
)
86 conf
->flags
|= IEEE80211_KEY_DEFAULT_WEP_ONLY
;
87 memcpy(conf
->key
, data
->key
, data
->keylen
);
92 struct ieee80211_key
*ieee80211_key_alloc(struct ieee80211_sub_if_data
*sdata
,
93 int idx
, size_t key_len
, gfp_t flags
)
95 struct ieee80211_key
*key
;
97 key
= kzalloc(sizeof(struct ieee80211_key
) + key_len
, flags
);
100 kref_init(&key
->kref
);
104 static void ieee80211_key_release(struct kref
*kref
)
106 struct ieee80211_key
*key
;
108 key
= container_of(kref
, struct ieee80211_key
, kref
);
109 if (key
->alg
== ALG_CCMP
)
110 ieee80211_aes_key_free(key
->u
.ccmp
.tfm
);
114 void ieee80211_key_free(struct ieee80211_key
*key
)
117 kref_put(&key
->kref
, ieee80211_key_release
);
120 static int rate_list_match(const int *rate_list
, int rate
)
127 for (i
= 0; rate_list
[i
] >= 0; i
++)
128 if (rate_list
[i
] == rate
)
135 void ieee80211_prepare_rates(struct ieee80211_local
*local
,
136 struct ieee80211_hw_mode
*mode
)
140 for (i
= 0; i
< mode
->num_rates
; i
++) {
141 struct ieee80211_rate
*rate
= &mode
->rates
[i
];
143 rate
->flags
&= ~(IEEE80211_RATE_SUPPORTED
|
144 IEEE80211_RATE_BASIC
);
146 if (local
->supp_rates
[mode
->mode
]) {
147 if (!rate_list_match(local
->supp_rates
[mode
->mode
],
152 rate
->flags
|= IEEE80211_RATE_SUPPORTED
;
154 /* Use configured basic rate set if it is available. If not,
155 * use defaults that are sane for most cases. */
156 if (local
->basic_rates
[mode
->mode
]) {
157 if (rate_list_match(local
->basic_rates
[mode
->mode
],
159 rate
->flags
|= IEEE80211_RATE_BASIC
;
160 } else switch (mode
->mode
) {
161 case MODE_IEEE80211A
:
162 if (rate
->rate
== 60 || rate
->rate
== 120 ||
164 rate
->flags
|= IEEE80211_RATE_BASIC
;
166 case MODE_IEEE80211B
:
167 if (rate
->rate
== 10 || rate
->rate
== 20)
168 rate
->flags
|= IEEE80211_RATE_BASIC
;
170 case MODE_ATHEROS_TURBO
:
171 if (rate
->rate
== 120 || rate
->rate
== 240 ||
173 rate
->flags
|= IEEE80211_RATE_BASIC
;
175 case MODE_IEEE80211G
:
176 if (rate
->rate
== 10 || rate
->rate
== 20 ||
177 rate
->rate
== 55 || rate
->rate
== 110)
178 rate
->flags
|= IEEE80211_RATE_BASIC
;
182 /* Set ERP and MANDATORY flags based on phymode */
183 switch (mode
->mode
) {
184 case MODE_IEEE80211A
:
185 if (rate
->rate
== 60 || rate
->rate
== 120 ||
187 rate
->flags
|= IEEE80211_RATE_MANDATORY
;
189 case MODE_IEEE80211B
:
190 if (rate
->rate
== 10)
191 rate
->flags
|= IEEE80211_RATE_MANDATORY
;
193 case MODE_ATHEROS_TURBO
:
195 case MODE_IEEE80211G
:
196 if (rate
->rate
== 10 || rate
->rate
== 20 ||
197 rate
->rate
== 55 || rate
->rate
== 110 ||
198 rate
->rate
== 60 || rate
->rate
== 120 ||
200 rate
->flags
|= IEEE80211_RATE_MANDATORY
;
203 if (ieee80211_is_erp_rate(mode
->mode
, rate
->rate
))
204 rate
->flags
|= IEEE80211_RATE_ERP
;
209 static void ieee80211_key_threshold_notify(struct net_device
*dev
,
210 struct ieee80211_key
*key
,
211 struct sta_info
*sta
)
213 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
215 struct ieee80211_msg_key_notification
*msg
;
217 /* if no one will get it anyway, don't even allocate it.
218 * unlikely because this is only relevant for APs
219 * where the device must be open... */
220 if (unlikely(!local
->apdev
))
223 skb
= dev_alloc_skb(sizeof(struct ieee80211_frame_info
) +
224 sizeof(struct ieee80211_msg_key_notification
));
228 skb_reserve(skb
, sizeof(struct ieee80211_frame_info
));
229 msg
= (struct ieee80211_msg_key_notification
*)
230 skb_put(skb
, sizeof(struct ieee80211_msg_key_notification
));
231 msg
->tx_rx_count
= key
->tx_rx_count
;
232 memcpy(msg
->ifname
, dev
->name
, IFNAMSIZ
);
234 memcpy(msg
->addr
, sta
->addr
, ETH_ALEN
);
236 memset(msg
->addr
, 0xff, ETH_ALEN
);
238 key
->tx_rx_count
= 0;
240 ieee80211_rx_mgmt(local
, skb
, NULL
,
241 ieee80211_msg_key_threshold_notification
);
245 static u8
* ieee80211_get_bssid(struct ieee80211_hdr
*hdr
, size_t len
)
252 fc
= le16_to_cpu(hdr
->frame_control
);
254 switch (fc
& IEEE80211_FCTL_FTYPE
) {
255 case IEEE80211_FTYPE_DATA
:
256 switch (fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) {
257 case IEEE80211_FCTL_TODS
:
259 case (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
):
261 case IEEE80211_FCTL_FROMDS
:
267 case IEEE80211_FTYPE_MGMT
:
269 case IEEE80211_FTYPE_CTL
:
270 if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_PSPOLL
)
279 int ieee80211_get_hdrlen(u16 fc
)
283 switch (fc
& IEEE80211_FCTL_FTYPE
) {
284 case IEEE80211_FTYPE_DATA
:
285 if ((fc
& IEEE80211_FCTL_FROMDS
) && (fc
& IEEE80211_FCTL_TODS
))
286 hdrlen
= 30; /* Addr4 */
288 * The QoS Control field is two bytes and its presence is
289 * indicated by the IEEE80211_STYPE_QOS_DATA bit. Add 2 to
290 * hdrlen if that bit is set.
291 * This works by masking out the bit and shifting it to
292 * bit position 1 so the result has the value 0 or 2.
294 hdrlen
+= (fc
& IEEE80211_STYPE_QOS_DATA
)
295 >> (ilog2(IEEE80211_STYPE_QOS_DATA
)-1);
297 case IEEE80211_FTYPE_CTL
:
299 * ACK and CTS are 10 bytes, all others 16. To see how
300 * to get this condition consider
301 * subtype mask: 0b0000000011110000 (0x00F0)
302 * ACK subtype: 0b0000000011010000 (0x00D0)
303 * CTS subtype: 0b0000000011000000 (0x00C0)
304 * bits that matter: ^^^ (0x00E0)
305 * value of those: 0b0000000011000000 (0x00C0)
307 if ((fc
& 0xE0) == 0xC0)
316 EXPORT_SYMBOL(ieee80211_get_hdrlen
);
318 int ieee80211_get_hdrlen_from_skb(const struct sk_buff
*skb
)
320 const struct ieee80211_hdr
*hdr
= (const struct ieee80211_hdr
*) skb
->data
;
323 if (unlikely(skb
->len
< 10))
325 hdrlen
= ieee80211_get_hdrlen(le16_to_cpu(hdr
->frame_control
));
326 if (unlikely(hdrlen
> skb
->len
))
330 EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb
);
332 static int ieee80211_get_radiotap_len(struct sk_buff
*skb
)
334 struct ieee80211_radiotap_header
*hdr
=
335 (struct ieee80211_radiotap_header
*) skb
->data
;
337 return le16_to_cpu(hdr
->it_len
);
340 #ifdef CONFIG_MAC80211_LOWTX_FRAME_DUMP
341 static void ieee80211_dump_frame(const char *ifname
, const char *title
,
342 const struct sk_buff
*skb
)
344 const struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
348 printk(KERN_DEBUG
"%s: %s (len=%d)", ifname
, title
, skb
->len
);
354 fc
= le16_to_cpu(hdr
->frame_control
);
355 hdrlen
= ieee80211_get_hdrlen(fc
);
356 if (hdrlen
> skb
->len
)
359 printk(" FC=0x%04x DUR=0x%04x",
360 fc
, le16_to_cpu(hdr
->duration_id
));
362 printk(" A1=" MAC_FMT
, MAC_ARG(hdr
->addr1
));
364 printk(" A2=" MAC_FMT
, MAC_ARG(hdr
->addr2
));
366 printk(" A3=" MAC_FMT
, MAC_ARG(hdr
->addr3
));
368 printk(" A4=" MAC_FMT
, MAC_ARG(hdr
->addr4
));
371 #else /* CONFIG_MAC80211_LOWTX_FRAME_DUMP */
372 static inline void ieee80211_dump_frame(const char *ifname
, const char *title
,
376 #endif /* CONFIG_MAC80211_LOWTX_FRAME_DUMP */
379 static int ieee80211_is_eapol(const struct sk_buff
*skb
)
381 const struct ieee80211_hdr
*hdr
;
385 if (unlikely(skb
->len
< 10))
388 hdr
= (const struct ieee80211_hdr
*) skb
->data
;
389 fc
= le16_to_cpu(hdr
->frame_control
);
391 if (unlikely(!WLAN_FC_DATA_PRESENT(fc
)))
394 hdrlen
= ieee80211_get_hdrlen(fc
);
396 if (unlikely(skb
->len
>= hdrlen
+ sizeof(eapol_header
) &&
397 memcmp(skb
->data
+ hdrlen
, eapol_header
,
398 sizeof(eapol_header
)) == 0))
405 static ieee80211_txrx_result
406 ieee80211_tx_h_rate_ctrl(struct ieee80211_txrx_data
*tx
)
408 struct rate_control_extra extra
;
410 memset(&extra
, 0, sizeof(extra
));
411 extra
.mode
= tx
->u
.tx
.mode
;
412 extra
.mgmt_data
= tx
->sdata
&&
413 tx
->sdata
->type
== IEEE80211_IF_TYPE_MGMT
;
414 extra
.ethertype
= tx
->ethertype
;
416 tx
->u
.tx
.rate
= rate_control_get_rate(tx
->local
, tx
->dev
, tx
->skb
,
418 if (unlikely(extra
.probe
!= NULL
)) {
419 tx
->u
.tx
.control
->flags
|= IEEE80211_TXCTL_RATE_CTRL_PROBE
;
420 tx
->u
.tx
.probe_last_frag
= 1;
421 tx
->u
.tx
.control
->alt_retry_rate
= tx
->u
.tx
.rate
->val
;
422 tx
->u
.tx
.rate
= extra
.probe
;
424 tx
->u
.tx
.control
->alt_retry_rate
= -1;
428 if (tx
->u
.tx
.mode
->mode
== MODE_IEEE80211G
&&
429 tx
->local
->cts_protect_erp_frames
&& tx
->fragmented
&&
431 tx
->u
.tx
.last_frag_rate
= tx
->u
.tx
.rate
;
432 tx
->u
.tx
.probe_last_frag
= extra
.probe
? 1 : 0;
434 tx
->u
.tx
.rate
= extra
.nonerp
;
435 tx
->u
.tx
.control
->rate
= extra
.nonerp
;
436 tx
->u
.tx
.control
->flags
&= ~IEEE80211_TXCTL_RATE_CTRL_PROBE
;
438 tx
->u
.tx
.last_frag_rate
= tx
->u
.tx
.rate
;
439 tx
->u
.tx
.control
->rate
= tx
->u
.tx
.rate
;
441 tx
->u
.tx
.control
->tx_rate
= tx
->u
.tx
.rate
->val
;
442 if ((tx
->u
.tx
.rate
->flags
& IEEE80211_RATE_PREAMBLE2
) &&
443 tx
->local
->short_preamble
&&
444 (!tx
->sta
|| (tx
->sta
->flags
& WLAN_STA_SHORT_PREAMBLE
))) {
445 tx
->u
.tx
.short_preamble
= 1;
446 tx
->u
.tx
.control
->tx_rate
= tx
->u
.tx
.rate
->val2
;
449 return TXRX_CONTINUE
;
453 static ieee80211_txrx_result
454 ieee80211_tx_h_select_key(struct ieee80211_txrx_data
*tx
)
457 tx
->u
.tx
.control
->key_idx
= tx
->sta
->key_idx_compression
;
459 tx
->u
.tx
.control
->key_idx
= HW_KEY_IDX_INVALID
;
461 if (unlikely(tx
->u
.tx
.control
->flags
& IEEE80211_TXCTL_DO_NOT_ENCRYPT
))
463 else if (tx
->sta
&& tx
->sta
->key
)
464 tx
->key
= tx
->sta
->key
;
465 else if (tx
->sdata
->default_key
)
466 tx
->key
= tx
->sdata
->default_key
;
467 else if (tx
->sdata
->drop_unencrypted
&&
468 !(tx
->sdata
->eapol
&& ieee80211_is_eapol(tx
->skb
))) {
469 I802_DEBUG_INC(tx
->local
->tx_handlers_drop_unencrypted
);
475 tx
->key
->tx_rx_count
++;
476 if (unlikely(tx
->local
->key_tx_rx_threshold
&&
477 tx
->key
->tx_rx_count
>
478 tx
->local
->key_tx_rx_threshold
)) {
479 ieee80211_key_threshold_notify(tx
->dev
, tx
->key
,
484 return TXRX_CONTINUE
;
488 static ieee80211_txrx_result
489 ieee80211_tx_h_fragment(struct ieee80211_txrx_data
*tx
)
491 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) tx
->skb
->data
;
492 size_t hdrlen
, per_fragm
, num_fragm
, payload_len
, left
;
493 struct sk_buff
**frags
, *first
, *frag
;
497 int frag_threshold
= tx
->local
->fragmentation_threshold
;
500 return TXRX_CONTINUE
;
504 hdrlen
= ieee80211_get_hdrlen(tx
->fc
);
505 payload_len
= first
->len
- hdrlen
;
506 per_fragm
= frag_threshold
- hdrlen
- FCS_LEN
;
507 num_fragm
= (payload_len
+ per_fragm
- 1) / per_fragm
;
509 frags
= kzalloc(num_fragm
* sizeof(struct sk_buff
*), GFP_ATOMIC
);
513 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_MOREFRAGS
);
514 seq
= le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_SEQ
;
515 pos
= first
->data
+ hdrlen
+ per_fragm
;
516 left
= payload_len
- per_fragm
;
517 for (i
= 0; i
< num_fragm
- 1; i
++) {
518 struct ieee80211_hdr
*fhdr
;
524 /* reserve enough extra head and tail room for possible
527 dev_alloc_skb(tx
->local
->hw
.extra_tx_headroom
+
529 IEEE80211_ENCRYPT_HEADROOM
+
530 IEEE80211_ENCRYPT_TAILROOM
);
533 /* Make sure that all fragments use the same priority so
534 * that they end up using the same TX queue */
535 frag
->priority
= first
->priority
;
536 skb_reserve(frag
, tx
->local
->hw
.extra_tx_headroom
+
537 IEEE80211_ENCRYPT_HEADROOM
);
538 fhdr
= (struct ieee80211_hdr
*) skb_put(frag
, hdrlen
);
539 memcpy(fhdr
, first
->data
, hdrlen
);
540 if (i
== num_fragm
- 2)
541 fhdr
->frame_control
&= cpu_to_le16(~IEEE80211_FCTL_MOREFRAGS
);
542 fhdr
->seq_ctrl
= cpu_to_le16(seq
| ((i
+ 1) & IEEE80211_SCTL_FRAG
));
543 copylen
= left
> per_fragm
? per_fragm
: left
;
544 memcpy(skb_put(frag
, copylen
), pos
, copylen
);
549 skb_trim(first
, hdrlen
+ per_fragm
);
551 tx
->u
.tx
.num_extra_frag
= num_fragm
- 1;
552 tx
->u
.tx
.extra_frag
= frags
;
554 return TXRX_CONTINUE
;
557 printk(KERN_DEBUG
"%s: failed to fragment frame\n", tx
->dev
->name
);
559 for (i
= 0; i
< num_fragm
- 1; i
++)
561 dev_kfree_skb(frags
[i
]);
564 I802_DEBUG_INC(tx
->local
->tx_handlers_drop_fragment
);
569 static int wep_encrypt_skb(struct ieee80211_txrx_data
*tx
, struct sk_buff
*skb
)
571 if (tx
->key
->force_sw_encrypt
) {
572 if (ieee80211_wep_encrypt(tx
->local
, skb
, tx
->key
))
575 tx
->u
.tx
.control
->key_idx
= tx
->key
->hw_key_idx
;
576 if (tx
->local
->hw
.flags
& IEEE80211_HW_WEP_INCLUDE_IV
) {
577 if (ieee80211_wep_add_iv(tx
->local
, skb
, tx
->key
) ==
586 void ieee80211_tx_set_iswep(struct ieee80211_txrx_data
*tx
)
588 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) tx
->skb
->data
;
590 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
591 if (tx
->u
.tx
.extra_frag
) {
592 struct ieee80211_hdr
*fhdr
;
594 for (i
= 0; i
< tx
->u
.tx
.num_extra_frag
; i
++) {
595 fhdr
= (struct ieee80211_hdr
*)
596 tx
->u
.tx
.extra_frag
[i
]->data
;
597 fhdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
603 static ieee80211_txrx_result
604 ieee80211_tx_h_wep_encrypt(struct ieee80211_txrx_data
*tx
)
606 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) tx
->skb
->data
;
609 fc
= le16_to_cpu(hdr
->frame_control
);
611 if (!tx
->key
|| tx
->key
->alg
!= ALG_WEP
||
612 ((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
&&
613 ((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_MGMT
||
614 (fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_AUTH
)))
615 return TXRX_CONTINUE
;
617 tx
->u
.tx
.control
->iv_len
= WEP_IV_LEN
;
618 tx
->u
.tx
.control
->icv_len
= WEP_ICV_LEN
;
619 ieee80211_tx_set_iswep(tx
);
621 if (wep_encrypt_skb(tx
, tx
->skb
) < 0) {
622 I802_DEBUG_INC(tx
->local
->tx_handlers_drop_wep
);
626 if (tx
->u
.tx
.extra_frag
) {
628 for (i
= 0; i
< tx
->u
.tx
.num_extra_frag
; i
++) {
629 if (wep_encrypt_skb(tx
, tx
->u
.tx
.extra_frag
[i
]) < 0) {
630 I802_DEBUG_INC(tx
->local
->
631 tx_handlers_drop_wep
);
637 return TXRX_CONTINUE
;
641 static int ieee80211_frame_duration(struct ieee80211_local
*local
, size_t len
,
642 int rate
, int erp
, int short_preamble
)
646 /* calculate duration (in microseconds, rounded up to next higher
647 * integer if it includes a fractional microsecond) to send frame of
648 * len bytes (does not include FCS) at the given rate. Duration will
651 * rate is in 100 kbps, so divident is multiplied by 10 in the
652 * DIV_ROUND_UP() operations.
655 if (local
->hw
.conf
.phymode
== MODE_IEEE80211A
|| erp
||
656 local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBO
) {
660 * N_DBPS = DATARATE x 4
661 * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
662 * (16 = SIGNAL time, 6 = tail bits)
663 * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
666 * 802.11a - 17.5.2: aSIFSTime = 16 usec
667 * 802.11g - 19.8.4: aSIFSTime = 10 usec +
668 * signal ext = 6 usec
670 /* FIX: Atheros Turbo may have different (shorter) duration? */
671 dur
= 16; /* SIFS + signal ext */
672 dur
+= 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */
673 dur
+= 4; /* 17.3.2.3: T_SIGNAL = 4 usec */
674 dur
+= 4 * DIV_ROUND_UP((16 + 8 * (len
+ 4) + 6) * 10,
675 4 * rate
); /* T_SYM x N_SYM */
678 * 802.11b or 802.11g with 802.11b compatibility:
679 * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
680 * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
682 * 802.11 (DS): 15.3.3, 802.11b: 18.3.4
683 * aSIFSTime = 10 usec
684 * aPreambleLength = 144 usec or 72 usec with short preamble
685 * aPLCPHeaderLength = 48 usec or 24 usec with short preamble
687 dur
= 10; /* aSIFSTime = 10 usec */
688 dur
+= short_preamble
? (72 + 24) : (144 + 48);
690 dur
+= DIV_ROUND_UP(8 * (len
+ 4) * 10, rate
);
697 /* Exported duration function for driver use */
698 __le16
ieee80211_generic_frame_duration(struct ieee80211_hw
*hw
,
699 size_t frame_len
, int rate
)
701 struct ieee80211_local
*local
= hw_to_local(hw
);
705 erp
= ieee80211_is_erp_rate(hw
->conf
.phymode
, rate
);
706 dur
= ieee80211_frame_duration(local
, frame_len
, rate
,
707 erp
, local
->short_preamble
);
709 return cpu_to_le16(dur
);
711 EXPORT_SYMBOL(ieee80211_generic_frame_duration
);
714 static u16
ieee80211_duration(struct ieee80211_txrx_data
*tx
, int group_addr
,
717 int rate
, mrate
, erp
, dur
, i
;
718 struct ieee80211_rate
*txrate
= tx
->u
.tx
.rate
;
719 struct ieee80211_local
*local
= tx
->local
;
720 struct ieee80211_hw_mode
*mode
= tx
->u
.tx
.mode
;
722 erp
= txrate
->flags
& IEEE80211_RATE_ERP
;
725 * data and mgmt (except PS Poll):
726 * - during CFP: 32768
727 * - during contention period:
728 * if addr1 is group address: 0
729 * if more fragments = 0 and addr1 is individual address: time to
730 * transmit one ACK plus SIFS
731 * if more fragments = 1 and addr1 is individual address: time to
732 * transmit next fragment plus 2 x ACK plus 3 x SIFS
735 * - control response frame (CTS or ACK) shall be transmitted using the
736 * same rate as the immediately previous frame in the frame exchange
737 * sequence, if this rate belongs to the PHY mandatory rates, or else
738 * at the highest possible rate belonging to the PHY rates in the
742 if ((tx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_CTL
) {
743 /* TODO: These control frames are not currently sent by
744 * 80211.o, but should they be implemented, this function
745 * needs to be updated to support duration field calculation.
747 * RTS: time needed to transmit pending data/mgmt frame plus
748 * one CTS frame plus one ACK frame plus 3 x SIFS
749 * CTS: duration of immediately previous RTS minus time
750 * required to transmit CTS and its SIFS
751 * ACK: 0 if immediately previous directed data/mgmt had
752 * more=0, with more=1 duration in ACK frame is duration
753 * from previous frame minus time needed to transmit ACK
755 * PS Poll: BIT(15) | BIT(14) | aid
761 if (0 /* FIX: data/mgmt during CFP */)
764 if (group_addr
) /* Group address as the destination - no ACK */
767 /* Individual destination address:
768 * IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes)
769 * CTS and ACK frames shall be transmitted using the highest rate in
770 * basic rate set that is less than or equal to the rate of the
771 * immediately previous frame and that is using the same modulation
772 * (CCK or OFDM). If no basic rate set matches with these requirements,
773 * the highest mandatory rate of the PHY that is less than or equal to
774 * the rate of the previous frame is used.
775 * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps
778 mrate
= 10; /* use 1 Mbps if everything fails */
779 for (i
= 0; i
< mode
->num_rates
; i
++) {
780 struct ieee80211_rate
*r
= &mode
->rates
[i
];
781 if (r
->rate
> txrate
->rate
)
784 if (IEEE80211_RATE_MODULATION(txrate
->flags
) !=
785 IEEE80211_RATE_MODULATION(r
->flags
))
788 if (r
->flags
& IEEE80211_RATE_BASIC
)
790 else if (r
->flags
& IEEE80211_RATE_MANDATORY
)
794 /* No matching basic rate found; use highest suitable mandatory
799 /* Time needed to transmit ACK
800 * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
801 * to closest integer */
803 dur
= ieee80211_frame_duration(local
, 10, rate
, erp
,
804 local
->short_preamble
);
807 /* Frame is fragmented: duration increases with time needed to
808 * transmit next fragment plus ACK and 2 x SIFS. */
809 dur
*= 2; /* ACK + SIFS */
811 dur
+= ieee80211_frame_duration(local
, next_frag_len
,
813 local
->short_preamble
);
820 static ieee80211_txrx_result
821 ieee80211_tx_h_misc(struct ieee80211_txrx_data
*tx
)
823 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) tx
->skb
->data
;
825 struct ieee80211_tx_control
*control
= tx
->u
.tx
.control
;
826 struct ieee80211_hw_mode
*mode
= tx
->u
.tx
.mode
;
828 if (!is_multicast_ether_addr(hdr
->addr1
)) {
829 if (tx
->skb
->len
+ FCS_LEN
> tx
->local
->rts_threshold
&&
830 tx
->local
->rts_threshold
< IEEE80211_MAX_RTS_THRESHOLD
) {
831 control
->flags
|= IEEE80211_TXCTL_USE_RTS_CTS
;
832 control
->retry_limit
=
833 tx
->local
->long_retry_limit
;
835 control
->retry_limit
=
836 tx
->local
->short_retry_limit
;
839 control
->retry_limit
= 1;
842 if (tx
->fragmented
) {
843 /* Do not use multiple retry rates when sending fragmented
845 * TODO: The last fragment could still use multiple retry
847 control
->alt_retry_rate
= -1;
850 /* Use CTS protection for unicast frames sent using extended rates if
851 * there are associated non-ERP stations and RTS/CTS is not configured
853 if (mode
->mode
== MODE_IEEE80211G
&&
854 (tx
->u
.tx
.rate
->flags
& IEEE80211_RATE_ERP
) &&
856 tx
->local
->cts_protect_erp_frames
&&
857 !(control
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
))
858 control
->flags
|= IEEE80211_TXCTL_USE_CTS_PROTECT
;
860 /* Setup duration field for the first fragment of the frame. Duration
861 * for remaining fragments will be updated when they are being sent
862 * to low-level driver in ieee80211_tx(). */
863 dur
= ieee80211_duration(tx
, is_multicast_ether_addr(hdr
->addr1
),
864 tx
->fragmented
? tx
->u
.tx
.extra_frag
[0]->len
:
866 hdr
->duration_id
= cpu_to_le16(dur
);
868 if ((control
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
) ||
869 (control
->flags
& IEEE80211_TXCTL_USE_CTS_PROTECT
)) {
870 struct ieee80211_rate
*rate
;
872 /* Do not use multiple retry rates when using RTS/CTS */
873 control
->alt_retry_rate
= -1;
875 /* Use min(data rate, max base rate) as CTS/RTS rate */
876 rate
= tx
->u
.tx
.rate
;
877 while (rate
> mode
->rates
&&
878 !(rate
->flags
& IEEE80211_RATE_BASIC
))
881 control
->rts_cts_rate
= rate
->val
;
882 control
->rts_rate
= rate
;
886 tx
->sta
->tx_packets
++;
887 tx
->sta
->tx_fragments
++;
888 tx
->sta
->tx_bytes
+= tx
->skb
->len
;
889 if (tx
->u
.tx
.extra_frag
) {
891 tx
->sta
->tx_fragments
+= tx
->u
.tx
.num_extra_frag
;
892 for (i
= 0; i
< tx
->u
.tx
.num_extra_frag
; i
++) {
894 tx
->u
.tx
.extra_frag
[i
]->len
;
899 return TXRX_CONTINUE
;
903 static ieee80211_txrx_result
904 ieee80211_tx_h_check_assoc(struct ieee80211_txrx_data
*tx
)
906 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
907 struct sk_buff
*skb
= tx
->skb
;
908 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
909 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
912 if (unlikely(tx
->local
->sta_scanning
!= 0) &&
913 ((tx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_MGMT
||
914 (tx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_PROBE_REQ
))
917 if (tx
->u
.tx
.ps_buffered
)
918 return TXRX_CONTINUE
;
920 sta_flags
= tx
->sta
? tx
->sta
->flags
: 0;
922 if (likely(tx
->u
.tx
.unicast
)) {
923 if (unlikely(!(sta_flags
& WLAN_STA_ASSOC
) &&
924 tx
->sdata
->type
!= IEEE80211_IF_TYPE_IBSS
&&
925 (tx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
)) {
926 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
927 printk(KERN_DEBUG
"%s: dropped data frame to not "
928 "associated station " MAC_FMT
"\n",
929 tx
->dev
->name
, MAC_ARG(hdr
->addr1
));
930 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
931 I802_DEBUG_INC(tx
->local
->tx_handlers_drop_not_assoc
);
935 if (unlikely((tx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
&&
936 tx
->local
->num_sta
== 0 &&
937 !tx
->local
->allow_broadcast_always
&&
938 tx
->sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)) {
940 * No associated STAs - no need to send multicast
945 return TXRX_CONTINUE
;
948 if (unlikely(!tx
->u
.tx
.mgmt_interface
&& tx
->sdata
->ieee802_1x
&&
949 !(sta_flags
& WLAN_STA_AUTHORIZED
))) {
950 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
951 printk(KERN_DEBUG
"%s: dropped frame to " MAC_FMT
952 " (unauthorized port)\n", tx
->dev
->name
,
953 MAC_ARG(hdr
->addr1
));
955 I802_DEBUG_INC(tx
->local
->tx_handlers_drop_unauth_port
);
959 return TXRX_CONTINUE
;
962 static ieee80211_txrx_result
963 ieee80211_tx_h_sequence(struct ieee80211_txrx_data
*tx
)
965 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)tx
->skb
->data
;
967 if (ieee80211_get_hdrlen(le16_to_cpu(hdr
->frame_control
)) >= 24)
968 ieee80211_include_sequence(tx
->sdata
, hdr
);
970 return TXRX_CONTINUE
;
973 /* This function is called whenever the AP is about to exceed the maximum limit
974 * of buffered frames for power saving STAs. This situation should not really
975 * happen often during normal operation, so dropping the oldest buffered packet
976 * from each queue should be OK to make some room for new frames. */
977 static void purge_old_ps_buffers(struct ieee80211_local
*local
)
979 int total
= 0, purged
= 0;
981 struct ieee80211_sub_if_data
*sdata
;
982 struct sta_info
*sta
;
984 read_lock(&local
->sub_if_lock
);
985 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
986 struct ieee80211_if_ap
*ap
;
987 if (sdata
->dev
== local
->mdev
||
988 sdata
->type
!= IEEE80211_IF_TYPE_AP
)
991 skb
= skb_dequeue(&ap
->ps_bc_buf
);
996 total
+= skb_queue_len(&ap
->ps_bc_buf
);
998 read_unlock(&local
->sub_if_lock
);
1000 spin_lock_bh(&local
->sta_lock
);
1001 list_for_each_entry(sta
, &local
->sta_list
, list
) {
1002 skb
= skb_dequeue(&sta
->ps_tx_buf
);
1007 total
+= skb_queue_len(&sta
->ps_tx_buf
);
1009 spin_unlock_bh(&local
->sta_lock
);
1011 local
->total_ps_buffered
= total
;
1012 printk(KERN_DEBUG
"%s: PS buffers full - purged %d frames\n",
1013 local
->mdev
->name
, purged
);
1017 static inline ieee80211_txrx_result
1018 ieee80211_tx_h_multicast_ps_buf(struct ieee80211_txrx_data
*tx
)
1020 /* broadcast/multicast frame */
1021 /* If any of the associated stations is in power save mode,
1022 * the frame is buffered to be sent after DTIM beacon frame */
1023 if ((tx
->local
->hw
.flags
& IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING
) &&
1024 tx
->sdata
->type
!= IEEE80211_IF_TYPE_WDS
&&
1025 tx
->sdata
->bss
&& atomic_read(&tx
->sdata
->bss
->num_sta_ps
) &&
1026 !(tx
->fc
& IEEE80211_FCTL_ORDER
)) {
1027 if (tx
->local
->total_ps_buffered
>= TOTAL_MAX_TX_BUFFER
)
1028 purge_old_ps_buffers(tx
->local
);
1029 if (skb_queue_len(&tx
->sdata
->bss
->ps_bc_buf
) >=
1031 if (net_ratelimit()) {
1032 printk(KERN_DEBUG
"%s: BC TX buffer full - "
1033 "dropping the oldest frame\n",
1036 dev_kfree_skb(skb_dequeue(&tx
->sdata
->bss
->ps_bc_buf
));
1038 tx
->local
->total_ps_buffered
++;
1039 skb_queue_tail(&tx
->sdata
->bss
->ps_bc_buf
, tx
->skb
);
1043 return TXRX_CONTINUE
;
1047 static inline ieee80211_txrx_result
1048 ieee80211_tx_h_unicast_ps_buf(struct ieee80211_txrx_data
*tx
)
1050 struct sta_info
*sta
= tx
->sta
;
1052 if (unlikely(!sta
||
1053 ((tx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
&&
1054 (tx
->fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_PROBE_RESP
)))
1055 return TXRX_CONTINUE
;
1057 if (unlikely((sta
->flags
& WLAN_STA_PS
) && !sta
->pspoll
)) {
1058 struct ieee80211_tx_packet_data
*pkt_data
;
1059 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
1060 printk(KERN_DEBUG
"STA " MAC_FMT
" aid %d: PS buffer (entries "
1062 MAC_ARG(sta
->addr
), sta
->aid
,
1063 skb_queue_len(&sta
->ps_tx_buf
));
1064 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1065 sta
->flags
|= WLAN_STA_TIM
;
1066 if (tx
->local
->total_ps_buffered
>= TOTAL_MAX_TX_BUFFER
)
1067 purge_old_ps_buffers(tx
->local
);
1068 if (skb_queue_len(&sta
->ps_tx_buf
) >= STA_MAX_TX_BUFFER
) {
1069 struct sk_buff
*old
= skb_dequeue(&sta
->ps_tx_buf
);
1070 if (net_ratelimit()) {
1071 printk(KERN_DEBUG
"%s: STA " MAC_FMT
" TX "
1072 "buffer full - dropping oldest frame\n",
1073 tx
->dev
->name
, MAC_ARG(sta
->addr
));
1077 tx
->local
->total_ps_buffered
++;
1078 /* Queue frame to be sent after STA sends an PS Poll frame */
1079 if (skb_queue_empty(&sta
->ps_tx_buf
)) {
1080 if (tx
->local
->ops
->set_tim
)
1081 tx
->local
->ops
->set_tim(local_to_hw(tx
->local
),
1084 bss_tim_set(tx
->local
, tx
->sdata
->bss
, sta
->aid
);
1086 pkt_data
= (struct ieee80211_tx_packet_data
*)tx
->skb
->cb
;
1087 pkt_data
->jiffies
= jiffies
;
1088 skb_queue_tail(&sta
->ps_tx_buf
, tx
->skb
);
1091 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
1092 else if (unlikely(sta
->flags
& WLAN_STA_PS
)) {
1093 printk(KERN_DEBUG
"%s: STA " MAC_FMT
" in PS mode, but pspoll "
1094 "set -> send frame\n", tx
->dev
->name
,
1095 MAC_ARG(sta
->addr
));
1097 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1100 return TXRX_CONTINUE
;
1104 static ieee80211_txrx_result
1105 ieee80211_tx_h_ps_buf(struct ieee80211_txrx_data
*tx
)
1107 if (unlikely(tx
->u
.tx
.ps_buffered
))
1108 return TXRX_CONTINUE
;
1110 if (tx
->u
.tx
.unicast
)
1111 return ieee80211_tx_h_unicast_ps_buf(tx
);
1113 return ieee80211_tx_h_multicast_ps_buf(tx
);
1118 __ieee80211_tx_prepare(struct ieee80211_txrx_data
*tx
,
1119 struct sk_buff
*skb
,
1120 struct net_device
*dev
,
1121 struct ieee80211_tx_control
*control
)
1123 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1124 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1127 memset(tx
, 0, sizeof(*tx
));
1129 tx
->dev
= dev
; /* use original interface */
1131 tx
->sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1132 tx
->sta
= sta_info_get(local
, hdr
->addr1
);
1133 tx
->fc
= le16_to_cpu(hdr
->frame_control
);
1134 control
->power_level
= local
->hw
.conf
.power_level
;
1135 tx
->u
.tx
.control
= control
;
1136 tx
->u
.tx
.unicast
= !is_multicast_ether_addr(hdr
->addr1
);
1137 if (is_multicast_ether_addr(hdr
->addr1
))
1138 control
->flags
|= IEEE80211_TXCTL_NO_ACK
;
1140 control
->flags
&= ~IEEE80211_TXCTL_NO_ACK
;
1141 tx
->fragmented
= local
->fragmentation_threshold
<
1142 IEEE80211_MAX_FRAG_THRESHOLD
&& tx
->u
.tx
.unicast
&&
1143 skb
->len
+ FCS_LEN
> local
->fragmentation_threshold
&&
1144 (!local
->ops
->set_frag_threshold
);
1146 control
->flags
|= IEEE80211_TXCTL_CLEAR_DST_MASK
;
1147 else if (tx
->sta
->clear_dst_mask
) {
1148 control
->flags
|= IEEE80211_TXCTL_CLEAR_DST_MASK
;
1149 tx
->sta
->clear_dst_mask
= 0;
1151 control
->antenna_sel_tx
= local
->hw
.conf
.antenna_sel_tx
;
1152 if (local
->sta_antenna_sel
!= STA_ANTENNA_SEL_AUTO
&& tx
->sta
)
1153 control
->antenna_sel_tx
= tx
->sta
->antenna_sel_tx
;
1154 hdrlen
= ieee80211_get_hdrlen(tx
->fc
);
1155 if (skb
->len
> hdrlen
+ sizeof(rfc1042_header
) + 2) {
1156 u8
*pos
= &skb
->data
[hdrlen
+ sizeof(rfc1042_header
)];
1157 tx
->ethertype
= (pos
[0] << 8) | pos
[1];
1159 control
->flags
|= IEEE80211_TXCTL_FIRST_FRAGMENT
;
1163 static int inline is_ieee80211_device(struct net_device
*dev
,
1164 struct net_device
*master
)
1166 return (wdev_priv(dev
->ieee80211_ptr
) ==
1167 wdev_priv(master
->ieee80211_ptr
));
1170 /* Device in tx->dev has a reference added; use dev_put(tx->dev) when
1171 * finished with it. */
1172 static int inline ieee80211_tx_prepare(struct ieee80211_txrx_data
*tx
,
1173 struct sk_buff
*skb
,
1174 struct net_device
*mdev
,
1175 struct ieee80211_tx_control
*control
)
1177 struct ieee80211_tx_packet_data
*pkt_data
;
1178 struct net_device
*dev
;
1180 pkt_data
= (struct ieee80211_tx_packet_data
*)skb
->cb
;
1181 dev
= dev_get_by_index(pkt_data
->ifindex
);
1182 if (unlikely(dev
&& !is_ieee80211_device(dev
, mdev
))) {
1188 __ieee80211_tx_prepare(tx
, skb
, dev
, control
);
1192 static inline int __ieee80211_queue_stopped(const struct ieee80211_local
*local
,
1195 return test_bit(IEEE80211_LINK_STATE_XOFF
, &local
->state
[queue
]);
1198 static inline int __ieee80211_queue_pending(const struct ieee80211_local
*local
,
1201 return test_bit(IEEE80211_LINK_STATE_PENDING
, &local
->state
[queue
]);
1204 #define IEEE80211_TX_OK 0
1205 #define IEEE80211_TX_AGAIN 1
1206 #define IEEE80211_TX_FRAG_AGAIN 2
1208 static int __ieee80211_tx(struct ieee80211_local
*local
, struct sk_buff
*skb
,
1209 struct ieee80211_txrx_data
*tx
)
1211 struct ieee80211_tx_control
*control
= tx
->u
.tx
.control
;
1214 if (!ieee80211_qdisc_installed(local
->mdev
) &&
1215 __ieee80211_queue_stopped(local
, 0)) {
1216 netif_stop_queue(local
->mdev
);
1217 return IEEE80211_TX_AGAIN
;
1220 ieee80211_dump_frame(local
->mdev
->name
, "TX to low-level driver", skb
);
1221 ret
= local
->ops
->tx(local_to_hw(local
), skb
, control
);
1223 return IEEE80211_TX_AGAIN
;
1224 local
->mdev
->trans_start
= jiffies
;
1225 ieee80211_led_tx(local
, 1);
1227 if (tx
->u
.tx
.extra_frag
) {
1228 control
->flags
&= ~(IEEE80211_TXCTL_USE_RTS_CTS
|
1229 IEEE80211_TXCTL_USE_CTS_PROTECT
|
1230 IEEE80211_TXCTL_CLEAR_DST_MASK
|
1231 IEEE80211_TXCTL_FIRST_FRAGMENT
);
1232 for (i
= 0; i
< tx
->u
.tx
.num_extra_frag
; i
++) {
1233 if (!tx
->u
.tx
.extra_frag
[i
])
1235 if (__ieee80211_queue_stopped(local
, control
->queue
))
1236 return IEEE80211_TX_FRAG_AGAIN
;
1237 if (i
== tx
->u
.tx
.num_extra_frag
) {
1238 control
->tx_rate
= tx
->u
.tx
.last_frag_hwrate
;
1239 control
->rate
= tx
->u
.tx
.last_frag_rate
;
1240 if (tx
->u
.tx
.probe_last_frag
)
1242 IEEE80211_TXCTL_RATE_CTRL_PROBE
;
1245 ~IEEE80211_TXCTL_RATE_CTRL_PROBE
;
1248 ieee80211_dump_frame(local
->mdev
->name
,
1249 "TX to low-level driver",
1250 tx
->u
.tx
.extra_frag
[i
]);
1251 ret
= local
->ops
->tx(local_to_hw(local
),
1252 tx
->u
.tx
.extra_frag
[i
],
1255 return IEEE80211_TX_FRAG_AGAIN
;
1256 local
->mdev
->trans_start
= jiffies
;
1257 ieee80211_led_tx(local
, 1);
1258 tx
->u
.tx
.extra_frag
[i
] = NULL
;
1260 kfree(tx
->u
.tx
.extra_frag
);
1261 tx
->u
.tx
.extra_frag
= NULL
;
1263 return IEEE80211_TX_OK
;
1266 static int ieee80211_tx(struct net_device
*dev
, struct sk_buff
*skb
,
1267 struct ieee80211_tx_control
*control
, int mgmt
)
1269 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1270 struct sta_info
*sta
;
1271 ieee80211_tx_handler
*handler
;
1272 struct ieee80211_txrx_data tx
;
1273 ieee80211_txrx_result res
= TXRX_DROP
;
1276 WARN_ON(__ieee80211_queue_pending(local
, control
->queue
));
1278 if (unlikely(skb
->len
< 10)) {
1283 __ieee80211_tx_prepare(&tx
, skb
, dev
, control
);
1285 tx
.u
.tx
.mgmt_interface
= mgmt
;
1286 tx
.u
.tx
.mode
= local
->hw
.conf
.mode
;
1288 for (handler
= local
->tx_handlers
; *handler
!= NULL
; handler
++) {
1289 res
= (*handler
)(&tx
);
1290 if (res
!= TXRX_CONTINUE
)
1294 skb
= tx
.skb
; /* handlers are allowed to change skb */
1299 if (unlikely(res
== TXRX_DROP
)) {
1300 I802_DEBUG_INC(local
->tx_handlers_drop
);
1304 if (unlikely(res
== TXRX_QUEUED
)) {
1305 I802_DEBUG_INC(local
->tx_handlers_queued
);
1309 if (tx
.u
.tx
.extra_frag
) {
1310 for (i
= 0; i
< tx
.u
.tx
.num_extra_frag
; i
++) {
1312 struct ieee80211_hdr
*hdr
=
1313 (struct ieee80211_hdr
*)
1314 tx
.u
.tx
.extra_frag
[i
]->data
;
1316 if (i
+ 1 < tx
.u
.tx
.num_extra_frag
) {
1317 next_len
= tx
.u
.tx
.extra_frag
[i
+ 1]->len
;
1320 tx
.u
.tx
.rate
= tx
.u
.tx
.last_frag_rate
;
1321 tx
.u
.tx
.last_frag_hwrate
= tx
.u
.tx
.rate
->val
;
1323 dur
= ieee80211_duration(&tx
, 0, next_len
);
1324 hdr
->duration_id
= cpu_to_le16(dur
);
1329 ret
= __ieee80211_tx(local
, skb
, &tx
);
1331 struct ieee80211_tx_stored_packet
*store
=
1332 &local
->pending_packet
[control
->queue
];
1334 if (ret
== IEEE80211_TX_FRAG_AGAIN
)
1336 set_bit(IEEE80211_LINK_STATE_PENDING
,
1337 &local
->state
[control
->queue
]);
1339 /* When the driver gets out of buffers during sending of
1340 * fragments and calls ieee80211_stop_queue, there is
1341 * a small window between IEEE80211_LINK_STATE_XOFF and
1342 * IEEE80211_LINK_STATE_PENDING flags are set. If a buffer
1343 * gets available in that window (i.e. driver calls
1344 * ieee80211_wake_queue), we would end up with ieee80211_tx
1345 * called with IEEE80211_LINK_STATE_PENDING. Prevent this by
1346 * continuing transmitting here when that situation is
1347 * possible to have happened. */
1348 if (!__ieee80211_queue_stopped(local
, control
->queue
)) {
1349 clear_bit(IEEE80211_LINK_STATE_PENDING
,
1350 &local
->state
[control
->queue
]);
1353 memcpy(&store
->control
, control
,
1354 sizeof(struct ieee80211_tx_control
));
1356 store
->extra_frag
= tx
.u
.tx
.extra_frag
;
1357 store
->num_extra_frag
= tx
.u
.tx
.num_extra_frag
;
1358 store
->last_frag_hwrate
= tx
.u
.tx
.last_frag_hwrate
;
1359 store
->last_frag_rate
= tx
.u
.tx
.last_frag_rate
;
1360 store
->last_frag_rate_ctrl_probe
= tx
.u
.tx
.probe_last_frag
;
1367 for (i
= 0; i
< tx
.u
.tx
.num_extra_frag
; i
++)
1368 if (tx
.u
.tx
.extra_frag
[i
])
1369 dev_kfree_skb(tx
.u
.tx
.extra_frag
[i
]);
1370 kfree(tx
.u
.tx
.extra_frag
);
1374 static void ieee80211_tx_pending(unsigned long data
)
1376 struct ieee80211_local
*local
= (struct ieee80211_local
*)data
;
1377 struct net_device
*dev
= local
->mdev
;
1378 struct ieee80211_tx_stored_packet
*store
;
1379 struct ieee80211_txrx_data tx
;
1380 int i
, ret
, reschedule
= 0;
1382 netif_tx_lock_bh(dev
);
1383 for (i
= 0; i
< local
->hw
.queues
; i
++) {
1384 if (__ieee80211_queue_stopped(local
, i
))
1386 if (!__ieee80211_queue_pending(local
, i
)) {
1390 store
= &local
->pending_packet
[i
];
1391 tx
.u
.tx
.control
= &store
->control
;
1392 tx
.u
.tx
.extra_frag
= store
->extra_frag
;
1393 tx
.u
.tx
.num_extra_frag
= store
->num_extra_frag
;
1394 tx
.u
.tx
.last_frag_hwrate
= store
->last_frag_hwrate
;
1395 tx
.u
.tx
.last_frag_rate
= store
->last_frag_rate
;
1396 tx
.u
.tx
.probe_last_frag
= store
->last_frag_rate_ctrl_probe
;
1397 ret
= __ieee80211_tx(local
, store
->skb
, &tx
);
1399 if (ret
== IEEE80211_TX_FRAG_AGAIN
)
1402 clear_bit(IEEE80211_LINK_STATE_PENDING
,
1407 netif_tx_unlock_bh(dev
);
1409 if (!ieee80211_qdisc_installed(dev
)) {
1410 if (!__ieee80211_queue_stopped(local
, 0))
1411 netif_wake_queue(dev
);
1413 netif_schedule(dev
);
1417 static void ieee80211_clear_tx_pending(struct ieee80211_local
*local
)
1420 struct ieee80211_tx_stored_packet
*store
;
1422 for (i
= 0; i
< local
->hw
.queues
; i
++) {
1423 if (!__ieee80211_queue_pending(local
, i
))
1425 store
= &local
->pending_packet
[i
];
1426 kfree_skb(store
->skb
);
1427 for (j
= 0; j
< store
->num_extra_frag
; j
++)
1428 kfree_skb(store
->extra_frag
[j
]);
1429 kfree(store
->extra_frag
);
1430 clear_bit(IEEE80211_LINK_STATE_PENDING
, &local
->state
[i
]);
1434 static int ieee80211_master_start_xmit(struct sk_buff
*skb
,
1435 struct net_device
*dev
)
1437 struct ieee80211_tx_control control
;
1438 struct ieee80211_tx_packet_data
*pkt_data
;
1439 struct net_device
*odev
= NULL
;
1440 struct ieee80211_sub_if_data
*osdata
;
1445 * copy control out of the skb so other people can use skb->cb
1447 pkt_data
= (struct ieee80211_tx_packet_data
*)skb
->cb
;
1448 memset(&control
, 0, sizeof(struct ieee80211_tx_control
));
1450 if (pkt_data
->ifindex
)
1451 odev
= dev_get_by_index(pkt_data
->ifindex
);
1452 if (unlikely(odev
&& !is_ieee80211_device(odev
, dev
))) {
1456 if (unlikely(!odev
)) {
1457 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1458 printk(KERN_DEBUG
"%s: Discarded packet with nonexistent "
1459 "originating device\n", dev
->name
);
1464 osdata
= IEEE80211_DEV_TO_SUB_IF(odev
);
1466 headroom
= osdata
->local
->hw
.extra_tx_headroom
+
1467 IEEE80211_ENCRYPT_HEADROOM
;
1468 if (skb_headroom(skb
) < headroom
) {
1469 if (pskb_expand_head(skb
, headroom
, 0, GFP_ATOMIC
)) {
1475 control
.ifindex
= odev
->ifindex
;
1476 control
.type
= osdata
->type
;
1477 if (pkt_data
->req_tx_status
)
1478 control
.flags
|= IEEE80211_TXCTL_REQ_TX_STATUS
;
1479 if (pkt_data
->do_not_encrypt
)
1480 control
.flags
|= IEEE80211_TXCTL_DO_NOT_ENCRYPT
;
1481 if (pkt_data
->requeue
)
1482 control
.flags
|= IEEE80211_TXCTL_REQUEUE
;
1483 control
.queue
= pkt_data
->queue
;
1485 ret
= ieee80211_tx(odev
, skb
, &control
,
1486 control
.type
== IEEE80211_IF_TYPE_MGMT
);
1494 * ieee80211_subif_start_xmit - netif start_xmit function for Ethernet-type
1495 * subinterfaces (wlan#, WDS, and VLAN interfaces)
1496 * @skb: packet to be sent
1497 * @dev: incoming interface
1499 * Returns: 0 on success (and frees skb in this case) or 1 on failure (skb will
1500 * not be freed, and caller is responsible for either retrying later or freeing
1503 * This function takes in an Ethernet header and encapsulates it with suitable
1504 * IEEE 802.11 header based on which interface the packet is coming in. The
1505 * encapsulated packet will then be passed to master interface, wlan#.11, for
1506 * transmission (through low-level driver).
1508 static int ieee80211_subif_start_xmit(struct sk_buff
*skb
,
1509 struct net_device
*dev
)
1511 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1512 struct ieee80211_tx_packet_data
*pkt_data
;
1513 struct ieee80211_sub_if_data
*sdata
;
1514 int ret
= 1, head_need
;
1515 u16 ethertype
, hdrlen
, fc
;
1516 struct ieee80211_hdr hdr
;
1517 const u8
*encaps_data
;
1518 int encaps_len
, skip_header_bytes
;
1519 int nh_pos
, h_pos
, no_encrypt
= 0;
1520 struct sta_info
*sta
;
1522 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1523 if (unlikely(skb
->len
< ETH_HLEN
)) {
1524 printk(KERN_DEBUG
"%s: short skb (len=%d)\n",
1525 dev
->name
, skb
->len
);
1530 nh_pos
= skb_network_header(skb
) - skb
->data
;
1531 h_pos
= skb_transport_header(skb
) - skb
->data
;
1533 /* convert Ethernet header to proper 802.11 header (based on
1534 * operation mode) */
1535 ethertype
= (skb
->data
[12] << 8) | skb
->data
[13];
1536 /* TODO: handling for 802.1x authorized/unauthorized port */
1537 fc
= IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_DATA
;
1539 if (likely(sdata
->type
== IEEE80211_IF_TYPE_AP
||
1540 sdata
->type
== IEEE80211_IF_TYPE_VLAN
)) {
1541 fc
|= IEEE80211_FCTL_FROMDS
;
1543 memcpy(hdr
.addr1
, skb
->data
, ETH_ALEN
);
1544 memcpy(hdr
.addr2
, dev
->dev_addr
, ETH_ALEN
);
1545 memcpy(hdr
.addr3
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
1547 } else if (sdata
->type
== IEEE80211_IF_TYPE_WDS
) {
1548 fc
|= IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
;
1550 memcpy(hdr
.addr1
, sdata
->u
.wds
.remote_addr
, ETH_ALEN
);
1551 memcpy(hdr
.addr2
, dev
->dev_addr
, ETH_ALEN
);
1552 memcpy(hdr
.addr3
, skb
->data
, ETH_ALEN
);
1553 memcpy(hdr
.addr4
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
1555 } else if (sdata
->type
== IEEE80211_IF_TYPE_STA
) {
1556 fc
|= IEEE80211_FCTL_TODS
;
1558 memcpy(hdr
.addr1
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
1559 memcpy(hdr
.addr2
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
1560 memcpy(hdr
.addr3
, skb
->data
, ETH_ALEN
);
1562 } else if (sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
1564 memcpy(hdr
.addr1
, skb
->data
, ETH_ALEN
);
1565 memcpy(hdr
.addr2
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
1566 memcpy(hdr
.addr3
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
1573 /* receiver is QoS enabled, use a QoS type frame */
1574 sta
= sta_info_get(local
, hdr
.addr1
);
1576 if (sta
->flags
& WLAN_STA_WME
) {
1577 fc
|= IEEE80211_STYPE_QOS_DATA
;
1583 hdr
.frame_control
= cpu_to_le16(fc
);
1584 hdr
.duration_id
= 0;
1587 skip_header_bytes
= ETH_HLEN
;
1588 if (ethertype
== ETH_P_AARP
|| ethertype
== ETH_P_IPX
) {
1589 encaps_data
= bridge_tunnel_header
;
1590 encaps_len
= sizeof(bridge_tunnel_header
);
1591 skip_header_bytes
-= 2;
1592 } else if (ethertype
>= 0x600) {
1593 encaps_data
= rfc1042_header
;
1594 encaps_len
= sizeof(rfc1042_header
);
1595 skip_header_bytes
-= 2;
1601 skb_pull(skb
, skip_header_bytes
);
1602 nh_pos
-= skip_header_bytes
;
1603 h_pos
-= skip_header_bytes
;
1605 /* TODO: implement support for fragments so that there is no need to
1606 * reallocate and copy payload; it might be enough to support one
1607 * extra fragment that would be copied in the beginning of the frame
1608 * data.. anyway, it would be nice to include this into skb structure
1611 * There are few options for this:
1612 * use skb->cb as an extra space for 802.11 header
1613 * allocate new buffer if not enough headroom
1614 * make sure that there is enough headroom in every skb by increasing
1615 * build in headroom in __dev_alloc_skb() (linux/skbuff.h) and
1616 * alloc_skb() (net/core/skbuff.c)
1618 head_need
= hdrlen
+ encaps_len
+ local
->hw
.extra_tx_headroom
;
1619 head_need
-= skb_headroom(skb
);
1621 /* We are going to modify skb data, so make a copy of it if happens to
1622 * be cloned. This could happen, e.g., with Linux bridge code passing
1623 * us broadcast frames. */
1625 if (head_need
> 0 || skb_cloned(skb
)) {
1627 printk(KERN_DEBUG
"%s: need to reallocate buffer for %d bytes "
1628 "of headroom\n", dev
->name
, head_need
);
1631 if (skb_cloned(skb
))
1632 I802_DEBUG_INC(local
->tx_expand_skb_head_cloned
);
1634 I802_DEBUG_INC(local
->tx_expand_skb_head
);
1635 /* Since we have to reallocate the buffer, make sure that there
1636 * is enough room for possible WEP IV/ICV and TKIP (8 bytes
1637 * before payload and 12 after). */
1638 if (pskb_expand_head(skb
, (head_need
> 0 ? head_need
+ 8 : 8),
1640 printk(KERN_DEBUG
"%s: failed to reallocate TX buffer"
1647 memcpy(skb_push(skb
, encaps_len
), encaps_data
, encaps_len
);
1648 nh_pos
+= encaps_len
;
1649 h_pos
+= encaps_len
;
1651 memcpy(skb_push(skb
, hdrlen
), &hdr
, hdrlen
);
1655 pkt_data
= (struct ieee80211_tx_packet_data
*)skb
->cb
;
1656 memset(pkt_data
, 0, sizeof(struct ieee80211_tx_packet_data
));
1657 pkt_data
->ifindex
= sdata
->dev
->ifindex
;
1658 pkt_data
->mgmt_iface
= (sdata
->type
== IEEE80211_IF_TYPE_MGMT
);
1659 pkt_data
->do_not_encrypt
= no_encrypt
;
1661 skb
->dev
= local
->mdev
;
1662 sdata
->stats
.tx_packets
++;
1663 sdata
->stats
.tx_bytes
+= skb
->len
;
1665 /* Update skb pointers to various headers since this modified frame
1666 * is going to go through Linux networking code that may potentially
1667 * need things like pointer to IP header. */
1668 skb_set_mac_header(skb
, 0);
1669 skb_set_network_header(skb
, nh_pos
);
1670 skb_set_transport_header(skb
, h_pos
);
1672 dev
->trans_start
= jiffies
;
1673 dev_queue_xmit(skb
);
1686 * This is the transmit routine for the 802.11 type interfaces
1687 * called by upper layers of the linux networking
1688 * stack when it has a frame to transmit
1691 ieee80211_mgmt_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1693 struct ieee80211_sub_if_data
*sdata
;
1694 struct ieee80211_tx_packet_data
*pkt_data
;
1695 struct ieee80211_hdr
*hdr
;
1698 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1700 if (skb
->len
< 10) {
1705 if (skb_headroom(skb
) < sdata
->local
->hw
.extra_tx_headroom
) {
1706 if (pskb_expand_head(skb
,
1707 sdata
->local
->hw
.extra_tx_headroom
, 0, GFP_ATOMIC
)) {
1713 hdr
= (struct ieee80211_hdr
*) skb
->data
;
1714 fc
= le16_to_cpu(hdr
->frame_control
);
1716 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
1717 memset(pkt_data
, 0, sizeof(struct ieee80211_tx_packet_data
));
1718 pkt_data
->ifindex
= sdata
->dev
->ifindex
;
1719 pkt_data
->mgmt_iface
= (sdata
->type
== IEEE80211_IF_TYPE_MGMT
);
1721 skb
->priority
= 20; /* use hardcoded priority for mgmt TX queue */
1722 skb
->dev
= sdata
->local
->mdev
;
1725 * We're using the protocol field of the the frame control header
1726 * to request TX callback for hostapd. BIT(1) is checked.
1728 if ((fc
& BIT(1)) == BIT(1)) {
1729 pkt_data
->req_tx_status
= 1;
1731 hdr
->frame_control
= cpu_to_le16(fc
);
1734 pkt_data
->do_not_encrypt
= !(fc
& IEEE80211_FCTL_PROTECTED
);
1736 sdata
->stats
.tx_packets
++;
1737 sdata
->stats
.tx_bytes
+= skb
->len
;
1739 dev_queue_xmit(skb
);
1745 static void ieee80211_beacon_add_tim(struct ieee80211_local
*local
,
1746 struct ieee80211_if_ap
*bss
,
1747 struct sk_buff
*skb
)
1751 int i
, have_bits
= 0, n1
, n2
;
1753 /* Generate bitmap for TIM only if there are any STAs in power save
1755 spin_lock_bh(&local
->sta_lock
);
1756 if (atomic_read(&bss
->num_sta_ps
) > 0)
1757 /* in the hope that this is faster than
1758 * checking byte-for-byte */
1759 have_bits
= !bitmap_empty((unsigned long*)bss
->tim
,
1760 IEEE80211_MAX_AID
+1);
1762 if (bss
->dtim_count
== 0)
1763 bss
->dtim_count
= bss
->dtim_period
- 1;
1767 tim
= pos
= (u8
*) skb_put(skb
, 6);
1768 *pos
++ = WLAN_EID_TIM
;
1770 *pos
++ = bss
->dtim_count
;
1771 *pos
++ = bss
->dtim_period
;
1773 if (bss
->dtim_count
== 0 && !skb_queue_empty(&bss
->ps_bc_buf
))
1777 /* Find largest even number N1 so that bits numbered 1 through
1778 * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
1779 * (N2 + 1) x 8 through 2007 are 0. */
1781 for (i
= 0; i
< IEEE80211_MAX_TIM_LEN
; i
++) {
1788 for (i
= IEEE80211_MAX_TIM_LEN
- 1; i
>= n1
; i
--) {
1795 /* Bitmap control */
1797 /* Part Virt Bitmap */
1798 memcpy(pos
, bss
->tim
+ n1
, n2
- n1
+ 1);
1800 tim
[1] = n2
- n1
+ 4;
1801 skb_put(skb
, n2
- n1
);
1803 *pos
++ = aid0
; /* Bitmap control */
1804 *pos
++ = 0; /* Part Virt Bitmap */
1806 spin_unlock_bh(&local
->sta_lock
);
1810 struct sk_buff
* ieee80211_beacon_get(struct ieee80211_hw
*hw
, int if_id
,
1811 struct ieee80211_tx_control
*control
)
1813 struct ieee80211_local
*local
= hw_to_local(hw
);
1814 struct sk_buff
*skb
;
1815 struct net_device
*bdev
;
1816 struct ieee80211_sub_if_data
*sdata
= NULL
;
1817 struct ieee80211_if_ap
*ap
= NULL
;
1818 struct ieee80211_rate
*rate
;
1819 struct rate_control_extra extra
;
1820 u8
*b_head
, *b_tail
;
1823 bdev
= dev_get_by_index(if_id
);
1825 sdata
= IEEE80211_DEV_TO_SUB_IF(bdev
);
1830 if (!ap
|| sdata
->type
!= IEEE80211_IF_TYPE_AP
||
1832 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1833 if (net_ratelimit())
1834 printk(KERN_DEBUG
"no beacon data avail for idx=%d "
1835 "(%s)\n", if_id
, bdev
? bdev
->name
: "N/A");
1836 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
1840 /* Assume we are generating the normal beacon locally */
1841 b_head
= ap
->beacon_head
;
1842 b_tail
= ap
->beacon_tail
;
1843 bh_len
= ap
->beacon_head_len
;
1844 bt_len
= ap
->beacon_tail_len
;
1846 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
1847 bh_len
+ bt_len
+ 256 /* maximum TIM len */);
1851 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1852 memcpy(skb_put(skb
, bh_len
), b_head
, bh_len
);
1854 ieee80211_include_sequence(sdata
, (struct ieee80211_hdr
*)skb
->data
);
1856 ieee80211_beacon_add_tim(local
, ap
, skb
);
1859 memcpy(skb_put(skb
, bt_len
), b_tail
, bt_len
);
1863 memset(&extra
, 0, sizeof(extra
));
1864 extra
.mode
= local
->oper_hw_mode
;
1866 rate
= rate_control_get_rate(local
, local
->mdev
, skb
, &extra
);
1868 if (net_ratelimit()) {
1869 printk(KERN_DEBUG
"%s: ieee80211_beacon_get: no rate "
1870 "found\n", local
->mdev
->name
);
1876 control
->tx_rate
= (local
->short_preamble
&&
1877 (rate
->flags
& IEEE80211_RATE_PREAMBLE2
)) ?
1878 rate
->val2
: rate
->val
;
1879 control
->antenna_sel_tx
= local
->hw
.conf
.antenna_sel_tx
;
1880 control
->power_level
= local
->hw
.conf
.power_level
;
1881 control
->flags
|= IEEE80211_TXCTL_NO_ACK
;
1882 control
->retry_limit
= 1;
1883 control
->flags
|= IEEE80211_TXCTL_CLEAR_DST_MASK
;
1889 EXPORT_SYMBOL(ieee80211_beacon_get
);
1891 __le16
ieee80211_rts_duration(struct ieee80211_hw
*hw
,
1893 const struct ieee80211_tx_control
*frame_txctl
)
1895 struct ieee80211_local
*local
= hw_to_local(hw
);
1896 struct ieee80211_rate
*rate
;
1897 int short_preamble
= local
->short_preamble
;
1901 rate
= frame_txctl
->rts_rate
;
1902 erp
= !!(rate
->flags
& IEEE80211_RATE_ERP
);
1905 dur
= ieee80211_frame_duration(local
, 10, rate
->rate
,
1906 erp
, short_preamble
);
1907 /* Data frame duration */
1908 dur
+= ieee80211_frame_duration(local
, frame_len
, rate
->rate
,
1909 erp
, short_preamble
);
1911 dur
+= ieee80211_frame_duration(local
, 10, rate
->rate
,
1912 erp
, short_preamble
);
1914 return cpu_to_le16(dur
);
1916 EXPORT_SYMBOL(ieee80211_rts_duration
);
1919 __le16
ieee80211_ctstoself_duration(struct ieee80211_hw
*hw
,
1921 const struct ieee80211_tx_control
*frame_txctl
)
1923 struct ieee80211_local
*local
= hw_to_local(hw
);
1924 struct ieee80211_rate
*rate
;
1925 int short_preamble
= local
->short_preamble
;
1929 rate
= frame_txctl
->rts_rate
;
1930 erp
= !!(rate
->flags
& IEEE80211_RATE_ERP
);
1932 /* Data frame duration */
1933 dur
= ieee80211_frame_duration(local
, frame_len
, rate
->rate
,
1934 erp
, short_preamble
);
1935 if (!(frame_txctl
->flags
& IEEE80211_TXCTL_NO_ACK
)) {
1937 dur
+= ieee80211_frame_duration(local
, 10, rate
->rate
,
1938 erp
, short_preamble
);
1941 return cpu_to_le16(dur
);
1943 EXPORT_SYMBOL(ieee80211_ctstoself_duration
);
1945 void ieee80211_rts_get(struct ieee80211_hw
*hw
,
1946 const void *frame
, size_t frame_len
,
1947 const struct ieee80211_tx_control
*frame_txctl
,
1948 struct ieee80211_rts
*rts
)
1950 const struct ieee80211_hdr
*hdr
= frame
;
1953 fctl
= IEEE80211_FTYPE_CTL
| IEEE80211_STYPE_RTS
;
1954 rts
->frame_control
= cpu_to_le16(fctl
);
1955 rts
->duration
= ieee80211_rts_duration(hw
, frame_len
, frame_txctl
);
1956 memcpy(rts
->ra
, hdr
->addr1
, sizeof(rts
->ra
));
1957 memcpy(rts
->ta
, hdr
->addr2
, sizeof(rts
->ta
));
1959 EXPORT_SYMBOL(ieee80211_rts_get
);
1961 void ieee80211_ctstoself_get(struct ieee80211_hw
*hw
,
1962 const void *frame
, size_t frame_len
,
1963 const struct ieee80211_tx_control
*frame_txctl
,
1964 struct ieee80211_cts
*cts
)
1966 const struct ieee80211_hdr
*hdr
= frame
;
1969 fctl
= IEEE80211_FTYPE_CTL
| IEEE80211_STYPE_CTS
;
1970 cts
->frame_control
= cpu_to_le16(fctl
);
1971 cts
->duration
= ieee80211_ctstoself_duration(hw
, frame_len
, frame_txctl
);
1972 memcpy(cts
->ra
, hdr
->addr1
, sizeof(cts
->ra
));
1974 EXPORT_SYMBOL(ieee80211_ctstoself_get
);
1977 ieee80211_get_buffered_bc(struct ieee80211_hw
*hw
, int if_id
,
1978 struct ieee80211_tx_control
*control
)
1980 struct ieee80211_local
*local
= hw_to_local(hw
);
1981 struct sk_buff
*skb
;
1982 struct sta_info
*sta
;
1983 ieee80211_tx_handler
*handler
;
1984 struct ieee80211_txrx_data tx
;
1985 ieee80211_txrx_result res
= TXRX_DROP
;
1986 struct net_device
*bdev
;
1987 struct ieee80211_sub_if_data
*sdata
;
1988 struct ieee80211_if_ap
*bss
= NULL
;
1990 bdev
= dev_get_by_index(if_id
);
1992 sdata
= IEEE80211_DEV_TO_SUB_IF(bdev
);
1996 if (!bss
|| sdata
->type
!= IEEE80211_IF_TYPE_AP
|| !bss
->beacon_head
)
1999 if (bss
->dtim_count
!= 0)
2000 return NULL
; /* send buffered bc/mc only after DTIM beacon */
2001 memset(control
, 0, sizeof(*control
));
2003 skb
= skb_dequeue(&bss
->ps_bc_buf
);
2006 local
->total_ps_buffered
--;
2008 if (!skb_queue_empty(&bss
->ps_bc_buf
) && skb
->len
>= 2) {
2009 struct ieee80211_hdr
*hdr
=
2010 (struct ieee80211_hdr
*) skb
->data
;
2011 /* more buffered multicast/broadcast frames ==> set
2012 * MoreData flag in IEEE 802.11 header to inform PS
2014 hdr
->frame_control
|=
2015 cpu_to_le16(IEEE80211_FCTL_MOREDATA
);
2018 if (ieee80211_tx_prepare(&tx
, skb
, local
->mdev
, control
) == 0)
2020 dev_kfree_skb_any(skb
);
2023 tx
.u
.tx
.ps_buffered
= 1;
2025 for (handler
= local
->tx_handlers
; *handler
!= NULL
; handler
++) {
2026 res
= (*handler
)(&tx
);
2027 if (res
== TXRX_DROP
|| res
== TXRX_QUEUED
)
2031 skb
= tx
.skb
; /* handlers are allowed to change skb */
2033 if (res
== TXRX_DROP
) {
2034 I802_DEBUG_INC(local
->tx_handlers_drop
);
2037 } else if (res
== TXRX_QUEUED
) {
2038 I802_DEBUG_INC(local
->tx_handlers_queued
);
2047 EXPORT_SYMBOL(ieee80211_get_buffered_bc
);
2049 static int __ieee80211_if_config(struct net_device
*dev
,
2050 struct sk_buff
*beacon
,
2051 struct ieee80211_tx_control
*control
)
2053 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2054 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2055 struct ieee80211_if_conf conf
;
2056 static u8 scan_bssid
[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2058 if (!local
->ops
->config_interface
|| !netif_running(dev
))
2061 memset(&conf
, 0, sizeof(conf
));
2062 conf
.type
= sdata
->type
;
2063 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
2064 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
2065 if (local
->sta_scanning
&&
2066 local
->scan_dev
== dev
)
2067 conf
.bssid
= scan_bssid
;
2069 conf
.bssid
= sdata
->u
.sta
.bssid
;
2070 conf
.ssid
= sdata
->u
.sta
.ssid
;
2071 conf
.ssid_len
= sdata
->u
.sta
.ssid_len
;
2072 conf
.generic_elem
= sdata
->u
.sta
.extra_ie
;
2073 conf
.generic_elem_len
= sdata
->u
.sta
.extra_ie_len
;
2074 } else if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
2075 conf
.ssid
= sdata
->u
.ap
.ssid
;
2076 conf
.ssid_len
= sdata
->u
.ap
.ssid_len
;
2077 conf
.generic_elem
= sdata
->u
.ap
.generic_elem
;
2078 conf
.generic_elem_len
= sdata
->u
.ap
.generic_elem_len
;
2079 conf
.beacon
= beacon
;
2080 conf
.beacon_control
= control
;
2082 return local
->ops
->config_interface(local_to_hw(local
),
2083 dev
->ifindex
, &conf
);
2086 int ieee80211_if_config(struct net_device
*dev
)
2088 return __ieee80211_if_config(dev
, NULL
, NULL
);
2091 int ieee80211_if_config_beacon(struct net_device
*dev
)
2093 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2094 struct ieee80211_tx_control control
;
2095 struct sk_buff
*skb
;
2097 if (!(local
->hw
.flags
& IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE
))
2099 skb
= ieee80211_beacon_get(local_to_hw(local
), dev
->ifindex
, &control
);
2102 return __ieee80211_if_config(dev
, skb
, &control
);
2105 int ieee80211_hw_config(struct ieee80211_local
*local
)
2107 struct ieee80211_hw_mode
*mode
;
2108 struct ieee80211_channel
*chan
;
2111 if (local
->sta_scanning
) {
2112 chan
= local
->scan_channel
;
2113 mode
= local
->scan_hw_mode
;
2115 chan
= local
->oper_channel
;
2116 mode
= local
->oper_hw_mode
;
2119 local
->hw
.conf
.channel
= chan
->chan
;
2120 local
->hw
.conf
.channel_val
= chan
->val
;
2121 local
->hw
.conf
.power_level
= chan
->power_level
;
2122 local
->hw
.conf
.freq
= chan
->freq
;
2123 local
->hw
.conf
.phymode
= mode
->mode
;
2124 local
->hw
.conf
.antenna_max
= chan
->antenna_max
;
2125 local
->hw
.conf
.chan
= chan
;
2126 local
->hw
.conf
.mode
= mode
;
2128 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2129 printk(KERN_DEBUG
"HW CONFIG: channel=%d freq=%d "
2130 "phymode=%d\n", local
->hw
.conf
.channel
, local
->hw
.conf
.freq
,
2131 local
->hw
.conf
.phymode
);
2132 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
2134 if (local
->ops
->config
)
2135 ret
= local
->ops
->config(local_to_hw(local
), &local
->hw
.conf
);
2141 static int ieee80211_change_mtu(struct net_device
*dev
, int new_mtu
)
2143 /* FIX: what would be proper limits for MTU?
2144 * This interface uses 802.3 frames. */
2145 if (new_mtu
< 256 || new_mtu
> IEEE80211_MAX_DATA_LEN
- 24 - 6) {
2146 printk(KERN_WARNING
"%s: invalid MTU %d\n",
2147 dev
->name
, new_mtu
);
2151 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2152 printk(KERN_DEBUG
"%s: setting MTU %d\n", dev
->name
, new_mtu
);
2153 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
2159 static int ieee80211_change_mtu_apdev(struct net_device
*dev
, int new_mtu
)
2161 /* FIX: what would be proper limits for MTU?
2162 * This interface uses 802.11 frames. */
2163 if (new_mtu
< 256 || new_mtu
> IEEE80211_MAX_DATA_LEN
) {
2164 printk(KERN_WARNING
"%s: invalid MTU %d\n",
2165 dev
->name
, new_mtu
);
2169 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2170 printk(KERN_DEBUG
"%s: setting MTU %d\n", dev
->name
, new_mtu
);
2171 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
2176 enum netif_tx_lock_class
{
2181 static inline void netif_tx_lock_nested(struct net_device
*dev
, int subclass
)
2183 spin_lock_nested(&dev
->_xmit_lock
, subclass
);
2184 dev
->xmit_lock_owner
= smp_processor_id();
2187 static void ieee80211_set_multicast_list(struct net_device
*dev
)
2189 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2190 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2191 unsigned short flags
;
2193 netif_tx_lock_nested(local
->mdev
, TX_LOCK_MASTER
);
2194 if (((dev
->flags
& IFF_ALLMULTI
) != 0) ^ (sdata
->allmulti
!= 0)) {
2195 if (sdata
->allmulti
) {
2196 sdata
->allmulti
= 0;
2197 local
->iff_allmultis
--;
2199 sdata
->allmulti
= 1;
2200 local
->iff_allmultis
++;
2203 if (((dev
->flags
& IFF_PROMISC
) != 0) ^ (sdata
->promisc
!= 0)) {
2204 if (sdata
->promisc
) {
2206 local
->iff_promiscs
--;
2209 local
->iff_promiscs
++;
2212 if (dev
->mc_count
!= sdata
->mc_count
) {
2213 local
->mc_count
= local
->mc_count
- sdata
->mc_count
+
2215 sdata
->mc_count
= dev
->mc_count
;
2217 if (local
->ops
->set_multicast_list
) {
2218 flags
= local
->mdev
->flags
;
2219 if (local
->iff_allmultis
)
2220 flags
|= IFF_ALLMULTI
;
2221 if (local
->iff_promiscs
)
2222 flags
|= IFF_PROMISC
;
2223 read_lock(&local
->sub_if_lock
);
2224 local
->ops
->set_multicast_list(local_to_hw(local
), flags
,
2226 read_unlock(&local
->sub_if_lock
);
2228 netif_tx_unlock(local
->mdev
);
2231 struct dev_mc_list
*ieee80211_get_mc_list_item(struct ieee80211_hw
*hw
,
2232 struct dev_mc_list
*prev
,
2235 struct ieee80211_local
*local
= hw_to_local(hw
);
2236 struct ieee80211_sub_if_data
*sdata
= *ptr
;
2237 struct dev_mc_list
*mc
;
2243 if (!prev
|| !prev
->next
) {
2245 sdata
= list_entry(sdata
->list
.next
,
2246 struct ieee80211_sub_if_data
, list
);
2248 sdata
= list_entry(local
->sub_if_list
.next
,
2249 struct ieee80211_sub_if_data
, list
);
2250 if (&sdata
->list
!= &local
->sub_if_list
)
2251 mc
= sdata
->dev
->mc_list
;
2260 EXPORT_SYMBOL(ieee80211_get_mc_list_item
);
2262 static struct net_device_stats
*ieee80211_get_stats(struct net_device
*dev
)
2264 struct ieee80211_sub_if_data
*sdata
;
2265 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2266 return &(sdata
->stats
);
2269 static void ieee80211_if_shutdown(struct net_device
*dev
)
2271 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2272 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2275 switch (sdata
->type
) {
2276 case IEEE80211_IF_TYPE_STA
:
2277 case IEEE80211_IF_TYPE_IBSS
:
2278 sdata
->u
.sta
.state
= IEEE80211_DISABLED
;
2279 del_timer_sync(&sdata
->u
.sta
.timer
);
2280 skb_queue_purge(&sdata
->u
.sta
.skb_queue
);
2281 if (!local
->ops
->hw_scan
&&
2282 local
->scan_dev
== sdata
->dev
) {
2283 local
->sta_scanning
= 0;
2284 cancel_delayed_work(&local
->scan_work
);
2286 flush_workqueue(local
->hw
.workqueue
);
2291 static inline int identical_mac_addr_allowed(int type1
, int type2
)
2293 return (type1
== IEEE80211_IF_TYPE_MNTR
||
2294 type2
== IEEE80211_IF_TYPE_MNTR
||
2295 (type1
== IEEE80211_IF_TYPE_AP
&&
2296 type2
== IEEE80211_IF_TYPE_WDS
) ||
2297 (type1
== IEEE80211_IF_TYPE_WDS
&&
2298 (type2
== IEEE80211_IF_TYPE_WDS
||
2299 type2
== IEEE80211_IF_TYPE_AP
)) ||
2300 (type1
== IEEE80211_IF_TYPE_AP
&&
2301 type2
== IEEE80211_IF_TYPE_VLAN
) ||
2302 (type1
== IEEE80211_IF_TYPE_VLAN
&&
2303 (type2
== IEEE80211_IF_TYPE_AP
||
2304 type2
== IEEE80211_IF_TYPE_VLAN
)));
2307 static int ieee80211_master_open(struct net_device
*dev
)
2309 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2310 struct ieee80211_sub_if_data
*sdata
;
2311 int res
= -EOPNOTSUPP
;
2313 read_lock(&local
->sub_if_lock
);
2314 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
2315 if (sdata
->dev
!= dev
&& netif_running(sdata
->dev
)) {
2320 read_unlock(&local
->sub_if_lock
);
2324 static int ieee80211_master_stop(struct net_device
*dev
)
2326 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2327 struct ieee80211_sub_if_data
*sdata
;
2329 read_lock(&local
->sub_if_lock
);
2330 list_for_each_entry(sdata
, &local
->sub_if_list
, list
)
2331 if (sdata
->dev
!= dev
&& netif_running(sdata
->dev
))
2332 dev_close(sdata
->dev
);
2333 read_unlock(&local
->sub_if_lock
);
2338 static int ieee80211_mgmt_open(struct net_device
*dev
)
2340 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2342 if (!netif_running(local
->mdev
))
2347 static int ieee80211_mgmt_stop(struct net_device
*dev
)
2352 /* Check if running monitor interfaces should go to a "soft monitor" mode
2353 * and switch them if necessary. */
2354 static inline void ieee80211_start_soft_monitor(struct ieee80211_local
*local
)
2356 struct ieee80211_if_init_conf conf
;
2358 if (local
->open_count
&& local
->open_count
== local
->monitors
&&
2359 !(local
->hw
.flags
& IEEE80211_HW_MONITOR_DURING_OPER
) &&
2360 local
->ops
->remove_interface
) {
2362 conf
.type
= IEEE80211_IF_TYPE_MNTR
;
2363 conf
.mac_addr
= NULL
;
2364 local
->ops
->remove_interface(local_to_hw(local
), &conf
);
2368 /* Check if running monitor interfaces should go to a "hard monitor" mode
2369 * and switch them if necessary. */
2370 static void ieee80211_start_hard_monitor(struct ieee80211_local
*local
)
2372 struct ieee80211_if_init_conf conf
;
2374 if (local
->open_count
&& local
->open_count
== local
->monitors
&&
2375 !(local
->hw
.flags
& IEEE80211_HW_MONITOR_DURING_OPER
) &&
2376 local
->ops
->add_interface
) {
2378 conf
.type
= IEEE80211_IF_TYPE_MNTR
;
2379 conf
.mac_addr
= NULL
;
2380 local
->ops
->add_interface(local_to_hw(local
), &conf
);
2384 static int ieee80211_open(struct net_device
*dev
)
2386 struct ieee80211_sub_if_data
*sdata
, *nsdata
;
2387 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2388 struct ieee80211_if_init_conf conf
;
2391 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2392 read_lock(&local
->sub_if_lock
);
2393 list_for_each_entry(nsdata
, &local
->sub_if_list
, list
) {
2394 struct net_device
*ndev
= nsdata
->dev
;
2396 if (ndev
!= dev
&& ndev
!= local
->mdev
&& netif_running(ndev
) &&
2397 compare_ether_addr(dev
->dev_addr
, ndev
->dev_addr
) == 0 &&
2398 !identical_mac_addr_allowed(sdata
->type
, nsdata
->type
)) {
2399 read_unlock(&local
->sub_if_lock
);
2403 read_unlock(&local
->sub_if_lock
);
2405 if (sdata
->type
== IEEE80211_IF_TYPE_WDS
&&
2406 is_zero_ether_addr(sdata
->u
.wds
.remote_addr
))
2409 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
&& local
->open_count
&&
2410 !(local
->hw
.flags
& IEEE80211_HW_MONITOR_DURING_OPER
)) {
2411 /* run the interface in a "soft monitor" mode */
2413 local
->open_count
++;
2414 local
->hw
.conf
.flags
|= IEEE80211_CONF_RADIOTAP
;
2417 ieee80211_start_soft_monitor(local
);
2419 if (local
->ops
->add_interface
) {
2420 conf
.if_id
= dev
->ifindex
;
2421 conf
.type
= sdata
->type
;
2422 conf
.mac_addr
= dev
->dev_addr
;
2423 res
= local
->ops
->add_interface(local_to_hw(local
), &conf
);
2425 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
)
2426 ieee80211_start_hard_monitor(local
);
2430 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
2432 if (local
->open_count
> 0)
2436 if (local
->open_count
== 0) {
2438 tasklet_enable(&local
->tx_pending_tasklet
);
2439 tasklet_enable(&local
->tasklet
);
2440 if (local
->ops
->open
)
2441 res
= local
->ops
->open(local_to_hw(local
));
2443 res
= dev_open(local
->mdev
);
2445 if (local
->ops
->stop
)
2446 local
->ops
->stop(local_to_hw(local
));
2448 res
= ieee80211_hw_config(local
);
2449 if (res
&& local
->ops
->stop
)
2450 local
->ops
->stop(local_to_hw(local
));
2451 else if (!res
&& local
->apdev
)
2452 dev_open(local
->apdev
);
2456 if (local
->ops
->remove_interface
)
2457 local
->ops
->remove_interface(local_to_hw(local
),
2462 local
->open_count
++;
2464 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
) {
2466 local
->hw
.conf
.flags
|= IEEE80211_CONF_RADIOTAP
;
2468 ieee80211_if_config(dev
);
2470 if (sdata
->type
== IEEE80211_IF_TYPE_STA
&&
2471 !local
->user_space_mlme
)
2472 netif_carrier_off(dev
);
2474 netif_start_queue(dev
);
2479 static int ieee80211_stop(struct net_device
*dev
)
2481 struct ieee80211_sub_if_data
*sdata
;
2482 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2484 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2486 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
&&
2487 local
->open_count
> 1 &&
2488 !(local
->hw
.flags
& IEEE80211_HW_MONITOR_DURING_OPER
)) {
2489 /* remove "soft monitor" interface */
2490 local
->open_count
--;
2492 if (!local
->monitors
)
2493 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_RADIOTAP
;
2497 netif_stop_queue(dev
);
2498 ieee80211_if_shutdown(dev
);
2500 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
) {
2502 if (!local
->monitors
)
2503 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_RADIOTAP
;
2506 local
->open_count
--;
2507 if (local
->open_count
== 0) {
2508 if (netif_running(local
->mdev
))
2509 dev_close(local
->mdev
);
2511 dev_close(local
->apdev
);
2512 if (local
->ops
->stop
)
2513 local
->ops
->stop(local_to_hw(local
));
2514 tasklet_disable(&local
->tx_pending_tasklet
);
2515 tasklet_disable(&local
->tasklet
);
2517 if (local
->ops
->remove_interface
) {
2518 struct ieee80211_if_init_conf conf
;
2520 conf
.if_id
= dev
->ifindex
;
2521 conf
.type
= sdata
->type
;
2522 conf
.mac_addr
= dev
->dev_addr
;
2523 local
->ops
->remove_interface(local_to_hw(local
), &conf
);
2526 ieee80211_start_hard_monitor(local
);
2532 static int header_parse_80211(struct sk_buff
*skb
, unsigned char *haddr
)
2534 memcpy(haddr
, skb_mac_header(skb
) + 10, ETH_ALEN
); /* addr2 */
2538 static inline int ieee80211_bssid_match(const u8
*raddr
, const u8
*addr
)
2540 return compare_ether_addr(raddr
, addr
) == 0 ||
2541 is_broadcast_ether_addr(raddr
);
2545 static ieee80211_txrx_result
2546 ieee80211_rx_h_data(struct ieee80211_txrx_data
*rx
)
2548 struct net_device
*dev
= rx
->dev
;
2549 struct ieee80211_local
*local
= rx
->local
;
2550 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
2551 u16 fc
, hdrlen
, ethertype
;
2555 struct sk_buff
*skb
= rx
->skb
, *skb2
;
2556 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2559 if (unlikely((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
))
2560 return TXRX_CONTINUE
;
2562 if (unlikely(!WLAN_FC_DATA_PRESENT(fc
)))
2565 hdrlen
= ieee80211_get_hdrlen(fc
);
2567 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
2569 * IEEE 802.11 address fields:
2570 * ToDS FromDS Addr1 Addr2 Addr3 Addr4
2571 * 0 0 DA SA BSSID n/a
2572 * 0 1 DA BSSID SA n/a
2573 * 1 0 BSSID SA DA n/a
2577 switch (fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) {
2578 case IEEE80211_FCTL_TODS
:
2580 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
2581 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
2583 if (unlikely(sdata
->type
!= IEEE80211_IF_TYPE_AP
&&
2584 sdata
->type
!= IEEE80211_IF_TYPE_VLAN
)) {
2585 printk(KERN_DEBUG
"%s: dropped ToDS frame (BSSID="
2586 MAC_FMT
" SA=" MAC_FMT
" DA=" MAC_FMT
")\n",
2587 dev
->name
, MAC_ARG(hdr
->addr1
),
2588 MAC_ARG(hdr
->addr2
), MAC_ARG(hdr
->addr3
));
2592 case (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
):
2594 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
2595 memcpy(src
, hdr
->addr4
, ETH_ALEN
);
2597 if (unlikely(sdata
->type
!= IEEE80211_IF_TYPE_WDS
)) {
2598 printk(KERN_DEBUG
"%s: dropped FromDS&ToDS frame (RA="
2599 MAC_FMT
" TA=" MAC_FMT
" DA=" MAC_FMT
" SA="
2601 rx
->dev
->name
, MAC_ARG(hdr
->addr1
),
2602 MAC_ARG(hdr
->addr2
), MAC_ARG(hdr
->addr3
),
2603 MAC_ARG(hdr
->addr4
));
2607 case IEEE80211_FCTL_FROMDS
:
2609 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
2610 memcpy(src
, hdr
->addr3
, ETH_ALEN
);
2612 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
) {
2618 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
2619 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
2621 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
) {
2622 if (net_ratelimit()) {
2623 printk(KERN_DEBUG
"%s: dropped IBSS frame (DA="
2624 MAC_FMT
" SA=" MAC_FMT
" BSSID=" MAC_FMT
2626 dev
->name
, MAC_ARG(hdr
->addr1
),
2627 MAC_ARG(hdr
->addr2
),
2628 MAC_ARG(hdr
->addr3
));
2635 payload
= skb
->data
+ hdrlen
;
2637 if (unlikely(skb
->len
- hdrlen
< 8)) {
2638 if (net_ratelimit()) {
2639 printk(KERN_DEBUG
"%s: RX too short data frame "
2640 "payload\n", dev
->name
);
2645 ethertype
= (payload
[6] << 8) | payload
[7];
2647 if (likely((compare_ether_addr(payload
, rfc1042_header
) == 0 &&
2648 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
2649 compare_ether_addr(payload
, bridge_tunnel_header
) == 0)) {
2650 /* remove RFC1042 or Bridge-Tunnel encapsulation and
2651 * replace EtherType */
2652 skb_pull(skb
, hdrlen
+ 6);
2653 memcpy(skb_push(skb
, ETH_ALEN
), src
, ETH_ALEN
);
2654 memcpy(skb_push(skb
, ETH_ALEN
), dst
, ETH_ALEN
);
2656 struct ethhdr
*ehdr
;
2658 skb_pull(skb
, hdrlen
);
2659 len
= htons(skb
->len
);
2660 ehdr
= (struct ethhdr
*) skb_push(skb
, sizeof(struct ethhdr
));
2661 memcpy(ehdr
->h_dest
, dst
, ETH_ALEN
);
2662 memcpy(ehdr
->h_source
, src
, ETH_ALEN
);
2663 ehdr
->h_proto
= len
;
2669 sdata
->stats
.rx_packets
++;
2670 sdata
->stats
.rx_bytes
+= skb
->len
;
2672 if (local
->bridge_packets
&& (sdata
->type
== IEEE80211_IF_TYPE_AP
2673 || sdata
->type
== IEEE80211_IF_TYPE_VLAN
) && rx
->u
.rx
.ra_match
) {
2674 if (is_multicast_ether_addr(skb
->data
)) {
2675 /* send multicast frames both to higher layers in
2676 * local net stack and back to the wireless media */
2677 skb2
= skb_copy(skb
, GFP_ATOMIC
);
2679 printk(KERN_DEBUG
"%s: failed to clone "
2680 "multicast frame\n", dev
->name
);
2682 struct sta_info
*dsta
;
2683 dsta
= sta_info_get(local
, skb
->data
);
2684 if (dsta
&& !dsta
->dev
) {
2685 printk(KERN_DEBUG
"Station with null dev "
2687 } else if (dsta
&& dsta
->dev
== dev
) {
2688 /* Destination station is associated to this
2689 * AP, so send the frame directly to it and
2690 * do not pass the frame to local net stack.
2701 /* deliver to local stack */
2702 skb
->protocol
= eth_type_trans(skb
, dev
);
2703 memset(skb
->cb
, 0, sizeof(skb
->cb
));
2708 /* send to wireless media */
2709 skb2
->protocol
= __constant_htons(ETH_P_802_3
);
2710 skb_set_network_header(skb2
, 0);
2711 skb_set_mac_header(skb2
, 0);
2712 dev_queue_xmit(skb2
);
2719 static struct ieee80211_rate
*
2720 ieee80211_get_rate(struct ieee80211_local
*local
, int phymode
, int hw_rate
)
2722 struct ieee80211_hw_mode
*mode
;
2725 list_for_each_entry(mode
, &local
->modes_list
, list
) {
2726 if (mode
->mode
!= phymode
)
2728 for (r
= 0; r
< mode
->num_rates
; r
++) {
2729 struct ieee80211_rate
*rate
= &mode
->rates
[r
];
2730 if (rate
->val
== hw_rate
||
2731 (rate
->flags
& IEEE80211_RATE_PREAMBLE2
&&
2732 rate
->val2
== hw_rate
))
2741 ieee80211_fill_frame_info(struct ieee80211_local
*local
,
2742 struct ieee80211_frame_info
*fi
,
2743 struct ieee80211_rx_status
*status
)
2747 struct ieee80211_rate
*rate
;
2749 jiffies_to_timespec(jiffies
, &ts
);
2750 fi
->hosttime
= cpu_to_be64((u64
) ts
.tv_sec
* 1000000 +
2752 fi
->mactime
= cpu_to_be64(status
->mactime
);
2753 switch (status
->phymode
) {
2754 case MODE_IEEE80211A
:
2755 fi
->phytype
= htonl(ieee80211_phytype_ofdm_dot11_a
);
2757 case MODE_IEEE80211B
:
2758 fi
->phytype
= htonl(ieee80211_phytype_dsss_dot11_b
);
2760 case MODE_IEEE80211G
:
2761 fi
->phytype
= htonl(ieee80211_phytype_pbcc_dot11_g
);
2763 case MODE_ATHEROS_TURBO
:
2765 htonl(ieee80211_phytype_dsss_dot11_turbo
);
2768 fi
->phytype
= htonl(0xAAAAAAAA);
2771 fi
->channel
= htonl(status
->channel
);
2772 rate
= ieee80211_get_rate(local
, status
->phymode
,
2775 fi
->datarate
= htonl(rate
->rate
);
2776 if (rate
->flags
& IEEE80211_RATE_PREAMBLE2
) {
2777 if (status
->rate
== rate
->val
)
2778 fi
->preamble
= htonl(2); /* long */
2779 else if (status
->rate
== rate
->val2
)
2780 fi
->preamble
= htonl(1); /* short */
2782 fi
->preamble
= htonl(0);
2784 fi
->datarate
= htonl(0);
2785 fi
->preamble
= htonl(0);
2788 fi
->antenna
= htonl(status
->antenna
);
2789 fi
->priority
= htonl(0xffffffff); /* no clue */
2790 fi
->ssi_type
= htonl(ieee80211_ssi_raw
);
2791 fi
->ssi_signal
= htonl(status
->ssi
);
2792 fi
->ssi_noise
= 0x00000000;
2795 /* clear everything because we really don't know.
2796 * the msg_type field isn't present on monitor frames
2797 * so we don't know whether it will be present or not,
2798 * but it's ok to not clear it since it'll be assigned
2800 memset(fi
, 0, sizeof(*fi
) - sizeof(fi
->msg_type
));
2802 fi
->ssi_type
= htonl(ieee80211_ssi_none
);
2804 fi
->version
= htonl(IEEE80211_FI_VERSION
);
2805 fi
->length
= cpu_to_be32(sizeof(*fi
) - sizeof(fi
->msg_type
));
2808 /* this routine is actually not just for this, but also
2809 * for pushing fake 'management' frames into userspace.
2810 * it shall be replaced by a netlink-based system. */
2812 ieee80211_rx_mgmt(struct ieee80211_local
*local
, struct sk_buff
*skb
,
2813 struct ieee80211_rx_status
*status
, u32 msg_type
)
2815 struct ieee80211_frame_info
*fi
;
2816 const size_t hlen
= sizeof(struct ieee80211_frame_info
);
2817 struct ieee80211_sub_if_data
*sdata
;
2819 skb
->dev
= local
->apdev
;
2821 sdata
= IEEE80211_DEV_TO_SUB_IF(local
->apdev
);
2823 if (skb_headroom(skb
) < hlen
) {
2824 I802_DEBUG_INC(local
->rx_expand_skb_head
);
2825 if (pskb_expand_head(skb
, hlen
, 0, GFP_ATOMIC
)) {
2831 fi
= (struct ieee80211_frame_info
*) skb_push(skb
, hlen
);
2833 ieee80211_fill_frame_info(local
, fi
, status
);
2834 fi
->msg_type
= htonl(msg_type
);
2836 sdata
->stats
.rx_packets
++;
2837 sdata
->stats
.rx_bytes
+= skb
->len
;
2839 skb_set_mac_header(skb
, 0);
2840 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2841 skb
->pkt_type
= PACKET_OTHERHOST
;
2842 skb
->protocol
= htons(ETH_P_802_2
);
2843 memset(skb
->cb
, 0, sizeof(skb
->cb
));
2848 ieee80211_rx_monitor(struct net_device
*dev
, struct sk_buff
*skb
,
2849 struct ieee80211_rx_status
*status
)
2851 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2852 struct ieee80211_sub_if_data
*sdata
;
2853 struct ieee80211_rate
*rate
;
2854 struct ieee80211_rtap_hdr
{
2855 struct ieee80211_radiotap_header hdr
;
2861 } __attribute__ ((packed
)) *rthdr
;
2865 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2867 if (status
->flag
& RX_FLAG_RADIOTAP
)
2870 if (skb_headroom(skb
) < sizeof(*rthdr
)) {
2871 I802_DEBUG_INC(local
->rx_expand_skb_head
);
2872 if (pskb_expand_head(skb
, sizeof(*rthdr
), 0, GFP_ATOMIC
)) {
2878 rthdr
= (struct ieee80211_rtap_hdr
*) skb_push(skb
, sizeof(*rthdr
));
2879 memset(rthdr
, 0, sizeof(*rthdr
));
2880 rthdr
->hdr
.it_len
= cpu_to_le16(sizeof(*rthdr
));
2881 rthdr
->hdr
.it_present
=
2882 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS
) |
2883 (1 << IEEE80211_RADIOTAP_RATE
) |
2884 (1 << IEEE80211_RADIOTAP_CHANNEL
) |
2885 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL
));
2886 rthdr
->flags
= local
->hw
.flags
& IEEE80211_HW_RX_INCLUDES_FCS
?
2887 IEEE80211_RADIOTAP_F_FCS
: 0;
2888 rate
= ieee80211_get_rate(local
, status
->phymode
, status
->rate
);
2890 rthdr
->rate
= rate
->rate
/ 5;
2891 rthdr
->chan_freq
= cpu_to_le16(status
->freq
);
2893 status
->phymode
== MODE_IEEE80211A
?
2894 cpu_to_le16(IEEE80211_CHAN_OFDM
| IEEE80211_CHAN_5GHZ
) :
2895 cpu_to_le16(IEEE80211_CHAN_DYN
| IEEE80211_CHAN_2GHZ
);
2896 rthdr
->antsignal
= status
->ssi
;
2899 sdata
->stats
.rx_packets
++;
2900 sdata
->stats
.rx_bytes
+= skb
->len
;
2902 skb_set_mac_header(skb
, 0);
2903 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2904 skb
->pkt_type
= PACKET_OTHERHOST
;
2905 skb
->protocol
= htons(ETH_P_802_2
);
2906 memset(skb
->cb
, 0, sizeof(skb
->cb
));
2910 int ieee80211_radar_status(struct ieee80211_hw
*hw
, int channel
,
2911 int radar
, int radar_type
)
2913 struct sk_buff
*skb
;
2914 struct ieee80211_radar_info
*msg
;
2915 struct ieee80211_local
*local
= hw_to_local(hw
);
2920 skb
= dev_alloc_skb(sizeof(struct ieee80211_frame_info
) +
2921 sizeof(struct ieee80211_radar_info
));
2925 skb_reserve(skb
, sizeof(struct ieee80211_frame_info
));
2927 msg
= (struct ieee80211_radar_info
*)
2928 skb_put(skb
, sizeof(struct ieee80211_radar_info
));
2929 msg
->channel
= channel
;
2931 msg
->radar_type
= radar_type
;
2933 ieee80211_rx_mgmt(local
, skb
, NULL
, ieee80211_msg_radar
);
2936 EXPORT_SYMBOL(ieee80211_radar_status
);
2938 int ieee80211_set_aid_for_sta(struct ieee80211_hw
*hw
, u8
*peer_address
,
2941 struct sk_buff
*skb
;
2942 struct ieee80211_msg_set_aid_for_sta
*msg
;
2943 struct ieee80211_local
*local
= hw_to_local(hw
);
2945 /* unlikely because if this event only happens for APs,
2946 * which require an open ap device. */
2947 if (unlikely(!local
->apdev
))
2950 skb
= dev_alloc_skb(sizeof(struct ieee80211_frame_info
) +
2951 sizeof(struct ieee80211_msg_set_aid_for_sta
));
2955 skb_reserve(skb
, sizeof(struct ieee80211_frame_info
));
2957 msg
= (struct ieee80211_msg_set_aid_for_sta
*)
2958 skb_put(skb
, sizeof(struct ieee80211_msg_set_aid_for_sta
));
2959 memcpy(msg
->sta_address
, peer_address
, ETH_ALEN
);
2962 ieee80211_rx_mgmt(local
, skb
, NULL
, ieee80211_msg_set_aid_for_sta
);
2965 EXPORT_SYMBOL(ieee80211_set_aid_for_sta
);
2967 static void ap_sta_ps_start(struct net_device
*dev
, struct sta_info
*sta
)
2969 struct ieee80211_sub_if_data
*sdata
;
2970 sdata
= IEEE80211_DEV_TO_SUB_IF(sta
->dev
);
2973 atomic_inc(&sdata
->bss
->num_sta_ps
);
2974 sta
->flags
|= WLAN_STA_PS
;
2976 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
2977 printk(KERN_DEBUG
"%s: STA " MAC_FMT
" aid %d enters power "
2978 "save mode\n", dev
->name
, MAC_ARG(sta
->addr
), sta
->aid
);
2979 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
2983 static int ap_sta_ps_end(struct net_device
*dev
, struct sta_info
*sta
)
2985 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2986 struct sk_buff
*skb
;
2988 struct ieee80211_sub_if_data
*sdata
;
2989 struct ieee80211_tx_packet_data
*pkt_data
;
2991 sdata
= IEEE80211_DEV_TO_SUB_IF(sta
->dev
);
2993 atomic_dec(&sdata
->bss
->num_sta_ps
);
2994 sta
->flags
&= ~(WLAN_STA_PS
| WLAN_STA_TIM
);
2996 if (!skb_queue_empty(&sta
->ps_tx_buf
)) {
2997 if (local
->ops
->set_tim
)
2998 local
->ops
->set_tim(local_to_hw(local
), sta
->aid
, 0);
3000 bss_tim_clear(local
, sdata
->bss
, sta
->aid
);
3002 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
3003 printk(KERN_DEBUG
"%s: STA " MAC_FMT
" aid %d exits power "
3004 "save mode\n", dev
->name
, MAC_ARG(sta
->addr
), sta
->aid
);
3005 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
3006 /* Send all buffered frames to the station */
3007 while ((skb
= skb_dequeue(&sta
->tx_filtered
)) != NULL
) {
3008 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
3010 pkt_data
->requeue
= 1;
3011 dev_queue_xmit(skb
);
3013 while ((skb
= skb_dequeue(&sta
->ps_tx_buf
)) != NULL
) {
3014 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
3015 local
->total_ps_buffered
--;
3017 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
3018 printk(KERN_DEBUG
"%s: STA " MAC_FMT
" aid %d send PS frame "
3019 "since STA not sleeping anymore\n", dev
->name
,
3020 MAC_ARG(sta
->addr
), sta
->aid
);
3021 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
3022 pkt_data
->requeue
= 1;
3023 dev_queue_xmit(skb
);
3030 static ieee80211_txrx_result
3031 ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data
*rx
)
3033 struct sk_buff
*skb
;
3034 int no_pending_pkts
;
3036 if (likely(!rx
->sta
||
3037 (rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_CTL
||
3038 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_PSPOLL
||
3039 !rx
->u
.rx
.ra_match
))
3040 return TXRX_CONTINUE
;
3042 skb
= skb_dequeue(&rx
->sta
->tx_filtered
);
3044 skb
= skb_dequeue(&rx
->sta
->ps_tx_buf
);
3046 rx
->local
->total_ps_buffered
--;
3048 no_pending_pkts
= skb_queue_empty(&rx
->sta
->tx_filtered
) &&
3049 skb_queue_empty(&rx
->sta
->ps_tx_buf
);
3052 struct ieee80211_hdr
*hdr
=
3053 (struct ieee80211_hdr
*) skb
->data
;
3055 /* tell TX path to send one frame even though the STA may
3056 * still remain is PS mode after this frame exchange */
3057 rx
->sta
->pspoll
= 1;
3059 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
3060 printk(KERN_DEBUG
"STA " MAC_FMT
" aid %d: PS Poll (entries "
3062 MAC_ARG(rx
->sta
->addr
), rx
->sta
->aid
,
3063 skb_queue_len(&rx
->sta
->ps_tx_buf
));
3064 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
3066 /* Use MoreData flag to indicate whether there are more
3067 * buffered frames for this STA */
3068 if (no_pending_pkts
) {
3069 hdr
->frame_control
&= cpu_to_le16(~IEEE80211_FCTL_MOREDATA
);
3070 rx
->sta
->flags
&= ~WLAN_STA_TIM
;
3072 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_MOREDATA
);
3074 dev_queue_xmit(skb
);
3076 if (no_pending_pkts
) {
3077 if (rx
->local
->ops
->set_tim
)
3078 rx
->local
->ops
->set_tim(local_to_hw(rx
->local
),
3081 bss_tim_clear(rx
->local
, rx
->sdata
->bss
, rx
->sta
->aid
);
3083 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
3084 } else if (!rx
->u
.rx
.sent_ps_buffered
) {
3085 printk(KERN_DEBUG
"%s: STA " MAC_FMT
" sent PS Poll even "
3086 "though there is no buffered frames for it\n",
3087 rx
->dev
->name
, MAC_ARG(rx
->sta
->addr
));
3088 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
3092 /* Free PS Poll skb here instead of returning TXRX_DROP that would
3093 * count as an dropped frame. */
3094 dev_kfree_skb(rx
->skb
);
3100 static inline struct ieee80211_fragment_entry
*
3101 ieee80211_reassemble_add(struct ieee80211_sub_if_data
*sdata
,
3102 unsigned int frag
, unsigned int seq
, int rx_queue
,
3103 struct sk_buff
**skb
)
3105 struct ieee80211_fragment_entry
*entry
;
3108 idx
= sdata
->fragment_next
;
3109 entry
= &sdata
->fragments
[sdata
->fragment_next
++];
3110 if (sdata
->fragment_next
>= IEEE80211_FRAGMENT_MAX
)
3111 sdata
->fragment_next
= 0;
3113 if (!skb_queue_empty(&entry
->skb_list
)) {
3114 #ifdef CONFIG_MAC80211_DEBUG
3115 struct ieee80211_hdr
*hdr
=
3116 (struct ieee80211_hdr
*) entry
->skb_list
.next
->data
;
3117 printk(KERN_DEBUG
"%s: RX reassembly removed oldest "
3118 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
3119 "addr1=" MAC_FMT
" addr2=" MAC_FMT
"\n",
3120 sdata
->dev
->name
, idx
,
3121 jiffies
- entry
->first_frag_time
, entry
->seq
,
3122 entry
->last_frag
, MAC_ARG(hdr
->addr1
),
3123 MAC_ARG(hdr
->addr2
));
3124 #endif /* CONFIG_MAC80211_DEBUG */
3125 __skb_queue_purge(&entry
->skb_list
);
3128 __skb_queue_tail(&entry
->skb_list
, *skb
); /* no need for locking */
3130 entry
->first_frag_time
= jiffies
;
3132 entry
->rx_queue
= rx_queue
;
3133 entry
->last_frag
= frag
;
3135 entry
->extra_len
= 0;
3141 static inline struct ieee80211_fragment_entry
*
3142 ieee80211_reassemble_find(struct ieee80211_sub_if_data
*sdata
,
3143 u16 fc
, unsigned int frag
, unsigned int seq
,
3144 int rx_queue
, struct ieee80211_hdr
*hdr
)
3146 struct ieee80211_fragment_entry
*entry
;
3149 idx
= sdata
->fragment_next
;
3150 for (i
= 0; i
< IEEE80211_FRAGMENT_MAX
; i
++) {
3151 struct ieee80211_hdr
*f_hdr
;
3156 idx
= IEEE80211_FRAGMENT_MAX
- 1;
3158 entry
= &sdata
->fragments
[idx
];
3159 if (skb_queue_empty(&entry
->skb_list
) || entry
->seq
!= seq
||
3160 entry
->rx_queue
!= rx_queue
||
3161 entry
->last_frag
+ 1 != frag
)
3164 f_hdr
= (struct ieee80211_hdr
*) entry
->skb_list
.next
->data
;
3165 f_fc
= le16_to_cpu(f_hdr
->frame_control
);
3167 if ((fc
& IEEE80211_FCTL_FTYPE
) != (f_fc
& IEEE80211_FCTL_FTYPE
) ||
3168 compare_ether_addr(hdr
->addr1
, f_hdr
->addr1
) != 0 ||
3169 compare_ether_addr(hdr
->addr2
, f_hdr
->addr2
) != 0)
3172 if (entry
->first_frag_time
+ 2 * HZ
< jiffies
) {
3173 __skb_queue_purge(&entry
->skb_list
);
3183 static ieee80211_txrx_result
3184 ieee80211_rx_h_defragment(struct ieee80211_txrx_data
*rx
)
3186 struct ieee80211_hdr
*hdr
;
3188 unsigned int frag
, seq
;
3189 struct ieee80211_fragment_entry
*entry
;
3190 struct sk_buff
*skb
;
3192 hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
3193 sc
= le16_to_cpu(hdr
->seq_ctrl
);
3194 frag
= sc
& IEEE80211_SCTL_FRAG
;
3196 if (likely((!(rx
->fc
& IEEE80211_FCTL_MOREFRAGS
) && frag
== 0) ||
3197 (rx
->skb
)->len
< 24 ||
3198 is_multicast_ether_addr(hdr
->addr1
))) {
3199 /* not fragmented */
3202 I802_DEBUG_INC(rx
->local
->rx_handlers_fragments
);
3204 seq
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
3207 /* This is the first fragment of a new frame. */
3208 entry
= ieee80211_reassemble_add(rx
->sdata
, frag
, seq
,
3209 rx
->u
.rx
.queue
, &(rx
->skb
));
3210 if (rx
->key
&& rx
->key
->alg
== ALG_CCMP
&&
3211 (rx
->fc
& IEEE80211_FCTL_PROTECTED
)) {
3212 /* Store CCMP PN so that we can verify that the next
3213 * fragment has a sequential PN value. */
3215 memcpy(entry
->last_pn
,
3216 rx
->key
->u
.ccmp
.rx_pn
[rx
->u
.rx
.queue
],
3222 /* This is a fragment for a frame that should already be pending in
3223 * fragment cache. Add this fragment to the end of the pending entry.
3225 entry
= ieee80211_reassemble_find(rx
->sdata
, rx
->fc
, frag
, seq
,
3226 rx
->u
.rx
.queue
, hdr
);
3228 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_defrag
);
3232 /* Verify that MPDUs within one MSDU have sequential PN values.
3233 * (IEEE 802.11i, 8.3.3.4.5) */
3236 u8 pn
[CCMP_PN_LEN
], *rpn
;
3237 if (!rx
->key
|| rx
->key
->alg
!= ALG_CCMP
)
3239 memcpy(pn
, entry
->last_pn
, CCMP_PN_LEN
);
3240 for (i
= CCMP_PN_LEN
- 1; i
>= 0; i
--) {
3245 rpn
= rx
->key
->u
.ccmp
.rx_pn
[rx
->u
.rx
.queue
];
3246 if (memcmp(pn
, rpn
, CCMP_PN_LEN
) != 0) {
3247 printk(KERN_DEBUG
"%s: defrag: CCMP PN not sequential"
3248 " A2=" MAC_FMT
" PN=%02x%02x%02x%02x%02x%02x "
3249 "(expected %02x%02x%02x%02x%02x%02x)\n",
3250 rx
->dev
->name
, MAC_ARG(hdr
->addr2
),
3251 rpn
[0], rpn
[1], rpn
[2], rpn
[3], rpn
[4], rpn
[5],
3252 pn
[0], pn
[1], pn
[2], pn
[3], pn
[4], pn
[5]);
3255 memcpy(entry
->last_pn
, pn
, CCMP_PN_LEN
);
3258 skb_pull(rx
->skb
, ieee80211_get_hdrlen(rx
->fc
));
3259 __skb_queue_tail(&entry
->skb_list
, rx
->skb
);
3260 entry
->last_frag
= frag
;
3261 entry
->extra_len
+= rx
->skb
->len
;
3262 if (rx
->fc
& IEEE80211_FCTL_MOREFRAGS
) {
3267 rx
->skb
= __skb_dequeue(&entry
->skb_list
);
3268 if (skb_tailroom(rx
->skb
) < entry
->extra_len
) {
3269 I802_DEBUG_INC(rx
->local
->rx_expand_skb_head2
);
3270 if (unlikely(pskb_expand_head(rx
->skb
, 0, entry
->extra_len
,
3272 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_defrag
);
3273 __skb_queue_purge(&entry
->skb_list
);
3277 while ((skb
= __skb_dequeue(&entry
->skb_list
)))
3278 memcpy(skb_put(rx
->skb
, skb
->len
), skb
->data
, skb
->len
);
3280 /* Complete frame has been reassembled - process it now */
3285 rx
->sta
->rx_packets
++;
3286 if (is_multicast_ether_addr(hdr
->addr1
))
3287 rx
->local
->dot11MulticastReceivedFrameCount
++;
3289 ieee80211_led_rx(rx
->local
);
3290 return TXRX_CONTINUE
;
3294 static ieee80211_txrx_result
3295 ieee80211_rx_h_monitor(struct ieee80211_txrx_data
*rx
)
3297 if (rx
->sdata
->type
== IEEE80211_IF_TYPE_MNTR
) {
3298 ieee80211_rx_monitor(rx
->dev
, rx
->skb
, rx
->u
.rx
.status
);
3302 if (rx
->u
.rx
.status
->flag
& RX_FLAG_RADIOTAP
)
3303 skb_pull(rx
->skb
, ieee80211_get_radiotap_len(rx
->skb
));
3305 return TXRX_CONTINUE
;
3309 static ieee80211_txrx_result
3310 ieee80211_rx_h_check(struct ieee80211_txrx_data
*rx
)
3312 struct ieee80211_hdr
*hdr
;
3314 hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
3316 /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
3317 if (rx
->sta
&& !is_multicast_ether_addr(hdr
->addr1
)) {
3318 if (unlikely(rx
->fc
& IEEE80211_FCTL_RETRY
&&
3319 rx
->sta
->last_seq_ctrl
[rx
->u
.rx
.queue
] ==
3321 if (rx
->u
.rx
.ra_match
) {
3322 rx
->local
->dot11FrameDuplicateCount
++;
3323 rx
->sta
->num_duplicates
++;
3327 rx
->sta
->last_seq_ctrl
[rx
->u
.rx
.queue
] = hdr
->seq_ctrl
;
3330 if ((rx
->local
->hw
.flags
& IEEE80211_HW_RX_INCLUDES_FCS
) &&
3331 rx
->skb
->len
> FCS_LEN
)
3332 skb_trim(rx
->skb
, rx
->skb
->len
- FCS_LEN
);
3334 if (unlikely(rx
->skb
->len
< 16)) {
3335 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_short
);
3339 if (!rx
->u
.rx
.ra_match
)
3340 rx
->skb
->pkt_type
= PACKET_OTHERHOST
;
3341 else if (compare_ether_addr(rx
->dev
->dev_addr
, hdr
->addr1
) == 0)
3342 rx
->skb
->pkt_type
= PACKET_HOST
;
3343 else if (is_multicast_ether_addr(hdr
->addr1
)) {
3344 if (is_broadcast_ether_addr(hdr
->addr1
))
3345 rx
->skb
->pkt_type
= PACKET_BROADCAST
;
3347 rx
->skb
->pkt_type
= PACKET_MULTICAST
;
3349 rx
->skb
->pkt_type
= PACKET_OTHERHOST
;
3351 /* Drop disallowed frame classes based on STA auth/assoc state;
3352 * IEEE 802.11, Chap 5.5.
3354 * 80211.o does filtering only based on association state, i.e., it
3355 * drops Class 3 frames from not associated stations. hostapd sends
3356 * deauth/disassoc frames when needed. In addition, hostapd is
3357 * responsible for filtering on both auth and assoc states.
3359 if (unlikely(((rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
||
3360 ((rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_CTL
&&
3361 (rx
->fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_PSPOLL
)) &&
3362 rx
->sdata
->type
!= IEEE80211_IF_TYPE_IBSS
&&
3363 (!rx
->sta
|| !(rx
->sta
->flags
& WLAN_STA_ASSOC
)))) {
3364 if ((!(rx
->fc
& IEEE80211_FCTL_FROMDS
) &&
3365 !(rx
->fc
& IEEE80211_FCTL_TODS
) &&
3366 (rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
)
3367 || !rx
->u
.rx
.ra_match
) {
3368 /* Drop IBSS frames and frames for other hosts
3373 if (!rx
->local
->apdev
)
3376 ieee80211_rx_mgmt(rx
->local
, rx
->skb
, rx
->u
.rx
.status
,
3377 ieee80211_msg_sta_not_assoc
);
3381 if (rx
->sdata
->type
== IEEE80211_IF_TYPE_STA
)
3386 if (rx
->sta
&& rx
->sta
->key
&& always_sta_key
) {
3387 rx
->key
= rx
->sta
->key
;
3389 if (rx
->sta
&& rx
->sta
->key
)
3390 rx
->key
= rx
->sta
->key
;
3392 rx
->key
= rx
->sdata
->default_key
;
3394 if ((rx
->local
->hw
.flags
& IEEE80211_HW_WEP_INCLUDE_IV
) &&
3395 rx
->fc
& IEEE80211_FCTL_PROTECTED
) {
3396 int keyidx
= ieee80211_wep_get_keyidx(rx
->skb
);
3398 if (keyidx
>= 0 && keyidx
< NUM_DEFAULT_KEYS
&&
3399 (!rx
->sta
|| !rx
->sta
->key
|| keyidx
> 0))
3400 rx
->key
= rx
->sdata
->keys
[keyidx
];
3403 if (!rx
->u
.rx
.ra_match
)
3405 printk(KERN_DEBUG
"%s: RX WEP frame with "
3406 "unknown keyidx %d (A1=" MAC_FMT
" A2="
3407 MAC_FMT
" A3=" MAC_FMT
")\n",
3408 rx
->dev
->name
, keyidx
,
3409 MAC_ARG(hdr
->addr1
),
3410 MAC_ARG(hdr
->addr2
),
3411 MAC_ARG(hdr
->addr3
));
3412 if (!rx
->local
->apdev
)
3415 rx
->local
, rx
->skb
, rx
->u
.rx
.status
,
3416 ieee80211_msg_wep_frame_unknown_key
);
3422 if (rx
->fc
& IEEE80211_FCTL_PROTECTED
&& rx
->key
&& rx
->u
.rx
.ra_match
) {
3423 rx
->key
->tx_rx_count
++;
3424 if (unlikely(rx
->local
->key_tx_rx_threshold
&&
3425 rx
->key
->tx_rx_count
>
3426 rx
->local
->key_tx_rx_threshold
)) {
3427 ieee80211_key_threshold_notify(rx
->dev
, rx
->key
,
3432 return TXRX_CONTINUE
;
3436 static ieee80211_txrx_result
3437 ieee80211_rx_h_sta_process(struct ieee80211_txrx_data
*rx
)
3439 struct sta_info
*sta
= rx
->sta
;
3440 struct net_device
*dev
= rx
->dev
;
3441 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
3444 return TXRX_CONTINUE
;
3446 /* Update last_rx only for IBSS packets which are for the current
3447 * BSSID to avoid keeping the current IBSS network alive in cases where
3448 * other STAs are using different BSSID. */
3449 if (rx
->sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
3450 u8
*bssid
= ieee80211_get_bssid(hdr
, rx
->skb
->len
);
3451 if (compare_ether_addr(bssid
, rx
->sdata
->u
.sta
.bssid
) == 0)
3452 sta
->last_rx
= jiffies
;
3454 if (!is_multicast_ether_addr(hdr
->addr1
) ||
3455 rx
->sdata
->type
== IEEE80211_IF_TYPE_STA
) {
3456 /* Update last_rx only for unicast frames in order to prevent
3457 * the Probe Request frames (the only broadcast frames from a
3458 * STA in infrastructure mode) from keeping a connection alive.
3460 sta
->last_rx
= jiffies
;
3463 if (!rx
->u
.rx
.ra_match
)
3464 return TXRX_CONTINUE
;
3466 sta
->rx_fragments
++;
3467 sta
->rx_bytes
+= rx
->skb
->len
;
3468 sta
->last_rssi
= (sta
->last_rssi
* 15 +
3469 rx
->u
.rx
.status
->ssi
) / 16;
3470 sta
->last_signal
= (sta
->last_signal
* 15 +
3471 rx
->u
.rx
.status
->signal
) / 16;
3472 sta
->last_noise
= (sta
->last_noise
* 15 +
3473 rx
->u
.rx
.status
->noise
) / 16;
3475 if (!(rx
->fc
& IEEE80211_FCTL_MOREFRAGS
)) {
3476 /* Change STA power saving mode only in the end of a frame
3477 * exchange sequence */
3478 if ((sta
->flags
& WLAN_STA_PS
) && !(rx
->fc
& IEEE80211_FCTL_PM
))
3479 rx
->u
.rx
.sent_ps_buffered
+= ap_sta_ps_end(dev
, sta
);
3480 else if (!(sta
->flags
& WLAN_STA_PS
) &&
3481 (rx
->fc
& IEEE80211_FCTL_PM
))
3482 ap_sta_ps_start(dev
, sta
);
3485 /* Drop data::nullfunc frames silently, since they are used only to
3486 * control station power saving mode. */
3487 if ((rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
&&
3488 (rx
->fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_NULLFUNC
) {
3489 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_nullfunc
);
3490 /* Update counter and free packet here to avoid counting this
3491 * as a dropped packed. */
3493 dev_kfree_skb(rx
->skb
);
3497 return TXRX_CONTINUE
;
3498 } /* ieee80211_rx_h_sta_process */
3501 static ieee80211_txrx_result
3502 ieee80211_rx_h_wep_weak_iv_detection(struct ieee80211_txrx_data
*rx
)
3504 if (!rx
->sta
|| !(rx
->fc
& IEEE80211_FCTL_PROTECTED
) ||
3505 (rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
||
3506 !rx
->key
|| rx
->key
->alg
!= ALG_WEP
|| !rx
->u
.rx
.ra_match
)
3507 return TXRX_CONTINUE
;
3509 /* Check for weak IVs, if hwaccel did not remove IV from the frame */
3510 if ((rx
->local
->hw
.flags
& IEEE80211_HW_WEP_INCLUDE_IV
) ||
3511 rx
->key
->force_sw_encrypt
) {
3512 u8
*iv
= ieee80211_wep_is_weak_iv(rx
->skb
, rx
->key
);
3514 rx
->sta
->wep_weak_iv_count
++;
3518 return TXRX_CONTINUE
;
3522 static ieee80211_txrx_result
3523 ieee80211_rx_h_wep_decrypt(struct ieee80211_txrx_data
*rx
)
3525 /* If the device handles decryption totally, skip this test */
3526 if (rx
->local
->hw
.flags
& IEEE80211_HW_DEVICE_HIDES_WEP
)
3527 return TXRX_CONTINUE
;
3529 if ((rx
->key
&& rx
->key
->alg
!= ALG_WEP
) ||
3530 !(rx
->fc
& IEEE80211_FCTL_PROTECTED
) ||
3531 ((rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
&&
3532 ((rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_MGMT
||
3533 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_AUTH
)))
3534 return TXRX_CONTINUE
;
3537 printk(KERN_DEBUG
"%s: RX WEP frame, but no key set\n",
3542 if (!(rx
->u
.rx
.status
->flag
& RX_FLAG_DECRYPTED
) ||
3543 rx
->key
->force_sw_encrypt
) {
3544 if (ieee80211_wep_decrypt(rx
->local
, rx
->skb
, rx
->key
)) {
3545 printk(KERN_DEBUG
"%s: RX WEP frame, decrypt "
3546 "failed\n", rx
->dev
->name
);
3549 } else if (rx
->local
->hw
.flags
& IEEE80211_HW_WEP_INCLUDE_IV
) {
3550 ieee80211_wep_remove_iv(rx
->local
, rx
->skb
, rx
->key
);
3552 skb_trim(rx
->skb
, rx
->skb
->len
- 4);
3555 return TXRX_CONTINUE
;
3559 static ieee80211_txrx_result
3560 ieee80211_rx_h_802_1x_pae(struct ieee80211_txrx_data
*rx
)
3562 if (rx
->sdata
->eapol
&& ieee80211_is_eapol(rx
->skb
) &&
3563 rx
->sdata
->type
!= IEEE80211_IF_TYPE_STA
&& rx
->u
.rx
.ra_match
) {
3564 /* Pass both encrypted and unencrypted EAPOL frames to user
3565 * space for processing. */
3566 if (!rx
->local
->apdev
)
3568 ieee80211_rx_mgmt(rx
->local
, rx
->skb
, rx
->u
.rx
.status
,
3569 ieee80211_msg_normal
);
3573 if (unlikely(rx
->sdata
->ieee802_1x
&&
3574 (rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
&&
3575 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_NULLFUNC
&&
3576 (!rx
->sta
|| !(rx
->sta
->flags
& WLAN_STA_AUTHORIZED
)) &&
3577 !ieee80211_is_eapol(rx
->skb
))) {
3578 #ifdef CONFIG_MAC80211_DEBUG
3579 struct ieee80211_hdr
*hdr
=
3580 (struct ieee80211_hdr
*) rx
->skb
->data
;
3581 printk(KERN_DEBUG
"%s: dropped frame from " MAC_FMT
3582 " (unauthorized port)\n", rx
->dev
->name
,
3583 MAC_ARG(hdr
->addr2
));
3584 #endif /* CONFIG_MAC80211_DEBUG */
3588 return TXRX_CONTINUE
;
3592 static ieee80211_txrx_result
3593 ieee80211_rx_h_drop_unencrypted(struct ieee80211_txrx_data
*rx
)
3595 /* If the device handles decryption totally, skip this test */
3596 if (rx
->local
->hw
.flags
& IEEE80211_HW_DEVICE_HIDES_WEP
)
3597 return TXRX_CONTINUE
;
3599 /* Drop unencrypted frames if key is set. */
3600 if (unlikely(!(rx
->fc
& IEEE80211_FCTL_PROTECTED
) &&
3601 (rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
&&
3602 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_NULLFUNC
&&
3603 (rx
->key
|| rx
->sdata
->drop_unencrypted
) &&
3604 (rx
->sdata
->eapol
== 0 ||
3605 !ieee80211_is_eapol(rx
->skb
)))) {
3606 printk(KERN_DEBUG
"%s: RX non-WEP frame, but expected "
3607 "encryption\n", rx
->dev
->name
);
3610 return TXRX_CONTINUE
;
3614 static ieee80211_txrx_result
3615 ieee80211_rx_h_mgmt(struct ieee80211_txrx_data
*rx
)
3617 struct ieee80211_sub_if_data
*sdata
;
3619 if (!rx
->u
.rx
.ra_match
)
3622 sdata
= IEEE80211_DEV_TO_SUB_IF(rx
->dev
);
3623 if ((sdata
->type
== IEEE80211_IF_TYPE_STA
||
3624 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) &&
3625 !rx
->local
->user_space_mlme
) {
3626 ieee80211_sta_rx_mgmt(rx
->dev
, rx
->skb
, rx
->u
.rx
.status
);
3628 /* Management frames are sent to hostapd for processing */
3629 if (!rx
->local
->apdev
)
3631 ieee80211_rx_mgmt(rx
->local
, rx
->skb
, rx
->u
.rx
.status
,
3632 ieee80211_msg_normal
);
3638 static ieee80211_txrx_result
3639 ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data
*rx
)
3641 struct ieee80211_local
*local
= rx
->local
;
3642 struct sk_buff
*skb
= rx
->skb
;
3644 if (unlikely(local
->sta_scanning
!= 0)) {
3645 ieee80211_sta_rx_scan(rx
->dev
, skb
, rx
->u
.rx
.status
);
3649 if (unlikely(rx
->u
.rx
.in_scan
)) {
3650 /* scanning finished during invoking of handlers */
3651 I802_DEBUG_INC(local
->rx_handlers_drop_passive_scan
);
3655 return TXRX_CONTINUE
;
3659 static void ieee80211_rx_michael_mic_report(struct net_device
*dev
,
3660 struct ieee80211_hdr
*hdr
,
3661 struct sta_info
*sta
,
3662 struct ieee80211_txrx_data
*rx
)
3666 hdrlen
= ieee80211_get_hdrlen_from_skb(rx
->skb
);
3667 if (rx
->skb
->len
>= hdrlen
+ 4)
3668 keyidx
= rx
->skb
->data
[hdrlen
+ 3] >> 6;
3672 /* TODO: verify that this is not triggered by fragmented
3673 * frames (hw does not verify MIC for them). */
3674 printk(KERN_DEBUG
"%s: TKIP hwaccel reported Michael MIC "
3675 "failure from " MAC_FMT
" to " MAC_FMT
" keyidx=%d\n",
3676 dev
->name
, MAC_ARG(hdr
->addr2
), MAC_ARG(hdr
->addr1
), keyidx
);
3679 /* Some hardware versions seem to generate incorrect
3680 * Michael MIC reports; ignore them to avoid triggering
3681 * countermeasures. */
3682 printk(KERN_DEBUG
"%s: ignored spurious Michael MIC "
3683 "error for unknown address " MAC_FMT
"\n",
3684 dev
->name
, MAC_ARG(hdr
->addr2
));
3688 if (!(rx
->fc
& IEEE80211_FCTL_PROTECTED
)) {
3689 printk(KERN_DEBUG
"%s: ignored spurious Michael MIC "
3690 "error for a frame with no ISWEP flag (src "
3691 MAC_FMT
")\n", dev
->name
, MAC_ARG(hdr
->addr2
));
3695 if ((rx
->local
->hw
.flags
& IEEE80211_HW_WEP_INCLUDE_IV
) &&
3696 rx
->sdata
->type
== IEEE80211_IF_TYPE_AP
) {
3697 keyidx
= ieee80211_wep_get_keyidx(rx
->skb
);
3698 /* AP with Pairwise keys support should never receive Michael
3699 * MIC errors for non-zero keyidx because these are reserved
3700 * for group keys and only the AP is sending real multicast
3703 printk(KERN_DEBUG
"%s: ignored Michael MIC error for "
3704 "a frame with non-zero keyidx (%d) (src " MAC_FMT
3705 ")\n", dev
->name
, keyidx
, MAC_ARG(hdr
->addr2
));
3710 if ((rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
&&
3711 ((rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_MGMT
||
3712 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_AUTH
)) {
3713 printk(KERN_DEBUG
"%s: ignored spurious Michael MIC "
3714 "error for a frame that cannot be encrypted "
3715 "(fc=0x%04x) (src " MAC_FMT
")\n",
3716 dev
->name
, rx
->fc
, MAC_ARG(hdr
->addr2
));
3721 union iwreq_data wrqu
;
3722 char *buf
= kmalloc(128, GFP_ATOMIC
);
3726 /* TODO: needed parameters: count, key type, TSC */
3727 sprintf(buf
, "MLME-MICHAELMICFAILURE.indication("
3728 "keyid=%d %scast addr=" MAC_FMT
")",
3729 keyidx
, hdr
->addr1
[0] & 0x01 ? "broad" : "uni",
3730 MAC_ARG(hdr
->addr2
));
3731 memset(&wrqu
, 0, sizeof(wrqu
));
3732 wrqu
.data
.length
= strlen(buf
);
3733 wireless_send_event(rx
->dev
, IWEVCUSTOM
, &wrqu
, buf
);
3737 /* TODO: consider verifying the MIC error report with software
3738 * implementation if we get too many spurious reports from the
3740 if (!rx
->local
->apdev
)
3742 ieee80211_rx_mgmt(rx
->local
, rx
->skb
, rx
->u
.rx
.status
,
3743 ieee80211_msg_michael_mic_failure
);
3747 dev_kfree_skb(rx
->skb
);
3751 static inline ieee80211_txrx_result
__ieee80211_invoke_rx_handlers(
3752 struct ieee80211_local
*local
,
3753 ieee80211_rx_handler
*handlers
,
3754 struct ieee80211_txrx_data
*rx
,
3755 struct sta_info
*sta
)
3757 ieee80211_rx_handler
*handler
;
3758 ieee80211_txrx_result res
= TXRX_DROP
;
3760 for (handler
= handlers
; *handler
!= NULL
; handler
++) {
3761 res
= (*handler
)(rx
);
3762 if (res
!= TXRX_CONTINUE
) {
3763 if (res
== TXRX_DROP
) {
3764 I802_DEBUG_INC(local
->rx_handlers_drop
);
3768 if (res
== TXRX_QUEUED
)
3769 I802_DEBUG_INC(local
->rx_handlers_queued
);
3774 if (res
== TXRX_DROP
) {
3775 dev_kfree_skb(rx
->skb
);
3780 static inline void ieee80211_invoke_rx_handlers(struct ieee80211_local
*local
,
3781 ieee80211_rx_handler
*handlers
,
3782 struct ieee80211_txrx_data
*rx
,
3783 struct sta_info
*sta
)
3785 if (__ieee80211_invoke_rx_handlers(local
, handlers
, rx
, sta
) ==
3787 dev_kfree_skb(rx
->skb
);
3791 * This is the receive path handler. It is called by a low level driver when an
3792 * 802.11 MPDU is received from the hardware.
3794 void __ieee80211_rx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
3795 struct ieee80211_rx_status
*status
)
3797 struct ieee80211_local
*local
= hw_to_local(hw
);
3798 struct ieee80211_sub_if_data
*sdata
;
3799 struct sta_info
*sta
;
3800 struct ieee80211_hdr
*hdr
;
3801 struct ieee80211_txrx_data rx
;
3804 int radiotap_len
= 0;
3806 if (status
->flag
& RX_FLAG_RADIOTAP
) {
3807 radiotap_len
= ieee80211_get_radiotap_len(skb
);
3808 skb_pull(skb
, radiotap_len
);
3811 hdr
= (struct ieee80211_hdr
*) skb
->data
;
3812 memset(&rx
, 0, sizeof(rx
));
3816 rx
.u
.rx
.status
= status
;
3817 rx
.fc
= skb
->len
>= 2 ? le16_to_cpu(hdr
->frame_control
) : 0;
3818 type
= rx
.fc
& IEEE80211_FCTL_FTYPE
;
3819 if (type
== IEEE80211_FTYPE_DATA
|| type
== IEEE80211_FTYPE_MGMT
)
3820 local
->dot11ReceivedFragmentCount
++;
3821 multicast
= is_multicast_ether_addr(hdr
->addr1
);
3824 sta
= rx
.sta
= sta_info_get(local
, hdr
->addr2
);
3826 sta
= rx
.sta
= NULL
;
3830 rx
.sdata
= IEEE80211_DEV_TO_SUB_IF(rx
.dev
);
3833 if ((status
->flag
& RX_FLAG_MMIC_ERROR
)) {
3834 ieee80211_rx_michael_mic_report(local
->mdev
, hdr
, sta
, &rx
);
3838 if (unlikely(local
->sta_scanning
))
3839 rx
.u
.rx
.in_scan
= 1;
3841 if (__ieee80211_invoke_rx_handlers(local
, local
->rx_pre_handlers
, &rx
,
3842 sta
) != TXRX_CONTINUE
)
3846 skb_push(skb
, radiotap_len
);
3847 if (sta
&& !sta
->assoc_ap
&& !(sta
->flags
& WLAN_STA_WDS
) &&
3848 !local
->iff_promiscs
&& !multicast
) {
3849 rx
.u
.rx
.ra_match
= 1;
3850 ieee80211_invoke_rx_handlers(local
, local
->rx_handlers
, &rx
,
3853 struct ieee80211_sub_if_data
*prev
= NULL
;
3854 struct sk_buff
*skb_new
;
3855 u8
*bssid
= ieee80211_get_bssid(hdr
, skb
->len
- radiotap_len
);
3857 read_lock(&local
->sub_if_lock
);
3858 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
3859 rx
.u
.rx
.ra_match
= 1;
3860 switch (sdata
->type
) {
3861 case IEEE80211_IF_TYPE_STA
:
3864 if (!ieee80211_bssid_match(bssid
,
3865 sdata
->u
.sta
.bssid
)) {
3866 if (!rx
.u
.rx
.in_scan
)
3868 rx
.u
.rx
.ra_match
= 0;
3869 } else if (!multicast
&&
3870 compare_ether_addr(sdata
->dev
->dev_addr
,
3872 if (!sdata
->promisc
)
3874 rx
.u
.rx
.ra_match
= 0;
3877 case IEEE80211_IF_TYPE_IBSS
:
3880 if (!ieee80211_bssid_match(bssid
,
3881 sdata
->u
.sta
.bssid
)) {
3882 if (!rx
.u
.rx
.in_scan
)
3884 rx
.u
.rx
.ra_match
= 0;
3885 } else if (!multicast
&&
3886 compare_ether_addr(sdata
->dev
->dev_addr
,
3888 if (!sdata
->promisc
)
3890 rx
.u
.rx
.ra_match
= 0;
3893 ieee80211_ibss_add_sta(sdata
->dev
,
3897 case IEEE80211_IF_TYPE_AP
:
3899 if (compare_ether_addr(sdata
->dev
->dev_addr
,
3902 } else if (!ieee80211_bssid_match(bssid
,
3903 sdata
->dev
->dev_addr
)) {
3904 if (!rx
.u
.rx
.in_scan
)
3906 rx
.u
.rx
.ra_match
= 0;
3908 if (sdata
->dev
== local
->mdev
&&
3910 /* do not receive anything via
3911 * master device when not scanning */
3914 case IEEE80211_IF_TYPE_WDS
:
3916 (rx
.fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
)
3918 if (compare_ether_addr(sdata
->u
.wds
.remote_addr
,
3925 skb_new
= skb_copy(skb
, GFP_ATOMIC
);
3927 if (net_ratelimit())
3928 printk(KERN_DEBUG
"%s: failed to copy "
3929 "multicast frame for %s",
3930 local
->mdev
->name
, prev
->dev
->name
);
3936 ieee80211_invoke_rx_handlers(local
,
3946 ieee80211_invoke_rx_handlers(local
, local
->rx_handlers
,
3950 read_unlock(&local
->sub_if_lock
);
3957 EXPORT_SYMBOL(__ieee80211_rx
);
3959 static ieee80211_txrx_result
3960 ieee80211_tx_h_load_stats(struct ieee80211_txrx_data
*tx
)
3962 struct ieee80211_local
*local
= tx
->local
;
3963 struct ieee80211_hw_mode
*mode
= tx
->u
.tx
.mode
;
3964 struct sk_buff
*skb
= tx
->skb
;
3965 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
3966 u32 load
= 0, hdrtime
;
3968 /* TODO: this could be part of tx_status handling, so that the number
3969 * of retries would be known; TX rate should in that case be stored
3970 * somewhere with the packet */
3972 /* Estimate total channel use caused by this frame */
3974 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
3975 * 1 usec = 1/8 * (1080 / 10) = 13.5 */
3977 if (mode
->mode
== MODE_IEEE80211A
||
3978 mode
->mode
== MODE_ATHEROS_TURBO
||
3979 mode
->mode
== MODE_ATHEROS_TURBOG
||
3980 (mode
->mode
== MODE_IEEE80211G
&&
3981 tx
->u
.tx
.rate
->flags
& IEEE80211_RATE_ERP
))
3982 hdrtime
= CHAN_UTIL_HDR_SHORT
;
3984 hdrtime
= CHAN_UTIL_HDR_LONG
;
3987 if (!is_multicast_ether_addr(hdr
->addr1
))
3990 if (tx
->u
.tx
.control
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
)
3991 load
+= 2 * hdrtime
;
3992 else if (tx
->u
.tx
.control
->flags
& IEEE80211_TXCTL_USE_CTS_PROTECT
)
3995 load
+= skb
->len
* tx
->u
.tx
.rate
->rate_inv
;
3997 if (tx
->u
.tx
.extra_frag
) {
3999 for (i
= 0; i
< tx
->u
.tx
.num_extra_frag
; i
++) {
4000 load
+= 2 * hdrtime
;
4001 load
+= tx
->u
.tx
.extra_frag
[i
]->len
*
4002 tx
->u
.tx
.rate
->rate
;
4006 /* Divide channel_use by 8 to avoid wrapping around the counter */
4007 load
>>= CHAN_UTIL_SHIFT
;
4008 local
->channel_use_raw
+= load
;
4010 tx
->sta
->channel_use_raw
+= load
;
4011 tx
->sdata
->channel_use_raw
+= load
;
4013 return TXRX_CONTINUE
;
4017 static ieee80211_txrx_result
4018 ieee80211_rx_h_load_stats(struct ieee80211_txrx_data
*rx
)
4020 struct ieee80211_local
*local
= rx
->local
;
4021 struct sk_buff
*skb
= rx
->skb
;
4022 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
4023 u32 load
= 0, hdrtime
;
4024 struct ieee80211_rate
*rate
;
4025 struct ieee80211_hw_mode
*mode
= local
->hw
.conf
.mode
;
4028 /* Estimate total channel use caused by this frame */
4030 if (unlikely(mode
->num_rates
< 0))
4031 return TXRX_CONTINUE
;
4033 rate
= &mode
->rates
[0];
4034 for (i
= 0; i
< mode
->num_rates
; i
++) {
4035 if (mode
->rates
[i
].val
== rx
->u
.rx
.status
->rate
) {
4036 rate
= &mode
->rates
[i
];
4041 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
4042 * 1 usec = 1/8 * (1080 / 10) = 13.5 */
4044 if (mode
->mode
== MODE_IEEE80211A
||
4045 mode
->mode
== MODE_ATHEROS_TURBO
||
4046 mode
->mode
== MODE_ATHEROS_TURBOG
||
4047 (mode
->mode
== MODE_IEEE80211G
&&
4048 rate
->flags
& IEEE80211_RATE_ERP
))
4049 hdrtime
= CHAN_UTIL_HDR_SHORT
;
4051 hdrtime
= CHAN_UTIL_HDR_LONG
;
4054 if (!is_multicast_ether_addr(hdr
->addr1
))
4057 load
+= skb
->len
* rate
->rate_inv
;
4059 /* Divide channel_use by 8 to avoid wrapping around the counter */
4060 load
>>= CHAN_UTIL_SHIFT
;
4061 local
->channel_use_raw
+= load
;
4063 rx
->sta
->channel_use_raw
+= load
;
4064 rx
->u
.rx
.load
= load
;
4066 return TXRX_CONTINUE
;
4069 static ieee80211_txrx_result
4070 ieee80211_rx_h_if_stats(struct ieee80211_txrx_data
*rx
)
4072 rx
->sdata
->channel_use_raw
+= rx
->u
.rx
.load
;
4073 return TXRX_CONTINUE
;
4076 static void ieee80211_stat_refresh(unsigned long data
)
4078 struct ieee80211_local
*local
= (struct ieee80211_local
*) data
;
4079 struct sta_info
*sta
;
4080 struct ieee80211_sub_if_data
*sdata
;
4082 if (!local
->stat_time
)
4085 /* go through all stations */
4086 spin_lock_bh(&local
->sta_lock
);
4087 list_for_each_entry(sta
, &local
->sta_list
, list
) {
4088 sta
->channel_use
= (sta
->channel_use_raw
/ local
->stat_time
) /
4090 sta
->channel_use_raw
= 0;
4092 spin_unlock_bh(&local
->sta_lock
);
4094 /* go through all subinterfaces */
4095 read_lock(&local
->sub_if_lock
);
4096 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
4097 sdata
->channel_use
= (sdata
->channel_use_raw
/
4098 local
->stat_time
) / CHAN_UTIL_PER_10MS
;
4099 sdata
->channel_use_raw
= 0;
4101 read_unlock(&local
->sub_if_lock
);
4103 /* hardware interface */
4104 local
->channel_use
= (local
->channel_use_raw
/
4105 local
->stat_time
) / CHAN_UTIL_PER_10MS
;
4106 local
->channel_use_raw
= 0;
4108 local
->stat_timer
.expires
= jiffies
+ HZ
* local
->stat_time
/ 100;
4109 add_timer(&local
->stat_timer
);
4113 /* This is a version of the rx handler that can be called from hard irq
4114 * context. Post the skb on the queue and schedule the tasklet */
4115 void ieee80211_rx_irqsafe(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
4116 struct ieee80211_rx_status
*status
)
4118 struct ieee80211_local
*local
= hw_to_local(hw
);
4120 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status
) > sizeof(skb
->cb
));
4122 skb
->dev
= local
->mdev
;
4123 /* copy status into skb->cb for use by tasklet */
4124 memcpy(skb
->cb
, status
, sizeof(*status
));
4125 skb
->pkt_type
= IEEE80211_RX_MSG
;
4126 skb_queue_tail(&local
->skb_queue
, skb
);
4127 tasklet_schedule(&local
->tasklet
);
4129 EXPORT_SYMBOL(ieee80211_rx_irqsafe
);
4131 void ieee80211_tx_status_irqsafe(struct ieee80211_hw
*hw
,
4132 struct sk_buff
*skb
,
4133 struct ieee80211_tx_status
*status
)
4135 struct ieee80211_local
*local
= hw_to_local(hw
);
4136 struct ieee80211_tx_status
*saved
;
4139 skb
->dev
= local
->mdev
;
4140 saved
= kmalloc(sizeof(struct ieee80211_tx_status
), GFP_ATOMIC
);
4141 if (unlikely(!saved
)) {
4142 if (net_ratelimit())
4143 printk(KERN_WARNING
"%s: Not enough memory, "
4144 "dropping tx status", skb
->dev
->name
);
4145 /* should be dev_kfree_skb_irq, but due to this function being
4146 * named _irqsafe instead of just _irq we can't be sure that
4147 * people won't call it from non-irq contexts */
4148 dev_kfree_skb_any(skb
);
4151 memcpy(saved
, status
, sizeof(struct ieee80211_tx_status
));
4152 /* copy pointer to saved status into skb->cb for use by tasklet */
4153 memcpy(skb
->cb
, &saved
, sizeof(saved
));
4155 skb
->pkt_type
= IEEE80211_TX_STATUS_MSG
;
4156 skb_queue_tail(status
->control
.flags
& IEEE80211_TXCTL_REQ_TX_STATUS
?
4157 &local
->skb_queue
: &local
->skb_queue_unreliable
, skb
);
4158 tmp
= skb_queue_len(&local
->skb_queue
) +
4159 skb_queue_len(&local
->skb_queue_unreliable
);
4160 while (tmp
> IEEE80211_IRQSAFE_QUEUE_LIMIT
&&
4161 (skb
= skb_dequeue(&local
->skb_queue_unreliable
))) {
4162 memcpy(&saved
, skb
->cb
, sizeof(saved
));
4164 dev_kfree_skb_irq(skb
);
4166 I802_DEBUG_INC(local
->tx_status_drop
);
4168 tasklet_schedule(&local
->tasklet
);
4170 EXPORT_SYMBOL(ieee80211_tx_status_irqsafe
);
4172 static void ieee80211_tasklet_handler(unsigned long data
)
4174 struct ieee80211_local
*local
= (struct ieee80211_local
*) data
;
4175 struct sk_buff
*skb
;
4176 struct ieee80211_rx_status rx_status
;
4177 struct ieee80211_tx_status
*tx_status
;
4179 while ((skb
= skb_dequeue(&local
->skb_queue
)) ||
4180 (skb
= skb_dequeue(&local
->skb_queue_unreliable
))) {
4181 switch (skb
->pkt_type
) {
4182 case IEEE80211_RX_MSG
:
4183 /* status is in skb->cb */
4184 memcpy(&rx_status
, skb
->cb
, sizeof(rx_status
));
4185 /* Clear skb->type in order to not confuse kernel
4188 __ieee80211_rx(local_to_hw(local
), skb
, &rx_status
);
4190 case IEEE80211_TX_STATUS_MSG
:
4191 /* get pointer to saved status out of skb->cb */
4192 memcpy(&tx_status
, skb
->cb
, sizeof(tx_status
));
4194 ieee80211_tx_status(local_to_hw(local
),
4198 default: /* should never get here! */
4199 printk(KERN_ERR
"%s: Unknown message type (%d)\n",
4200 local
->mdev
->name
, skb
->pkt_type
);
4208 /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
4209 * make a prepared TX frame (one that has been given to hw) to look like brand
4210 * new IEEE 802.11 frame that is ready to go through TX processing again.
4211 * Also, tx_packet_data in cb is restored from tx_control. */
4212 static void ieee80211_remove_tx_extra(struct ieee80211_local
*local
,
4213 struct ieee80211_key
*key
,
4214 struct sk_buff
*skb
,
4215 struct ieee80211_tx_control
*control
)
4217 int hdrlen
, iv_len
, mic_len
;
4218 struct ieee80211_tx_packet_data
*pkt_data
;
4220 pkt_data
= (struct ieee80211_tx_packet_data
*)skb
->cb
;
4221 pkt_data
->ifindex
= control
->ifindex
;
4222 pkt_data
->mgmt_iface
= (control
->type
== IEEE80211_IF_TYPE_MGMT
);
4223 pkt_data
->req_tx_status
= !!(control
->flags
& IEEE80211_TXCTL_REQ_TX_STATUS
);
4224 pkt_data
->do_not_encrypt
= !!(control
->flags
& IEEE80211_TXCTL_DO_NOT_ENCRYPT
);
4225 pkt_data
->requeue
= !!(control
->flags
& IEEE80211_TXCTL_REQUEUE
);
4226 pkt_data
->queue
= control
->queue
;
4228 hdrlen
= ieee80211_get_hdrlen_from_skb(skb
);
4235 iv_len
= WEP_IV_LEN
;
4236 mic_len
= WEP_ICV_LEN
;
4239 iv_len
= TKIP_IV_LEN
;
4240 mic_len
= TKIP_ICV_LEN
;
4243 iv_len
= CCMP_HDR_LEN
;
4244 mic_len
= CCMP_MIC_LEN
;
4250 if (skb
->len
>= mic_len
&& key
->force_sw_encrypt
)
4251 skb_trim(skb
, skb
->len
- mic_len
);
4252 if (skb
->len
>= iv_len
&& skb
->len
> hdrlen
) {
4253 memmove(skb
->data
+ iv_len
, skb
->data
, hdrlen
);
4254 skb_pull(skb
, iv_len
);
4259 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
4260 u16 fc
= le16_to_cpu(hdr
->frame_control
);
4261 if ((fc
& 0x8C) == 0x88) /* QoS Control Field */ {
4262 fc
&= ~IEEE80211_STYPE_QOS_DATA
;
4263 hdr
->frame_control
= cpu_to_le16(fc
);
4264 memmove(skb
->data
+ 2, skb
->data
, hdrlen
- 2);
4271 void ieee80211_tx_status(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
4272 struct ieee80211_tx_status
*status
)
4274 struct sk_buff
*skb2
;
4275 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
4276 struct ieee80211_local
*local
= hw_to_local(hw
);
4282 "%s: ieee80211_tx_status called with NULL status\n",
4288 if (status
->excessive_retries
) {
4289 struct sta_info
*sta
;
4290 sta
= sta_info_get(local
, hdr
->addr1
);
4292 if (sta
->flags
& WLAN_STA_PS
) {
4293 /* The STA is in power save mode, so assume
4294 * that this TX packet failed because of that.
4296 status
->excessive_retries
= 0;
4297 status
->flags
|= IEEE80211_TX_STATUS_TX_FILTERED
;
4303 if (status
->flags
& IEEE80211_TX_STATUS_TX_FILTERED
) {
4304 struct sta_info
*sta
;
4305 sta
= sta_info_get(local
, hdr
->addr1
);
4307 sta
->tx_filtered_count
++;
4309 /* Clear the TX filter mask for this STA when sending
4310 * the next packet. If the STA went to power save mode,
4311 * this will happen when it is waking up for the next
4313 sta
->clear_dst_mask
= 1;
4315 /* TODO: Is the WLAN_STA_PS flag always set here or is
4316 * the race between RX and TX status causing some
4317 * packets to be filtered out before 80211.o gets an
4318 * update for PS status? This seems to be the case, so
4319 * no changes are likely to be needed. */
4320 if (sta
->flags
& WLAN_STA_PS
&&
4321 skb_queue_len(&sta
->tx_filtered
) <
4322 STA_MAX_TX_BUFFER
) {
4323 ieee80211_remove_tx_extra(local
, sta
->key
,
4326 skb_queue_tail(&sta
->tx_filtered
, skb
);
4327 } else if (!(sta
->flags
& WLAN_STA_PS
) &&
4328 !(status
->control
.flags
& IEEE80211_TXCTL_REQUEUE
)) {
4329 /* Software retry the packet once */
4330 status
->control
.flags
|= IEEE80211_TXCTL_REQUEUE
;
4331 ieee80211_remove_tx_extra(local
, sta
->key
,
4334 dev_queue_xmit(skb
);
4336 if (net_ratelimit()) {
4337 printk(KERN_DEBUG
"%s: dropped TX "
4338 "filtered frame queue_len=%d "
4343 !!(sta
->flags
& WLAN_STA_PS
),
4352 /* FIXME: STUPID to call this with both local and local->mdev */
4353 rate_control_tx_status(local
, local
->mdev
, skb
, status
);
4356 ieee80211_led_tx(local
, 0);
4359 * Fragments are passed to low-level drivers as separate skbs, so these
4360 * are actually fragments, not frames. Update frame counters only for
4361 * the first fragment of the frame. */
4363 frag
= le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_FRAG
;
4364 type
= le16_to_cpu(hdr
->frame_control
) & IEEE80211_FCTL_FTYPE
;
4366 if (status
->flags
& IEEE80211_TX_STATUS_ACK
) {
4368 local
->dot11TransmittedFrameCount
++;
4369 if (is_multicast_ether_addr(hdr
->addr1
))
4370 local
->dot11MulticastTransmittedFrameCount
++;
4371 if (status
->retry_count
> 0)
4372 local
->dot11RetryCount
++;
4373 if (status
->retry_count
> 1)
4374 local
->dot11MultipleRetryCount
++;
4377 /* This counter shall be incremented for an acknowledged MPDU
4378 * with an individual address in the address 1 field or an MPDU
4379 * with a multicast address in the address 1 field of type Data
4381 if (!is_multicast_ether_addr(hdr
->addr1
) ||
4382 type
== IEEE80211_FTYPE_DATA
||
4383 type
== IEEE80211_FTYPE_MGMT
)
4384 local
->dot11TransmittedFragmentCount
++;
4387 local
->dot11FailedCount
++;
4390 if (!(status
->control
.flags
& IEEE80211_TXCTL_REQ_TX_STATUS
)
4391 || unlikely(!local
->apdev
)) {
4396 msg_type
= (status
->flags
& IEEE80211_TX_STATUS_ACK
) ?
4397 ieee80211_msg_tx_callback_ack
: ieee80211_msg_tx_callback_fail
;
4399 /* skb was the original skb used for TX. Clone it and give the clone
4400 * to netif_rx(). Free original skb. */
4401 skb2
= skb_copy(skb
, GFP_ATOMIC
);
4409 /* Send frame to hostapd */
4410 ieee80211_rx_mgmt(local
, skb
, NULL
, msg_type
);
4412 EXPORT_SYMBOL(ieee80211_tx_status
);
4414 /* TODO: implement register/unregister functions for adding TX/RX handlers
4415 * into ordered list */
4417 /* rx_pre handlers don't have dev and sdata fields available in
4418 * ieee80211_txrx_data */
4419 static ieee80211_rx_handler ieee80211_rx_pre_handlers
[] =
4421 ieee80211_rx_h_parse_qos
,
4422 ieee80211_rx_h_load_stats
,
4426 static ieee80211_rx_handler ieee80211_rx_handlers
[] =
4428 ieee80211_rx_h_if_stats
,
4429 ieee80211_rx_h_monitor
,
4430 ieee80211_rx_h_passive_scan
,
4431 ieee80211_rx_h_check
,
4432 ieee80211_rx_h_sta_process
,
4433 ieee80211_rx_h_ccmp_decrypt
,
4434 ieee80211_rx_h_tkip_decrypt
,
4435 ieee80211_rx_h_wep_weak_iv_detection
,
4436 ieee80211_rx_h_wep_decrypt
,
4437 ieee80211_rx_h_defragment
,
4438 ieee80211_rx_h_ps_poll
,
4439 ieee80211_rx_h_michael_mic_verify
,
4440 /* this must be after decryption - so header is counted in MPDU mic
4441 * must be before pae and data, so QOS_DATA format frames
4442 * are not passed to user space by these functions
4444 ieee80211_rx_h_remove_qos_control
,
4445 ieee80211_rx_h_802_1x_pae
,
4446 ieee80211_rx_h_drop_unencrypted
,
4447 ieee80211_rx_h_data
,
4448 ieee80211_rx_h_mgmt
,
4452 static ieee80211_tx_handler ieee80211_tx_handlers
[] =
4454 ieee80211_tx_h_check_assoc
,
4455 ieee80211_tx_h_sequence
,
4456 ieee80211_tx_h_ps_buf
,
4457 ieee80211_tx_h_select_key
,
4458 ieee80211_tx_h_michael_mic_add
,
4459 ieee80211_tx_h_fragment
,
4460 ieee80211_tx_h_tkip_encrypt
,
4461 ieee80211_tx_h_ccmp_encrypt
,
4462 ieee80211_tx_h_wep_encrypt
,
4463 ieee80211_tx_h_rate_ctrl
,
4464 ieee80211_tx_h_misc
,
4465 ieee80211_tx_h_load_stats
,
4470 int ieee80211_if_update_wds(struct net_device
*dev
, u8
*remote_addr
)
4472 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
4473 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4474 struct sta_info
*sta
;
4476 if (compare_ether_addr(remote_addr
, sdata
->u
.wds
.remote_addr
) == 0)
4479 /* Create STA entry for the new peer */
4480 sta
= sta_info_add(local
, dev
, remote_addr
, GFP_KERNEL
);
4485 /* Remove STA entry for the old peer */
4486 sta
= sta_info_get(local
, sdata
->u
.wds
.remote_addr
);
4489 sta_info_free(sta
, 0);
4491 printk(KERN_DEBUG
"%s: could not find STA entry for WDS link "
4492 "peer " MAC_FMT
"\n",
4493 dev
->name
, MAC_ARG(sdata
->u
.wds
.remote_addr
));
4496 /* Update WDS link data */
4497 memcpy(&sdata
->u
.wds
.remote_addr
, remote_addr
, ETH_ALEN
);
4502 /* Must not be called for mdev and apdev */
4503 void ieee80211_if_setup(struct net_device
*dev
)
4506 dev
->hard_start_xmit
= ieee80211_subif_start_xmit
;
4507 dev
->wireless_handlers
= &ieee80211_iw_handler_def
;
4508 dev
->set_multicast_list
= ieee80211_set_multicast_list
;
4509 dev
->change_mtu
= ieee80211_change_mtu
;
4510 dev
->get_stats
= ieee80211_get_stats
;
4511 dev
->open
= ieee80211_open
;
4512 dev
->stop
= ieee80211_stop
;
4513 dev
->uninit
= ieee80211_if_reinit
;
4514 dev
->destructor
= ieee80211_if_free
;
4517 void ieee80211_if_mgmt_setup(struct net_device
*dev
)
4520 dev
->hard_start_xmit
= ieee80211_mgmt_start_xmit
;
4521 dev
->change_mtu
= ieee80211_change_mtu_apdev
;
4522 dev
->get_stats
= ieee80211_get_stats
;
4523 dev
->open
= ieee80211_mgmt_open
;
4524 dev
->stop
= ieee80211_mgmt_stop
;
4525 dev
->type
= ARPHRD_IEEE80211_PRISM
;
4526 dev
->hard_header_parse
= header_parse_80211
;
4527 dev
->uninit
= ieee80211_if_reinit
;
4528 dev
->destructor
= ieee80211_if_free
;
4531 int ieee80211_init_rate_ctrl_alg(struct ieee80211_local
*local
,
4534 struct rate_control_ref
*ref
, *old
;
4537 if (local
->open_count
|| netif_running(local
->mdev
) ||
4538 (local
->apdev
&& netif_running(local
->apdev
)))
4541 ref
= rate_control_alloc(name
, local
);
4543 printk(KERN_WARNING
"%s: Failed to select rate control "
4544 "algorithm\n", local
->mdev
->name
);
4548 old
= local
->rate_ctrl
;
4549 local
->rate_ctrl
= ref
;
4551 rate_control_put(old
);
4552 sta_info_flush(local
, NULL
);
4555 printk(KERN_DEBUG
"%s: Selected rate control "
4556 "algorithm '%s'\n", local
->mdev
->name
,
4563 static void rate_control_deinitialize(struct ieee80211_local
*local
)
4565 struct rate_control_ref
*ref
;
4567 ref
= local
->rate_ctrl
;
4568 local
->rate_ctrl
= NULL
;
4569 rate_control_put(ref
);
4572 struct ieee80211_hw
*ieee80211_alloc_hw(size_t priv_data_len
,
4573 const struct ieee80211_ops
*ops
)
4575 struct net_device
*mdev
;
4576 struct ieee80211_local
*local
;
4577 struct ieee80211_sub_if_data
*sdata
;
4579 struct wiphy
*wiphy
;
4581 /* Ensure 32-byte alignment of our private data and hw private data.
4582 * We use the wiphy priv data for both our ieee80211_local and for
4583 * the driver's private data
4585 * In memory it'll be like this:
4587 * +-------------------------+
4589 * +-------------------------+
4590 * | struct ieee80211_local |
4591 * +-------------------------+
4592 * | driver's private data |
4593 * +-------------------------+
4596 priv_size
= ((sizeof(struct ieee80211_local
) +
4597 NETDEV_ALIGN_CONST
) & ~NETDEV_ALIGN_CONST
) +
4600 wiphy
= wiphy_new(&mac80211_config_ops
, priv_size
);
4605 wiphy
->privid
= mac80211_wiphy_privid
;
4607 local
= wiphy_priv(wiphy
);
4608 local
->hw
.wiphy
= wiphy
;
4610 local
->hw
.priv
= (char *)local
+
4611 ((sizeof(struct ieee80211_local
) +
4612 NETDEV_ALIGN_CONST
) & ~NETDEV_ALIGN_CONST
);
4616 /* for now, mdev needs sub_if_data :/ */
4617 mdev
= alloc_netdev(sizeof(struct ieee80211_sub_if_data
),
4618 "wmaster%d", ether_setup
);
4624 sdata
= IEEE80211_DEV_TO_SUB_IF(mdev
);
4625 mdev
->ieee80211_ptr
= &sdata
->wdev
;
4626 sdata
->wdev
.wiphy
= wiphy
;
4628 local
->hw
.queues
= 1; /* default */
4631 local
->rx_pre_handlers
= ieee80211_rx_pre_handlers
;
4632 local
->rx_handlers
= ieee80211_rx_handlers
;
4633 local
->tx_handlers
= ieee80211_tx_handlers
;
4635 local
->bridge_packets
= 1;
4637 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
4638 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
4639 local
->short_retry_limit
= 7;
4640 local
->long_retry_limit
= 4;
4641 local
->hw
.conf
.radio_enabled
= 1;
4642 local
->rate_ctrl_num_up
= RATE_CONTROL_NUM_UP
;
4643 local
->rate_ctrl_num_down
= RATE_CONTROL_NUM_DOWN
;
4645 local
->enabled_modes
= (unsigned int) -1;
4647 INIT_LIST_HEAD(&local
->modes_list
);
4649 rwlock_init(&local
->sub_if_lock
);
4650 INIT_LIST_HEAD(&local
->sub_if_list
);
4652 INIT_DELAYED_WORK(&local
->scan_work
, ieee80211_sta_scan_work
);
4653 init_timer(&local
->stat_timer
);
4654 local
->stat_timer
.function
= ieee80211_stat_refresh
;
4655 local
->stat_timer
.data
= (unsigned long) local
;
4656 ieee80211_rx_bss_list_init(mdev
);
4658 sta_info_init(local
);
4660 mdev
->hard_start_xmit
= ieee80211_master_start_xmit
;
4661 mdev
->open
= ieee80211_master_open
;
4662 mdev
->stop
= ieee80211_master_stop
;
4663 mdev
->type
= ARPHRD_IEEE80211
;
4664 mdev
->hard_header_parse
= header_parse_80211
;
4666 sdata
->type
= IEEE80211_IF_TYPE_AP
;
4668 sdata
->local
= local
;
4669 sdata
->u
.ap
.force_unicast_rateidx
= -1;
4670 sdata
->u
.ap
.max_ratectrl_rateidx
= -1;
4671 ieee80211_if_sdata_init(sdata
);
4672 list_add_tail(&sdata
->list
, &local
->sub_if_list
);
4674 tasklet_init(&local
->tx_pending_tasklet
, ieee80211_tx_pending
,
4675 (unsigned long)local
);
4676 tasklet_disable(&local
->tx_pending_tasklet
);
4678 tasklet_init(&local
->tasklet
,
4679 ieee80211_tasklet_handler
,
4680 (unsigned long) local
);
4681 tasklet_disable(&local
->tasklet
);
4683 skb_queue_head_init(&local
->skb_queue
);
4684 skb_queue_head_init(&local
->skb_queue_unreliable
);
4686 return local_to_hw(local
);
4688 EXPORT_SYMBOL(ieee80211_alloc_hw
);
4690 int ieee80211_register_hw(struct ieee80211_hw
*hw
)
4692 struct ieee80211_local
*local
= hw_to_local(hw
);
4696 result
= wiphy_register(local
->hw
.wiphy
);
4700 name
= wiphy_dev(local
->hw
.wiphy
)->driver
->name
;
4701 local
->hw
.workqueue
= create_singlethread_workqueue(name
);
4702 if (!local
->hw
.workqueue
) {
4704 goto fail_workqueue
;
4707 local
->hw
.conf
.beacon_int
= 1000;
4709 local
->wstats_flags
|= local
->hw
.max_rssi
?
4710 IW_QUAL_LEVEL_UPDATED
: IW_QUAL_LEVEL_INVALID
;
4711 local
->wstats_flags
|= local
->hw
.max_signal
?
4712 IW_QUAL_QUAL_UPDATED
: IW_QUAL_QUAL_INVALID
;
4713 local
->wstats_flags
|= local
->hw
.max_noise
?
4714 IW_QUAL_NOISE_UPDATED
: IW_QUAL_NOISE_INVALID
;
4715 if (local
->hw
.max_rssi
< 0 || local
->hw
.max_noise
< 0)
4716 local
->wstats_flags
|= IW_QUAL_DBM
;
4718 result
= sta_info_start(local
);
4723 result
= dev_alloc_name(local
->mdev
, local
->mdev
->name
);
4727 memcpy(local
->mdev
->dev_addr
, local
->hw
.wiphy
->perm_addr
, ETH_ALEN
);
4728 SET_NETDEV_DEV(local
->mdev
, wiphy_dev(local
->hw
.wiphy
));
4730 result
= register_netdevice(local
->mdev
);
4734 result
= ieee80211_init_rate_ctrl_alg(local
, NULL
);
4736 printk(KERN_DEBUG
"%s: Failed to initialize rate control "
4737 "algorithm\n", local
->mdev
->name
);
4741 result
= ieee80211_wep_init(local
);
4744 printk(KERN_DEBUG
"%s: Failed to initialize wep\n",
4749 ieee80211_install_qdisc(local
->mdev
);
4751 /* add one default STA interface */
4752 result
= ieee80211_if_add(local
->mdev
, "wlan%d", NULL
,
4753 IEEE80211_IF_TYPE_STA
);
4755 printk(KERN_WARNING
"%s: Failed to add default virtual iface\n",
4758 local
->reg_state
= IEEE80211_DEV_REGISTERED
;
4761 ieee80211_led_init(local
);
4766 rate_control_deinitialize(local
);
4768 unregister_netdevice(local
->mdev
);
4771 sta_info_stop(local
);
4773 destroy_workqueue(local
->hw
.workqueue
);
4775 wiphy_unregister(local
->hw
.wiphy
);
4778 EXPORT_SYMBOL(ieee80211_register_hw
);
4780 int ieee80211_register_hwmode(struct ieee80211_hw
*hw
,
4781 struct ieee80211_hw_mode
*mode
)
4783 struct ieee80211_local
*local
= hw_to_local(hw
);
4784 struct ieee80211_rate
*rate
;
4787 INIT_LIST_HEAD(&mode
->list
);
4788 list_add_tail(&mode
->list
, &local
->modes_list
);
4790 local
->hw_modes
|= (1 << mode
->mode
);
4791 for (i
= 0; i
< mode
->num_rates
; i
++) {
4792 rate
= &(mode
->rates
[i
]);
4793 rate
->rate_inv
= CHAN_UTIL_RATE_LCM
/ rate
->rate
;
4795 ieee80211_prepare_rates(local
, mode
);
4797 if (!local
->oper_hw_mode
) {
4798 /* Default to this mode */
4799 local
->hw
.conf
.phymode
= mode
->mode
;
4800 local
->oper_hw_mode
= local
->scan_hw_mode
= mode
;
4801 local
->oper_channel
= local
->scan_channel
= &mode
->channels
[0];
4802 local
->hw
.conf
.mode
= local
->oper_hw_mode
;
4803 local
->hw
.conf
.chan
= local
->oper_channel
;
4806 if (!(hw
->flags
& IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED
))
4807 ieee80211_init_client(local
->mdev
);
4811 EXPORT_SYMBOL(ieee80211_register_hwmode
);
4813 void ieee80211_unregister_hw(struct ieee80211_hw
*hw
)
4815 struct ieee80211_local
*local
= hw_to_local(hw
);
4816 struct ieee80211_sub_if_data
*sdata
, *tmp
;
4817 struct list_head tmp_list
;
4820 tasklet_kill(&local
->tx_pending_tasklet
);
4821 tasklet_kill(&local
->tasklet
);
4825 BUG_ON(local
->reg_state
!= IEEE80211_DEV_REGISTERED
);
4827 local
->reg_state
= IEEE80211_DEV_UNREGISTERED
;
4829 ieee80211_if_del_mgmt(local
);
4831 write_lock_bh(&local
->sub_if_lock
);
4832 list_replace_init(&local
->sub_if_list
, &tmp_list
);
4833 write_unlock_bh(&local
->sub_if_lock
);
4835 list_for_each_entry_safe(sdata
, tmp
, &tmp_list
, list
)
4836 __ieee80211_if_del(local
, sdata
);
4840 if (local
->stat_time
)
4841 del_timer_sync(&local
->stat_timer
);
4843 ieee80211_rx_bss_list_deinit(local
->mdev
);
4844 ieee80211_clear_tx_pending(local
);
4845 sta_info_stop(local
);
4846 rate_control_deinitialize(local
);
4848 for (i
= 0; i
< NUM_IEEE80211_MODES
; i
++) {
4849 kfree(local
->supp_rates
[i
]);
4850 kfree(local
->basic_rates
[i
]);
4853 if (skb_queue_len(&local
->skb_queue
)
4854 || skb_queue_len(&local
->skb_queue_unreliable
))
4855 printk(KERN_WARNING
"%s: skb_queue not empty\n",
4857 skb_queue_purge(&local
->skb_queue
);
4858 skb_queue_purge(&local
->skb_queue_unreliable
);
4860 destroy_workqueue(local
->hw
.workqueue
);
4861 wiphy_unregister(local
->hw
.wiphy
);
4862 ieee80211_wep_free(local
);
4863 ieee80211_led_exit(local
);
4865 EXPORT_SYMBOL(ieee80211_unregister_hw
);
4867 void ieee80211_free_hw(struct ieee80211_hw
*hw
)
4869 struct ieee80211_local
*local
= hw_to_local(hw
);
4871 ieee80211_if_free(local
->mdev
);
4872 wiphy_free(local
->hw
.wiphy
);
4874 EXPORT_SYMBOL(ieee80211_free_hw
);
4876 void ieee80211_wake_queue(struct ieee80211_hw
*hw
, int queue
)
4878 struct ieee80211_local
*local
= hw_to_local(hw
);
4880 if (test_and_clear_bit(IEEE80211_LINK_STATE_XOFF
,
4881 &local
->state
[queue
])) {
4882 if (test_bit(IEEE80211_LINK_STATE_PENDING
,
4883 &local
->state
[queue
]))
4884 tasklet_schedule(&local
->tx_pending_tasklet
);
4886 if (!ieee80211_qdisc_installed(local
->mdev
)) {
4888 netif_wake_queue(local
->mdev
);
4890 __netif_schedule(local
->mdev
);
4893 EXPORT_SYMBOL(ieee80211_wake_queue
);
4895 void ieee80211_stop_queue(struct ieee80211_hw
*hw
, int queue
)
4897 struct ieee80211_local
*local
= hw_to_local(hw
);
4899 if (!ieee80211_qdisc_installed(local
->mdev
) && queue
== 0)
4900 netif_stop_queue(local
->mdev
);
4901 set_bit(IEEE80211_LINK_STATE_XOFF
, &local
->state
[queue
]);
4903 EXPORT_SYMBOL(ieee80211_stop_queue
);
4905 void ieee80211_start_queues(struct ieee80211_hw
*hw
)
4907 struct ieee80211_local
*local
= hw_to_local(hw
);
4910 for (i
= 0; i
< local
->hw
.queues
; i
++)
4911 clear_bit(IEEE80211_LINK_STATE_XOFF
, &local
->state
[i
]);
4912 if (!ieee80211_qdisc_installed(local
->mdev
))
4913 netif_start_queue(local
->mdev
);
4915 EXPORT_SYMBOL(ieee80211_start_queues
);
4917 void ieee80211_stop_queues(struct ieee80211_hw
*hw
)
4921 for (i
= 0; i
< hw
->queues
; i
++)
4922 ieee80211_stop_queue(hw
, i
);
4924 EXPORT_SYMBOL(ieee80211_stop_queues
);
4926 void ieee80211_wake_queues(struct ieee80211_hw
*hw
)
4930 for (i
= 0; i
< hw
->queues
; i
++)
4931 ieee80211_wake_queue(hw
, i
);
4933 EXPORT_SYMBOL(ieee80211_wake_queues
);
4935 struct net_device_stats
*ieee80211_dev_stats(struct net_device
*dev
)
4937 struct ieee80211_sub_if_data
*sdata
;
4938 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4939 return &sdata
->stats
;
4942 static int __init
ieee80211_init(void)
4944 struct sk_buff
*skb
;
4947 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data
) > sizeof(skb
->cb
));
4949 ret
= ieee80211_wme_register();
4951 printk(KERN_DEBUG
"ieee80211_init: failed to "
4952 "initialize WME (err=%d)\n", ret
);
4960 static void __exit
ieee80211_exit(void)
4962 ieee80211_wme_unregister();
4966 module_init(ieee80211_init
);
4967 module_exit(ieee80211_exit
);
4969 MODULE_DESCRIPTION("IEEE 802.11 subsystem");
4970 MODULE_LICENSE("GPL");