2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
10 #include <net/d80211.h>
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/netdevice.h>
14 #include <linux/types.h>
15 #include <linux/slab.h>
16 #include <linux/skbuff.h>
17 #include <linux/etherdevice.h>
18 #include <linux/if_arp.h>
19 #include <linux/wireless.h>
20 #include <linux/rtnetlink.h>
21 #include <net/iw_handler.h>
22 #include <linux/compiler.h>
23 #include <linux/bitmap.h>
25 #include <net/d80211_common.h>
26 #include <net/d80211_mgmt.h>
27 #include "ieee80211_i.h"
28 #include "ieee80211_rate.h"
34 #include "ieee80211_led.h"
36 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
37 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
38 static unsigned char rfc1042_header
[] =
39 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
40 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
41 static unsigned char bridge_tunnel_header
[] =
42 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
43 /* No encapsulation header if EtherType < 0x600 (=length) */
45 static unsigned char eapol_header
[] =
46 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x88, 0x8e };
49 static u8
* ieee80211_get_bssid(struct ieee80211_hdr
*hdr
, size_t len
);
51 static int ieee80211_mgmt_start_xmit(struct sk_buff
*skb
,
52 struct net_device
*dev
);
54 struct ieee80211_key_conf
*
55 ieee80211_key_data2conf(struct ieee80211_local
*local
,
56 struct ieee80211_key
*data
)
58 struct ieee80211_key_conf
*conf
;
60 conf
= kmalloc(sizeof(*conf
) + data
->keylen
, GFP_ATOMIC
);
64 conf
->hw_key_idx
= data
->hw_key_idx
;
65 conf
->alg
= data
->alg
;
66 conf
->keylen
= data
->keylen
;
68 if (data
->force_sw_encrypt
)
69 conf
->flags
|= IEEE80211_KEY_FORCE_SW_ENCRYPT
;
70 conf
->keyidx
= data
->keyidx
;
71 if (data
->default_tx_key
)
72 conf
->flags
|= IEEE80211_KEY_DEFAULT_TX_KEY
;
73 if (local
->default_wep_only
)
74 conf
->flags
|= IEEE80211_KEY_DEFAULT_WEP_ONLY
;
75 memcpy(conf
->key
, data
->key
, data
->keylen
);
80 struct ieee80211_key
*ieee80211_key_alloc(struct ieee80211_sub_if_data
*sdata
,
81 int idx
, size_t key_len
, gfp_t flags
)
83 struct ieee80211_key
*key
;
86 key
= kzalloc(sizeof(struct ieee80211_key
) + key_len
, flags
);
90 res
= kobject_set_name(&key
->kobj
, "%d", idx
);
92 res
= kobject_set_name(&key
->kobj
, "key");
97 ieee80211_key_sysfs_set_kset(key
, sdata
? &sdata
->key_kset
: NULL
);
98 kobject_init(&key
->kobj
);
102 void ieee80211_key_free(struct ieee80211_key
*key
)
105 kobject_put(&key
->kobj
);
108 void ieee80211_key_release(struct kobject
*kobj
)
110 struct ieee80211_key
*key
;
112 key
= container_of(kobj
, struct ieee80211_key
, kobj
);
113 if (key
->alg
== ALG_CCMP
)
114 ieee80211_aes_key_free(key
->u
.ccmp
.tfm
);
118 static int rate_list_match(int *rate_list
, int rate
)
125 for (i
= 0; rate_list
[i
] >= 0; i
++)
126 if (rate_list
[i
] == rate
)
133 void ieee80211_prepare_rates(struct ieee80211_local
*local
)
137 for (i
= 0; i
< local
->num_curr_rates
; i
++) {
138 struct ieee80211_rate
*rate
= &local
->curr_rates
[i
];
140 rate
->flags
&= ~(IEEE80211_RATE_SUPPORTED
|
141 IEEE80211_RATE_BASIC
);
143 if (local
->supp_rates
[local
->hw
.conf
.phymode
]) {
144 if (!rate_list_match(local
->supp_rates
145 [local
->hw
.conf
.phymode
],
150 rate
->flags
|= IEEE80211_RATE_SUPPORTED
;
152 /* Use configured basic rate set if it is available. If not,
153 * use defaults that are sane for most cases. */
154 if (local
->basic_rates
[local
->hw
.conf
.phymode
]) {
155 if (rate_list_match(local
->basic_rates
156 [local
->hw
.conf
.phymode
],
158 rate
->flags
|= IEEE80211_RATE_BASIC
;
159 } else switch (local
->hw
.conf
.phymode
) {
160 case MODE_IEEE80211A
:
161 if (rate
->rate
== 60 || rate
->rate
== 120 ||
163 rate
->flags
|= IEEE80211_RATE_BASIC
;
165 case MODE_IEEE80211B
:
166 if (rate
->rate
== 10 || rate
->rate
== 20)
167 rate
->flags
|= IEEE80211_RATE_BASIC
;
169 case MODE_ATHEROS_TURBO
:
170 if (rate
->rate
== 120 || rate
->rate
== 240 ||
172 rate
->flags
|= IEEE80211_RATE_BASIC
;
174 case MODE_IEEE80211G
:
175 if (rate
->rate
== 10 || rate
->rate
== 20 ||
176 rate
->rate
== 55 || rate
->rate
== 110)
177 rate
->flags
|= IEEE80211_RATE_BASIC
;
181 /* Set ERP and MANDATORY flags based on phymode */
182 switch (local
->hw
.conf
.phymode
) {
183 case MODE_IEEE80211A
:
184 if (rate
->rate
== 60 || rate
->rate
== 120 ||
186 rate
->flags
|= IEEE80211_RATE_MANDATORY
;
188 case MODE_IEEE80211B
:
189 if (rate
->rate
== 10)
190 rate
->flags
|= IEEE80211_RATE_MANDATORY
;
192 case MODE_ATHEROS_TURBO
:
194 case MODE_IEEE80211G
:
195 if (rate
->rate
== 10 || rate
->rate
== 20 ||
196 rate
->rate
== 55 || rate
->rate
== 110 ||
197 rate
->rate
== 60 || rate
->rate
== 120 ||
199 rate
->flags
|= IEEE80211_RATE_MANDATORY
;
200 if (rate
->rate
!= 10 && rate
->rate
!= 20 &&
201 rate
->rate
!= 55 && rate
->rate
!= 110)
202 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
= 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 int ieee80211_get_hdrlen(u16 fc
)
249 switch (fc
& IEEE80211_FCTL_FTYPE
) {
250 case IEEE80211_FTYPE_DATA
:
251 if ((fc
& IEEE80211_FCTL_FROMDS
) && (fc
& IEEE80211_FCTL_TODS
))
252 hdrlen
= 30; /* Addr4 */
253 if (fc
& IEEE80211_STYPE_QOS_DATA
)
254 hdrlen
+= 2; /* QoS Control Field */
256 case IEEE80211_FTYPE_CTL
:
257 switch (fc
& IEEE80211_FCTL_STYPE
) {
258 case IEEE80211_STYPE_CTS
:
259 case IEEE80211_STYPE_ACK
:
271 EXPORT_SYMBOL(ieee80211_get_hdrlen
);
273 int ieee80211_get_hdrlen_from_skb(struct sk_buff
*skb
)
275 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
278 if (unlikely(skb
->len
< 10))
280 hdrlen
= ieee80211_get_hdrlen(le16_to_cpu(hdr
->frame_control
));
281 if (unlikely(hdrlen
> skb
->len
))
285 EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb
);
287 #ifdef CONFIG_D80211_LOWTX_FRAME_DUMP
288 static void ieee80211_dump_frame(const char *ifname
, const char *title
,
291 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
295 printk(KERN_DEBUG
"%s: %s (len=%d)", ifname
, title
, skb
->len
);
301 fc
= le16_to_cpu(hdr
->frame_control
);
302 hdrlen
= ieee80211_get_hdrlen(fc
);
303 if (hdrlen
> skb
->len
)
306 printk(" FC=0x%04x DUR=0x%04x",
307 fc
, le16_to_cpu(hdr
->duration_id
));
309 printk(" A1=" MAC_FMT
, MAC_ARG(hdr
->addr1
));
311 printk(" A2=" MAC_FMT
, MAC_ARG(hdr
->addr2
));
313 printk(" A3=" MAC_FMT
, MAC_ARG(hdr
->addr3
));
315 printk(" A4=" MAC_FMT
, MAC_ARG(hdr
->addr4
));
318 #else /* CONFIG_D80211_LOWTX_FRAME_DUMP */
319 static inline void ieee80211_dump_frame(const char *ifname
, const char *title
,
323 #endif /* CONFIG_D80211_LOWTX_FRAME_DUMP */
326 static int ieee80211_is_eapol(struct sk_buff
*skb
)
328 struct ieee80211_hdr
*hdr
;
332 if (unlikely(skb
->len
< 10))
335 hdr
= (struct ieee80211_hdr
*) skb
->data
;
336 fc
= le16_to_cpu(hdr
->frame_control
);
338 if (unlikely(!WLAN_FC_DATA_PRESENT(fc
)))
341 hdrlen
= ieee80211_get_hdrlen(fc
);
343 if (unlikely(skb
->len
>= hdrlen
+ sizeof(eapol_header
) &&
344 memcmp(skb
->data
+ hdrlen
, eapol_header
,
345 sizeof(eapol_header
)) == 0))
352 static ieee80211_txrx_result
353 ieee80211_tx_h_rate_ctrl(struct ieee80211_txrx_data
*tx
)
355 struct rate_control_extra extra
;
357 memset(&extra
, 0, sizeof(extra
));
358 extra
.mgmt_data
= tx
->sdata
&&
359 tx
->sdata
->type
== IEEE80211_IF_TYPE_MGMT
;
360 extra
.ethertype
= tx
->ethertype
;
362 extra
.endidx
= tx
->local
->num_curr_rates
;
364 tx
->u
.tx
.rate
= rate_control_get_rate(tx
->local
, tx
->dev
, tx
->skb
,
366 if (unlikely(extra
.probe
!= NULL
)) {
367 tx
->u
.tx
.control
->flags
|= IEEE80211_TXCTL_RATE_CTRL_PROBE
;
368 tx
->u
.tx
.probe_last_frag
= 1;
369 tx
->u
.tx
.control
->alt_retry_rate
= tx
->u
.tx
.rate
->val
;
370 tx
->u
.tx
.rate
= extra
.probe
;
372 tx
->u
.tx
.control
->alt_retry_rate
= -1;
376 if (tx
->local
->hw
.conf
.phymode
== MODE_IEEE80211G
&&
377 tx
->local
->cts_protect_erp_frames
&& tx
->fragmented
&&
379 tx
->u
.tx
.last_frag_rate
= tx
->u
.tx
.rate
;
380 tx
->u
.tx
.last_frag_rateidx
= extra
.rateidx
;
381 tx
->u
.tx
.probe_last_frag
= extra
.probe
? 1 : 0;
383 tx
->u
.tx
.rate
= extra
.nonerp
;
384 tx
->u
.tx
.control
->rateidx
= extra
.nonerp_idx
;
385 tx
->u
.tx
.control
->flags
&= ~IEEE80211_TXCTL_RATE_CTRL_PROBE
;
387 tx
->u
.tx
.last_frag_rate
= tx
->u
.tx
.rate
;
388 tx
->u
.tx
.last_frag_rateidx
= extra
.rateidx
;
389 tx
->u
.tx
.control
->rateidx
= extra
.rateidx
;
391 tx
->u
.tx
.control
->tx_rate
= tx
->u
.tx
.rate
->val
;
392 if ((tx
->u
.tx
.rate
->flags
& IEEE80211_RATE_PREAMBLE2
) &&
393 tx
->local
->short_preamble
&&
394 (!tx
->sta
|| (tx
->sta
->flags
& WLAN_STA_SHORT_PREAMBLE
))) {
395 tx
->u
.tx
.short_preamble
= 1;
396 tx
->u
.tx
.control
->tx_rate
= tx
->u
.tx
.rate
->val2
;
399 return TXRX_CONTINUE
;
403 static ieee80211_txrx_result
404 ieee80211_tx_h_select_key(struct ieee80211_txrx_data
*tx
)
407 tx
->u
.tx
.control
->key_idx
= tx
->sta
->key_idx_compression
;
409 tx
->u
.tx
.control
->key_idx
= HW_KEY_IDX_INVALID
;
411 if (unlikely(tx
->u
.tx
.control
->flags
& IEEE80211_TXCTL_DO_NOT_ENCRYPT
))
413 else if (tx
->sta
&& tx
->sta
->key
)
414 tx
->key
= tx
->sta
->key
;
415 else if (tx
->sdata
->default_key
)
416 tx
->key
= tx
->sdata
->default_key
;
417 else if (tx
->sdata
->drop_unencrypted
&&
418 !(tx
->sdata
->eapol
&& ieee80211_is_eapol(tx
->skb
))) {
419 I802_DEBUG_INC(tx
->local
->tx_handlers_drop_unencrypted
);
425 tx
->key
->tx_rx_count
++;
426 if (unlikely(tx
->local
->key_tx_rx_threshold
&&
427 tx
->key
->tx_rx_count
>
428 tx
->local
->key_tx_rx_threshold
)) {
429 ieee80211_key_threshold_notify(tx
->dev
, tx
->key
,
434 return TXRX_CONTINUE
;
438 static ieee80211_txrx_result
439 ieee80211_tx_h_fragment(struct ieee80211_txrx_data
*tx
)
441 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) tx
->skb
->data
;
442 size_t hdrlen
, per_fragm
, num_fragm
, payload_len
, left
;
443 struct sk_buff
**frags
, *first
, *frag
;
446 int frag_threshold
= tx
->local
->fragmentation_threshold
;
449 return TXRX_CONTINUE
;
453 hdrlen
= ieee80211_get_hdrlen(tx
->fc
);
454 payload_len
= first
->len
- hdrlen
;
455 per_fragm
= frag_threshold
- hdrlen
- FCS_LEN
;
456 num_fragm
= (payload_len
+ per_fragm
- 1) / per_fragm
;
458 frags
= kzalloc(num_fragm
* sizeof(struct sk_buff
*), GFP_ATOMIC
);
462 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_MOREFRAGS
);
463 pos
= first
->data
+ hdrlen
+ per_fragm
;
464 left
= payload_len
- per_fragm
;
465 for (i
= 0; i
< num_fragm
- 1; i
++) {
466 struct ieee80211_hdr
*fhdr
;
472 /* reserve enough extra head and tail room for possible
474 #define IEEE80211_ENCRYPT_HEADROOM 8
475 #define IEEE80211_ENCRYPT_TAILROOM 12
477 dev_alloc_skb(frag_threshold
+
478 IEEE80211_ENCRYPT_HEADROOM
+
479 IEEE80211_ENCRYPT_TAILROOM
);
482 /* Make sure that all fragments use the same priority so
483 * that they end up using the same TX queue */
484 frag
->priority
= first
->priority
;
485 skb_reserve(frag
, IEEE80211_ENCRYPT_HEADROOM
);
486 fhdr
= (struct ieee80211_hdr
*) skb_put(frag
, hdrlen
);
487 memcpy(fhdr
, first
->data
, hdrlen
);
488 if (i
== num_fragm
- 2)
489 fhdr
->frame_control
&= cpu_to_le16(~IEEE80211_FCTL_MOREFRAGS
);
490 fhdr
->seq_ctrl
= cpu_to_le16(i
+ 1);
491 copylen
= left
> per_fragm
? per_fragm
: left
;
492 memcpy(skb_put(frag
, copylen
), pos
, copylen
);
497 skb_trim(first
, hdrlen
+ per_fragm
);
499 tx
->u
.tx
.num_extra_frag
= num_fragm
- 1;
500 tx
->u
.tx
.extra_frag
= frags
;
502 return TXRX_CONTINUE
;
505 printk(KERN_DEBUG
"%s: failed to fragment frame\n", tx
->dev
->name
);
507 for (i
= 0; i
< num_fragm
- 1; i
++)
509 dev_kfree_skb(frags
[i
]);
512 I802_DEBUG_INC(tx
->local
->tx_handlers_drop_fragment
);
517 static int wep_encrypt_skb(struct ieee80211_txrx_data
*tx
, struct sk_buff
*skb
)
519 if (tx
->key
->force_sw_encrypt
) {
520 if (ieee80211_wep_encrypt(tx
->local
, skb
, tx
->key
))
523 tx
->u
.tx
.control
->key_idx
= tx
->key
->hw_key_idx
;
524 if (tx
->local
->hw
.flags
& IEEE80211_HW_WEP_INCLUDE_IV
) {
525 if (ieee80211_wep_add_iv(tx
->local
, skb
, tx
->key
) ==
534 void ieee80211_tx_set_iswep(struct ieee80211_txrx_data
*tx
)
536 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) tx
->skb
->data
;
538 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
539 if (tx
->u
.tx
.extra_frag
) {
540 struct ieee80211_hdr
*fhdr
;
542 for (i
= 0; i
< tx
->u
.tx
.num_extra_frag
; i
++) {
543 fhdr
= (struct ieee80211_hdr
*)
544 tx
->u
.tx
.extra_frag
[i
]->data
;
545 fhdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
551 static ieee80211_txrx_result
552 ieee80211_tx_h_wep_encrypt(struct ieee80211_txrx_data
*tx
)
554 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) tx
->skb
->data
;
557 fc
= le16_to_cpu(hdr
->frame_control
);
559 if (!tx
->key
|| tx
->key
->alg
!= ALG_WEP
||
560 ((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
&&
561 ((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_MGMT
||
562 (fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_AUTH
)))
563 return TXRX_CONTINUE
;
565 tx
->u
.tx
.control
->iv_len
= WEP_IV_LEN
;
566 tx
->u
.tx
.control
->icv_len
= WEP_ICV_LEN
;
567 ieee80211_tx_set_iswep(tx
);
569 if (wep_encrypt_skb(tx
, tx
->skb
) < 0) {
570 I802_DEBUG_INC(tx
->local
->tx_handlers_drop_wep
);
574 if (tx
->u
.tx
.extra_frag
) {
576 for (i
= 0; i
< tx
->u
.tx
.num_extra_frag
; i
++) {
577 if (wep_encrypt_skb(tx
, tx
->u
.tx
.extra_frag
[i
]) < 0) {
578 I802_DEBUG_INC(tx
->local
->
579 tx_handlers_drop_wep
);
585 return TXRX_CONTINUE
;
589 static inline int ceiling_div(int dividend
, int divisor
)
591 return ((dividend
+ divisor
- 1) / divisor
);
595 static int ieee80211_frame_duration(struct ieee80211_local
*local
, size_t len
,
596 int rate
, int erp
, int short_preamble
)
600 /* calculate duration (in microseconds, rounded up to next higher
601 * integer if it includes a fractional microsecond) to send frame of
602 * len bytes (does not include FCS) at the given rate. Duration will
605 * rate is in 100 kbps, so divident is multiplied by 10 in the
606 * ceiling_div() operations.
609 if (local
->hw
.conf
.phymode
== MODE_IEEE80211A
|| erp
||
610 local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBO
) {
614 * N_DBPS = DATARATE x 4
615 * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
616 * (16 = SIGNAL time, 6 = tail bits)
617 * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
620 * 802.11a - 17.5.2: aSIFSTime = 16 usec
621 * 802.11g - 19.8.4: aSIFSTime = 10 usec +
622 * signal ext = 6 usec
624 /* FIX: Atheros Turbo may have different (shorter) duration? */
625 dur
= 16; /* SIFS + signal ext */
626 dur
+= 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */
627 dur
+= 4; /* 17.3.2.3: T_SIGNAL = 4 usec */
628 dur
+= 4 * ceiling_div((16 + 8 * (len
+ 4) + 6) * 10,
629 4 * rate
); /* T_SYM x N_SYM */
632 * 802.11b or 802.11g with 802.11b compatibility:
633 * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
634 * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
636 * 802.11 (DS): 15.3.3, 802.11b: 18.3.4
637 * aSIFSTime = 10 usec
638 * aPreambleLength = 144 usec or 72 usec with short preamble
639 * aPLCPHeaderLength = 48 usec or 24 usec with short preamble
641 dur
= 10; /* aSIFSTime = 10 usec */
642 dur
+= short_preamble
? (72 + 24) : (144 + 48);
644 dur
+= ceiling_div(8 * (len
+ 4) * 10, rate
);
651 static u16
ieee80211_duration(struct ieee80211_txrx_data
*tx
, int group_addr
,
654 int rate
, mrate
, erp
, dur
, i
;
655 struct ieee80211_rate
*txrate
= tx
->u
.tx
.rate
;
656 struct ieee80211_local
*local
= tx
->local
;
658 erp
= txrate
->flags
& IEEE80211_RATE_ERP
;
661 * data and mgmt (except PS Poll):
662 * - during CFP: 32768
663 * - during contention period:
664 * if addr1 is group address: 0
665 * if more fragments = 0 and addr1 is individual address: time to
666 * transmit one ACK plus SIFS
667 * if more fragments = 1 and addr1 is individual address: time to
668 * transmit next fragment plus 2 x ACK plus 3 x SIFS
671 * - control response frame (CTS or ACK) shall be transmitted using the
672 * same rate as the immediately previous frame in the frame exchange
673 * sequence, if this rate belongs to the PHY mandatory rates, or else
674 * at the highest possible rate belonging to the PHY rates in the
678 if ((tx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_CTL
) {
679 /* TODO: These control frames are not currently sent by
680 * 80211.o, but should they be implemented, this function
681 * needs to be updated to support duration field calculation.
683 * RTS: time needed to transmit pending data/mgmt frame plus
684 * one CTS frame plus one ACK frame plus 3 x SIFS
685 * CTS: duration of immediately previous RTS minus time
686 * required to transmit CTS and its SIFS
687 * ACK: 0 if immediately previous directed data/mgmt had
688 * more=0, with more=1 duration in ACK frame is duration
689 * from previous frame minus time needed to transmit ACK
691 * PS Poll: BIT(15) | BIT(14) | aid
697 if (0 /* FIX: data/mgmt during CFP */)
700 if (group_addr
) /* Group address as the destination - no ACK */
703 /* Individual destination address:
704 * IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes)
705 * CTS and ACK frames shall be transmitted using the highest rate in
706 * basic rate set that is less than or equal to the rate of the
707 * immediately previous frame and that is using the same modulation
708 * (CCK or OFDM). If no basic rate set matches with these requirements,
709 * the highest mandatory rate of the PHY that is less than or equal to
710 * the rate of the previous frame is used.
711 * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps
714 mrate
= 10; /* use 1 Mbps if everything fails */
715 for (i
= 0; i
< local
->num_curr_rates
; i
++) {
716 struct ieee80211_rate
*r
= &local
->curr_rates
[i
];
717 if (r
->rate
> txrate
->rate
)
720 if (IEEE80211_RATE_MODULATION(txrate
->flags
) !=
721 IEEE80211_RATE_MODULATION(r
->flags
))
724 if (r
->flags
& IEEE80211_RATE_BASIC
)
726 else if (r
->flags
& IEEE80211_RATE_MANDATORY
)
730 /* No matching basic rate found; use highest suitable mandatory
735 /* Time needed to transmit ACK
736 * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
737 * to closest integer */
739 dur
= ieee80211_frame_duration(local
, 10, rate
, erp
,
740 local
->short_preamble
);
743 /* Frame is fragmented: duration increases with time needed to
744 * transmit next fragment plus ACK and 2 x SIFS. */
745 dur
*= 2; /* ACK + SIFS */
747 dur
+= ieee80211_frame_duration(local
, next_frag_len
,
749 local
->short_preamble
);
756 static ieee80211_txrx_result
757 ieee80211_tx_h_misc(struct ieee80211_txrx_data
*tx
)
759 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) tx
->skb
->data
;
761 struct ieee80211_tx_control
*control
= tx
->u
.tx
.control
;
763 if (!is_multicast_ether_addr(hdr
->addr1
)) {
764 if (tx
->skb
->len
+ FCS_LEN
> tx
->local
->rts_threshold
&&
765 tx
->local
->rts_threshold
< IEEE80211_MAX_RTS_THRESHOLD
) {
766 control
->flags
|= IEEE80211_TXCTL_USE_RTS_CTS
;
767 control
->retry_limit
=
768 tx
->local
->long_retry_limit
;
770 control
->retry_limit
=
771 tx
->local
->short_retry_limit
;
774 control
->retry_limit
= 1;
777 if (tx
->fragmented
) {
778 /* Do not use multiple retry rates when sending fragmented
780 * TODO: The last fragment could still use multiple retry
782 control
->alt_retry_rate
= -1;
785 /* Use CTS protection for unicast frames sent using extended rates if
786 * there are associated non-ERP stations and RTS/CTS is not configured
788 if (tx
->local
->hw
.conf
.phymode
== MODE_IEEE80211G
&&
789 (tx
->u
.tx
.rate
->flags
& IEEE80211_RATE_ERP
) &&
791 tx
->local
->cts_protect_erp_frames
&&
792 !(control
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
))
793 control
->flags
|= IEEE80211_TXCTL_USE_CTS_PROTECT
;
795 /* Setup duration field for the first fragment of the frame. Duration
796 * for remaining fragments will be updated when they are being sent
797 * to low-level driver in ieee80211_tx(). */
798 dur
= ieee80211_duration(tx
, is_multicast_ether_addr(hdr
->addr1
),
799 tx
->fragmented
? tx
->u
.tx
.extra_frag
[0]->len
:
801 hdr
->duration_id
= cpu_to_le16(dur
);
803 if ((control
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
) ||
804 (control
->flags
& IEEE80211_TXCTL_USE_CTS_PROTECT
)) {
805 struct ieee80211_rate
*rate
;
806 int erp
= tx
->u
.tx
.rate
->flags
& IEEE80211_RATE_ERP
;
808 /* Do not use multiple retry rates when using RTS/CTS */
809 control
->alt_retry_rate
= -1;
811 /* Use min(data rate, max base rate) as CTS/RTS rate */
812 rate
= tx
->u
.tx
.rate
;
813 while (rate
> tx
->local
->curr_rates
&&
814 !(rate
->flags
& IEEE80211_RATE_BASIC
))
817 if (control
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
)
818 dur
+= ieee80211_frame_duration(tx
->local
, 10,
822 dur
+= ieee80211_frame_duration(tx
->local
, tx
->skb
->len
,
823 tx
->u
.tx
.rate
->rate
, erp
,
824 tx
->u
.tx
.short_preamble
);
825 control
->rts_cts_duration
= dur
;
826 control
->rts_cts_rate
= rate
->val
;
830 tx
->sta
->tx_packets
++;
831 tx
->sta
->tx_fragments
++;
832 tx
->sta
->tx_bytes
+= tx
->skb
->len
;
833 if (tx
->u
.tx
.extra_frag
) {
835 tx
->sta
->tx_fragments
+= tx
->u
.tx
.num_extra_frag
;
836 for (i
= 0; i
< tx
->u
.tx
.num_extra_frag
; i
++) {
838 tx
->u
.tx
.extra_frag
[i
]->len
;
842 tx
->local
->scan
.txrx_count
++;
844 return TXRX_CONTINUE
;
848 static ieee80211_txrx_result
849 ieee80211_tx_h_check_assoc(struct ieee80211_txrx_data
*tx
)
851 #ifdef CONFIG_D80211_VERBOSE_DEBUG
852 struct sk_buff
*skb
= tx
->skb
;
853 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
854 #endif /* CONFIG_D80211_VERBOSE_DEBUG */
857 if (unlikely(tx
->local
->sta_scanning
!= 0) &&
858 ((tx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_MGMT
||
859 (tx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_PROBE_REQ
))
862 if (tx
->u
.tx
.ps_buffered
)
863 return TXRX_CONTINUE
;
865 sta_flags
= tx
->sta
? tx
->sta
->flags
: 0;
867 if (likely(tx
->u
.tx
.unicast
)) {
868 if (unlikely(!(sta_flags
& WLAN_STA_ASSOC
) &&
869 tx
->sdata
->type
!= IEEE80211_IF_TYPE_IBSS
&&
870 (tx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
)) {
871 #ifdef CONFIG_D80211_VERBOSE_DEBUG
872 printk(KERN_DEBUG
"%s: dropped data frame to not "
873 "associated station " MAC_FMT
"\n",
874 tx
->dev
->name
, MAC_ARG(hdr
->addr1
));
875 #endif /* CONFIG_D80211_VERBOSE_DEBUG */
876 I802_DEBUG_INC(tx
->local
->tx_handlers_drop_not_assoc
);
880 if (unlikely((tx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
&&
881 tx
->local
->num_sta
== 0 &&
882 !tx
->local
->allow_broadcast_always
&&
883 tx
->sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)) {
885 * No associated STAs - no need to send multicast
890 return TXRX_CONTINUE
;
893 if (unlikely(!tx
->u
.tx
.mgmt_interface
&& tx
->sdata
->ieee802_1x
&&
894 !(sta_flags
& WLAN_STA_AUTHORIZED
))) {
895 #ifdef CONFIG_D80211_DEBUG
896 struct ieee80211_hdr
*hdr
=
897 (struct ieee80211_hdr
*) tx
->skb
->data
;
898 printk(KERN_DEBUG
"%s: dropped frame to " MAC_FMT
899 " (unauthorized port)\n", tx
->dev
->name
,
900 MAC_ARG(hdr
->addr1
));
902 I802_DEBUG_INC(tx
->local
->tx_handlers_drop_unauth_port
);
906 return TXRX_CONTINUE
;
910 /* This function is called whenever the AP is about to exceed the maximum limit
911 * of buffered frames for power saving STAs. This situation should not really
912 * happen often during normal operation, so dropping the oldest buffered packet
913 * from each queue should be OK to make some room for new frames. */
914 static void purge_old_ps_buffers(struct ieee80211_local
*local
)
916 int total
= 0, purged
= 0;
918 struct ieee80211_sub_if_data
*sdata
;
919 struct sta_info
*sta
;
921 spin_lock_bh(&local
->sub_if_lock
);
922 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
923 struct ieee80211_if_ap
*ap
;
924 if (sdata
->dev
== local
->mdev
||
925 sdata
->type
!= IEEE80211_IF_TYPE_AP
)
928 skb
= skb_dequeue(&ap
->ps_bc_buf
);
933 total
+= skb_queue_len(&ap
->ps_bc_buf
);
935 spin_unlock_bh(&local
->sub_if_lock
);
937 spin_lock_bh(&local
->sta_lock
);
938 list_for_each_entry(sta
, &local
->sta_list
, list
) {
939 skb
= skb_dequeue(&sta
->ps_tx_buf
);
944 total
+= skb_queue_len(&sta
->ps_tx_buf
);
946 spin_unlock_bh(&local
->sta_lock
);
948 local
->total_ps_buffered
= total
;
949 printk(KERN_DEBUG
"%s: PS buffers full - purged %d frames\n",
950 local
->mdev
->name
, purged
);
954 static inline ieee80211_txrx_result
955 ieee80211_tx_h_multicast_ps_buf(struct ieee80211_txrx_data
*tx
)
957 /* broadcast/multicast frame */
958 /* If any of the associated stations is in power save mode,
959 * the frame is buffered to be sent after DTIM beacon frame */
960 if ((tx
->local
->hw
.flags
& IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING
) &&
961 tx
->sdata
->type
!= IEEE80211_IF_TYPE_WDS
&&
962 tx
->sdata
->bss
&& atomic_read(&tx
->sdata
->bss
->num_sta_ps
) &&
963 !(tx
->fc
& IEEE80211_FCTL_ORDER
)) {
964 if (tx
->local
->total_ps_buffered
>= TOTAL_MAX_TX_BUFFER
)
965 purge_old_ps_buffers(tx
->local
);
966 if (skb_queue_len(&tx
->sdata
->bss
->ps_bc_buf
) >=
968 if (net_ratelimit()) {
969 printk(KERN_DEBUG
"%s: BC TX buffer full - "
970 "dropping the oldest frame\n",
973 dev_kfree_skb(skb_dequeue(&tx
->sdata
->bss
->ps_bc_buf
));
975 tx
->local
->total_ps_buffered
++;
976 skb_queue_tail(&tx
->sdata
->bss
->ps_bc_buf
, tx
->skb
);
980 return TXRX_CONTINUE
;
984 static inline ieee80211_txrx_result
985 ieee80211_tx_h_unicast_ps_buf(struct ieee80211_txrx_data
*tx
)
987 struct sta_info
*sta
= tx
->sta
;
990 ((tx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
&&
991 (tx
->fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_PROBE_RESP
)))
992 return TXRX_CONTINUE
;
994 if (unlikely((sta
->flags
& WLAN_STA_PS
) && !sta
->pspoll
)) {
995 struct ieee80211_tx_packet_data
*pkt_data
;
996 #ifdef CONFIG_D80211_VERBOSE_PS_DEBUG
997 printk(KERN_DEBUG
"STA " MAC_FMT
" aid %d: PS buffer (entries "
999 MAC_ARG(sta
->addr
), sta
->aid
,
1000 skb_queue_len(&sta
->ps_tx_buf
));
1001 #endif /* CONFIG_D80211_VERBOSE_PS_DEBUG */
1002 sta
->flags
|= WLAN_STA_TIM
;
1003 if (tx
->local
->total_ps_buffered
>= TOTAL_MAX_TX_BUFFER
)
1004 purge_old_ps_buffers(tx
->local
);
1005 if (skb_queue_len(&sta
->ps_tx_buf
) >= STA_MAX_TX_BUFFER
) {
1006 struct sk_buff
*old
= skb_dequeue(&sta
->ps_tx_buf
);
1007 if (net_ratelimit()) {
1008 printk(KERN_DEBUG
"%s: STA " MAC_FMT
" TX "
1009 "buffer full - dropping oldest frame\n",
1010 tx
->dev
->name
, MAC_ARG(sta
->addr
));
1014 tx
->local
->total_ps_buffered
++;
1015 /* Queue frame to be sent after STA sends an PS Poll frame */
1016 if (skb_queue_empty(&sta
->ps_tx_buf
)) {
1017 if (tx
->local
->ops
->set_tim
)
1018 tx
->local
->ops
->set_tim(local_to_hw(tx
->local
),
1021 bss_tim_set(tx
->local
, tx
->sdata
->bss
, sta
->aid
);
1023 pkt_data
= (struct ieee80211_tx_packet_data
*)tx
->skb
->cb
;
1024 pkt_data
->jiffies
= jiffies
;
1025 skb_queue_tail(&sta
->ps_tx_buf
, tx
->skb
);
1028 #ifdef CONFIG_D80211_VERBOSE_PS_DEBUG
1029 else if (unlikely(sta
->flags
& WLAN_STA_PS
)) {
1030 printk(KERN_DEBUG
"%s: STA " MAC_FMT
" in PS mode, but pspoll "
1031 "set -> send frame\n", tx
->dev
->name
,
1032 MAC_ARG(sta
->addr
));
1034 #endif /* CONFIG_D80211_VERBOSE_PS_DEBUG */
1037 return TXRX_CONTINUE
;
1041 static ieee80211_txrx_result
1042 ieee80211_tx_h_ps_buf(struct ieee80211_txrx_data
*tx
)
1044 if (unlikely(tx
->u
.tx
.ps_buffered
))
1045 return TXRX_CONTINUE
;
1047 if (tx
->u
.tx
.unicast
)
1048 return ieee80211_tx_h_unicast_ps_buf(tx
);
1050 return ieee80211_tx_h_multicast_ps_buf(tx
);
1055 __ieee80211_tx_prepare(struct ieee80211_txrx_data
*tx
,
1056 struct sk_buff
*skb
,
1057 struct net_device
*dev
,
1058 struct ieee80211_tx_control
*control
)
1060 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1061 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1064 memset(tx
, 0, sizeof(*tx
));
1066 tx
->dev
= dev
; /* use original interface */
1068 tx
->sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1069 tx
->sta
= sta_info_get(local
, hdr
->addr1
);
1070 tx
->fc
= le16_to_cpu(hdr
->frame_control
);
1071 control
->power_level
= local
->hw
.conf
.power_level
;
1072 tx
->u
.tx
.control
= control
;
1073 tx
->u
.tx
.unicast
= !is_multicast_ether_addr(hdr
->addr1
);
1074 if (is_multicast_ether_addr(hdr
->addr1
))
1075 control
->flags
|= IEEE80211_TXCTL_NO_ACK
;
1077 control
->flags
&= ~IEEE80211_TXCTL_NO_ACK
;
1078 tx
->fragmented
= local
->fragmentation_threshold
<
1079 IEEE80211_MAX_FRAG_THRESHOLD
&& tx
->u
.tx
.unicast
&&
1080 skb
->len
+ FCS_LEN
> local
->fragmentation_threshold
&&
1081 (!local
->ops
->set_frag_threshold
);
1083 control
->flags
|= IEEE80211_TXCTL_CLEAR_DST_MASK
;
1084 else if (tx
->sta
->clear_dst_mask
) {
1085 control
->flags
|= IEEE80211_TXCTL_CLEAR_DST_MASK
;
1086 tx
->sta
->clear_dst_mask
= 0;
1088 control
->antenna_sel
= local
->hw
.conf
.antenna_sel
;
1089 if (local
->sta_antenna_sel
!= STA_ANTENNA_SEL_AUTO
&& tx
->sta
)
1090 control
->antenna_sel
= tx
->sta
->antenna_sel
;
1091 hdrlen
= ieee80211_get_hdrlen(tx
->fc
);
1092 if (skb
->len
> hdrlen
+ sizeof(rfc1042_header
) + 2) {
1093 u8
*pos
= &skb
->data
[hdrlen
+ sizeof(rfc1042_header
)];
1094 tx
->ethertype
= (pos
[0] << 8) | pos
[1];
1096 control
->flags
|= IEEE80211_TXCTL_FIRST_FRAGMENT
;
1100 static int inline is_ieee80211_device(struct net_device
*dev
,
1101 struct net_device
*master
)
1103 return (dev
->ieee80211_ptr
== master
->ieee80211_ptr
);
1106 /* Device in tx->dev has a reference added; use dev_put(tx->dev) when
1107 * finished with it. */
1108 static void inline ieee80211_tx_prepare(struct ieee80211_txrx_data
*tx
,
1109 struct sk_buff
*skb
,
1110 struct net_device
*mdev
,
1111 struct ieee80211_tx_control
*control
)
1113 struct ieee80211_tx_packet_data
*pkt_data
;
1114 struct net_device
*dev
;
1116 pkt_data
= (struct ieee80211_tx_packet_data
*)skb
->cb
;
1117 dev
= dev_get_by_index(pkt_data
->ifindex
);
1118 if (unlikely(dev
&& !is_ieee80211_device(dev
, mdev
))) {
1122 if (unlikely(!dev
)) {
1123 printk(KERN_WARNING
"%s: NULL ifindex in pkt_data\n",
1128 __ieee80211_tx_prepare(tx
, skb
, dev
, control
);
1131 static inline int __ieee80211_queue_stopped(struct ieee80211_local
*local
,
1134 return test_bit(IEEE80211_LINK_STATE_XOFF
, &local
->state
[queue
]);
1137 static inline int __ieee80211_queue_pending(struct ieee80211_local
*local
,
1140 return test_bit(IEEE80211_LINK_STATE_PENDING
, &local
->state
[queue
]);
1143 #define IEEE80211_TX_OK 0
1144 #define IEEE80211_TX_AGAIN 1
1145 #define IEEE80211_TX_FRAG_AGAIN 2
1147 static int __ieee80211_tx(struct ieee80211_local
*local
, struct sk_buff
*skb
,
1148 struct ieee80211_txrx_data
*tx
)
1150 struct ieee80211_tx_control
*control
= tx
->u
.tx
.control
;
1154 ieee80211_dump_frame(local
->mdev
->name
, "TX to low-level driver", skb
);
1155 ret
= local
->ops
->tx(local_to_hw(local
), skb
, control
);
1157 return IEEE80211_TX_AGAIN
;
1158 ieee80211_led_tx(local
, 1);
1160 if (tx
->u
.tx
.extra_frag
) {
1161 control
->flags
&= ~(IEEE80211_TXCTL_USE_RTS_CTS
|
1162 IEEE80211_TXCTL_USE_CTS_PROTECT
|
1163 IEEE80211_TXCTL_CLEAR_DST_MASK
|
1164 IEEE80211_TXCTL_FIRST_FRAGMENT
);
1165 for (i
= 0; i
< tx
->u
.tx
.num_extra_frag
; i
++) {
1166 if (!tx
->u
.tx
.extra_frag
[i
])
1168 if (__ieee80211_queue_stopped(local
, control
->queue
))
1169 return IEEE80211_TX_FRAG_AGAIN
;
1170 if (i
== tx
->u
.tx
.num_extra_frag
) {
1171 control
->tx_rate
= tx
->u
.tx
.last_frag_hwrate
;
1172 control
->rateidx
= tx
->u
.tx
.last_frag_rateidx
;
1173 if (tx
->u
.tx
.probe_last_frag
)
1175 IEEE80211_TXCTL_RATE_CTRL_PROBE
;
1178 ~IEEE80211_TXCTL_RATE_CTRL_PROBE
;
1181 ieee80211_dump_frame(local
->mdev
->name
,
1182 "TX to low-level driver", skb
);
1183 ret
= local
->ops
->tx(local_to_hw(local
),
1184 tx
->u
.tx
.extra_frag
[i
],
1187 return IEEE80211_TX_FRAG_AGAIN
;
1188 ieee80211_led_tx(local
, 1);
1189 tx
->u
.tx
.extra_frag
[i
] = NULL
;
1191 kfree(tx
->u
.tx
.extra_frag
);
1192 tx
->u
.tx
.extra_frag
= NULL
;
1194 return IEEE80211_TX_OK
;
1197 static int ieee80211_tx(struct net_device
*dev
, struct sk_buff
*skb
,
1198 struct ieee80211_tx_control
*control
, int mgmt
)
1200 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1201 struct sta_info
*sta
;
1202 ieee80211_tx_handler
*handler
;
1203 struct ieee80211_txrx_data tx
;
1204 ieee80211_txrx_result res
= TXRX_DROP
;
1207 WARN_ON(__ieee80211_queue_pending(local
, control
->queue
));
1209 if (unlikely(skb
->len
< 10)) {
1214 __ieee80211_tx_prepare(&tx
, skb
, dev
, control
);
1216 tx
.u
.tx
.mgmt_interface
= mgmt
;
1218 for (handler
= local
->tx_handlers
; *handler
!= NULL
; handler
++) {
1219 res
= (*handler
)(&tx
);
1220 if (res
!= TXRX_CONTINUE
)
1224 skb
= tx
.skb
; /* handlers are allowed to change skb */
1229 if (unlikely(res
== TXRX_DROP
)) {
1230 I802_DEBUG_INC(local
->tx_handlers_drop
);
1234 if (unlikely(res
== TXRX_QUEUED
)) {
1235 I802_DEBUG_INC(local
->tx_handlers_queued
);
1239 if (tx
.u
.tx
.extra_frag
) {
1240 for (i
= 0; i
< tx
.u
.tx
.num_extra_frag
; i
++) {
1242 struct ieee80211_hdr
*hdr
=
1243 (struct ieee80211_hdr
*)
1244 tx
.u
.tx
.extra_frag
[i
]->data
;
1246 if (i
+ 1 < tx
.u
.tx
.num_extra_frag
) {
1247 next_len
= tx
.u
.tx
.extra_frag
[i
+ 1]->len
;
1250 tx
.u
.tx
.rate
= tx
.u
.tx
.last_frag_rate
;
1251 tx
.u
.tx
.last_frag_hwrate
= tx
.u
.tx
.rate
->val
;
1253 dur
= ieee80211_duration(&tx
, 0, next_len
);
1254 hdr
->duration_id
= cpu_to_le16(dur
);
1259 ret
= __ieee80211_tx(local
, skb
, &tx
);
1261 struct ieee80211_tx_stored_packet
*store
=
1262 &local
->pending_packet
[control
->queue
];
1264 if (ret
== IEEE80211_TX_FRAG_AGAIN
)
1266 set_bit(IEEE80211_LINK_STATE_PENDING
,
1267 &local
->state
[control
->queue
]);
1269 /* When the driver gets out of buffers during sending of
1270 * fragments and calls ieee80211_stop_queue, there is
1271 * a small window between IEEE80211_LINK_STATE_XOFF and
1272 * IEEE80211_LINK_STATE_PENDING flags are set. If a buffer
1273 * gets available in that window (i.e. driver calls
1274 * ieee80211_wake_queue), we would end up with ieee80211_tx
1275 * called with IEEE80211_LINK_STATE_PENDING. Prevent this by
1276 * continuing transmitting here when that situation is
1277 * possible to have happened. */
1278 if (!__ieee80211_queue_stopped(local
, control
->queue
)) {
1279 clear_bit(IEEE80211_LINK_STATE_PENDING
,
1280 &local
->state
[control
->queue
]);
1283 memcpy(&store
->control
, control
,
1284 sizeof(struct ieee80211_tx_control
));
1286 store
->extra_frag
= tx
.u
.tx
.extra_frag
;
1287 store
->num_extra_frag
= tx
.u
.tx
.num_extra_frag
;
1288 store
->last_frag_hwrate
= tx
.u
.tx
.last_frag_hwrate
;
1289 store
->last_frag_rateidx
= tx
.u
.tx
.last_frag_rateidx
;
1290 store
->last_frag_rate_ctrl_probe
= tx
.u
.tx
.probe_last_frag
;
1297 for (i
= 0; i
< tx
.u
.tx
.num_extra_frag
; i
++)
1298 if (tx
.u
.tx
.extra_frag
[i
])
1299 dev_kfree_skb(tx
.u
.tx
.extra_frag
[i
]);
1300 kfree(tx
.u
.tx
.extra_frag
);
1304 static void ieee80211_tx_pending(unsigned long data
)
1306 struct ieee80211_local
*local
= (struct ieee80211_local
*)data
;
1307 struct net_device
*dev
= local
->mdev
;
1308 struct ieee80211_tx_stored_packet
*store
;
1309 struct ieee80211_txrx_data tx
;
1310 int i
, ret
, reschedule
= 0;
1312 netif_tx_lock_bh(dev
);
1313 for (i
= 0; i
< local
->hw
.queues
; i
++) {
1314 if (__ieee80211_queue_stopped(local
, i
))
1316 if (!__ieee80211_queue_pending(local
, i
)) {
1320 store
= &local
->pending_packet
[i
];
1321 tx
.u
.tx
.control
= &store
->control
;
1322 tx
.u
.tx
.extra_frag
= store
->extra_frag
;
1323 tx
.u
.tx
.num_extra_frag
= store
->num_extra_frag
;
1324 tx
.u
.tx
.last_frag_hwrate
= store
->last_frag_hwrate
;
1325 tx
.u
.tx
.last_frag_rateidx
= store
->last_frag_rateidx
;
1326 tx
.u
.tx
.probe_last_frag
= store
->last_frag_rate_ctrl_probe
;
1327 ret
= __ieee80211_tx(local
, store
->skb
, &tx
);
1329 if (ret
== IEEE80211_TX_FRAG_AGAIN
)
1332 clear_bit(IEEE80211_LINK_STATE_PENDING
,
1337 netif_tx_unlock_bh(dev
);
1339 netif_schedule(dev
);
1342 static void ieee80211_clear_tx_pending(struct ieee80211_local
*local
)
1345 struct ieee80211_tx_stored_packet
*store
;
1347 for (i
= 0; i
< local
->hw
.queues
; i
++) {
1348 if (!__ieee80211_queue_pending(local
, i
))
1350 store
= &local
->pending_packet
[i
];
1351 kfree_skb(store
->skb
);
1352 for (j
= 0; j
< store
->num_extra_frag
; j
++)
1353 kfree_skb(store
->extra_frag
[j
]);
1354 kfree(store
->extra_frag
);
1355 clear_bit(IEEE80211_LINK_STATE_PENDING
, &local
->state
[i
]);
1359 static int ieee80211_master_start_xmit(struct sk_buff
*skb
,
1360 struct net_device
*dev
)
1362 struct ieee80211_tx_control control
;
1363 struct ieee80211_tx_packet_data
*pkt_data
;
1364 struct net_device
*odev
= NULL
;
1365 struct ieee80211_sub_if_data
*sdata
, *osdata
;
1368 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1371 * copy control out of the skb so other people can use skb->cb
1373 pkt_data
= (struct ieee80211_tx_packet_data
*)skb
->cb
;
1374 memset(&control
, 0, sizeof(struct ieee80211_tx_control
));
1376 if (pkt_data
->ifindex
)
1377 odev
= dev_get_by_index(pkt_data
->ifindex
);
1378 if (unlikely(odev
&& !is_ieee80211_device(odev
, dev
))) {
1382 if (unlikely(!odev
)) {
1383 #ifdef CONFIG_D80211_VERBOSE_DEBUG
1384 printk(KERN_DEBUG
"%s: Discarded packet with nonexistent "
1385 "originating device\n", dev
->name
);
1390 osdata
= IEEE80211_DEV_TO_SUB_IF(odev
);
1392 control
.ifindex
= odev
->ifindex
;
1393 control
.type
= osdata
->type
;
1394 if (pkt_data
->req_tx_status
)
1395 control
.flags
|= IEEE80211_TXCTL_REQ_TX_STATUS
;
1396 if (pkt_data
->do_not_encrypt
)
1397 control
.flags
|= IEEE80211_TXCTL_DO_NOT_ENCRYPT
;
1399 pkt_data
->pkt_probe_resp
? PKT_PROBE_RESP
: PKT_NORMAL
;
1400 if (pkt_data
->requeue
)
1401 control
.flags
|= IEEE80211_TXCTL_REQUEUE
;
1402 control
.queue
= pkt_data
->queue
;
1404 ret
= ieee80211_tx(odev
, skb
, &control
,
1405 control
.type
== IEEE80211_IF_TYPE_MGMT
);
1413 * ieee80211_subif_start_xmit - netif start_xmit function for Ethernet-type
1414 * subinterfaces (wlan#, WDS, and VLAN interfaces)
1415 * @skb: packet to be sent
1416 * @dev: incoming interface
1418 * Returns: 0 on success (and frees skb in this case) or 1 on failure (skb will
1419 * not be freed, and caller is responsible for either retrying later or freeing
1422 * This function takes in an Ethernet header and encapsulates it with suitable
1423 * IEEE 802.11 header based on which interface the packet is coming in. The
1424 * encapsulated packet will then be passed to master interface, wlan#.11, for
1425 * transmission (through low-level driver).
1427 static int ieee80211_subif_start_xmit(struct sk_buff
*skb
,
1428 struct net_device
*dev
)
1430 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1431 struct ieee80211_tx_packet_data
*pkt_data
;
1432 struct ieee80211_sub_if_data
*sdata
;
1433 int ret
= 1, head_need
;
1434 u16 ethertype
, hdrlen
, fc
;
1435 struct ieee80211_hdr hdr
;
1437 int encaps_len
, skip_header_bytes
;
1438 int nh_pos
, h_pos
, no_encrypt
= 0;
1439 struct sta_info
*sta
;
1441 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1442 if (unlikely(skb
->len
< ETH_HLEN
)) {
1443 printk(KERN_DEBUG
"%s: short skb (len=%d)\n",
1444 dev
->name
, skb
->len
);
1449 nh_pos
= skb
->nh
.raw
- skb
->data
;
1450 h_pos
= skb
->h
.raw
- skb
->data
;
1452 /* convert Ethernet header to proper 802.11 header (based on
1453 * operation mode) */
1454 ethertype
= (skb
->data
[12] << 8) | skb
->data
[13];
1455 /* TODO: handling for 802.1x authorized/unauthorized port */
1456 fc
= IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_DATA
;
1458 if (likely(sdata
->type
== IEEE80211_IF_TYPE_AP
||
1459 sdata
->type
== IEEE80211_IF_TYPE_VLAN
)) {
1460 fc
|= IEEE80211_FCTL_FROMDS
;
1462 memcpy(hdr
.addr1
, skb
->data
, ETH_ALEN
);
1463 memcpy(hdr
.addr2
, dev
->dev_addr
, ETH_ALEN
);
1464 memcpy(hdr
.addr3
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
1466 } else if (sdata
->type
== IEEE80211_IF_TYPE_WDS
) {
1467 fc
|= IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
;
1469 memcpy(hdr
.addr1
, sdata
->u
.wds
.remote_addr
, ETH_ALEN
);
1470 memcpy(hdr
.addr2
, dev
->dev_addr
, ETH_ALEN
);
1471 memcpy(hdr
.addr3
, skb
->data
, ETH_ALEN
);
1472 memcpy(hdr
.addr4
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
1474 } else if (sdata
->type
== IEEE80211_IF_TYPE_STA
) {
1475 fc
|= IEEE80211_FCTL_TODS
;
1477 memcpy(hdr
.addr1
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
1478 memcpy(hdr
.addr2
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
1479 memcpy(hdr
.addr3
, skb
->data
, ETH_ALEN
);
1481 } else if (sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
1483 memcpy(hdr
.addr1
, skb
->data
, ETH_ALEN
);
1484 memcpy(hdr
.addr2
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
1485 memcpy(hdr
.addr3
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
1492 /* receiver is QoS enabled, use a QoS type frame */
1493 sta
= sta_info_get(local
, hdr
.addr1
);
1495 if (sta
->flags
& WLAN_STA_WME
) {
1496 fc
|= IEEE80211_STYPE_QOS_DATA
;
1502 hdr
.frame_control
= cpu_to_le16(fc
);
1503 hdr
.duration_id
= 0;
1506 skip_header_bytes
= ETH_HLEN
;
1507 if (ethertype
== ETH_P_AARP
|| ethertype
== ETH_P_IPX
) {
1508 encaps_data
= bridge_tunnel_header
;
1509 encaps_len
= sizeof(bridge_tunnel_header
);
1510 skip_header_bytes
-= 2;
1511 } else if (ethertype
>= 0x600) {
1512 encaps_data
= rfc1042_header
;
1513 encaps_len
= sizeof(rfc1042_header
);
1514 skip_header_bytes
-= 2;
1520 skb_pull(skb
, skip_header_bytes
);
1521 nh_pos
-= skip_header_bytes
;
1522 h_pos
-= skip_header_bytes
;
1524 /* TODO: implement support for fragments so that there is no need to
1525 * reallocate and copy payload; it might be enough to support one
1526 * extra fragment that would be copied in the beginning of the frame
1527 * data.. anyway, it would be nice to include this into skb structure
1530 * There are few options for this:
1531 * use skb->cb as an extra space for 802.11 header
1532 * allocate new buffer if not enough headroom
1533 * make sure that there is enough headroom in every skb by increasing
1534 * build in headroom in __dev_alloc_skb() (linux/skbuff.h) and
1535 * alloc_skb() (net/core/skbuff.c)
1537 head_need
= hdrlen
+ encaps_len
+ local
->hw
.extra_tx_headroom
;
1538 head_need
-= skb_headroom(skb
);
1540 /* We are going to modify skb data, so make a copy of it if happens to
1541 * be cloned. This could happen, e.g., with Linux bridge code passing
1542 * us broadcast frames. */
1544 if (head_need
> 0 || skb_cloned(skb
)) {
1546 printk(KERN_DEBUG
"%s: need to reallocate buffer for %d bytes "
1547 "of headroom\n", dev
->name
, head_need
);
1550 if (skb_cloned(skb
))
1551 I802_DEBUG_INC(local
->tx_expand_skb_head_cloned
);
1553 I802_DEBUG_INC(local
->tx_expand_skb_head
);
1554 /* Since we have to reallocate the buffer, make sure that there
1555 * is enough room for possible WEP IV/ICV and TKIP (8 bytes
1556 * before payload and 12 after). */
1557 if (pskb_expand_head(skb
, (head_need
> 0 ? head_need
+ 8 : 8),
1559 printk(KERN_DEBUG
"%s: failed to reallocate TX buffer"
1566 memcpy(skb_push(skb
, encaps_len
), encaps_data
, encaps_len
);
1567 nh_pos
+= encaps_len
;
1568 h_pos
+= encaps_len
;
1570 memcpy(skb_push(skb
, hdrlen
), &hdr
, hdrlen
);
1574 pkt_data
= (struct ieee80211_tx_packet_data
*)skb
->cb
;
1575 memset(pkt_data
, 0, sizeof(struct ieee80211_tx_packet_data
));
1576 pkt_data
->ifindex
= sdata
->dev
->ifindex
;
1577 pkt_data
->mgmt_iface
= (sdata
->type
== IEEE80211_IF_TYPE_MGMT
);
1578 pkt_data
->do_not_encrypt
= no_encrypt
;
1580 skb
->dev
= local
->mdev
;
1581 sdata
->stats
.tx_packets
++;
1582 sdata
->stats
.tx_bytes
+= skb
->len
;
1584 /* Update skb pointers to various headers since this modified frame
1585 * is going to go through Linux networking code that may potentially
1586 * need things like pointer to IP header. */
1587 skb
->mac
.raw
= skb
->data
;
1588 skb
->nh
.raw
= skb
->data
+ nh_pos
;
1589 skb
->h
.raw
= skb
->data
+ h_pos
;
1591 dev_queue_xmit(skb
);
1604 * This is the transmit routine for the 802.11 type interfaces
1605 * called by upper layers of the linux networking
1606 * stack when it has a frame to transmit
1609 ieee80211_mgmt_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1611 struct ieee80211_sub_if_data
*sdata
;
1612 struct ieee80211_tx_packet_data
*pkt_data
;
1613 struct ieee80211_hdr
*hdr
;
1616 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1618 if (skb
->len
< 10) {
1623 hdr
= (struct ieee80211_hdr
*) skb
->data
;
1624 fc
= le16_to_cpu(hdr
->frame_control
);
1626 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
1627 memset(pkt_data
, 0, sizeof(struct ieee80211_tx_packet_data
));
1628 pkt_data
->ifindex
= sdata
->dev
->ifindex
;
1629 pkt_data
->mgmt_iface
= (sdata
->type
== IEEE80211_IF_TYPE_MGMT
);
1631 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
&&
1632 (fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_PROBE_RESP
)
1633 pkt_data
->pkt_probe_resp
= 1;
1635 skb
->priority
= 20; /* use hardcoded priority for mgmt TX queue */
1636 skb
->dev
= sdata
->local
->mdev
;
1639 * We're using the protocol field of the the frame control header
1640 * to request TX callback for hostapd. BIT(1) is checked.
1642 if ((fc
& BIT(1)) == BIT(1)) {
1643 pkt_data
->req_tx_status
= 1;
1645 hdr
->frame_control
= cpu_to_le16(fc
);
1648 pkt_data
->do_not_encrypt
= !(fc
& IEEE80211_FCTL_PROTECTED
);
1650 sdata
->stats
.tx_packets
++;
1651 sdata
->stats
.tx_bytes
+= skb
->len
;
1653 dev_queue_xmit(skb
);
1659 static void ieee80211_beacon_add_tim(struct ieee80211_local
*local
,
1660 struct ieee80211_if_ap
*bss
,
1661 struct sk_buff
*skb
)
1665 int i
, have_bits
= 0, n1
, n2
;
1667 /* Generate bitmap for TIM only if there are any STAs in power save
1669 spin_lock_bh(&local
->sta_lock
);
1670 if (atomic_read(&bss
->num_sta_ps
) > 0)
1671 /* in the hope that this is faster than
1672 * checking byte-for-byte */
1673 have_bits
= !bitmap_empty((unsigned long*)bss
->tim
,
1674 IEEE80211_MAX_AID
+1);
1676 if (bss
->dtim_count
== 0)
1677 bss
->dtim_count
= bss
->dtim_period
- 1;
1681 tim
= pos
= (u8
*) skb_put(skb
, 6);
1682 *pos
++ = WLAN_EID_TIM
;
1684 *pos
++ = bss
->dtim_count
;
1685 *pos
++ = bss
->dtim_period
;
1687 if (bss
->dtim_count
== 0 && !skb_queue_empty(&bss
->ps_bc_buf
))
1691 /* Find largest even number N1 so that bits numbered 1 through
1692 * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
1693 * (N2 + 1) x 8 through 2007 are 0. */
1695 for (i
= 0; i
< IEEE80211_MAX_TIM_LEN
; i
++) {
1702 for (i
= IEEE80211_MAX_TIM_LEN
- 1; i
>= n1
; i
--) {
1709 /* Bitmap control */
1711 /* Part Virt Bitmap */
1712 memcpy(pos
, bss
->tim
+ n1
, n2
- n1
+ 1);
1714 tim
[1] = n2
- n1
+ 4;
1715 skb_put(skb
, n2
- n1
);
1717 *pos
++ = aid0
; /* Bitmap control */
1718 *pos
++ = 0; /* Part Virt Bitmap */
1720 spin_unlock_bh(&local
->sta_lock
);
1724 struct sk_buff
* ieee80211_beacon_get(struct ieee80211_hw
*hw
, int if_id
,
1725 struct ieee80211_tx_control
*control
)
1727 struct ieee80211_local
*local
= hw_to_local(hw
);
1728 struct sk_buff
*skb
;
1729 struct net_device
*bdev
;
1730 struct ieee80211_sub_if_data
*sdata
= NULL
;
1731 struct ieee80211_if_ap
*ap
= NULL
;
1732 struct ieee80211_rate
*rate
;
1733 struct rate_control_extra extra
;
1734 u8
*b_head
, *b_tail
;
1737 bdev
= dev_get_by_index(if_id
);
1739 sdata
= IEEE80211_DEV_TO_SUB_IF(bdev
);
1744 if (!ap
|| sdata
->type
!= IEEE80211_IF_TYPE_AP
||
1746 #ifdef CONFIG_D80211_VERBOSE_DEBUG
1747 if (net_ratelimit())
1748 printk(KERN_DEBUG
"no beacon data avail for idx=%d "
1749 "(%s)\n", if_id
, bdev
? bdev
->name
: "N/A");
1750 #endif /* CONFIG_D80211_VERBOSE_DEBUG */
1754 /* Assume we are generating the normal beacon locally */
1755 b_head
= ap
->beacon_head
;
1756 b_tail
= ap
->beacon_tail
;
1757 bh_len
= ap
->beacon_head_len
;
1758 bt_len
= ap
->beacon_tail_len
;
1760 skb
= dev_alloc_skb(bh_len
+ bt_len
+ 256 /* maximum TIM len */);
1764 memcpy(skb_put(skb
, bh_len
), b_head
, bh_len
);
1766 ieee80211_beacon_add_tim(local
, ap
, skb
);
1769 memcpy(skb_put(skb
, bt_len
), b_tail
, bt_len
);
1773 memset(&extra
, 0, sizeof(extra
));
1774 extra
.endidx
= local
->num_curr_rates
;
1776 rate
= rate_control_get_rate(local
, local
->mdev
, skb
, &extra
);
1778 if (net_ratelimit()) {
1779 printk(KERN_DEBUG
"%s: ieee80211_beacon_get: no rate "
1780 "found\n", local
->mdev
->name
);
1786 control
->tx_rate
= (local
->short_preamble
&&
1787 (rate
->flags
& IEEE80211_RATE_PREAMBLE2
)) ?
1788 rate
->val2
: rate
->val
;
1789 control
->antenna_sel
= local
->hw
.conf
.antenna_sel
;
1790 control
->power_level
= local
->hw
.conf
.power_level
;
1791 control
->flags
|= IEEE80211_TXCTL_NO_ACK
;
1792 control
->retry_limit
= 1;
1793 control
->rts_cts_duration
= 0;
1794 control
->flags
|= IEEE80211_TXCTL_CLEAR_DST_MASK
;
1800 EXPORT_SYMBOL(ieee80211_beacon_get
);
1803 ieee80211_get_buffered_bc(struct ieee80211_hw
*hw
, int if_id
,
1804 struct ieee80211_tx_control
*control
)
1806 struct ieee80211_local
*local
= hw_to_local(hw
);
1807 struct sk_buff
*skb
;
1808 struct sta_info
*sta
;
1809 ieee80211_tx_handler
*handler
;
1810 struct ieee80211_txrx_data tx
;
1811 ieee80211_txrx_result res
= TXRX_DROP
;
1812 struct net_device
*bdev
;
1813 struct ieee80211_sub_if_data
*sdata
;
1814 struct ieee80211_if_ap
*bss
= NULL
;
1816 bdev
= dev_get_by_index(if_id
);
1818 sdata
= IEEE80211_DEV_TO_SUB_IF(bdev
);
1822 if (!bss
|| sdata
->type
!= IEEE80211_IF_TYPE_AP
|| !bss
->beacon_head
)
1825 if (bss
->dtim_count
!= 0)
1826 return NULL
; /* send buffered bc/mc only after DTIM beacon */
1827 skb
= skb_dequeue(&bss
->ps_bc_buf
);
1828 memset(control
, 0, sizeof(*control
));
1831 local
->total_ps_buffered
--;
1833 if (!skb_queue_empty(&bss
->ps_bc_buf
) && skb
->len
>= 2) {
1834 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1835 /* more buffered multicast/broadcast frames ==> set MoreData
1836 * flag in IEEE 802.11 header to inform PS STAs */
1837 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_MOREDATA
);
1840 ieee80211_tx_prepare(&tx
, skb
, local
->mdev
, control
);
1842 tx
.u
.tx
.ps_buffered
= 1;
1844 for (handler
= local
->tx_handlers
; *handler
!= NULL
; handler
++) {
1845 res
= (*handler
)(&tx
);
1846 if (res
== TXRX_DROP
|| res
== TXRX_QUEUED
)
1850 skb
= tx
.skb
; /* handlers are allowed to change skb */
1852 if (res
== TXRX_DROP
) {
1853 I802_DEBUG_INC(local
->tx_handlers_drop
);
1856 } else if (res
== TXRX_QUEUED
) {
1857 I802_DEBUG_INC(local
->tx_handlers_queued
);
1866 EXPORT_SYMBOL(ieee80211_get_buffered_bc
);
1868 static int __ieee80211_if_config(struct net_device
*dev
,
1869 struct sk_buff
*beacon
)
1871 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1872 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1873 struct ieee80211_if_conf conf
;
1875 if (!local
->ops
->config_interface
|| !netif_running(dev
))
1878 memset(&conf
, 0, sizeof(conf
));
1879 conf
.type
= sdata
->type
;
1880 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1881 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
1882 conf
.bssid
= sdata
->u
.sta
.bssid
;
1883 conf
.ssid
= sdata
->u
.sta
.ssid
;
1884 conf
.ssid_len
= sdata
->u
.sta
.ssid_len
;
1885 conf
.generic_elem
= sdata
->u
.sta
.extra_ie
;
1886 conf
.generic_elem_len
= sdata
->u
.sta
.extra_ie_len
;
1887 } else if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
1888 conf
.ssid
= sdata
->u
.ap
.ssid
;
1889 conf
.ssid_len
= sdata
->u
.ap
.ssid_len
;
1890 conf
.generic_elem
= sdata
->u
.ap
.generic_elem
;
1891 conf
.generic_elem_len
= sdata
->u
.ap
.generic_elem_len
;
1892 conf
.beacon
= beacon
;
1894 return local
->ops
->config_interface(local_to_hw(local
),
1895 dev
->ifindex
, &conf
);
1898 int ieee80211_if_config(struct net_device
*dev
)
1900 return __ieee80211_if_config(dev
, NULL
);
1903 int ieee80211_if_config_beacon(struct net_device
*dev
)
1905 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1906 struct sk_buff
*skb
;
1908 if (!(local
->hw
.flags
& IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE
))
1910 skb
= ieee80211_beacon_get(local_to_hw(local
), dev
->ifindex
, NULL
);
1913 return __ieee80211_if_config(dev
, skb
);
1916 int ieee80211_hw_config(struct ieee80211_local
*local
)
1920 #ifdef CONFIG_D80211_VERBOSE_DEBUG
1921 printk(KERN_DEBUG
"HW CONFIG: channel=%d freq=%d "
1922 "phymode=%d\n", local
->hw
.conf
.channel
, local
->hw
.conf
.freq
,
1923 local
->hw
.conf
.phymode
);
1924 #endif /* CONFIG_D80211_VERBOSE_DEBUG */
1926 if (local
->ops
->config
)
1927 ret
= local
->ops
->config(local_to_hw(local
), &local
->hw
.conf
);
1929 for (i
= 0; i
< local
->hw
.num_modes
; i
++) {
1930 struct ieee80211_hw_modes
*mode
= &local
->hw
.modes
[i
];
1931 if (mode
->mode
== local
->hw
.conf
.phymode
) {
1932 if (local
->curr_rates
!= mode
->rates
) {
1933 rate_control_clear(local
);
1935 local
->curr_rates
= mode
->rates
;
1936 local
->num_curr_rates
= mode
->num_rates
;
1937 ieee80211_prepare_rates(local
);
1946 static int ieee80211_change_mtu(struct net_device
*dev
, int new_mtu
)
1948 /* FIX: what would be proper limits for MTU?
1949 * This interface uses 802.3 frames. */
1950 if (new_mtu
< 256 || new_mtu
> IEEE80211_DATA_LEN
- 24 - 6) {
1951 printk(KERN_WARNING
"%s: invalid MTU %d\n",
1952 dev
->name
, new_mtu
);
1956 #ifdef CONFIG_D80211_VERBOSE_DEBUG
1957 printk(KERN_DEBUG
"%s: setting MTU %d\n", dev
->name
, new_mtu
);
1958 #endif /* CONFIG_D80211_VERBOSE_DEBUG */
1964 static int ieee80211_change_mtu_apdev(struct net_device
*dev
, int new_mtu
)
1966 /* FIX: what would be proper limits for MTU?
1967 * This interface uses 802.11 frames. */
1968 if (new_mtu
< 256 || new_mtu
> IEEE80211_DATA_LEN
) {
1969 printk(KERN_WARNING
"%s: invalid MTU %d\n",
1970 dev
->name
, new_mtu
);
1974 #ifdef CONFIG_D80211_VERBOSE_DEBUG
1975 printk(KERN_DEBUG
"%s: setting MTU %d\n", dev
->name
, new_mtu
);
1976 #endif /* CONFIG_D80211_VERBOSE_DEBUG */
1982 static void ieee80211_tx_timeout(struct net_device
*dev
)
1984 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1986 printk(KERN_WARNING
"%s: resetting interface.\n", dev
->name
);
1988 if (local
->ops
->reset(local_to_hw(local
)))
1989 printk(KERN_ERR
"%s: failed to reset interface.\n", dev
->name
);
1991 netif_wake_queue(dev
);
1995 static int ieee80211_set_mac_address(struct net_device
*dev
, void *addr
)
1997 struct sockaddr
*a
= addr
;
1999 if (netif_running(dev
))
2002 memcpy(dev
->dev_addr
, a
->sa_data
, ETH_ALEN
);
2006 static void ieee80211_set_multicast_list(struct net_device
*dev
)
2008 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2009 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2010 unsigned short flags
;
2012 if (((dev
->flags
& IFF_ALLMULTI
) != 0) ^ (sdata
->allmulti
!= 0)) {
2013 if (sdata
->allmulti
) {
2014 sdata
->allmulti
= 0;
2015 local
->iff_allmultis
--;
2017 sdata
->allmulti
= 1;
2018 local
->iff_allmultis
++;
2021 if (((dev
->flags
& IFF_PROMISC
) != 0) ^ (sdata
->promisc
!= 0)) {
2022 if (sdata
->promisc
) {
2024 local
->iff_promiscs
--;
2027 local
->iff_promiscs
++;
2030 if (dev
->mc_count
!= sdata
->mc_count
) {
2031 local
->mc_count
= local
->mc_count
- sdata
->mc_count
+
2033 sdata
->mc_count
= dev
->mc_count
;
2035 if (local
->ops
->set_multicast_list
) {
2036 flags
= local
->mdev
->flags
;
2037 if (local
->iff_allmultis
)
2038 flags
|= IFF_ALLMULTI
;
2039 if (local
->iff_promiscs
)
2040 flags
|= IFF_PROMISC
;
2041 local
->ops
->set_multicast_list(local_to_hw(local
), flags
,
2046 struct dev_mc_list
*ieee80211_get_mc_list_item(struct ieee80211_hw
*hw
,
2047 struct dev_mc_list
*prev
,
2050 struct ieee80211_local
*local
= hw_to_local(hw
);
2051 struct ieee80211_sub_if_data
*sdata
= *ptr
;
2052 struct dev_mc_list
*mc
;
2058 if (!prev
|| !prev
->next
) {
2060 sdata
= list_entry(sdata
->list
.next
,
2061 struct ieee80211_sub_if_data
, list
);
2063 sdata
= list_entry(local
->sub_if_list
.next
,
2064 struct ieee80211_sub_if_data
, list
);
2065 if (&sdata
->list
!= &local
->sub_if_list
)
2066 mc
= sdata
->dev
->mc_list
;
2075 EXPORT_SYMBOL(ieee80211_get_mc_list_item
);
2077 static struct net_device_stats
*ieee80211_get_stats(struct net_device
*dev
)
2079 struct ieee80211_sub_if_data
*sdata
;
2080 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2081 return &(sdata
->stats
);
2084 void ieee80211_if_shutdown(struct net_device
*dev
)
2086 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2087 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2090 switch (sdata
->type
) {
2091 case IEEE80211_IF_TYPE_STA
:
2092 case IEEE80211_IF_TYPE_IBSS
:
2093 sdata
->u
.sta
.state
= IEEE80211_DISABLED
;
2094 cancel_delayed_work(&sdata
->u
.sta
.work
);
2095 if (local
->scan_work
.data
== sdata
->dev
) {
2096 local
->sta_scanning
= 0;
2097 cancel_delayed_work(&local
->scan_work
);
2098 flush_scheduled_work();
2099 /* see comment in ieee80211_unregister_hw to
2100 * understand why this works */
2101 local
->scan_work
.data
= NULL
;
2103 flush_scheduled_work();
2108 static inline int identical_mac_addr_allowed(int type1
, int type2
)
2110 return (type1
== IEEE80211_IF_TYPE_MNTR
||
2111 type2
== IEEE80211_IF_TYPE_MNTR
||
2112 (type1
== IEEE80211_IF_TYPE_AP
&&
2113 type2
== IEEE80211_IF_TYPE_WDS
) ||
2114 (type1
== IEEE80211_IF_TYPE_WDS
&&
2115 (type2
== IEEE80211_IF_TYPE_WDS
||
2116 type2
== IEEE80211_IF_TYPE_AP
)) ||
2117 (type1
== IEEE80211_IF_TYPE_AP
&&
2118 type2
== IEEE80211_IF_TYPE_VLAN
) ||
2119 (type1
== IEEE80211_IF_TYPE_VLAN
&&
2120 (type2
== IEEE80211_IF_TYPE_AP
||
2121 type2
== IEEE80211_IF_TYPE_VLAN
)));
2124 static int ieee80211_master_open(struct net_device
*dev
)
2126 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2127 struct ieee80211_sub_if_data
*sdata
;
2128 int res
= -EOPNOTSUPP
;
2130 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
2131 if (sdata
->dev
!= dev
&& netif_running(sdata
->dev
)) {
2133 tasklet_enable(&local
->tx_pending_tasklet
);
2140 static int ieee80211_master_stop(struct net_device
*dev
)
2142 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2143 struct ieee80211_sub_if_data
*sdata
;
2145 tasklet_disable(&local
->tx_pending_tasklet
);
2146 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
2147 if (sdata
->dev
!= dev
&& netif_running(sdata
->dev
))
2153 static int ieee80211_mgmt_open(struct net_device
*dev
)
2155 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2157 if (!netif_running(local
->mdev
))
2162 static int ieee80211_mgmt_stop(struct net_device
*dev
)
2167 /* Check if running monitor interfaces should go to a "soft monitor" mode
2168 * and switch them if necessary. */
2169 static inline void ieee80211_start_soft_monitor(struct ieee80211_local
*local
)
2171 struct ieee80211_if_init_conf conf
;
2173 if (local
->open_count
&& local
->open_count
== local
->monitors
&&
2174 !(local
->hw
.flags
& IEEE80211_HW_MONITOR_DURING_OPER
) &&
2175 local
->ops
->remove_interface
) {
2177 conf
.type
= IEEE80211_IF_TYPE_MNTR
;
2178 conf
.mac_addr
= NULL
;
2179 local
->ops
->remove_interface(local_to_hw(local
), &conf
);
2183 /* Check if running monitor interfaces should go to a "hard monitor" mode
2184 * and switch them if necessary. */
2185 static void ieee80211_start_hard_monitor(struct ieee80211_local
*local
)
2187 struct ieee80211_if_init_conf conf
;
2189 if (local
->open_count
&& local
->open_count
== local
->monitors
&&
2190 !(local
->hw
.flags
& IEEE80211_HW_MONITOR_DURING_OPER
) &&
2191 local
->ops
->add_interface
) {
2193 conf
.type
= IEEE80211_IF_TYPE_MNTR
;
2194 conf
.mac_addr
= NULL
;
2195 local
->ops
->add_interface(local_to_hw(local
), &conf
);
2199 static int ieee80211_open(struct net_device
*dev
)
2201 struct ieee80211_sub_if_data
*sdata
, *nsdata
;
2202 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2203 struct ieee80211_if_init_conf conf
;
2206 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2207 list_for_each_entry(nsdata
, &local
->sub_if_list
, list
) {
2208 struct net_device
*ndev
= nsdata
->dev
;
2210 if (ndev
!= dev
&& ndev
!= local
->mdev
&&
2211 netif_running(ndev
) &&
2212 memcmp(dev
->dev_addr
, ndev
->dev_addr
, ETH_ALEN
) == 0 &&
2213 !identical_mac_addr_allowed(sdata
->type
, nsdata
->type
)) {
2217 if (sdata
->type
== IEEE80211_IF_TYPE_WDS
&&
2218 memcmp(sdata
->u
.wds
.remote_addr
, "\0\0\0\0\0\0", ETH_ALEN
) == 0)
2221 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
&& local
->open_count
&&
2222 !(local
->hw
.flags
& IEEE80211_HW_MONITOR_DURING_OPER
)) {
2223 /* run the interface in a "soft monitor" mode */
2225 local
->open_count
++;
2228 ieee80211_start_soft_monitor(local
);
2230 if (local
->ops
->add_interface
) {
2231 conf
.if_id
= dev
->ifindex
;
2232 conf
.type
= sdata
->type
;
2233 conf
.mac_addr
= dev
->dev_addr
;
2234 res
= local
->ops
->add_interface(local_to_hw(local
), &conf
);
2236 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
)
2237 ieee80211_start_hard_monitor(local
);
2241 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
2243 if (local
->open_count
> 0)
2247 if (local
->open_count
== 0) {
2249 if (local
->ops
->open
)
2250 res
= local
->ops
->open(local_to_hw(local
));
2252 res
= dev_open(local
->mdev
);
2254 if (local
->ops
->stop
)
2255 local
->ops
->stop(local_to_hw(local
));
2256 } else if (local
->apdev
)
2257 dev_open(local
->apdev
);
2260 if (local
->ops
->remove_interface
)
2261 local
->ops
->remove_interface(local_to_hw(local
),
2265 ieee80211_init_scan(local
);
2267 local
->open_count
++;
2269 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
)
2272 ieee80211_if_config(dev
);
2274 netif_start_queue(dev
);
2279 static int ieee80211_stop(struct net_device
*dev
)
2281 struct ieee80211_sub_if_data
*sdata
;
2282 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2284 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2286 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
&&
2287 local
->open_count
> 1 &&
2288 !(local
->hw
.flags
& IEEE80211_HW_MONITOR_DURING_OPER
)) {
2289 /* remove "soft monitor" interface */
2290 local
->open_count
--;
2295 netif_stop_queue(dev
);
2297 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
)
2300 local
->open_count
--;
2301 if (local
->open_count
== 0) {
2302 ieee80211_stop_scan(local
);
2303 dev_close(local
->mdev
);
2305 dev_close(local
->apdev
);
2306 if (local
->ops
->stop
)
2307 local
->ops
->stop(local_to_hw(local
));
2309 if (local
->ops
->remove_interface
) {
2310 struct ieee80211_if_init_conf conf
;
2312 conf
.if_id
= dev
->ifindex
;
2313 conf
.type
= sdata
->type
;
2314 conf
.mac_addr
= dev
->dev_addr
;
2315 local
->ops
->remove_interface(local_to_hw(local
), &conf
);
2317 ieee80211_if_shutdown(dev
);
2319 ieee80211_start_hard_monitor(local
);
2325 static int header_parse_80211(struct sk_buff
*skb
, unsigned char *haddr
)
2327 memcpy(haddr
, skb
->mac
.raw
+ 10, ETH_ALEN
); /* addr2 */
2331 static inline int ieee80211_bssid_match(u8
*raddr
, u8
*addr
)
2333 return memcmp(raddr
, addr
, ETH_ALEN
) == 0 ||
2334 is_broadcast_ether_addr(raddr
);
2338 static ieee80211_txrx_result
2339 ieee80211_rx_h_data(struct ieee80211_txrx_data
*rx
)
2341 struct net_device
*dev
= rx
->dev
;
2342 struct ieee80211_local
*local
= rx
->local
;
2343 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
2344 u16 fc
, hdrlen
, ethertype
;
2348 struct sk_buff
*skb
= rx
->skb
, *skb2
;
2349 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2352 if (unlikely((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
))
2353 return TXRX_CONTINUE
;
2355 if (unlikely(!WLAN_FC_DATA_PRESENT(fc
)))
2358 hdrlen
= ieee80211_get_hdrlen(fc
);
2360 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
2362 * IEEE 802.11 address fields:
2363 * ToDS FromDS Addr1 Addr2 Addr3 Addr4
2364 * 0 0 DA SA BSSID n/a
2365 * 0 1 DA BSSID SA n/a
2366 * 1 0 BSSID SA DA n/a
2370 switch (fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) {
2371 case IEEE80211_FCTL_TODS
:
2373 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
2374 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
2376 if (unlikely(sdata
->type
!= IEEE80211_IF_TYPE_AP
&&
2377 sdata
->type
!= IEEE80211_IF_TYPE_VLAN
)) {
2378 printk(KERN_DEBUG
"%s: dropped ToDS frame (BSSID="
2379 MAC_FMT
" SA=" MAC_FMT
" DA=" MAC_FMT
")\n",
2380 dev
->name
, MAC_ARG(hdr
->addr1
),
2381 MAC_ARG(hdr
->addr2
), MAC_ARG(hdr
->addr3
));
2385 case (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
):
2387 memcpy(dst
, hdr
->addr3
, ETH_ALEN
);
2388 memcpy(src
, hdr
->addr4
, ETH_ALEN
);
2390 if (unlikely(sdata
->type
!= IEEE80211_IF_TYPE_WDS
)) {
2391 printk(KERN_DEBUG
"%s: dropped FromDS&ToDS frame (RA="
2392 MAC_FMT
" TA=" MAC_FMT
" DA=" MAC_FMT
" SA="
2394 rx
->dev
->name
, MAC_ARG(hdr
->addr1
),
2395 MAC_ARG(hdr
->addr2
), MAC_ARG(hdr
->addr3
),
2396 MAC_ARG(hdr
->addr4
));
2400 case IEEE80211_FCTL_FROMDS
:
2402 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
2403 memcpy(src
, hdr
->addr3
, ETH_ALEN
);
2405 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
) {
2411 memcpy(dst
, hdr
->addr1
, ETH_ALEN
);
2412 memcpy(src
, hdr
->addr2
, ETH_ALEN
);
2414 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
) {
2415 if (net_ratelimit()) {
2416 printk(KERN_DEBUG
"%s: dropped IBSS frame (DA="
2417 MAC_FMT
" SA=" MAC_FMT
" BSSID=" MAC_FMT
2419 dev
->name
, MAC_ARG(hdr
->addr1
),
2420 MAC_ARG(hdr
->addr2
),
2421 MAC_ARG(hdr
->addr3
));
2428 payload
= skb
->data
+ hdrlen
;
2430 if (unlikely(skb
->len
- hdrlen
< 8)) {
2431 if (net_ratelimit()) {
2432 printk(KERN_DEBUG
"%s: RX too short data frame "
2433 "payload\n", dev
->name
);
2438 ethertype
= (payload
[6] << 8) | payload
[7];
2440 if (likely((memcmp(payload
, rfc1042_header
, 6) == 0 &&
2441 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
2442 memcmp(payload
, bridge_tunnel_header
, 6) == 0)) {
2443 /* remove RFC1042 or Bridge-Tunnel encapsulation and
2444 * replace EtherType */
2445 skb_pull(skb
, hdrlen
+ 6);
2446 memcpy(skb_push(skb
, ETH_ALEN
), src
, ETH_ALEN
);
2447 memcpy(skb_push(skb
, ETH_ALEN
), dst
, ETH_ALEN
);
2449 struct ethhdr
*ehdr
;
2451 skb_pull(skb
, hdrlen
);
2452 len
= htons(skb
->len
);
2453 ehdr
= (struct ethhdr
*) skb_push(skb
, sizeof(struct ethhdr
));
2454 memcpy(ehdr
->h_dest
, dst
, ETH_ALEN
);
2455 memcpy(ehdr
->h_source
, src
, ETH_ALEN
);
2456 ehdr
->h_proto
= len
;
2462 sdata
->stats
.rx_packets
++;
2463 sdata
->stats
.rx_bytes
+= skb
->len
;
2465 if (local
->bridge_packets
&& (sdata
->type
== IEEE80211_IF_TYPE_AP
2466 || sdata
->type
== IEEE80211_IF_TYPE_VLAN
) && rx
->u
.rx
.ra_match
) {
2467 if (is_multicast_ether_addr(skb
->data
)) {
2468 /* send multicast frames both to higher layers in
2469 * local net stack and back to the wireless media */
2470 skb2
= skb_copy(skb
, GFP_ATOMIC
);
2472 printk(KERN_DEBUG
"%s: failed to clone "
2473 "multicast frame\n", dev
->name
);
2475 struct sta_info
*dsta
;
2476 dsta
= sta_info_get(local
, skb
->data
);
2477 if (dsta
&& !dsta
->dev
) {
2478 printk(KERN_DEBUG
"Station with null dev "
2480 } else if (dsta
&& dsta
->dev
== dev
) {
2481 /* Destination station is associated to this
2482 * AP, so send the frame directly to it and
2483 * do not pass the frame to local net stack.
2494 /* deliver to local stack */
2495 skb
->protocol
= eth_type_trans(skb
, dev
);
2496 memset(skb
->cb
, 0, sizeof(skb
->cb
));
2501 /* send to wireless media */
2502 skb2
->protocol
= __constant_htons(ETH_P_802_3
);
2503 skb2
->mac
.raw
= skb2
->nh
.raw
= skb2
->data
;
2504 dev_queue_xmit(skb2
);
2511 static struct ieee80211_rate
*
2512 ieee80211_get_rate(struct ieee80211_local
*local
, int phymode
, int hw_rate
)
2516 for (m
= 0; m
< local
->hw
.num_modes
; m
++) {
2517 struct ieee80211_hw_modes
*mode
= &local
->hw
.modes
[m
];
2518 if (mode
->mode
!= phymode
)
2520 for (r
= 0; r
< mode
->num_rates
; r
++) {
2521 struct ieee80211_rate
*rate
= &mode
->rates
[r
];
2522 if (rate
->val
== hw_rate
||
2523 (rate
->flags
& IEEE80211_RATE_PREAMBLE2
&&
2524 rate
->val2
== hw_rate
))
2533 ieee80211_fill_frame_info(struct ieee80211_local
*local
,
2534 struct ieee80211_frame_info
*fi
,
2535 struct ieee80211_rx_status
*status
)
2539 struct ieee80211_rate
*rate
;
2541 jiffies_to_timespec(status
->hosttime
, &ts
);
2542 fi
->hosttime
= cpu_to_be64((u64
) ts
.tv_sec
* 1000000 +
2544 fi
->mactime
= cpu_to_be64(status
->mactime
);
2545 switch (status
->phymode
) {
2546 case MODE_IEEE80211A
:
2547 fi
->phytype
= htonl(ieee80211_phytype_ofdm_dot11_a
);
2549 case MODE_IEEE80211B
:
2550 fi
->phytype
= htonl(ieee80211_phytype_dsss_dot11_b
);
2552 case MODE_IEEE80211G
:
2553 fi
->phytype
= htonl(ieee80211_phytype_pbcc_dot11_g
);
2555 case MODE_ATHEROS_TURBO
:
2557 htonl(ieee80211_phytype_dsss_dot11_turbo
);
2560 fi
->phytype
= 0xAAAAAAAA;
2563 fi
->channel
= htonl(status
->channel
);
2564 rate
= ieee80211_get_rate(local
, status
->phymode
,
2567 fi
->datarate
= htonl(rate
->rate
);
2568 if (rate
->flags
& IEEE80211_RATE_PREAMBLE2
) {
2569 if (status
->rate
== rate
->val
)
2570 fi
->preamble
= htonl(2); /* long */
2571 else if (status
->rate
== rate
->val2
)
2572 fi
->preamble
= htonl(1); /* short */
2574 fi
->preamble
= htonl(0);
2576 fi
->datarate
= htonl(0);
2577 fi
->preamble
= htonl(0);
2580 fi
->antenna
= htonl(status
->antenna
);
2581 fi
->priority
= 0xffffffff; /* no clue */
2582 fi
->ssi_type
= htonl(ieee80211_ssi_raw
);
2583 fi
->ssi_signal
= htonl(status
->ssi
);
2584 fi
->ssi_noise
= 0x00000000;
2587 /* clear everything because we really don't know.
2588 * the msg_type field isn't present on monitor frames
2589 * so we don't know whether it will be present or not,
2590 * but it's ok to not clear it since it'll be assigned
2592 memset(fi
, 0, sizeof(*fi
) - sizeof(fi
->msg_type
));
2594 fi
->ssi_type
= htonl(ieee80211_ssi_none
);
2596 fi
->version
= htonl(IEEE80211_FI_VERSION
);
2597 fi
->length
= cpu_to_be32(sizeof(*fi
) - sizeof(fi
->msg_type
));
2600 /* this routine is actually not just for this, but also
2601 * for pushing fake 'management' frames into userspace.
2602 * it shall be replaced by a netlink-based system. */
2604 ieee80211_rx_mgmt(struct ieee80211_local
*local
, struct sk_buff
*skb
,
2605 struct ieee80211_rx_status
*status
, u32 msg_type
)
2607 struct ieee80211_frame_info
*fi
;
2608 const size_t hlen
= sizeof(struct ieee80211_frame_info
);
2609 struct ieee80211_sub_if_data
*sdata
;
2611 skb
->dev
= local
->apdev
;
2613 sdata
= IEEE80211_DEV_TO_SUB_IF(local
->apdev
);
2615 if (skb_headroom(skb
) < hlen
) {
2616 I802_DEBUG_INC(local
->rx_expand_skb_head
);
2617 if (pskb_expand_head(skb
, hlen
, 0, GFP_ATOMIC
)) {
2623 fi
= (struct ieee80211_frame_info
*) skb_push(skb
, hlen
);
2625 ieee80211_fill_frame_info(local
, fi
, status
);
2626 fi
->msg_type
= htonl(msg_type
);
2628 sdata
->stats
.rx_packets
++;
2629 sdata
->stats
.rx_bytes
+= skb
->len
;
2631 skb
->mac
.raw
= skb
->data
;
2632 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2633 skb
->pkt_type
= PACKET_OTHERHOST
;
2634 skb
->protocol
= htons(ETH_P_802_2
);
2635 memset(skb
->cb
, 0, sizeof(skb
->cb
));
2640 ieee80211_rx_monitor(struct net_device
*dev
, struct sk_buff
*skb
,
2641 struct ieee80211_rx_status
*status
)
2643 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2644 struct ieee80211_frame_info
*fi
;
2645 struct ieee80211_sub_if_data
*sdata
;
2646 const size_t hlen
= sizeof(struct ieee80211_frame_info
)
2647 - sizeof(fi
->msg_type
);
2651 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2653 if (skb_headroom(skb
) < hlen
) {
2654 I802_DEBUG_INC(local
->rx_expand_skb_head
);
2655 if (pskb_expand_head(skb
, hlen
, 0, GFP_ATOMIC
)) {
2661 fi
= (struct ieee80211_frame_info
*) skb_push(skb
, hlen
);
2663 ieee80211_fill_frame_info(local
, fi
, status
);
2664 sdata
->stats
.rx_packets
++;
2665 sdata
->stats
.rx_bytes
+= skb
->len
;
2667 skb
->mac
.raw
= skb
->data
;
2668 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2669 skb
->pkt_type
= PACKET_OTHERHOST
;
2670 skb
->protocol
= htons(ETH_P_802_2
);
2671 memset(skb
->cb
, 0, sizeof(skb
->cb
));
2675 int ieee80211_radar_status(struct ieee80211_hw
*hw
, int channel
,
2676 int radar
, int radar_type
)
2678 struct sk_buff
*skb
;
2679 struct ieee80211_radar_info
*msg
;
2680 struct ieee80211_local
*local
= hw_to_local(hw
);
2685 skb
= dev_alloc_skb(sizeof(struct ieee80211_frame_info
) +
2686 sizeof(struct ieee80211_radar_info
));
2690 skb_reserve(skb
, sizeof(struct ieee80211_frame_info
));
2692 msg
= (struct ieee80211_radar_info
*)
2693 skb_put(skb
, sizeof(struct ieee80211_radar_info
));
2694 msg
->channel
= channel
;
2696 msg
->radar_type
= radar_type
;
2698 ieee80211_rx_mgmt(local
, skb
, NULL
, ieee80211_msg_radar
);
2701 EXPORT_SYMBOL(ieee80211_radar_status
);
2703 int ieee80211_set_aid_for_sta(struct ieee80211_hw
*hw
, u8
*peer_address
,
2706 struct sk_buff
*skb
;
2707 struct ieee80211_msg_set_aid_for_sta
*msg
;
2708 struct ieee80211_local
*local
= hw_to_local(hw
);
2710 /* unlikely because if this event only happens for APs,
2711 * which require an open ap device. */
2712 if (unlikely(!local
->apdev
))
2715 skb
= dev_alloc_skb(sizeof(struct ieee80211_frame_info
) +
2716 sizeof(struct ieee80211_msg_set_aid_for_sta
));
2720 skb_reserve(skb
, sizeof(struct ieee80211_frame_info
));
2722 msg
= (struct ieee80211_msg_set_aid_for_sta
*)
2723 skb_put(skb
, sizeof(struct ieee80211_msg_set_aid_for_sta
));
2724 memcpy(msg
->sta_address
, peer_address
, ETH_ALEN
);
2727 ieee80211_rx_mgmt(local
, skb
, NULL
, ieee80211_msg_set_aid_for_sta
);
2730 EXPORT_SYMBOL(ieee80211_set_aid_for_sta
);
2732 static void ap_sta_ps_start(struct net_device
*dev
, struct sta_info
*sta
)
2734 struct ieee80211_sub_if_data
*sdata
;
2735 sdata
= IEEE80211_DEV_TO_SUB_IF(sta
->dev
);
2738 atomic_inc(&sdata
->bss
->num_sta_ps
);
2739 sta
->flags
|= WLAN_STA_PS
;
2741 #ifdef CONFIG_D80211_VERBOSE_PS_DEBUG
2742 printk(KERN_DEBUG
"%s: STA " MAC_FMT
" aid %d enters power "
2743 "save mode\n", dev
->name
, MAC_ARG(sta
->addr
), sta
->aid
);
2744 #endif /* CONFIG_D80211_VERBOSE_PS_DEBUG */
2748 static int ap_sta_ps_end(struct net_device
*dev
, struct sta_info
*sta
)
2750 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2751 struct sk_buff
*skb
;
2753 struct ieee80211_sub_if_data
*sdata
;
2754 struct ieee80211_tx_packet_data
*pkt_data
;
2756 sdata
= IEEE80211_DEV_TO_SUB_IF(sta
->dev
);
2758 atomic_dec(&sdata
->bss
->num_sta_ps
);
2759 sta
->flags
&= ~(WLAN_STA_PS
| WLAN_STA_TIM
);
2761 if (!skb_queue_empty(&sta
->ps_tx_buf
)) {
2762 if (local
->ops
->set_tim
)
2763 local
->ops
->set_tim(local_to_hw(local
), sta
->aid
, 0);
2765 bss_tim_clear(local
, sdata
->bss
, sta
->aid
);
2767 #ifdef CONFIG_D80211_VERBOSE_PS_DEBUG
2768 printk(KERN_DEBUG
"%s: STA " MAC_FMT
" aid %d exits power "
2769 "save mode\n", dev
->name
, MAC_ARG(sta
->addr
), sta
->aid
);
2770 #endif /* CONFIG_D80211_VERBOSE_PS_DEBUG */
2771 /* Send all buffered frames to the station */
2772 while ((skb
= skb_dequeue(&sta
->tx_filtered
)) != NULL
) {
2773 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
2775 pkt_data
->requeue
= 1;
2776 dev_queue_xmit(skb
);
2778 while ((skb
= skb_dequeue(&sta
->ps_tx_buf
)) != NULL
) {
2779 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
2780 local
->total_ps_buffered
--;
2782 #ifdef CONFIG_D80211_VERBOSE_PS_DEBUG
2783 printk(KERN_DEBUG
"%s: STA " MAC_FMT
" aid %d send PS frame "
2784 "since STA not sleeping anymore\n", dev
->name
,
2785 MAC_ARG(sta
->addr
), sta
->aid
);
2786 #endif /* CONFIG_D80211_VERBOSE_PS_DEBUG */
2787 pkt_data
->requeue
= 1;
2788 dev_queue_xmit(skb
);
2795 static ieee80211_txrx_result
2796 ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data
*rx
)
2798 struct sk_buff
*skb
;
2799 int no_pending_pkts
;
2801 if (likely(!rx
->sta
||
2802 (rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_CTL
||
2803 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_PSPOLL
||
2804 !rx
->u
.rx
.ra_match
))
2805 return TXRX_CONTINUE
;
2807 skb
= skb_dequeue(&rx
->sta
->tx_filtered
);
2809 skb
= skb_dequeue(&rx
->sta
->ps_tx_buf
);
2811 rx
->local
->total_ps_buffered
--;
2813 no_pending_pkts
= skb_queue_empty(&rx
->sta
->tx_filtered
) &&
2814 skb_queue_empty(&rx
->sta
->ps_tx_buf
);
2817 struct ieee80211_hdr
*hdr
=
2818 (struct ieee80211_hdr
*) skb
->data
;
2820 /* tell TX path to send one frame even though the STA may
2821 * still remain is PS mode after this frame exchange */
2822 rx
->sta
->pspoll
= 1;
2824 #ifdef CONFIG_D80211_VERBOSE_PS_DEBUG
2825 printk(KERN_DEBUG
"STA " MAC_FMT
" aid %d: PS Poll (entries "
2827 MAC_ARG(rx
->sta
->addr
), rx
->sta
->aid
,
2828 skb_queue_len(&rx
->sta
->ps_tx_buf
));
2829 #endif /* CONFIG_D80211_VERBOSE_PS_DEBUG */
2831 /* Use MoreData flag to indicate whether there are more
2832 * buffered frames for this STA */
2833 if (no_pending_pkts
) {
2834 hdr
->frame_control
&= cpu_to_le16(~IEEE80211_FCTL_MOREDATA
);
2835 rx
->sta
->flags
&= ~WLAN_STA_TIM
;
2837 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_MOREDATA
);
2839 dev_queue_xmit(skb
);
2841 if (no_pending_pkts
) {
2842 if (rx
->local
->ops
->set_tim
)
2843 rx
->local
->ops
->set_tim(local_to_hw(rx
->local
),
2846 bss_tim_clear(rx
->local
, rx
->sdata
->bss
, rx
->sta
->aid
);
2848 #ifdef CONFIG_D80211_VERBOSE_PS_DEBUG
2849 } else if (!rx
->u
.rx
.sent_ps_buffered
) {
2850 printk(KERN_DEBUG
"%s: STA " MAC_FMT
" sent PS Poll even "
2851 "though there is no buffered frames for it\n",
2852 rx
->dev
->name
, MAC_ARG(rx
->sta
->addr
));
2853 #endif /* CONFIG_D80211_VERBOSE_PS_DEBUG */
2857 /* Free PS Poll skb here instead of returning TXRX_DROP that would
2858 * count as an dropped frame. */
2859 dev_kfree_skb(rx
->skb
);
2865 static inline struct ieee80211_fragment_entry
*
2866 ieee80211_reassemble_add(struct ieee80211_sub_if_data
*sdata
,
2867 unsigned int frag
, unsigned int seq
, int rx_queue
,
2868 struct sk_buff
**skb
)
2870 struct ieee80211_fragment_entry
*entry
;
2873 idx
= sdata
->fragment_next
;
2874 entry
= &sdata
->fragments
[sdata
->fragment_next
++];
2875 if (sdata
->fragment_next
>= IEEE80211_FRAGMENT_MAX
)
2876 sdata
->fragment_next
= 0;
2878 if (!skb_queue_empty(&entry
->skb_list
)) {
2879 #ifdef CONFIG_D80211_DEBUG
2880 struct ieee80211_hdr
*hdr
=
2881 (struct ieee80211_hdr
*) entry
->skb_list
.next
->data
;
2882 printk(KERN_DEBUG
"%s: RX reassembly removed oldest "
2883 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
2884 "addr1=" MAC_FMT
" addr2=" MAC_FMT
"\n",
2885 sdata
->dev
->name
, idx
,
2886 jiffies
- entry
->first_frag_time
, entry
->seq
,
2887 entry
->last_frag
, MAC_ARG(hdr
->addr1
),
2888 MAC_ARG(hdr
->addr2
));
2889 #endif /* CONFIG_D80211_DEBUG */
2890 __skb_queue_purge(&entry
->skb_list
);
2893 __skb_queue_tail(&entry
->skb_list
, *skb
); /* no need for locking */
2895 entry
->first_frag_time
= jiffies
;
2897 entry
->rx_queue
= rx_queue
;
2898 entry
->last_frag
= frag
;
2900 entry
->extra_len
= 0;
2906 static inline struct ieee80211_fragment_entry
*
2907 ieee80211_reassemble_find(struct ieee80211_sub_if_data
*sdata
,
2908 u16 fc
, unsigned int frag
, unsigned int seq
,
2909 int rx_queue
, struct ieee80211_hdr
*hdr
)
2911 struct ieee80211_fragment_entry
*entry
;
2914 idx
= sdata
->fragment_next
;
2915 for (i
= 0; i
< IEEE80211_FRAGMENT_MAX
; i
++) {
2916 struct ieee80211_hdr
*f_hdr
;
2921 idx
= IEEE80211_FRAGMENT_MAX
- 1;
2923 entry
= &sdata
->fragments
[idx
];
2924 if (skb_queue_empty(&entry
->skb_list
) || entry
->seq
!= seq
||
2925 entry
->rx_queue
!= rx_queue
||
2926 entry
->last_frag
+ 1 != frag
)
2929 f_hdr
= (struct ieee80211_hdr
*) entry
->skb_list
.next
->data
;
2930 f_fc
= le16_to_cpu(f_hdr
->frame_control
);
2932 if ((fc
& IEEE80211_FCTL_FTYPE
) != (f_fc
& IEEE80211_FCTL_FTYPE
) ||
2933 memcmp(hdr
->addr1
, f_hdr
->addr1
, ETH_ALEN
) != 0 ||
2934 memcmp(hdr
->addr2
, f_hdr
->addr2
, ETH_ALEN
) != 0)
2937 if (entry
->first_frag_time
+ 2 * HZ
< jiffies
) {
2938 __skb_queue_purge(&entry
->skb_list
);
2948 static ieee80211_txrx_result
2949 ieee80211_rx_h_defragment(struct ieee80211_txrx_data
*rx
)
2951 struct ieee80211_hdr
*hdr
;
2953 unsigned int frag
, seq
;
2954 struct ieee80211_fragment_entry
*entry
;
2955 struct sk_buff
*skb
;
2957 hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
2958 sc
= le16_to_cpu(hdr
->seq_ctrl
);
2959 frag
= sc
& IEEE80211_SCTL_FRAG
;
2961 if (likely((!(rx
->fc
& IEEE80211_FCTL_MOREFRAGS
) && frag
== 0) ||
2962 (rx
->skb
)->len
< 24 ||
2963 is_multicast_ether_addr(hdr
->addr1
))) {
2964 /* not fragmented */
2967 I802_DEBUG_INC(rx
->local
->rx_handlers_fragments
);
2969 seq
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
2972 /* This is the first fragment of a new frame. */
2973 entry
= ieee80211_reassemble_add(rx
->sdata
, frag
, seq
,
2974 rx
->u
.rx
.queue
, &(rx
->skb
));
2975 if (rx
->key
&& rx
->key
->alg
== ALG_CCMP
&&
2976 (rx
->fc
& IEEE80211_FCTL_PROTECTED
)) {
2977 /* Store CCMP PN so that we can verify that the next
2978 * fragment has a sequential PN value. */
2980 memcpy(entry
->last_pn
,
2981 rx
->key
->u
.ccmp
.rx_pn
[rx
->u
.rx
.queue
],
2987 /* This is a fragment for a frame that should already be pending in
2988 * fragment cache. Add this fragment to the end of the pending entry.
2990 entry
= ieee80211_reassemble_find(rx
->sdata
, rx
->fc
, frag
, seq
,
2991 rx
->u
.rx
.queue
, hdr
);
2993 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_defrag
);
2997 /* Verify that MPDUs within one MSDU have sequential PN values.
2998 * (IEEE 802.11i, 8.3.3.4.5) */
3001 u8 pn
[CCMP_PN_LEN
], *rpn
;
3002 if (!rx
->key
|| rx
->key
->alg
!= ALG_CCMP
)
3004 memcpy(pn
, entry
->last_pn
, CCMP_PN_LEN
);
3005 for (i
= CCMP_PN_LEN
- 1; i
>= 0; i
--) {
3010 rpn
= rx
->key
->u
.ccmp
.rx_pn
[rx
->u
.rx
.queue
];
3011 if (memcmp(pn
, rpn
, CCMP_PN_LEN
) != 0) {
3012 printk(KERN_DEBUG
"%s: defrag: CCMP PN not sequential"
3013 " A2=" MAC_FMT
" PN=%02x%02x%02x%02x%02x%02x "
3014 "(expected %02x%02x%02x%02x%02x%02x)\n",
3015 rx
->dev
->name
, MAC_ARG(hdr
->addr2
),
3016 rpn
[0], rpn
[1], rpn
[2], rpn
[3], rpn
[4], rpn
[5],
3017 pn
[0], pn
[1], pn
[2], pn
[3], pn
[4], pn
[5]);
3020 memcpy(entry
->last_pn
, pn
, CCMP_PN_LEN
);
3023 skb_pull(rx
->skb
, ieee80211_get_hdrlen(rx
->fc
));
3024 __skb_queue_tail(&entry
->skb_list
, rx
->skb
);
3025 entry
->last_frag
= frag
;
3026 entry
->extra_len
+= rx
->skb
->len
;
3027 if (rx
->fc
& IEEE80211_FCTL_MOREFRAGS
) {
3032 rx
->skb
= __skb_dequeue(&entry
->skb_list
);
3033 if (skb_tailroom(rx
->skb
) < entry
->extra_len
) {
3034 I802_DEBUG_INC(rx
->local
->rx_expand_skb_head2
);
3035 if (unlikely(pskb_expand_head(rx
->skb
, 0, entry
->extra_len
,
3037 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_defrag
);
3038 __skb_queue_purge(&entry
->skb_list
);
3042 while ((skb
= __skb_dequeue(&entry
->skb_list
)))
3043 memcpy(skb_put(rx
->skb
, skb
->len
), skb
->data
, skb
->len
);
3045 /* Complete frame has been reassembled - process it now */
3050 rx
->sta
->rx_packets
++;
3051 if (is_multicast_ether_addr(hdr
->addr1
))
3052 rx
->local
->dot11MulticastReceivedFrameCount
++;
3054 ieee80211_led_rx(rx
->local
);
3055 return TXRX_CONTINUE
;
3059 static ieee80211_txrx_result
3060 ieee80211_rx_h_monitor(struct ieee80211_txrx_data
*rx
)
3062 if (rx
->sdata
->type
== IEEE80211_IF_TYPE_MNTR
) {
3063 ieee80211_rx_monitor(rx
->dev
, rx
->skb
, rx
->u
.rx
.status
);
3067 return TXRX_CONTINUE
;
3071 static ieee80211_txrx_result
3072 ieee80211_rx_h_check(struct ieee80211_txrx_data
*rx
)
3074 struct ieee80211_hdr
*hdr
;
3076 hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
3078 /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
3079 if (rx
->sta
&& !is_multicast_ether_addr(hdr
->addr1
)) {
3080 if (unlikely(rx
->fc
& IEEE80211_FCTL_RETRY
&&
3081 rx
->sta
->last_seq_ctrl
[rx
->u
.rx
.queue
] ==
3083 if (rx
->u
.rx
.ra_match
) {
3084 rx
->local
->dot11FrameDuplicateCount
++;
3085 rx
->sta
->num_duplicates
++;
3089 rx
->sta
->last_seq_ctrl
[rx
->u
.rx
.queue
] = hdr
->seq_ctrl
;
3092 if ((rx
->local
->hw
.flags
& IEEE80211_HW_RX_INCLUDES_FCS
) &&
3093 rx
->skb
->len
> FCS_LEN
)
3094 skb_trim(rx
->skb
, rx
->skb
->len
- FCS_LEN
);
3096 if (unlikely(rx
->skb
->len
< 16)) {
3097 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_short
);
3101 if (!rx
->u
.rx
.ra_match
)
3102 rx
->skb
->pkt_type
= PACKET_OTHERHOST
;
3103 else if (memcmp(rx
->dev
->dev_addr
, hdr
->addr1
, ETH_ALEN
) == 0)
3104 rx
->skb
->pkt_type
= PACKET_HOST
;
3105 else if (is_multicast_ether_addr(hdr
->addr1
)) {
3106 if (is_broadcast_ether_addr(hdr
->addr1
))
3107 rx
->skb
->pkt_type
= PACKET_BROADCAST
;
3109 rx
->skb
->pkt_type
= PACKET_MULTICAST
;
3111 rx
->skb
->pkt_type
= PACKET_OTHERHOST
;
3113 /* Drop disallowed frame classes based on STA auth/assoc state;
3114 * IEEE 802.11, Chap 5.5.
3116 * 80211.o does filtering only based on association state, i.e., it
3117 * drops Class 3 frames from not associated stations. hostapd sends
3118 * deauth/disassoc frames when needed. In addition, hostapd is
3119 * responsible for filtering on both auth and assoc states.
3121 if (unlikely(((rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
||
3122 ((rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_CTL
&&
3123 (rx
->fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_PSPOLL
)) &&
3124 rx
->sdata
->type
!= IEEE80211_IF_TYPE_IBSS
&&
3125 (!rx
->sta
|| !(rx
->sta
->flags
& WLAN_STA_ASSOC
)))) {
3126 if ((!(rx
->fc
& IEEE80211_FCTL_FROMDS
) &&
3127 !(rx
->fc
& IEEE80211_FCTL_TODS
) &&
3128 (rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
)
3129 || !rx
->u
.rx
.ra_match
) {
3130 /* Drop IBSS frames and frames for other hosts
3135 if (!rx
->local
->apdev
)
3138 ieee80211_rx_mgmt(rx
->local
, rx
->skb
, rx
->u
.rx
.status
,
3139 ieee80211_msg_sta_not_assoc
);
3143 if (rx
->sdata
->type
== IEEE80211_IF_TYPE_STA
)
3148 if (rx
->sta
&& rx
->sta
->key
&& always_sta_key
) {
3149 rx
->key
= rx
->sta
->key
;
3151 if (rx
->sta
&& rx
->sta
->key
)
3152 rx
->key
= rx
->sta
->key
;
3154 rx
->key
= rx
->sdata
->default_key
;
3156 if ((rx
->local
->hw
.flags
& IEEE80211_HW_WEP_INCLUDE_IV
) &&
3157 rx
->fc
& IEEE80211_FCTL_PROTECTED
) {
3158 int keyidx
= ieee80211_wep_get_keyidx(rx
->skb
);
3160 if (keyidx
>= 0 && keyidx
< NUM_DEFAULT_KEYS
&&
3161 (!rx
->sta
|| !rx
->sta
->key
|| keyidx
> 0))
3162 rx
->key
= rx
->sdata
->keys
[keyidx
];
3165 if (!rx
->u
.rx
.ra_match
)
3167 printk(KERN_DEBUG
"%s: RX WEP frame with "
3168 "unknown keyidx %d (A1=" MAC_FMT
" A2="
3169 MAC_FMT
" A3=" MAC_FMT
")\n",
3170 rx
->dev
->name
, keyidx
,
3171 MAC_ARG(hdr
->addr1
),
3172 MAC_ARG(hdr
->addr2
),
3173 MAC_ARG(hdr
->addr3
));
3174 if (!rx
->local
->apdev
)
3177 rx
->local
, rx
->skb
, rx
->u
.rx
.status
,
3178 ieee80211_msg_wep_frame_unknown_key
);
3184 if (rx
->fc
& IEEE80211_FCTL_PROTECTED
&& rx
->key
&& rx
->u
.rx
.ra_match
) {
3185 rx
->key
->tx_rx_count
++;
3186 if (unlikely(rx
->local
->key_tx_rx_threshold
&&
3187 rx
->key
->tx_rx_count
>
3188 rx
->local
->key_tx_rx_threshold
)) {
3189 ieee80211_key_threshold_notify(rx
->dev
, rx
->key
,
3194 return TXRX_CONTINUE
;
3198 static ieee80211_txrx_result
3199 ieee80211_rx_h_sta_process(struct ieee80211_txrx_data
*rx
)
3201 struct sta_info
*sta
= rx
->sta
;
3202 struct net_device
*dev
= rx
->dev
;
3203 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) rx
->skb
->data
;
3206 return TXRX_CONTINUE
;
3208 /* Update last_rx only for IBSS packets which are for the current
3209 * BSSID to avoid keeping the current IBSS network alive in cases where
3210 * other STAs are using different BSSID. */
3211 if (rx
->sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
3212 u8
*bssid
= ieee80211_get_bssid(hdr
, rx
->skb
->len
);
3213 if (memcmp(bssid
, rx
->sdata
->u
.sta
.bssid
, ETH_ALEN
) == 0)
3214 sta
->last_rx
= jiffies
;
3216 if (!is_multicast_ether_addr(hdr
->addr1
) ||
3217 rx
->sdata
->type
== IEEE80211_IF_TYPE_STA
) {
3218 /* Update last_rx only for unicast frames in order to prevent
3219 * the Probe Request frames (the only broadcast frames from a
3220 * STA in infrastructure mode) from keeping a connection alive.
3222 sta
->last_rx
= jiffies
;
3225 if (!rx
->u
.rx
.ra_match
)
3226 return TXRX_CONTINUE
;
3228 sta
->rx_fragments
++;
3229 sta
->rx_bytes
+= rx
->skb
->len
;
3230 sta
->last_rssi
= rx
->u
.rx
.status
->ssi
;
3231 sta
->last_signal
= rx
->u
.rx
.status
->signal
;
3232 sta
->last_noise
= rx
->u
.rx
.status
->noise
;
3234 if (!(rx
->fc
& IEEE80211_FCTL_MOREFRAGS
)) {
3235 /* Change STA power saving mode only in the end of a frame
3236 * exchange sequence */
3237 if ((sta
->flags
& WLAN_STA_PS
) && !(rx
->fc
& IEEE80211_FCTL_PM
))
3238 rx
->u
.rx
.sent_ps_buffered
+= ap_sta_ps_end(dev
, sta
);
3239 else if (!(sta
->flags
& WLAN_STA_PS
) &&
3240 (rx
->fc
& IEEE80211_FCTL_PM
))
3241 ap_sta_ps_start(dev
, sta
);
3244 /* Drop data::nullfunc frames silently, since they are used only to
3245 * control station power saving mode. */
3246 if ((rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
&&
3247 (rx
->fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_NULLFUNC
) {
3248 I802_DEBUG_INC(rx
->local
->rx_handlers_drop_nullfunc
);
3249 /* Update counter and free packet here to avoid counting this
3250 * as a dropped packed. */
3252 dev_kfree_skb(rx
->skb
);
3256 return TXRX_CONTINUE
;
3260 static ieee80211_txrx_result
3261 ieee80211_rx_h_wep_weak_iv_detection(struct ieee80211_txrx_data
*rx
)
3263 if (!rx
->sta
|| !(rx
->fc
& IEEE80211_FCTL_PROTECTED
) ||
3264 (rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
||
3265 !rx
->key
|| rx
->key
->alg
!= ALG_WEP
|| !rx
->u
.rx
.ra_match
)
3266 return TXRX_CONTINUE
;
3268 /* Check for weak IVs, if hwaccel did not remove IV from the frame */
3269 if ((rx
->local
->hw
.flags
& IEEE80211_HW_WEP_INCLUDE_IV
) ||
3270 rx
->key
->force_sw_encrypt
) {
3271 u8
*iv
= ieee80211_wep_is_weak_iv(rx
->skb
, rx
->key
);
3273 rx
->sta
->wep_weak_iv_count
++;
3277 return TXRX_CONTINUE
;
3281 static ieee80211_txrx_result
3282 ieee80211_rx_h_wep_decrypt(struct ieee80211_txrx_data
*rx
)
3284 /* If the device handles decryption totally, skip this test */
3285 if (rx
->local
->hw
.flags
& IEEE80211_HW_DEVICE_HIDES_WEP
)
3286 return TXRX_CONTINUE
;
3288 if ((rx
->key
&& rx
->key
->alg
!= ALG_WEP
) ||
3289 !(rx
->fc
& IEEE80211_FCTL_PROTECTED
) ||
3290 ((rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
&&
3291 ((rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_MGMT
||
3292 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_AUTH
)))
3293 return TXRX_CONTINUE
;
3296 printk(KERN_DEBUG
"%s: RX WEP frame, but no key set\n",
3301 if (!(rx
->u
.rx
.status
->flag
& RX_FLAG_DECRYPTED
) ||
3302 rx
->key
->force_sw_encrypt
) {
3303 if (ieee80211_wep_decrypt(rx
->local
, rx
->skb
, rx
->key
)) {
3304 printk(KERN_DEBUG
"%s: RX WEP frame, decrypt "
3305 "failed\n", rx
->dev
->name
);
3308 } else if (rx
->local
->hw
.flags
& IEEE80211_HW_WEP_INCLUDE_IV
) {
3309 ieee80211_wep_remove_iv(rx
->local
, rx
->skb
, rx
->key
);
3311 skb_trim(rx
->skb
, rx
->skb
->len
- 4);
3314 return TXRX_CONTINUE
;
3318 static ieee80211_txrx_result
3319 ieee80211_rx_h_802_1x_pae(struct ieee80211_txrx_data
*rx
)
3321 if (rx
->sdata
->eapol
&& ieee80211_is_eapol(rx
->skb
) &&
3322 rx
->sdata
->type
!= IEEE80211_IF_TYPE_STA
&& rx
->u
.rx
.ra_match
) {
3323 /* Pass both encrypted and unencrypted EAPOL frames to user
3324 * space for processing. */
3325 if (!rx
->local
->apdev
)
3327 ieee80211_rx_mgmt(rx
->local
, rx
->skb
, rx
->u
.rx
.status
,
3328 ieee80211_msg_normal
);
3332 if (unlikely(rx
->sdata
->ieee802_1x
&&
3333 (rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
&&
3334 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_NULLFUNC
&&
3335 (!rx
->sta
|| !(rx
->sta
->flags
& WLAN_STA_AUTHORIZED
)) &&
3336 !ieee80211_is_eapol(rx
->skb
))) {
3337 #ifdef CONFIG_D80211_DEBUG
3338 struct ieee80211_hdr
*hdr
=
3339 (struct ieee80211_hdr
*) rx
->skb
->data
;
3340 printk(KERN_DEBUG
"%s: dropped frame from " MAC_FMT
3341 " (unauthorized port)\n", rx
->dev
->name
,
3342 MAC_ARG(hdr
->addr2
));
3343 #endif /* CONFIG_D80211_DEBUG */
3347 return TXRX_CONTINUE
;
3351 static ieee80211_txrx_result
3352 ieee80211_rx_h_drop_unencrypted(struct ieee80211_txrx_data
*rx
)
3354 /* If the device handles decryption totally, skip this test */
3355 if (rx
->local
->hw
.flags
& IEEE80211_HW_DEVICE_HIDES_WEP
)
3356 return TXRX_CONTINUE
;
3358 /* Drop unencrypted frames if key is set. */
3359 if (unlikely(!(rx
->fc
& IEEE80211_FCTL_PROTECTED
) &&
3360 (rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
&&
3361 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_NULLFUNC
&&
3362 (rx
->key
|| rx
->sdata
->drop_unencrypted
) &&
3363 (rx
->sdata
->eapol
== 0 ||
3364 !ieee80211_is_eapol(rx
->skb
)))) {
3365 printk(KERN_DEBUG
"%s: RX non-WEP frame, but expected "
3366 "encryption\n", rx
->dev
->name
);
3369 return TXRX_CONTINUE
;
3373 static ieee80211_txrx_result
3374 ieee80211_rx_h_mgmt(struct ieee80211_txrx_data
*rx
)
3376 struct ieee80211_sub_if_data
*sdata
;
3378 if (!rx
->u
.rx
.ra_match
)
3381 sdata
= IEEE80211_DEV_TO_SUB_IF(rx
->dev
);
3382 if ((sdata
->type
== IEEE80211_IF_TYPE_STA
||
3383 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) &&
3384 !rx
->local
->user_space_mlme
) {
3385 ieee80211_sta_rx_mgmt(rx
->dev
, rx
->skb
, rx
->u
.rx
.status
);
3387 /* Management frames are sent to hostapd for processing */
3388 if (!rx
->local
->apdev
)
3390 ieee80211_rx_mgmt(rx
->local
, rx
->skb
, rx
->u
.rx
.status
,
3391 ieee80211_msg_normal
);
3397 static ieee80211_txrx_result
3398 ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data
*rx
)
3400 struct ieee80211_local
*local
= rx
->local
;
3401 struct sk_buff
*skb
= rx
->skb
;
3403 if (unlikely(local
->sta_scanning
!= 0)) {
3404 ieee80211_sta_rx_scan(rx
->dev
, skb
, rx
->u
.rx
.status
);
3408 if ((rx
->fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
)
3409 local
->scan
.txrx_count
++;
3410 if (unlikely(local
->scan
.in_scan
!= 0 &&
3411 rx
->u
.rx
.status
->freq
== local
->scan
.freq
)) {
3412 struct ieee80211_hdr
*hdr
;
3415 local
->scan
.rx_packets
++;
3417 hdr
= (struct ieee80211_hdr
*) skb
->data
;
3418 fc
= le16_to_cpu(hdr
->frame_control
);
3420 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
&&
3421 (fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_BEACON
&&
3422 rx
->dev
== local
->mdev
) {
3423 local
->scan
.rx_beacon
++;
3424 /* Need to trim FCS here because it is normally
3425 * removed only after this passive scan handler. */
3426 if ((rx
->local
->hw
.flags
& IEEE80211_HW_RX_INCLUDES_FCS
) &&
3427 rx
->skb
->len
> FCS_LEN
)
3428 skb_trim(rx
->skb
, rx
->skb
->len
- FCS_LEN
);
3430 if (!rx
->local
->apdev
)
3432 ieee80211_rx_mgmt(rx
->local
, rx
->skb
,
3434 ieee80211_msg_passive_scan
);
3437 I802_DEBUG_INC(local
->rx_handlers_drop_passive_scan
);
3442 if (unlikely(rx
->u
.rx
.in_scan
)) {
3443 /* scanning finished during invoking of handlers */
3444 I802_DEBUG_INC(local
->rx_handlers_drop_passive_scan
);
3448 return TXRX_CONTINUE
;
3452 static u8
* ieee80211_get_bssid(struct ieee80211_hdr
*hdr
, size_t len
)
3459 fc
= le16_to_cpu(hdr
->frame_control
);
3461 switch (fc
& IEEE80211_FCTL_FTYPE
) {
3462 case IEEE80211_FTYPE_DATA
:
3463 switch (fc
& (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) {
3464 case IEEE80211_FCTL_TODS
:
3466 case (IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
):
3468 case IEEE80211_FCTL_FROMDS
:
3474 case IEEE80211_FTYPE_MGMT
:
3476 case IEEE80211_FTYPE_CTL
:
3477 if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_PSPOLL
)
3486 static void ieee80211_rx_michael_mic_report(struct net_device
*dev
,
3487 struct ieee80211_hdr
*hdr
,
3488 struct sta_info
*sta
,
3489 struct ieee80211_txrx_data
*rx
)
3493 hdrlen
= ieee80211_get_hdrlen_from_skb(rx
->skb
);
3494 if (rx
->skb
->len
>= hdrlen
+ 4)
3495 keyidx
= rx
->skb
->data
[hdrlen
+ 3] >> 6;
3499 /* TODO: verify that this is not triggered by fragmented
3500 * frames (hw does not verify MIC for them). */
3501 printk(KERN_DEBUG
"%s: TKIP hwaccel reported Michael MIC "
3502 "failure from " MAC_FMT
" to " MAC_FMT
" keyidx=%d\n",
3503 dev
->name
, MAC_ARG(hdr
->addr2
), MAC_ARG(hdr
->addr1
), keyidx
);
3506 /* Some hardware versions seem to generate incorrect
3507 * Michael MIC reports; ignore them to avoid triggering
3508 * countermeasures. */
3509 printk(KERN_DEBUG
"%s: ignored spurious Michael MIC "
3510 "error for unknown address " MAC_FMT
"\n",
3511 dev
->name
, MAC_ARG(hdr
->addr2
));
3515 if (!(rx
->fc
& IEEE80211_FCTL_PROTECTED
)) {
3516 printk(KERN_DEBUG
"%s: ignored spurious Michael MIC "
3517 "error for a frame with no ISWEP flag (src "
3518 MAC_FMT
")\n", dev
->name
, MAC_ARG(hdr
->addr2
));
3522 if ((rx
->local
->hw
.flags
& IEEE80211_HW_WEP_INCLUDE_IV
) &&
3523 rx
->sdata
->type
== IEEE80211_IF_TYPE_AP
) {
3524 int keyidx
= ieee80211_wep_get_keyidx(rx
->skb
);
3525 /* AP with Pairwise keys support should never receive Michael
3526 * MIC errors for non-zero keyidx because these are reserved
3527 * for group keys and only the AP is sending real multicast
3530 printk(KERN_DEBUG
"%s: ignored Michael MIC error for "
3531 "a frame with non-zero keyidx (%d) (src " MAC_FMT
3532 ")\n", dev
->name
, keyidx
, MAC_ARG(hdr
->addr2
));
3537 if ((rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
&&
3538 ((rx
->fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_MGMT
||
3539 (rx
->fc
& IEEE80211_FCTL_STYPE
) != IEEE80211_STYPE_AUTH
)) {
3540 printk(KERN_DEBUG
"%s: ignored spurious Michael MIC "
3541 "error for a frame that cannot be encrypted "
3542 "(fc=0x%04x) (src " MAC_FMT
")\n",
3543 dev
->name
, rx
->fc
, MAC_ARG(hdr
->addr2
));
3548 union iwreq_data wrqu
;
3549 char *buf
= kmalloc(128, GFP_ATOMIC
);
3553 /* TODO: needed parameters: count, key type, TSC */
3554 sprintf(buf
, "MLME-MICHAELMICFAILURE.indication("
3555 "keyid=%d %scast addr=" MAC_FMT
")",
3556 keyidx
, hdr
->addr1
[0] & 0x01 ? "broad" : "uni",
3557 MAC_ARG(hdr
->addr2
));
3558 memset(&wrqu
, 0, sizeof(wrqu
));
3559 wrqu
.data
.length
= strlen(buf
);
3560 wireless_send_event(rx
->dev
, IWEVCUSTOM
, &wrqu
, buf
);
3564 /* TODO: consider verifying the MIC error report with software
3565 * implementation if we get too many spurious reports from the
3567 if (!rx
->local
->apdev
)
3569 ieee80211_rx_mgmt(rx
->local
, rx
->skb
, rx
->u
.rx
.status
,
3570 ieee80211_msg_michael_mic_failure
);
3574 dev_kfree_skb(rx
->skb
);
3578 static inline ieee80211_txrx_result
__ieee80211_invoke_rx_handlers(
3579 struct ieee80211_local
*local
,
3580 ieee80211_rx_handler
*handlers
,
3581 struct ieee80211_txrx_data
*rx
,
3582 struct sta_info
*sta
)
3584 ieee80211_rx_handler
*handler
;
3585 ieee80211_txrx_result res
= TXRX_DROP
;
3587 for (handler
= handlers
; *handler
!= NULL
; handler
++) {
3588 res
= (*handler
)(rx
);
3589 if (res
!= TXRX_CONTINUE
) {
3590 if (res
== TXRX_DROP
) {
3591 I802_DEBUG_INC(local
->rx_handlers_drop
);
3595 if (res
== TXRX_QUEUED
)
3596 I802_DEBUG_INC(local
->rx_handlers_queued
);
3601 if (res
== TXRX_DROP
) {
3602 dev_kfree_skb(rx
->skb
);
3607 static inline void ieee80211_invoke_rx_handlers(struct ieee80211_local
*local
,
3608 ieee80211_rx_handler
*handlers
,
3609 struct ieee80211_txrx_data
*rx
,
3610 struct sta_info
*sta
)
3612 if (__ieee80211_invoke_rx_handlers(local
, handlers
, rx
, sta
) ==
3614 dev_kfree_skb(rx
->skb
);
3618 * This is the receive path handler. It is called by a low level driver when an
3619 * 802.11 MPDU is received from the hardware.
3621 void __ieee80211_rx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
3622 struct ieee80211_rx_status
*status
)
3624 struct ieee80211_local
*local
= hw_to_local(hw
);
3625 struct ieee80211_sub_if_data
*sdata
;
3626 struct sta_info
*sta
;
3627 struct ieee80211_hdr
*hdr
;
3628 struct ieee80211_txrx_data rx
;
3632 hdr
= (struct ieee80211_hdr
*) skb
->data
;
3633 memset(&rx
, 0, sizeof(rx
));
3637 rx
.u
.rx
.status
= status
;
3638 rx
.fc
= skb
->len
>= 2 ? le16_to_cpu(hdr
->frame_control
) : 0;
3639 type
= rx
.fc
& IEEE80211_FCTL_FTYPE
;
3640 if (type
== IEEE80211_FTYPE_DATA
|| type
== IEEE80211_FTYPE_MGMT
)
3641 local
->dot11ReceivedFragmentCount
++;
3642 multicast
= is_multicast_ether_addr(hdr
->addr1
);
3645 sta
= rx
.sta
= sta_info_get(local
, hdr
->addr2
);
3647 sta
= rx
.sta
= NULL
;
3651 rx
.sdata
= IEEE80211_DEV_TO_SUB_IF(rx
.dev
);
3654 if ((status
->flag
& RX_FLAG_MMIC_ERROR
)) {
3655 ieee80211_rx_michael_mic_report(local
->mdev
, hdr
, sta
, &rx
);
3659 if (unlikely(local
->sta_scanning
|| local
->scan
.in_scan
))
3660 rx
.u
.rx
.in_scan
= 1;
3662 if (__ieee80211_invoke_rx_handlers(local
, local
->rx_pre_handlers
, &rx
,
3663 sta
) != TXRX_CONTINUE
)
3667 if (sta
&& !sta
->assoc_ap
&& !(sta
->flags
& WLAN_STA_WDS
) &&
3668 !local
->iff_promiscs
&& !multicast
) {
3669 rx
.u
.rx
.ra_match
= 1;
3670 ieee80211_invoke_rx_handlers(local
, local
->rx_handlers
, &rx
,
3673 struct ieee80211_sub_if_data
*prev
= NULL
;
3674 struct sk_buff
*skb_new
;
3675 u8
*bssid
= ieee80211_get_bssid(hdr
, skb
->len
);
3677 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
3678 rx
.u
.rx
.ra_match
= 1;
3679 switch (sdata
->type
) {
3680 case IEEE80211_IF_TYPE_STA
:
3683 if (!ieee80211_bssid_match(bssid
,
3684 sdata
->u
.sta
.bssid
)) {
3685 if (!rx
.u
.rx
.in_scan
)
3687 rx
.u
.rx
.ra_match
= 0;
3688 } else if (!multicast
&&
3689 memcmp(sdata
->dev
->dev_addr
,
3690 hdr
->addr1
, ETH_ALEN
) != 0) {
3691 if (!sdata
->promisc
)
3693 rx
.u
.rx
.ra_match
= 0;
3696 case IEEE80211_IF_TYPE_IBSS
:
3699 if (!ieee80211_bssid_match(bssid
,
3700 sdata
->u
.sta
.bssid
)) {
3701 if (!rx
.u
.rx
.in_scan
)
3703 rx
.u
.rx
.ra_match
= 0;
3704 } else if (!multicast
&&
3705 memcmp(sdata
->dev
->dev_addr
,
3706 hdr
->addr1
, ETH_ALEN
) != 0) {
3707 if (!sdata
->promisc
)
3709 rx
.u
.rx
.ra_match
= 0;
3712 ieee80211_ibss_add_sta(local
->mdev
,
3715 /* FIXME: call with sdata->dev */
3717 case IEEE80211_IF_TYPE_AP
:
3719 if (memcmp(sdata
->dev
->dev_addr
,
3720 hdr
->addr1
, ETH_ALEN
) != 0)
3722 } else if (!ieee80211_bssid_match(bssid
,
3723 sdata
->dev
->dev_addr
)) {
3724 if (!rx
.u
.rx
.in_scan
)
3726 rx
.u
.rx
.ra_match
= 0;
3728 if (sdata
->dev
== local
->mdev
&&
3730 /* do not receive anything via
3731 * master device when not scanning */
3734 case IEEE80211_IF_TYPE_WDS
:
3736 (rx
.fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
)
3738 if (memcmp(sdata
->u
.wds
.remote_addr
,
3739 hdr
->addr2
, ETH_ALEN
) != 0)
3745 skb_new
= skb_copy(skb
, GFP_ATOMIC
);
3747 if (net_ratelimit())
3748 printk(KERN_DEBUG
"%s: failed to copy "
3749 "multicast frame for %s",
3750 local
->mdev
->name
, prev
->dev
->name
);
3756 ieee80211_invoke_rx_handlers(local
,
3766 ieee80211_invoke_rx_handlers(local
, local
->rx_handlers
,
3776 EXPORT_SYMBOL(__ieee80211_rx
);
3778 static ieee80211_txrx_result
3779 ieee80211_tx_h_load_stats(struct ieee80211_txrx_data
*tx
)
3781 struct ieee80211_local
*local
= tx
->local
;
3782 struct sk_buff
*skb
= tx
->skb
;
3783 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
3784 u32 load
= 0, hdrtime
;
3786 /* TODO: this could be part of tx_status handling, so that the number
3787 * of retries would be known; TX rate should in that case be stored
3788 * somewhere with the packet */
3790 /* Estimate total channel use caused by this frame */
3792 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
3793 * 1 usec = 1/8 * (1080 / 10) = 13.5 */
3795 if (local
->hw
.conf
.phymode
== MODE_IEEE80211A
||
3796 local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBO
||
3797 local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBOG
||
3798 (local
->hw
.conf
.phymode
== MODE_IEEE80211G
&&
3799 tx
->u
.tx
.rate
->flags
& IEEE80211_RATE_ERP
))
3800 hdrtime
= CHAN_UTIL_HDR_SHORT
;
3802 hdrtime
= CHAN_UTIL_HDR_LONG
;
3805 if (!is_multicast_ether_addr(hdr
->addr1
))
3808 if (tx
->u
.tx
.control
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
)
3809 load
+= 2 * hdrtime
;
3810 else if (tx
->u
.tx
.control
->flags
& IEEE80211_TXCTL_USE_CTS_PROTECT
)
3813 load
+= skb
->len
* tx
->u
.tx
.rate
->rate_inv
;
3815 if (tx
->u
.tx
.extra_frag
) {
3817 for (i
= 0; i
< tx
->u
.tx
.num_extra_frag
; i
++) {
3818 load
+= 2 * hdrtime
;
3819 load
+= tx
->u
.tx
.extra_frag
[i
]->len
*
3820 tx
->u
.tx
.rate
->rate
;
3824 /* Divide channel_use by 8 to avoid wrapping around the counter */
3825 load
>>= CHAN_UTIL_SHIFT
;
3826 local
->channel_use_raw
+= load
;
3828 tx
->sta
->channel_use_raw
+= load
;
3829 tx
->sdata
->channel_use_raw
+= load
;
3831 return TXRX_CONTINUE
;
3835 static ieee80211_txrx_result
3836 ieee80211_rx_h_load_stats(struct ieee80211_txrx_data
*rx
)
3838 struct ieee80211_local
*local
= rx
->local
;
3839 struct sk_buff
*skb
= rx
->skb
;
3840 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
3841 u32 load
= 0, hdrtime
;
3842 struct ieee80211_rate
*rate
;
3845 /* Estimate total channel use caused by this frame */
3847 if (unlikely(local
->num_curr_rates
< 0))
3848 return TXRX_CONTINUE
;
3850 rate
= &local
->curr_rates
[0];
3851 for (i
= 0; i
< local
->num_curr_rates
; i
++) {
3852 if (local
->curr_rates
[i
].val
== rx
->u
.rx
.status
->rate
) {
3853 rate
= &local
->curr_rates
[i
];
3858 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
3859 * 1 usec = 1/8 * (1080 / 10) = 13.5 */
3861 if (local
->hw
.conf
.phymode
== MODE_IEEE80211A
||
3862 local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBO
||
3863 local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBOG
||
3864 (local
->hw
.conf
.phymode
== MODE_IEEE80211G
&&
3865 rate
->flags
& IEEE80211_RATE_ERP
))
3866 hdrtime
= CHAN_UTIL_HDR_SHORT
;
3868 hdrtime
= CHAN_UTIL_HDR_LONG
;
3871 if (!is_multicast_ether_addr(hdr
->addr1
))
3874 load
+= skb
->len
* rate
->rate_inv
;
3876 /* Divide channel_use by 8 to avoid wrapping around the counter */
3877 load
>>= CHAN_UTIL_SHIFT
;
3878 local
->channel_use_raw
+= load
;
3880 rx
->sta
->channel_use_raw
+= load
;
3881 rx
->u
.rx
.load
= load
;
3883 return TXRX_CONTINUE
;
3886 static ieee80211_txrx_result
3887 ieee80211_rx_h_if_stats(struct ieee80211_txrx_data
*rx
)
3889 rx
->sdata
->channel_use_raw
+= rx
->u
.rx
.load
;
3890 return TXRX_CONTINUE
;
3893 static void ieee80211_stat_refresh(unsigned long data
)
3895 struct ieee80211_local
*local
= (struct ieee80211_local
*) data
;
3896 struct sta_info
*sta
;
3897 struct ieee80211_sub_if_data
*sdata
;
3899 if (!local
->stat_time
)
3902 /* go through all stations */
3903 spin_lock_bh(&local
->sta_lock
);
3904 list_for_each_entry(sta
, &local
->sta_list
, list
) {
3905 sta
->channel_use
= (sta
->channel_use_raw
/ local
->stat_time
) /
3907 sta
->channel_use_raw
= 0;
3909 spin_unlock_bh(&local
->sta_lock
);
3911 /* go through all subinterfaces */
3912 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
3913 sdata
->channel_use
= (sdata
->channel_use_raw
/
3914 local
->stat_time
) / CHAN_UTIL_PER_10MS
;
3915 sdata
->channel_use_raw
= 0;
3918 /* hardware interface */
3919 local
->channel_use
= (local
->channel_use_raw
/
3920 local
->stat_time
) / CHAN_UTIL_PER_10MS
;
3921 local
->channel_use_raw
= 0;
3923 local
->stat_timer
.expires
= jiffies
+ HZ
* local
->stat_time
/ 100;
3924 add_timer(&local
->stat_timer
);
3928 /* This is a version of the rx handler that can be called from hard irq
3929 * context. Post the skb on the queue and schedule the tasklet */
3930 void ieee80211_rx_irqsafe(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
3931 struct ieee80211_rx_status
*status
)
3933 struct ieee80211_rx_status
*saved
;
3934 struct ieee80211_local
*local
= hw_to_local(hw
);
3936 skb
->dev
= local
->mdev
;
3937 saved
= kmalloc(sizeof(struct ieee80211_rx_status
), GFP_ATOMIC
);
3938 if (unlikely(!saved
)) {
3939 if (net_ratelimit())
3940 printk(KERN_WARNING
"%s: Not enough memory, "
3941 "dropping packet", skb
->dev
->name
);
3942 /* should be dev_kfree_skb_irq, but due to this function being
3943 * named _irqsafe instead of just _irq we can't be sure that
3944 * people won't call it from non-irq contexts */
3945 dev_kfree_skb_any(skb
);
3948 memcpy(saved
, status
, sizeof(struct ieee80211_rx_status
));
3949 /* copy pointer to saved status into skb->cb for use by tasklet */
3950 memcpy(skb
->cb
, &saved
, sizeof(saved
));
3952 skb
->pkt_type
= ieee80211_rx_msg
;
3953 skb_queue_tail(&local
->skb_queue
, skb
);
3954 tasklet_schedule(&local
->tasklet
);
3956 EXPORT_SYMBOL(ieee80211_rx_irqsafe
);
3958 void ieee80211_tx_status_irqsafe(struct ieee80211_hw
*hw
,
3959 struct sk_buff
*skb
,
3960 struct ieee80211_tx_status
*status
)
3962 struct ieee80211_local
*local
= hw_to_local(hw
);
3963 struct ieee80211_tx_status
*saved
;
3966 skb
->dev
= local
->mdev
;
3967 saved
= kmalloc(sizeof(struct ieee80211_tx_status
), GFP_ATOMIC
);
3968 if (unlikely(!saved
)) {
3969 if (net_ratelimit())
3970 printk(KERN_WARNING
"%s: Not enough memory, "
3971 "dropping tx status", skb
->dev
->name
);
3972 /* should be dev_kfree_skb_irq, but due to this function being
3973 * named _irqsafe instead of just _irq we can't be sure that
3974 * people won't call it from non-irq contexts */
3975 dev_kfree_skb_any(skb
);
3978 memcpy(saved
, status
, sizeof(struct ieee80211_tx_status
));
3979 /* copy pointer to saved status into skb->cb for use by tasklet */
3980 memcpy(skb
->cb
, &saved
, sizeof(saved
));
3982 skb
->pkt_type
= ieee80211_tx_status_msg
;
3983 skb_queue_tail(status
->control
.flags
& IEEE80211_TXCTL_REQ_TX_STATUS
?
3984 &local
->skb_queue
: &local
->skb_queue_unreliable
, skb
);
3985 tmp
= skb_queue_len(&local
->skb_queue
) +
3986 skb_queue_len(&local
->skb_queue_unreliable
);
3987 while (tmp
> IEEE80211_IRQSAFE_QUEUE_LIMIT
&&
3988 (skb
= skb_dequeue(&local
->skb_queue_unreliable
))) {
3989 memcpy(&saved
, skb
->cb
, sizeof(saved
));
3991 dev_kfree_skb_irq(skb
);
3993 I802_DEBUG_INC(local
->tx_status_drop
);
3995 tasklet_schedule(&local
->tasklet
);
3997 EXPORT_SYMBOL(ieee80211_tx_status_irqsafe
);
3999 static void ieee80211_tasklet_handler(unsigned long data
)
4001 struct ieee80211_local
*local
= (struct ieee80211_local
*) data
;
4002 struct sk_buff
*skb
;
4003 struct ieee80211_rx_status
*rx_status
;
4004 struct ieee80211_tx_status
*tx_status
;
4006 while ((skb
= skb_dequeue(&local
->skb_queue
)) ||
4007 (skb
= skb_dequeue(&local
->skb_queue_unreliable
))) {
4008 switch (skb
->pkt_type
) {
4009 case ieee80211_rx_msg
:
4010 /* get pointer to saved status out of skb->cb */
4011 memcpy(&rx_status
, skb
->cb
, sizeof(rx_status
));
4012 /* Clear skb->type in order to not confuse kernel
4015 __ieee80211_rx(local_to_hw(local
), skb
, rx_status
);
4018 case ieee80211_tx_status_msg
:
4019 /* get pointer to saved status out of skb->cb */
4020 memcpy(&tx_status
, skb
->cb
, sizeof(tx_status
));
4022 ieee80211_tx_status(local_to_hw(local
),
4026 default: /* should never get here! */
4027 printk(KERN_ERR
"%s: Unknown message type (%d)\n",
4028 local
->mdev
->name
, skb
->pkt_type
);
4036 /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
4037 * make a prepared TX frame (one that has been given to hw) to look like brand
4038 * new IEEE 802.11 frame that is ready to go through TX processing again.
4039 * Also, tx_packet_data in cb is restored from tx_control. */
4040 static void ieee80211_remove_tx_extra(struct ieee80211_local
*local
,
4041 struct ieee80211_key
*key
,
4042 struct sk_buff
*skb
,
4043 struct ieee80211_tx_control
*control
)
4045 int hdrlen
, iv_len
, mic_len
;
4046 struct ieee80211_tx_packet_data
*pkt_data
;
4048 pkt_data
= (struct ieee80211_tx_packet_data
*)skb
->cb
;
4049 pkt_data
->ifindex
= control
->ifindex
;
4050 pkt_data
->mgmt_iface
= (control
->type
== IEEE80211_IF_TYPE_MGMT
);
4051 pkt_data
->req_tx_status
= !!(control
->flags
& IEEE80211_TXCTL_REQ_TX_STATUS
);
4052 pkt_data
->do_not_encrypt
= !!(control
->flags
& IEEE80211_TXCTL_DO_NOT_ENCRYPT
);
4053 pkt_data
->pkt_probe_resp
= (control
->pkt_type
== PKT_PROBE_RESP
);
4054 pkt_data
->requeue
= !!(control
->flags
& IEEE80211_TXCTL_REQUEUE
);
4055 pkt_data
->queue
= control
->queue
;
4057 hdrlen
= ieee80211_get_hdrlen_from_skb(skb
);
4064 iv_len
= WEP_IV_LEN
;
4065 mic_len
= WEP_ICV_LEN
;
4068 iv_len
= TKIP_IV_LEN
;
4069 mic_len
= TKIP_ICV_LEN
;
4072 iv_len
= CCMP_HDR_LEN
;
4073 mic_len
= CCMP_MIC_LEN
;
4079 if (skb
->len
>= mic_len
&& key
->force_sw_encrypt
)
4080 skb_trim(skb
, skb
->len
- mic_len
);
4081 if (skb
->len
>= iv_len
&& skb
->len
> hdrlen
) {
4082 memmove(skb
->data
+ iv_len
, skb
->data
, hdrlen
);
4083 skb_pull(skb
, iv_len
);
4088 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
4089 u16 fc
= le16_to_cpu(hdr
->frame_control
);
4090 if ((fc
& 0x8C) == 0x88) /* QoS Control Field */ {
4091 fc
&= ~IEEE80211_STYPE_QOS_DATA
;
4092 hdr
->frame_control
= cpu_to_le16(fc
);
4093 memmove(skb
->data
+ 2, skb
->data
, hdrlen
- 2);
4100 void ieee80211_tx_status(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
4101 struct ieee80211_tx_status
*status
)
4103 struct sk_buff
*skb2
;
4104 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
4105 struct ieee80211_local
*local
= hw_to_local(hw
);
4111 "%s: ieee80211_tx_status called with NULL status\n",
4117 if (status
->excessive_retries
) {
4118 struct sta_info
*sta
;
4119 sta
= sta_info_get(local
, hdr
->addr1
);
4121 if (sta
->flags
& WLAN_STA_PS
) {
4122 /* The STA is in power save mode, so assume
4123 * that this TX packet failed because of that.
4125 status
->excessive_retries
= 0;
4126 status
->flags
|= IEEE80211_TX_STATUS_TX_FILTERED
;
4132 if (status
->flags
& IEEE80211_TX_STATUS_TX_FILTERED
) {
4133 struct sta_info
*sta
;
4134 sta
= sta_info_get(local
, hdr
->addr1
);
4136 sta
->tx_filtered_count
++;
4138 /* Clear the TX filter mask for this STA when sending
4139 * the next packet. If the STA went to power save mode,
4140 * this will happen when it is waking up for the next
4142 sta
->clear_dst_mask
= 1;
4144 /* TODO: Is the WLAN_STA_PS flag always set here or is
4145 * the race between RX and TX status causing some
4146 * packets to be filtered out before 80211.o gets an
4147 * update for PS status? This seems to be the case, so
4148 * no changes are likely to be needed. */
4149 if (sta
->flags
& WLAN_STA_PS
&&
4150 skb_queue_len(&sta
->tx_filtered
) <
4151 STA_MAX_TX_BUFFER
) {
4152 ieee80211_remove_tx_extra(local
, sta
->key
,
4155 skb_queue_tail(&sta
->tx_filtered
, skb
);
4156 } else if (!(sta
->flags
& WLAN_STA_PS
) &&
4157 !(status
->control
.flags
& IEEE80211_TXCTL_REQUEUE
)) {
4158 /* Software retry the packet once */
4159 status
->control
.flags
|= IEEE80211_TXCTL_REQUEUE
;
4160 ieee80211_remove_tx_extra(local
, sta
->key
,
4163 dev_queue_xmit(skb
);
4165 if (net_ratelimit()) {
4166 printk(KERN_DEBUG
"%s: dropped TX "
4167 "filtered frame queue_len=%d "
4172 !!(sta
->flags
& WLAN_STA_PS
),
4181 /* FIXME: STUPID to call this with both local and local->mdev */
4182 rate_control_tx_status(local
, local
->mdev
, skb
, status
);
4185 ieee80211_led_tx(local
, 0);
4188 * Fragments are passed to low-level drivers as separate skbs, so these
4189 * are actually fragments, not frames. Update frame counters only for
4190 * the first fragment of the frame. */
4192 frag
= le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_FRAG
;
4193 type
= le16_to_cpu(hdr
->frame_control
) & IEEE80211_FCTL_FTYPE
;
4195 if (status
->flags
& IEEE80211_TX_STATUS_ACK
) {
4197 local
->dot11TransmittedFrameCount
++;
4198 if (is_multicast_ether_addr(hdr
->addr1
))
4199 local
->dot11MulticastTransmittedFrameCount
++;
4200 if (status
->retry_count
> 0)
4201 local
->dot11RetryCount
++;
4202 if (status
->retry_count
> 1)
4203 local
->dot11MultipleRetryCount
++;
4206 /* This counter shall be incremented for an acknowledged MPDU
4207 * with an individual address in the address 1 field or an MPDU
4208 * with a multicast address in the address 1 field of type Data
4210 if (!is_multicast_ether_addr(hdr
->addr1
) ||
4211 type
== IEEE80211_FTYPE_DATA
||
4212 type
== IEEE80211_FTYPE_MGMT
)
4213 local
->dot11TransmittedFragmentCount
++;
4216 local
->dot11FailedCount
++;
4219 if (!(status
->control
.flags
& IEEE80211_TXCTL_REQ_TX_STATUS
)
4220 || unlikely(!local
->apdev
)) {
4225 msg_type
= (status
->flags
& IEEE80211_TX_STATUS_ACK
) ?
4226 ieee80211_msg_tx_callback_ack
: ieee80211_msg_tx_callback_fail
;
4228 /* skb was the original skb used for TX. Clone it and give the clone
4229 * to netif_rx(). Free original skb. */
4230 skb2
= skb_copy(skb
, GFP_ATOMIC
);
4238 /* Send frame to hostapd */
4239 ieee80211_rx_mgmt(local
, skb
, NULL
, msg_type
);
4241 EXPORT_SYMBOL(ieee80211_tx_status
);
4243 /* TODO: implement register/unregister functions for adding TX/RX handlers
4244 * into ordered list */
4246 /* rx_pre handlers don't have dev and sdata fields available in
4247 * ieee80211_txrx_data */
4248 static ieee80211_rx_handler ieee80211_rx_pre_handlers
[] =
4250 ieee80211_rx_h_parse_qos
,
4251 ieee80211_rx_h_load_stats
,
4255 static ieee80211_rx_handler ieee80211_rx_handlers
[] =
4257 ieee80211_rx_h_if_stats
,
4258 ieee80211_rx_h_monitor
,
4259 ieee80211_rx_h_passive_scan
,
4260 ieee80211_rx_h_check
,
4261 ieee80211_rx_h_sta_process
,
4262 ieee80211_rx_h_ccmp_decrypt
,
4263 ieee80211_rx_h_tkip_decrypt
,
4264 ieee80211_rx_h_wep_weak_iv_detection
,
4265 ieee80211_rx_h_wep_decrypt
,
4266 ieee80211_rx_h_defragment
,
4267 ieee80211_rx_h_ps_poll
,
4268 ieee80211_rx_h_michael_mic_verify
,
4269 /* this must be after decryption - so header is counted in MPDU mic
4270 * must be before pae and data, so QOS_DATA format frames
4271 * are not passed to user space by these functions
4273 ieee80211_rx_h_remove_qos_control
,
4274 ieee80211_rx_h_802_1x_pae
,
4275 ieee80211_rx_h_drop_unencrypted
,
4276 ieee80211_rx_h_data
,
4277 ieee80211_rx_h_mgmt
,
4281 static ieee80211_tx_handler ieee80211_tx_handlers
[] =
4283 ieee80211_tx_h_check_assoc
,
4284 ieee80211_tx_h_ps_buf
,
4285 ieee80211_tx_h_select_key
,
4286 ieee80211_tx_h_michael_mic_add
,
4287 ieee80211_tx_h_fragment
,
4288 ieee80211_tx_h_tkip_encrypt
,
4289 ieee80211_tx_h_ccmp_encrypt
,
4290 ieee80211_tx_h_wep_encrypt
,
4291 ieee80211_tx_h_rate_ctrl
,
4292 ieee80211_tx_h_misc
,
4293 ieee80211_tx_h_load_stats
,
4298 int ieee80211_if_update_wds(struct net_device
*dev
, u8
*remote_addr
)
4300 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
4301 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4302 struct sta_info
*sta
;
4304 /* Remove STA entry for the old peer */
4305 sta
= sta_info_get(local
, sdata
->u
.wds
.remote_addr
);
4308 sta_info_free(sta
, 0);
4310 printk(KERN_DEBUG
"%s: could not find STA entry for WDS link "
4311 "peer " MAC_FMT
"\n",
4312 dev
->name
, MAC_ARG(sdata
->u
.wds
.remote_addr
));
4315 /* Update WDS link data */
4316 memcpy(&sdata
->u
.wds
.remote_addr
, remote_addr
, ETH_ALEN
);
4321 /* Must not be called for mdev and apdev */
4322 void ieee80211_if_setup(struct net_device
*dev
)
4325 dev
->hard_start_xmit
= ieee80211_subif_start_xmit
;
4326 dev
->wireless_handlers
=
4327 (struct iw_handler_def
*) &ieee80211_iw_handler_def
;
4328 dev
->do_ioctl
= ieee80211_ioctl
;
4329 dev
->set_mac_address
= ieee80211_set_mac_address
;
4330 dev
->set_multicast_list
= ieee80211_set_multicast_list
;
4331 dev
->change_mtu
= ieee80211_change_mtu
;
4332 dev
->tx_timeout
= ieee80211_tx_timeout
;
4333 dev
->get_stats
= ieee80211_get_stats
;
4334 dev
->open
= ieee80211_open
;
4335 dev
->stop
= ieee80211_stop
;
4336 dev
->tx_queue_len
= 0;
4337 dev
->destructor
= ieee80211_if_free
;
4340 void ieee80211_if_mgmt_setup(struct net_device
*dev
)
4343 dev
->hard_start_xmit
= ieee80211_mgmt_start_xmit
;
4344 dev
->change_mtu
= ieee80211_change_mtu_apdev
;
4345 dev
->get_stats
= ieee80211_get_stats
;
4346 dev
->open
= ieee80211_mgmt_open
;
4347 dev
->stop
= ieee80211_mgmt_stop
;
4348 dev
->type
= ARPHRD_IEEE80211_PRISM
;
4349 dev
->hard_header_parse
= header_parse_80211
;
4350 dev
->tx_queue_len
= 0;
4351 dev
->destructor
= ieee80211_if_free
;
4354 static void ieee80211_precalc_modes(struct ieee80211_local
*local
)
4356 struct ieee80211_hw_modes
*mode
;
4357 struct ieee80211_rate
*rate
;
4358 struct ieee80211_hw
*hw
= &local
->hw
;
4361 local
->hw_modes
= 0;
4362 for (m
= 0; m
< hw
->num_modes
; m
++) {
4363 mode
= &hw
->modes
[m
];
4364 local
->hw_modes
|= 1 << mode
->mode
;
4365 for (r
= 0; r
< mode
->num_rates
; r
++) {
4366 rate
= &mode
->rates
[r
];
4367 rate
->rate_inv
= CHAN_UTIL_RATE_LCM
/ rate
->rate
;
4372 int ieee80211_init_rate_ctrl_alg(struct ieee80211_local
*local
,
4375 struct rate_control_ref
*ref
, *old
;
4379 if (local
->open_count
|| netif_running(local
->mdev
) ||
4380 (local
->apdev
&& netif_running(local
->apdev
)))
4383 ref
= rate_control_alloc(name
, local
);
4385 printk(KERN_WARNING
"%s: Failed to select rate control "
4386 "algorithm\n", local
->mdev
->name
);
4389 res
= rate_control_add_attrs(ref
, &local
->class_dev
.kobj
);
4391 printk(KERN_DEBUG
"%s: Failed to register sysfs attributes "
4392 "for rate control\n", local
->mdev
->name
);
4393 rate_control_put(ref
);
4397 old
= local
->rate_ctrl
;
4398 local
->rate_ctrl
= ref
;
4400 rate_control_remove_attrs(ref
, &local
->class_dev
.kobj
);
4401 rate_control_put(old
);
4402 sta_info_flush(local
, NULL
);
4405 printk(KERN_DEBUG
"%s: Selected rate control "
4406 "algorithm '%s'\n", local
->mdev
->name
,
4413 static void rate_control_deinitialize(struct ieee80211_local
*local
)
4415 struct rate_control_ref
*ref
;
4417 ref
= local
->rate_ctrl
;
4418 local
->rate_ctrl
= NULL
;
4419 rate_control_remove_attrs(ref
, &local
->class_dev
.kobj
);
4420 rate_control_put(ref
);
4423 struct ieee80211_hw
*ieee80211_alloc_hw(size_t priv_data_len
,
4424 struct ieee80211_ops
*ops
)
4426 struct net_device
*mdev
;
4427 struct ieee80211_local
*local
;
4428 struct ieee80211_sub_if_data
*sdata
;
4431 local
= ieee80211_dev_alloc(GFP_KERNEL
);
4437 /* Ensure 32-byte alignment of our private data and hw private data.
4438 * Each net_device is followed by a sub_if_data which is used for
4439 * interface specific information.
4441 * Sample memory map looks something like:
4443 * 0000 *****************
4445 * 0160 *****************
4447 * 0b80 *****************
4449 * 1664 *****************
4451 priv_size
= ((sizeof(struct ieee80211_sub_if_data
) +
4452 NETDEV_ALIGN_CONST
) & ~NETDEV_ALIGN_CONST
) +
4454 mdev
= alloc_netdev(priv_size
, "wmaster%d", ether_setup
);
4456 ieee80211_dev_free(local
);
4460 mdev
->ieee80211_ptr
= local
;
4461 local
->hw
.priv
= (char *)mdev
->priv
+
4462 ((sizeof(struct ieee80211_sub_if_data
) +
4463 NETDEV_ALIGN_CONST
) & ~NETDEV_ALIGN_CONST
);
4466 local
->rx_pre_handlers
= ieee80211_rx_pre_handlers
;
4467 local
->rx_handlers
= ieee80211_rx_handlers
;
4468 local
->tx_handlers
= ieee80211_tx_handlers
;
4470 local
->bridge_packets
= 1;
4472 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
4473 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
4474 local
->short_retry_limit
= 7;
4475 local
->long_retry_limit
= 4;
4476 local
->hw
.conf
.radio_enabled
= 1;
4477 local
->rate_ctrl_num_up
= RATE_CONTROL_NUM_UP
;
4478 local
->rate_ctrl_num_down
= RATE_CONTROL_NUM_DOWN
;
4480 local
->scan
.in_scan
= 0;
4481 local
->enabled_modes
= (unsigned int) -1;
4483 init_timer(&local
->scan
.timer
); /* clear it out */
4485 spin_lock_init(&local
->sub_if_lock
);
4486 INIT_LIST_HEAD(&local
->sub_if_list
);
4488 spin_lock_init(&local
->generic_lock
);
4489 init_timer(&local
->stat_timer
);
4490 local
->stat_timer
.function
= ieee80211_stat_refresh
;
4491 local
->stat_timer
.data
= (unsigned long) local
;
4492 ieee80211_rx_bss_list_init(mdev
);
4494 sta_info_init(local
);
4496 mdev
->hard_start_xmit
= ieee80211_master_start_xmit
;
4497 mdev
->wireless_handlers
=
4498 (struct iw_handler_def
*) &ieee80211_iw_master_handler_def
;
4499 mdev
->do_ioctl
= ieee80211_ioctl
;
4500 mdev
->change_mtu
= ieee80211_change_mtu
;
4501 mdev
->tx_timeout
= ieee80211_tx_timeout
;
4502 mdev
->get_stats
= ieee80211_get_stats
;
4503 mdev
->open
= ieee80211_master_open
;
4504 mdev
->stop
= ieee80211_master_stop
;
4505 mdev
->type
= ARPHRD_IEEE80211
;
4506 mdev
->hard_header_parse
= header_parse_80211
;
4508 sdata
= IEEE80211_DEV_TO_SUB_IF(mdev
);
4509 sdata
->type
= IEEE80211_IF_TYPE_AP
;
4511 sdata
->local
= local
;
4512 sdata
->u
.ap
.force_unicast_rateidx
= -1;
4513 sdata
->u
.ap
.max_ratectrl_rateidx
= -1;
4514 ieee80211_if_sdata_init(sdata
);
4515 list_add_tail(&sdata
->list
, &local
->sub_if_list
);
4517 tasklet_init(&local
->tx_pending_tasklet
, ieee80211_tx_pending
,
4518 (unsigned long)local
);
4519 tasklet_disable(&local
->tx_pending_tasklet
);
4521 tasklet_init(&local
->tasklet
,
4522 ieee80211_tasklet_handler
,
4523 (unsigned long) local
);
4524 skb_queue_head_init(&local
->skb_queue
);
4525 skb_queue_head_init(&local
->skb_queue_unreliable
);
4527 return local_to_hw(local
);
4529 EXPORT_SYMBOL(ieee80211_alloc_hw
);
4531 int ieee80211_register_hw(struct ieee80211_hw
*hw
)
4533 struct ieee80211_local
*local
= hw_to_local(hw
);
4534 struct net_device
*sta_dev
;
4537 result
= ieee80211_dev_alloc_index(local
);
4541 local
->class_dev
.dev
= local
->hw
.dev
;
4543 result
= ieee80211_dev_sysfs_add(local
);
4547 local
->hw
.conf
.beacon_int
= 1000;
4549 /* Don't care about the result */
4550 ieee80211_update_hw(local_to_hw(local
));
4552 result
= sta_info_start(local
);
4556 if (hw
->flags
& IEEE80211_HW_FRAGLIST
)
4557 local
->mdev
->features
|= NETIF_F_FRAGLIST
;
4559 result
= dev_alloc_name(local
->mdev
, local
->mdev
->name
);
4565 memcpy(local
->mdev
->dev_addr
, local
->hw
.perm_addr
, ETH_ALEN
);
4566 SET_NETDEV_DEV(local
->mdev
, local
->hw
.dev
);
4568 result
= register_netdevice(local
->mdev
);
4573 result
= sysfs_create_link(&local
->class_dev
.kobj
,
4574 &local
->mdev
->class_dev
.kobj
,
4578 goto fail_masterlink
;
4580 result
= ieee80211_sysfs_add_netdevice(local
->mdev
);
4586 result
= ieee80211_init_rate_ctrl_alg(local
, NULL
);
4589 printk(KERN_DEBUG
"%s: Failed to initialize rate control "
4590 "algorithm\n", local
->mdev
->name
);
4594 result
= ieee80211_wep_init(local
);
4597 printk(KERN_DEBUG
"%s: Failed to initialize wep\n",
4602 /* TODO: add rtnl locking around device creation and qdisc install */
4603 ieee80211_install_qdisc(local
->mdev
);
4605 /* add one default STA interface */
4607 result
= ieee80211_if_add(local
->mdev
, "wlan%d", 1, &sta_dev
);
4609 ieee80211_if_set_type(sta_dev
, IEEE80211_IF_TYPE_STA
);
4611 local
->reg_state
= IEEE80211_DEV_REGISTERED
;
4614 ieee80211_led_init(local
);
4619 rate_control_deinitialize(local
);
4621 ieee80211_sysfs_remove_netdevice(local
->mdev
);
4623 sysfs_remove_link(&local
->class_dev
.kobj
, "master");
4625 unregister_netdev(local
->mdev
);
4627 sta_info_stop(local
);
4629 ieee80211_dev_sysfs_del(local
);
4631 ieee80211_dev_free_index(local
);
4634 EXPORT_SYMBOL(ieee80211_register_hw
);
4636 int ieee80211_update_hw(struct ieee80211_hw
*hw
)
4638 struct ieee80211_local
*local
= hw_to_local(hw
);
4640 /* Backwards compatibility for low-level drivers that do not set number
4642 if (hw
->queues
== 0)
4645 if (!hw
->modes
|| !hw
->modes
->channels
|| !hw
->modes
->rates
||
4646 !hw
->modes
->num_channels
|| !hw
->modes
->num_rates
)
4649 ieee80211_precalc_modes(local
);
4650 local
->hw
.conf
.phymode
= hw
->modes
[0].mode
;
4651 local
->curr_rates
= hw
->modes
[0].rates
;
4652 local
->num_curr_rates
= hw
->modes
[0].num_rates
;
4653 ieee80211_prepare_rates(local
);
4655 local
->hw
.conf
.freq
= local
->hw
.modes
[0].channels
[0].freq
;
4656 local
->hw
.conf
.channel
= local
->hw
.modes
[0].channels
[0].chan
;
4657 local
->hw
.conf
.channel_val
= local
->hw
.modes
[0].channels
[0].val
;
4659 ieee80211_init_client(local
->mdev
);
4660 /* FIXME: Invoke config to allow driver to set the channel. */
4664 EXPORT_SYMBOL(ieee80211_update_hw
);
4666 void ieee80211_unregister_hw(struct ieee80211_hw
*hw
)
4668 struct ieee80211_local
*local
= hw_to_local(hw
);
4669 struct ieee80211_sub_if_data
*sdata
, *tmp
;
4672 tasklet_disable(&local
->tasklet
);
4673 /* TODO: skb_queue should be empty here, no need to do anything? */
4676 local
->reg_state
= IEEE80211_DEV_UNREGISTERED
;
4678 ieee80211_if_del_mgmt(local
);
4680 sysfs_remove_link(&local
->class_dev
.kobj
, "master");
4682 list_for_each_entry_safe(sdata
, tmp
, &local
->sub_if_list
, list
)
4683 __ieee80211_if_del(local
, sdata
);
4687 if (local
->stat_time
)
4688 del_timer_sync(&local
->stat_timer
);
4689 if (local
->scan_work
.data
) {
4690 local
->sta_scanning
= 0;
4691 cancel_delayed_work(&local
->scan_work
);
4692 flush_scheduled_work();
4693 /* The scan_work is guaranteed not to be called at this
4694 * point. It is not scheduled and not running now. It can be
4695 * scheduled again only by sta_work (stopped by now) or under
4699 ieee80211_rx_bss_list_deinit(local
->mdev
);
4700 ieee80211_clear_tx_pending(local
);
4701 sta_info_stop(local
);
4702 rate_control_deinitialize(local
);
4703 ieee80211_dev_sysfs_del(local
);
4705 for (i
= 0; i
< NUM_IEEE80211_MODES
; i
++) {
4706 kfree(local
->supp_rates
[i
]);
4707 kfree(local
->basic_rates
[i
]);
4710 if (skb_queue_len(&local
->skb_queue
)
4711 || skb_queue_len(&local
->skb_queue_unreliable
))
4712 printk(KERN_WARNING
"%s: skb_queue not empty",
4714 skb_queue_purge(&local
->skb_queue
);
4715 skb_queue_purge(&local
->skb_queue_unreliable
);
4717 ieee80211_dev_free_index(local
);
4718 ieee80211_led_exit(local
);
4720 EXPORT_SYMBOL(ieee80211_unregister_hw
);
4722 void ieee80211_free_hw(struct ieee80211_hw
*hw
)
4724 struct ieee80211_local
*local
= hw_to_local(hw
);
4726 ieee80211_if_free(local
->mdev
);
4727 ieee80211_wep_free(local
);
4728 ieee80211_dev_free(local
);
4730 EXPORT_SYMBOL(ieee80211_free_hw
);
4732 void ieee80211_release_hw(struct ieee80211_local
*local
)
4737 /* Perform netif operations on all configured interfaces */
4738 int ieee80211_netif_oper(struct ieee80211_hw
*hw
, Netif_Oper op
)
4740 struct ieee80211_local
*local
= hw_to_local(hw
);
4741 struct net_device
*dev
= local
->mdev
;
4745 netif_device_attach(dev
);
4748 netif_device_detach(dev
);
4751 netif_start_queue(dev
);
4756 if (local
->scan
.in_scan
== 0) {
4757 netif_wake_queue(dev
);
4759 if (/* FIX: 802.11 qdisc in use */ 1)
4760 __netif_schedule(dev
);
4764 case NETIF_IS_STOPPED
:
4765 if (netif_queue_stopped(dev
))
4768 case NETIF_UPDATE_TX_START
:
4769 dev
->trans_start
= jiffies
;
4775 EXPORT_SYMBOL(ieee80211_netif_oper
);
4777 void ieee80211_wake_queue(struct ieee80211_hw
*hw
, int queue
)
4779 struct ieee80211_local
*local
= hw_to_local(hw
);
4781 if (test_and_clear_bit(IEEE80211_LINK_STATE_XOFF
,
4782 &local
->state
[queue
])) {
4783 if (test_bit(IEEE80211_LINK_STATE_PENDING
,
4784 &local
->state
[queue
]))
4785 tasklet_schedule(&local
->tx_pending_tasklet
);
4787 __netif_schedule(local
->mdev
);
4790 EXPORT_SYMBOL(ieee80211_wake_queue
);
4792 void ieee80211_stop_queue(struct ieee80211_hw
*hw
, int queue
)
4794 struct ieee80211_local
*local
= hw_to_local(hw
);
4796 set_bit(IEEE80211_LINK_STATE_XOFF
, &local
->state
[queue
]);
4798 EXPORT_SYMBOL(ieee80211_stop_queue
);
4800 void ieee80211_start_queues(struct ieee80211_hw
*hw
)
4802 struct ieee80211_local
*local
= hw_to_local(hw
);
4805 for (i
= 0; i
< local
->hw
.queues
; i
++)
4806 clear_bit(IEEE80211_LINK_STATE_XOFF
, &local
->state
[i
]);
4808 EXPORT_SYMBOL(ieee80211_start_queues
);
4810 void ieee80211_stop_queues(struct ieee80211_hw
*hw
)
4812 struct ieee80211_local
*local
= hw_to_local(hw
);
4815 for (i
= 0; i
< local
->hw
.queues
; i
++)
4816 ieee80211_stop_queue(hw
, i
);
4818 EXPORT_SYMBOL(ieee80211_stop_queues
);
4820 struct net_device_stats
*ieee80211_dev_stats(struct net_device
*dev
)
4822 struct ieee80211_sub_if_data
*sdata
;
4823 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4824 return &sdata
->stats
;
4827 static int __init
ieee80211_init(void)
4829 struct sk_buff
*skb
;
4832 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data
) > sizeof(skb
->cb
));
4834 if ((ret
= ieee80211_sysfs_init())) {
4835 printk(KERN_WARNING
"ieee80211_init: sysfs initialization "
4841 ret
= ieee80211_wme_register();
4843 printk(KERN_DEBUG
"ieee80211_init: failed to "
4844 "initialize WME (err=%d)\n", ret
);
4845 ieee80211_sysfs_deinit();
4854 static void __exit
ieee80211_exit(void)
4856 ieee80211_wme_unregister();
4857 ieee80211_sysfs_deinit();
4861 module_init(ieee80211_init
);
4862 module_exit(ieee80211_exit
);
4864 MODULE_DESCRIPTION("IEEE 802.11 subsystem");
4865 MODULE_LICENSE("GPL");