2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <net/mac80211.h>
12 #include <net/ieee80211_radiotap.h>
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/netdevice.h>
16 #include <linux/types.h>
17 #include <linux/slab.h>
18 #include <linux/skbuff.h>
19 #include <linux/etherdevice.h>
20 #include <linux/if_arp.h>
21 #include <linux/wireless.h>
22 #include <linux/rtnetlink.h>
23 #include <linux/bitmap.h>
24 #include <net/net_namespace.h>
25 #include <net/cfg80211.h>
27 #include "ieee80211_i.h"
28 #include "ieee80211_rate.h"
33 #include "ieee80211_led.h"
36 #include "debugfs_netdev.h"
38 #define SUPP_MCS_SET_LEN 16
41 * For seeing transmitted packets on monitor interfaces
42 * we have a radiotap header too.
44 struct ieee80211_tx_status_rtap_hdr
{
45 struct ieee80211_radiotap_header hdr
;
48 } __attribute__ ((packed
));
50 /* common interface routines */
52 static int header_parse_80211(const struct sk_buff
*skb
, unsigned char *haddr
)
54 memcpy(haddr
, skb_mac_header(skb
) + 10, ETH_ALEN
); /* addr2 */
58 /* must be called under mdev tx lock */
59 static void ieee80211_configure_filter(struct ieee80211_local
*local
)
61 unsigned int changed_flags
;
62 unsigned int new_flags
= 0;
64 if (atomic_read(&local
->iff_promiscs
))
65 new_flags
|= FIF_PROMISC_IN_BSS
;
67 if (atomic_read(&local
->iff_allmultis
))
68 new_flags
|= FIF_ALLMULTI
;
71 new_flags
|= FIF_BCN_PRBRESP_PROMISC
;
73 if (local
->fif_fcsfail
)
74 new_flags
|= FIF_FCSFAIL
;
76 if (local
->fif_plcpfail
)
77 new_flags
|= FIF_PLCPFAIL
;
79 if (local
->fif_control
)
80 new_flags
|= FIF_CONTROL
;
82 if (local
->fif_other_bss
)
83 new_flags
|= FIF_OTHER_BSS
;
85 changed_flags
= local
->filter_flags
^ new_flags
;
90 local
->ops
->configure_filter(local_to_hw(local
),
91 changed_flags
, &new_flags
,
92 local
->mdev
->mc_count
,
93 local
->mdev
->mc_list
);
95 WARN_ON(new_flags
& (1<<31));
97 local
->filter_flags
= new_flags
& ~(1<<31);
100 /* master interface */
102 static int ieee80211_master_open(struct net_device
*dev
)
104 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
105 struct ieee80211_sub_if_data
*sdata
;
106 int res
= -EOPNOTSUPP
;
108 /* we hold the RTNL here so can safely walk the list */
109 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
110 if (sdata
->dev
!= dev
&& netif_running(sdata
->dev
)) {
118 static int ieee80211_master_stop(struct net_device
*dev
)
120 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
121 struct ieee80211_sub_if_data
*sdata
;
123 /* we hold the RTNL here so can safely walk the list */
124 list_for_each_entry(sdata
, &local
->interfaces
, list
)
125 if (sdata
->dev
!= dev
&& netif_running(sdata
->dev
))
126 dev_close(sdata
->dev
);
131 static void ieee80211_master_set_multicast_list(struct net_device
*dev
)
133 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
135 ieee80211_configure_filter(local
);
138 /* regular interfaces */
140 static int ieee80211_change_mtu(struct net_device
*dev
, int new_mtu
)
143 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
145 meshhdrlen
= (sdata
->vif
.type
== IEEE80211_IF_TYPE_MESH_POINT
) ? 5 : 0;
147 /* FIX: what would be proper limits for MTU?
148 * This interface uses 802.3 frames. */
150 new_mtu
> IEEE80211_MAX_DATA_LEN
- 24 - 6 - meshhdrlen
) {
151 printk(KERN_WARNING
"%s: invalid MTU %d\n",
156 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
157 printk(KERN_DEBUG
"%s: setting MTU %d\n", dev
->name
, new_mtu
);
158 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
163 static inline int identical_mac_addr_allowed(int type1
, int type2
)
165 return (type1
== IEEE80211_IF_TYPE_MNTR
||
166 type2
== IEEE80211_IF_TYPE_MNTR
||
167 (type1
== IEEE80211_IF_TYPE_AP
&&
168 type2
== IEEE80211_IF_TYPE_WDS
) ||
169 (type1
== IEEE80211_IF_TYPE_WDS
&&
170 (type2
== IEEE80211_IF_TYPE_WDS
||
171 type2
== IEEE80211_IF_TYPE_AP
)) ||
172 (type1
== IEEE80211_IF_TYPE_AP
&&
173 type2
== IEEE80211_IF_TYPE_VLAN
) ||
174 (type1
== IEEE80211_IF_TYPE_VLAN
&&
175 (type2
== IEEE80211_IF_TYPE_AP
||
176 type2
== IEEE80211_IF_TYPE_VLAN
)));
179 static int ieee80211_open(struct net_device
*dev
)
181 struct ieee80211_sub_if_data
*sdata
, *nsdata
;
182 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
183 struct ieee80211_if_init_conf conf
;
185 bool need_hw_reconfig
= 0;
187 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
189 /* we hold the RTNL here so can safely walk the list */
190 list_for_each_entry(nsdata
, &local
->interfaces
, list
) {
191 struct net_device
*ndev
= nsdata
->dev
;
193 if (ndev
!= dev
&& ndev
!= local
->mdev
&& netif_running(ndev
)) {
195 * Allow only a single IBSS interface to be up at any
196 * time. This is restricted because beacon distribution
197 * cannot work properly if both are in the same IBSS.
199 * To remove this restriction we'd have to disallow them
200 * from setting the same SSID on different IBSS interfaces
201 * belonging to the same hardware. Then, however, we're
202 * faced with having to adopt two different TSF timers...
204 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&&
205 nsdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
)
209 * Disallow multiple IBSS/STA mode interfaces.
211 * This is a technical restriction, it is possible although
212 * most likely not IEEE 802.11 compliant to have multiple
213 * STAs with just a single hardware (the TSF timer will not
214 * be adjusted properly.)
216 * However, because mac80211 uses the master device's BSS
217 * information for each STA/IBSS interface, doing this will
218 * currently corrupt that BSS information completely, unless,
219 * a not very useful case, both STAs are associated to the
222 * To remove this restriction, the BSS information needs to
223 * be embedded in the STA/IBSS mode sdata instead of using
224 * the master device's BSS structure.
226 if ((sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
227 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) &&
228 (nsdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
229 nsdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
))
233 * The remaining checks are only performed for interfaces
234 * with the same MAC address.
236 if (compare_ether_addr(dev
->dev_addr
, ndev
->dev_addr
))
240 * check whether it may have the same address
242 if (!identical_mac_addr_allowed(sdata
->vif
.type
,
247 * can only add VLANs to enabled APs
249 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_VLAN
&&
250 nsdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
251 sdata
->u
.vlan
.ap
= nsdata
;
255 switch (sdata
->vif
.type
) {
256 case IEEE80211_IF_TYPE_WDS
:
257 if (is_zero_ether_addr(sdata
->u
.wds
.remote_addr
))
260 case IEEE80211_IF_TYPE_VLAN
:
261 if (!sdata
->u
.vlan
.ap
)
264 case IEEE80211_IF_TYPE_AP
:
265 case IEEE80211_IF_TYPE_STA
:
266 case IEEE80211_IF_TYPE_MNTR
:
267 case IEEE80211_IF_TYPE_IBSS
:
268 case IEEE80211_IF_TYPE_MESH_POINT
:
269 /* no special treatment */
271 case IEEE80211_IF_TYPE_INVALID
:
277 if (local
->open_count
== 0) {
279 if (local
->ops
->start
)
280 res
= local
->ops
->start(local_to_hw(local
));
283 need_hw_reconfig
= 1;
284 ieee80211_led_radio(local
, local
->hw
.conf
.radio_enabled
);
287 switch (sdata
->vif
.type
) {
288 case IEEE80211_IF_TYPE_VLAN
:
289 list_add(&sdata
->u
.vlan
.list
, &sdata
->u
.vlan
.ap
->u
.ap
.vlans
);
290 /* no need to tell driver */
292 case IEEE80211_IF_TYPE_MNTR
:
293 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_COOK_FRAMES
) {
294 local
->cooked_mntrs
++;
298 /* must be before the call to ieee80211_configure_filter */
300 if (local
->monitors
== 1)
301 local
->hw
.conf
.flags
|= IEEE80211_CONF_RADIOTAP
;
303 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_FCSFAIL
)
304 local
->fif_fcsfail
++;
305 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_PLCPFAIL
)
306 local
->fif_plcpfail
++;
307 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_CONTROL
)
308 local
->fif_control
++;
309 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_OTHER_BSS
)
310 local
->fif_other_bss
++;
312 netif_tx_lock_bh(local
->mdev
);
313 ieee80211_configure_filter(local
);
314 netif_tx_unlock_bh(local
->mdev
);
316 case IEEE80211_IF_TYPE_STA
:
317 case IEEE80211_IF_TYPE_IBSS
:
318 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
321 conf
.vif
= &sdata
->vif
;
322 conf
.type
= sdata
->vif
.type
;
323 conf
.mac_addr
= dev
->dev_addr
;
324 res
= local
->ops
->add_interface(local_to_hw(local
), &conf
);
325 if (res
&& !local
->open_count
&& local
->ops
->stop
)
326 local
->ops
->stop(local_to_hw(local
));
330 ieee80211_if_config(dev
);
331 ieee80211_reset_erp_info(dev
);
332 ieee80211_enable_keys(sdata
);
334 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
&&
335 !(sdata
->flags
& IEEE80211_SDATA_USERSPACE_MLME
))
336 netif_carrier_off(dev
);
338 netif_carrier_on(dev
);
341 if (local
->open_count
== 0) {
342 res
= dev_open(local
->mdev
);
344 tasklet_enable(&local
->tx_pending_tasklet
);
345 tasklet_enable(&local
->tasklet
);
349 * set_multicast_list will be invoked by the networking core
350 * which will check whether any increments here were done in
351 * error and sync them down to the hardware as filter flags.
353 if (sdata
->flags
& IEEE80211_SDATA_ALLMULTI
)
354 atomic_inc(&local
->iff_allmultis
);
356 if (sdata
->flags
& IEEE80211_SDATA_PROMISC
)
357 atomic_inc(&local
->iff_promiscs
);
360 if (need_hw_reconfig
)
361 ieee80211_hw_config(local
);
363 netif_start_queue(dev
);
368 static int ieee80211_stop(struct net_device
*dev
)
370 struct ieee80211_sub_if_data
*sdata
;
371 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
372 struct ieee80211_if_init_conf conf
;
373 struct sta_info
*sta
;
376 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
378 list_for_each_entry(sta
, &local
->sta_list
, list
) {
380 for (i
= 0; i
< STA_TID_NUM
; i
++)
381 ieee80211_sta_stop_rx_ba_session(sta
->dev
,
384 WLAN_REASON_QSTA_LEAVE_QBSS
);
387 netif_stop_queue(dev
);
390 * Don't count this interface for promisc/allmulti while it
391 * is down. dev_mc_unsync() will invoke set_multicast_list
392 * on the master interface which will sync these down to the
393 * hardware as filter flags.
395 if (sdata
->flags
& IEEE80211_SDATA_ALLMULTI
)
396 atomic_dec(&local
->iff_allmultis
);
398 if (sdata
->flags
& IEEE80211_SDATA_PROMISC
)
399 atomic_dec(&local
->iff_promiscs
);
401 dev_mc_unsync(local
->mdev
, dev
);
403 /* APs need special treatment */
404 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
) {
405 struct ieee80211_sub_if_data
*vlan
, *tmp
;
406 struct beacon_data
*old_beacon
= sdata
->u
.ap
.beacon
;
409 rcu_assign_pointer(sdata
->u
.ap
.beacon
, NULL
);
413 /* down all dependent devices, that is VLANs */
414 list_for_each_entry_safe(vlan
, tmp
, &sdata
->u
.ap
.vlans
,
416 dev_close(vlan
->dev
);
417 WARN_ON(!list_empty(&sdata
->u
.ap
.vlans
));
422 switch (sdata
->vif
.type
) {
423 case IEEE80211_IF_TYPE_VLAN
:
424 list_del(&sdata
->u
.vlan
.list
);
425 sdata
->u
.vlan
.ap
= NULL
;
426 /* no need to tell driver */
428 case IEEE80211_IF_TYPE_MNTR
:
429 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_COOK_FRAMES
) {
430 local
->cooked_mntrs
--;
435 if (local
->monitors
== 0)
436 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_RADIOTAP
;
438 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_FCSFAIL
)
439 local
->fif_fcsfail
--;
440 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_PLCPFAIL
)
441 local
->fif_plcpfail
--;
442 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_CONTROL
)
443 local
->fif_control
--;
444 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_OTHER_BSS
)
445 local
->fif_other_bss
--;
447 netif_tx_lock_bh(local
->mdev
);
448 ieee80211_configure_filter(local
);
449 netif_tx_unlock_bh(local
->mdev
);
451 case IEEE80211_IF_TYPE_MESH_POINT
:
452 sta_info_flush(local
, dev
);
454 case IEEE80211_IF_TYPE_STA
:
455 case IEEE80211_IF_TYPE_IBSS
:
456 sdata
->u
.sta
.state
= IEEE80211_DISABLED
;
457 del_timer_sync(&sdata
->u
.sta
.timer
);
459 * When we get here, the interface is marked down.
460 * Call synchronize_rcu() to wait for the RX path
461 * should it be using the interface and enqueuing
462 * frames at this very time on another CPU.
465 skb_queue_purge(&sdata
->u
.sta
.skb_queue
);
467 if (local
->scan_dev
== sdata
->dev
) {
468 if (!local
->ops
->hw_scan
) {
469 local
->sta_sw_scanning
= 0;
470 cancel_delayed_work(&local
->scan_work
);
472 local
->sta_hw_scanning
= 0;
475 flush_workqueue(local
->hw
.workqueue
);
477 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_PRIVACY_INVOKED
;
478 kfree(sdata
->u
.sta
.extra_ie
);
479 sdata
->u
.sta
.extra_ie
= NULL
;
480 sdata
->u
.sta
.extra_ie_len
= 0;
483 conf
.vif
= &sdata
->vif
;
484 conf
.type
= sdata
->vif
.type
;
485 conf
.mac_addr
= dev
->dev_addr
;
486 /* disable all keys for as long as this netdev is down */
487 ieee80211_disable_keys(sdata
);
488 local
->ops
->remove_interface(local_to_hw(local
), &conf
);
491 if (local
->open_count
== 0) {
492 if (netif_running(local
->mdev
))
493 dev_close(local
->mdev
);
495 if (local
->ops
->stop
)
496 local
->ops
->stop(local_to_hw(local
));
498 ieee80211_led_radio(local
, 0);
500 tasklet_disable(&local
->tx_pending_tasklet
);
501 tasklet_disable(&local
->tasklet
);
507 int ieee80211_start_tx_ba_session(struct ieee80211_hw
*hw
, u8
*ra
, u16 tid
)
509 struct ieee80211_local
*local
= hw_to_local(hw
);
510 struct sta_info
*sta
;
511 struct ieee80211_sub_if_data
*sdata
;
512 u16 start_seq_num
= 0;
515 DECLARE_MAC_BUF(mac
);
517 if (tid
>= STA_TID_NUM
)
520 #ifdef CONFIG_MAC80211_HT_DEBUG
521 printk(KERN_DEBUG
"Open BA session requested for %s tid %u\n",
522 print_mac(mac
, ra
), tid
);
523 #endif /* CONFIG_MAC80211_HT_DEBUG */
525 sta
= sta_info_get(local
, ra
);
527 printk(KERN_DEBUG
"Could not find the station\n");
531 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
533 /* we have tried too many times, receiver does not want A-MPDU */
534 if (sta
->ampdu_mlme
.tid_tx
[tid
].addba_req_num
> HT_AGG_MAX_RETRIES
) {
539 state
= &sta
->ampdu_mlme
.tid_tx
[tid
].state
;
540 /* check if the TID is not in aggregation flow already */
541 if (*state
!= HT_AGG_STATE_IDLE
) {
542 #ifdef CONFIG_MAC80211_HT_DEBUG
543 printk(KERN_DEBUG
"BA request denied - session is not "
544 "idle on tid %u\n", tid
);
545 #endif /* CONFIG_MAC80211_HT_DEBUG */
550 /* ensure that TX flow won't interrupt us
551 * until the end of the call to requeue function */
552 spin_lock_bh(&local
->mdev
->queue_lock
);
554 /* create a new queue for this aggregation */
555 ret
= ieee80211_ht_agg_queue_add(local
, sta
, tid
);
557 /* case no queue is available to aggregation
558 * don't switch to aggregation */
560 #ifdef CONFIG_MAC80211_HT_DEBUG
561 printk(KERN_DEBUG
"BA request denied - no queue available for"
563 #endif /* CONFIG_MAC80211_HT_DEBUG */
564 spin_unlock_bh(&local
->mdev
->queue_lock
);
567 sdata
= IEEE80211_DEV_TO_SUB_IF(sta
->dev
);
569 /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
570 * call back right away, it must see that the flow has begun */
571 *state
|= HT_ADDBA_REQUESTED_MSK
;
573 if (local
->ops
->ampdu_action
)
574 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_TX_START
,
575 ra
, tid
, &start_seq_num
);
578 /* No need to requeue the packets in the agg queue, since we
579 * held the tx lock: no packet could be enqueued to the newly
581 ieee80211_ht_agg_queue_remove(local
, sta
, tid
, 0);
582 #ifdef CONFIG_MAC80211_HT_DEBUG
583 printk(KERN_DEBUG
"BA request denied - HW or queue unavailable"
584 " for tid %d\n", tid
);
585 #endif /* CONFIG_MAC80211_HT_DEBUG */
586 spin_unlock_bh(&local
->mdev
->queue_lock
);
587 *state
= HT_AGG_STATE_IDLE
;
591 /* Will put all the packets in the new SW queue */
592 ieee80211_requeue(local
, ieee802_1d_to_ac
[tid
]);
593 spin_unlock_bh(&local
->mdev
->queue_lock
);
595 /* We have most probably almost emptied the legacy queue */
596 /* ieee80211_wake_queue(local_to_hw(local), ieee802_1d_to_ac[tid]); */
598 /* send an addBA request */
599 sta
->ampdu_mlme
.dialog_token_allocator
++;
600 sta
->ampdu_mlme
.tid_tx
[tid
].dialog_token
=
601 sta
->ampdu_mlme
.dialog_token_allocator
;
602 sta
->ampdu_mlme
.tid_tx
[tid
].ssn
= start_seq_num
;
604 ieee80211_send_addba_request(sta
->dev
, ra
, tid
,
605 sta
->ampdu_mlme
.tid_tx
[tid
].dialog_token
,
606 sta
->ampdu_mlme
.tid_tx
[tid
].ssn
,
609 /* activate the timer for the recipient's addBA response */
610 sta
->ampdu_mlme
.tid_tx
[tid
].addba_resp_timer
.expires
=
611 jiffies
+ ADDBA_RESP_INTERVAL
;
612 add_timer(&sta
->ampdu_mlme
.tid_tx
[tid
].addba_resp_timer
);
613 printk(KERN_DEBUG
"activated addBA response timer on tid %d\n", tid
);
616 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
620 EXPORT_SYMBOL(ieee80211_start_tx_ba_session
);
622 int ieee80211_stop_tx_ba_session(struct ieee80211_hw
*hw
,
624 enum ieee80211_back_parties initiator
)
626 struct ieee80211_local
*local
= hw_to_local(hw
);
627 struct sta_info
*sta
;
630 DECLARE_MAC_BUF(mac
);
632 if (tid
>= STA_TID_NUM
)
635 #ifdef CONFIG_MAC80211_HT_DEBUG
636 printk(KERN_DEBUG
"Stop a BA session requested for %s tid %u\n",
637 print_mac(mac
, ra
), tid
);
638 #endif /* CONFIG_MAC80211_HT_DEBUG */
640 sta
= sta_info_get(local
, ra
);
644 /* check if the TID is in aggregation */
645 state
= &sta
->ampdu_mlme
.tid_tx
[tid
].state
;
646 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
648 if (*state
!= HT_AGG_STATE_OPERATIONAL
) {
649 #ifdef CONFIG_MAC80211_HT_DEBUG
650 printk(KERN_DEBUG
"Try to stop Tx aggregation on"
651 " non active TID\n");
652 #endif /* CONFIG_MAC80211_HT_DEBUG */
657 ieee80211_stop_queue(hw
, sta
->tid_to_tx_q
[tid
]);
659 *state
= HT_AGG_STATE_REQ_STOP_BA_MSK
|
660 (initiator
<< HT_AGG_STATE_INITIATOR_SHIFT
);
662 if (local
->ops
->ampdu_action
)
663 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_TX_STOP
,
666 /* case HW denied going back to legacy */
668 WARN_ON(ret
!= -EBUSY
);
669 *state
= HT_AGG_STATE_OPERATIONAL
;
670 ieee80211_wake_queue(hw
, sta
->tid_to_tx_q
[tid
]);
675 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
679 EXPORT_SYMBOL(ieee80211_stop_tx_ba_session
);
681 void ieee80211_start_tx_ba_cb(struct ieee80211_hw
*hw
, u8
*ra
, u16 tid
)
683 struct ieee80211_local
*local
= hw_to_local(hw
);
684 struct sta_info
*sta
;
686 DECLARE_MAC_BUF(mac
);
688 if (tid
>= STA_TID_NUM
) {
689 printk(KERN_DEBUG
"Bad TID value: tid = %d (>= %d)\n",
694 sta
= sta_info_get(local
, ra
);
696 printk(KERN_DEBUG
"Could not find station: %s\n",
701 state
= &sta
->ampdu_mlme
.tid_tx
[tid
].state
;
702 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
704 if (!(*state
& HT_ADDBA_REQUESTED_MSK
)) {
705 printk(KERN_DEBUG
"addBA was not requested yet, state is %d\n",
707 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
712 WARN_ON_ONCE(*state
& HT_ADDBA_DRV_READY_MSK
);
714 *state
|= HT_ADDBA_DRV_READY_MSK
;
716 if (*state
== HT_AGG_STATE_OPERATIONAL
) {
717 printk(KERN_DEBUG
"Aggregation is on for tid %d \n", tid
);
718 ieee80211_wake_queue(hw
, sta
->tid_to_tx_q
[tid
]);
720 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
723 EXPORT_SYMBOL(ieee80211_start_tx_ba_cb
);
725 void ieee80211_stop_tx_ba_cb(struct ieee80211_hw
*hw
, u8
*ra
, u8 tid
)
727 struct ieee80211_local
*local
= hw_to_local(hw
);
728 struct sta_info
*sta
;
731 DECLARE_MAC_BUF(mac
);
733 if (tid
>= STA_TID_NUM
) {
734 printk(KERN_DEBUG
"Bad TID value: tid = %d (>= %d)\n",
739 printk(KERN_DEBUG
"Stop a BA session requested on DA %s tid %d\n",
740 print_mac(mac
, ra
), tid
);
742 sta
= sta_info_get(local
, ra
);
744 printk(KERN_DEBUG
"Could not find station: %s\n",
748 state
= &sta
->ampdu_mlme
.tid_tx
[tid
].state
;
750 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
751 if ((*state
& HT_AGG_STATE_REQ_STOP_BA_MSK
) == 0) {
752 printk(KERN_DEBUG
"unexpected callback to A-MPDU stop\n");
754 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
758 if (*state
& HT_AGG_STATE_INITIATOR_MSK
)
759 ieee80211_send_delba(sta
->dev
, ra
, tid
,
760 WLAN_BACK_INITIATOR
, WLAN_REASON_QSTA_NOT_USE
);
762 agg_queue
= sta
->tid_to_tx_q
[tid
];
764 /* avoid ordering issues: we are the only one that can modify
765 * the content of the qdiscs */
766 spin_lock_bh(&local
->mdev
->queue_lock
);
767 /* remove the queue for this aggregation */
768 ieee80211_ht_agg_queue_remove(local
, sta
, tid
, 1);
769 spin_unlock_bh(&local
->mdev
->queue_lock
);
771 /* we just requeued the all the frames that were in the removed
772 * queue, and since we might miss a softirq we do netif_schedule.
773 * ieee80211_wake_queue is not used here as this queue is not
774 * necessarily stopped */
775 netif_schedule(local
->mdev
);
776 *state
= HT_AGG_STATE_IDLE
;
777 sta
->ampdu_mlme
.tid_tx
[tid
].addba_req_num
= 0;
778 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
782 EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb
);
784 void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw
*hw
,
785 const u8
*ra
, u16 tid
)
787 struct ieee80211_local
*local
= hw_to_local(hw
);
788 struct ieee80211_ra_tid
*ra_tid
;
789 struct sk_buff
*skb
= dev_alloc_skb(0);
791 if (unlikely(!skb
)) {
793 printk(KERN_WARNING
"%s: Not enough memory, "
794 "dropping start BA session", skb
->dev
->name
);
797 ra_tid
= (struct ieee80211_ra_tid
*) &skb
->cb
;
798 memcpy(&ra_tid
->ra
, ra
, ETH_ALEN
);
801 skb
->pkt_type
= IEEE80211_ADDBA_MSG
;
802 skb_queue_tail(&local
->skb_queue
, skb
);
803 tasklet_schedule(&local
->tasklet
);
805 EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe
);
807 void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw
*hw
,
808 const u8
*ra
, u16 tid
)
810 struct ieee80211_local
*local
= hw_to_local(hw
);
811 struct ieee80211_ra_tid
*ra_tid
;
812 struct sk_buff
*skb
= dev_alloc_skb(0);
814 if (unlikely(!skb
)) {
816 printk(KERN_WARNING
"%s: Not enough memory, "
817 "dropping stop BA session", skb
->dev
->name
);
820 ra_tid
= (struct ieee80211_ra_tid
*) &skb
->cb
;
821 memcpy(&ra_tid
->ra
, ra
, ETH_ALEN
);
824 skb
->pkt_type
= IEEE80211_DELBA_MSG
;
825 skb_queue_tail(&local
->skb_queue
, skb
);
826 tasklet_schedule(&local
->tasklet
);
828 EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe
);
830 static void ieee80211_set_multicast_list(struct net_device
*dev
)
832 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
833 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
834 int allmulti
, promisc
, sdata_allmulti
, sdata_promisc
;
836 allmulti
= !!(dev
->flags
& IFF_ALLMULTI
);
837 promisc
= !!(dev
->flags
& IFF_PROMISC
);
838 sdata_allmulti
= !!(sdata
->flags
& IEEE80211_SDATA_ALLMULTI
);
839 sdata_promisc
= !!(sdata
->flags
& IEEE80211_SDATA_PROMISC
);
841 if (allmulti
!= sdata_allmulti
) {
842 if (dev
->flags
& IFF_ALLMULTI
)
843 atomic_inc(&local
->iff_allmultis
);
845 atomic_dec(&local
->iff_allmultis
);
846 sdata
->flags
^= IEEE80211_SDATA_ALLMULTI
;
849 if (promisc
!= sdata_promisc
) {
850 if (dev
->flags
& IFF_PROMISC
)
851 atomic_inc(&local
->iff_promiscs
);
853 atomic_dec(&local
->iff_promiscs
);
854 sdata
->flags
^= IEEE80211_SDATA_PROMISC
;
857 dev_mc_sync(local
->mdev
, dev
);
860 static const struct header_ops ieee80211_header_ops
= {
861 .create
= eth_header
,
862 .parse
= header_parse_80211
,
863 .rebuild
= eth_rebuild_header
,
864 .cache
= eth_header_cache
,
865 .cache_update
= eth_header_cache_update
,
868 /* Must not be called for mdev */
869 void ieee80211_if_setup(struct net_device
*dev
)
872 dev
->hard_start_xmit
= ieee80211_subif_start_xmit
;
873 dev
->wireless_handlers
= &ieee80211_iw_handler_def
;
874 dev
->set_multicast_list
= ieee80211_set_multicast_list
;
875 dev
->change_mtu
= ieee80211_change_mtu
;
876 dev
->open
= ieee80211_open
;
877 dev
->stop
= ieee80211_stop
;
878 dev
->destructor
= ieee80211_if_free
;
881 /* WDS specialties */
883 int ieee80211_if_update_wds(struct net_device
*dev
, u8
*remote_addr
)
885 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
886 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
887 struct sta_info
*sta
;
888 DECLARE_MAC_BUF(mac
);
890 if (compare_ether_addr(remote_addr
, sdata
->u
.wds
.remote_addr
) == 0)
893 /* Create STA entry for the new peer */
894 sta
= sta_info_add(local
, dev
, remote_addr
, GFP_KERNEL
);
898 sta
->flags
|= WLAN_STA_AUTHORIZED
;
902 /* Remove STA entry for the old peer */
903 sta
= sta_info_get(local
, sdata
->u
.wds
.remote_addr
);
908 printk(KERN_DEBUG
"%s: could not find STA entry for WDS link "
910 dev
->name
, print_mac(mac
, sdata
->u
.wds
.remote_addr
));
913 /* Update WDS link data */
914 memcpy(&sdata
->u
.wds
.remote_addr
, remote_addr
, ETH_ALEN
);
919 /* everything else */
921 static int __ieee80211_if_config(struct net_device
*dev
,
922 struct sk_buff
*beacon
,
923 struct ieee80211_tx_control
*control
)
925 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
926 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
927 struct ieee80211_if_conf conf
;
929 if (!local
->ops
->config_interface
|| !netif_running(dev
))
932 memset(&conf
, 0, sizeof(conf
));
933 conf
.type
= sdata
->vif
.type
;
934 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
935 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
936 conf
.bssid
= sdata
->u
.sta
.bssid
;
937 conf
.ssid
= sdata
->u
.sta
.ssid
;
938 conf
.ssid_len
= sdata
->u
.sta
.ssid_len
;
939 } else if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
940 conf
.beacon
= beacon
;
941 ieee80211_start_mesh(dev
);
942 } else if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
) {
943 conf
.ssid
= sdata
->u
.ap
.ssid
;
944 conf
.ssid_len
= sdata
->u
.ap
.ssid_len
;
945 conf
.beacon
= beacon
;
946 conf
.beacon_control
= control
;
948 return local
->ops
->config_interface(local_to_hw(local
),
952 int ieee80211_if_config(struct net_device
*dev
)
954 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
955 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
956 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_MESH_POINT
&&
957 (local
->hw
.flags
& IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE
))
958 return ieee80211_if_config_beacon(dev
);
959 return __ieee80211_if_config(dev
, NULL
, NULL
);
962 int ieee80211_if_config_beacon(struct net_device
*dev
)
964 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
965 struct ieee80211_tx_control control
;
966 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
969 if (!(local
->hw
.flags
& IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE
))
971 skb
= ieee80211_beacon_get(local_to_hw(local
), &sdata
->vif
,
975 return __ieee80211_if_config(dev
, skb
, &control
);
978 int ieee80211_hw_config(struct ieee80211_local
*local
)
980 struct ieee80211_channel
*chan
;
983 if (local
->sta_sw_scanning
)
984 chan
= local
->scan_channel
;
986 chan
= local
->oper_channel
;
988 local
->hw
.conf
.channel
= chan
;
990 if (!local
->hw
.conf
.power_level
)
991 local
->hw
.conf
.power_level
= chan
->max_power
;
993 local
->hw
.conf
.power_level
= min(chan
->max_power
,
994 local
->hw
.conf
.power_level
);
996 local
->hw
.conf
.max_antenna_gain
= chan
->max_antenna_gain
;
998 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
999 printk(KERN_DEBUG
"%s: HW CONFIG: freq=%d\n",
1000 wiphy_name(local
->hw
.wiphy
), chan
->center_freq
);
1003 if (local
->open_count
)
1004 ret
= local
->ops
->config(local_to_hw(local
), &local
->hw
.conf
);
1010 * ieee80211_hw_config_ht should be used only after legacy configuration
1011 * has been determined, as ht configuration depends upon the hardware's
1012 * HT abilities for a _specific_ band.
1014 int ieee80211_hw_config_ht(struct ieee80211_local
*local
, int enable_ht
,
1015 struct ieee80211_ht_info
*req_ht_cap
,
1016 struct ieee80211_ht_bss_info
*req_bss_cap
)
1018 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1019 struct ieee80211_supported_band
*sband
;
1022 sband
= local
->hw
.wiphy
->bands
[conf
->channel
->band
];
1024 /* HT is not supported */
1025 if (!sband
->ht_info
.ht_supported
) {
1026 conf
->flags
&= ~IEEE80211_CONF_SUPPORT_HT_MODE
;
1032 conf
->flags
&= ~IEEE80211_CONF_SUPPORT_HT_MODE
;
1034 conf
->flags
|= IEEE80211_CONF_SUPPORT_HT_MODE
;
1035 conf
->ht_conf
.cap
= req_ht_cap
->cap
& sband
->ht_info
.cap
;
1036 conf
->ht_conf
.cap
&= ~(IEEE80211_HT_CAP_MIMO_PS
);
1037 conf
->ht_conf
.cap
|=
1038 sband
->ht_info
.cap
& IEEE80211_HT_CAP_MIMO_PS
;
1039 conf
->ht_bss_conf
.primary_channel
=
1040 req_bss_cap
->primary_channel
;
1041 conf
->ht_bss_conf
.bss_cap
= req_bss_cap
->bss_cap
;
1042 conf
->ht_bss_conf
.bss_op_mode
= req_bss_cap
->bss_op_mode
;
1043 for (i
= 0; i
< SUPP_MCS_SET_LEN
; i
++)
1044 conf
->ht_conf
.supp_mcs_set
[i
] =
1045 sband
->ht_info
.supp_mcs_set
[i
] &
1046 req_ht_cap
->supp_mcs_set
[i
];
1048 /* In STA mode, this gives us indication
1049 * to the AP's mode of operation */
1050 conf
->ht_conf
.ht_supported
= 1;
1051 conf
->ht_conf
.ampdu_factor
= req_ht_cap
->ampdu_factor
;
1052 conf
->ht_conf
.ampdu_density
= req_ht_cap
->ampdu_density
;
1055 local
->ops
->conf_ht(local_to_hw(local
), &local
->hw
.conf
);
1060 void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data
*sdata
,
1063 struct ieee80211_local
*local
= sdata
->local
;
1068 if (local
->ops
->bss_info_changed
)
1069 local
->ops
->bss_info_changed(local_to_hw(local
),
1075 void ieee80211_reset_erp_info(struct net_device
*dev
)
1077 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1079 sdata
->bss_conf
.use_cts_prot
= 0;
1080 sdata
->bss_conf
.use_short_preamble
= 0;
1081 ieee80211_bss_info_change_notify(sdata
,
1082 BSS_CHANGED_ERP_CTS_PROT
|
1083 BSS_CHANGED_ERP_PREAMBLE
);
1086 void ieee80211_tx_status_irqsafe(struct ieee80211_hw
*hw
,
1087 struct sk_buff
*skb
,
1088 struct ieee80211_tx_status
*status
)
1090 struct ieee80211_local
*local
= hw_to_local(hw
);
1091 struct ieee80211_tx_status
*saved
;
1094 skb
->dev
= local
->mdev
;
1095 saved
= kmalloc(sizeof(struct ieee80211_tx_status
), GFP_ATOMIC
);
1096 if (unlikely(!saved
)) {
1097 if (net_ratelimit())
1098 printk(KERN_WARNING
"%s: Not enough memory, "
1099 "dropping tx status", skb
->dev
->name
);
1100 /* should be dev_kfree_skb_irq, but due to this function being
1101 * named _irqsafe instead of just _irq we can't be sure that
1102 * people won't call it from non-irq contexts */
1103 dev_kfree_skb_any(skb
);
1106 memcpy(saved
, status
, sizeof(struct ieee80211_tx_status
));
1107 /* copy pointer to saved status into skb->cb for use by tasklet */
1108 memcpy(skb
->cb
, &saved
, sizeof(saved
));
1110 skb
->pkt_type
= IEEE80211_TX_STATUS_MSG
;
1111 skb_queue_tail(status
->control
.flags
& IEEE80211_TXCTL_REQ_TX_STATUS
?
1112 &local
->skb_queue
: &local
->skb_queue_unreliable
, skb
);
1113 tmp
= skb_queue_len(&local
->skb_queue
) +
1114 skb_queue_len(&local
->skb_queue_unreliable
);
1115 while (tmp
> IEEE80211_IRQSAFE_QUEUE_LIMIT
&&
1116 (skb
= skb_dequeue(&local
->skb_queue_unreliable
))) {
1117 memcpy(&saved
, skb
->cb
, sizeof(saved
));
1119 dev_kfree_skb_irq(skb
);
1121 I802_DEBUG_INC(local
->tx_status_drop
);
1123 tasklet_schedule(&local
->tasklet
);
1125 EXPORT_SYMBOL(ieee80211_tx_status_irqsafe
);
1127 static void ieee80211_tasklet_handler(unsigned long data
)
1129 struct ieee80211_local
*local
= (struct ieee80211_local
*) data
;
1130 struct sk_buff
*skb
;
1131 struct ieee80211_rx_status rx_status
;
1132 struct ieee80211_tx_status
*tx_status
;
1133 struct ieee80211_ra_tid
*ra_tid
;
1135 while ((skb
= skb_dequeue(&local
->skb_queue
)) ||
1136 (skb
= skb_dequeue(&local
->skb_queue_unreliable
))) {
1137 switch (skb
->pkt_type
) {
1138 case IEEE80211_RX_MSG
:
1139 /* status is in skb->cb */
1140 memcpy(&rx_status
, skb
->cb
, sizeof(rx_status
));
1141 /* Clear skb->pkt_type in order to not confuse kernel
1144 __ieee80211_rx(local_to_hw(local
), skb
, &rx_status
);
1146 case IEEE80211_TX_STATUS_MSG
:
1147 /* get pointer to saved status out of skb->cb */
1148 memcpy(&tx_status
, skb
->cb
, sizeof(tx_status
));
1150 ieee80211_tx_status(local_to_hw(local
),
1154 case IEEE80211_DELBA_MSG
:
1155 ra_tid
= (struct ieee80211_ra_tid
*) &skb
->cb
;
1156 ieee80211_stop_tx_ba_cb(local_to_hw(local
),
1157 ra_tid
->ra
, ra_tid
->tid
);
1160 case IEEE80211_ADDBA_MSG
:
1161 ra_tid
= (struct ieee80211_ra_tid
*) &skb
->cb
;
1162 ieee80211_start_tx_ba_cb(local_to_hw(local
),
1163 ra_tid
->ra
, ra_tid
->tid
);
1166 default: /* should never get here! */
1167 printk(KERN_ERR
"%s: Unknown message type (%d)\n",
1168 wiphy_name(local
->hw
.wiphy
), skb
->pkt_type
);
1175 /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
1176 * make a prepared TX frame (one that has been given to hw) to look like brand
1177 * new IEEE 802.11 frame that is ready to go through TX processing again.
1178 * Also, tx_packet_data in cb is restored from tx_control. */
1179 static void ieee80211_remove_tx_extra(struct ieee80211_local
*local
,
1180 struct ieee80211_key
*key
,
1181 struct sk_buff
*skb
,
1182 struct ieee80211_tx_control
*control
)
1184 int hdrlen
, iv_len
, mic_len
;
1185 struct ieee80211_tx_packet_data
*pkt_data
;
1187 pkt_data
= (struct ieee80211_tx_packet_data
*)skb
->cb
;
1188 pkt_data
->ifindex
= vif_to_sdata(control
->vif
)->dev
->ifindex
;
1189 pkt_data
->flags
= 0;
1190 if (control
->flags
& IEEE80211_TXCTL_REQ_TX_STATUS
)
1191 pkt_data
->flags
|= IEEE80211_TXPD_REQ_TX_STATUS
;
1192 if (control
->flags
& IEEE80211_TXCTL_DO_NOT_ENCRYPT
)
1193 pkt_data
->flags
|= IEEE80211_TXPD_DO_NOT_ENCRYPT
;
1194 if (control
->flags
& IEEE80211_TXCTL_REQUEUE
)
1195 pkt_data
->flags
|= IEEE80211_TXPD_REQUEUE
;
1196 if (control
->flags
& IEEE80211_TXCTL_EAPOL_FRAME
)
1197 pkt_data
->flags
|= IEEE80211_TXPD_EAPOL_FRAME
;
1198 pkt_data
->queue
= control
->queue
;
1200 hdrlen
= ieee80211_get_hdrlen_from_skb(skb
);
1205 switch (key
->conf
.alg
) {
1207 iv_len
= WEP_IV_LEN
;
1208 mic_len
= WEP_ICV_LEN
;
1211 iv_len
= TKIP_IV_LEN
;
1212 mic_len
= TKIP_ICV_LEN
;
1215 iv_len
= CCMP_HDR_LEN
;
1216 mic_len
= CCMP_MIC_LEN
;
1222 if (skb
->len
>= mic_len
&&
1223 !(key
->flags
& KEY_FLAG_UPLOADED_TO_HARDWARE
))
1224 skb_trim(skb
, skb
->len
- mic_len
);
1225 if (skb
->len
>= iv_len
&& skb
->len
> hdrlen
) {
1226 memmove(skb
->data
+ iv_len
, skb
->data
, hdrlen
);
1227 skb_pull(skb
, iv_len
);
1232 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1233 u16 fc
= le16_to_cpu(hdr
->frame_control
);
1234 if ((fc
& 0x8C) == 0x88) /* QoS Control Field */ {
1235 fc
&= ~IEEE80211_STYPE_QOS_DATA
;
1236 hdr
->frame_control
= cpu_to_le16(fc
);
1237 memmove(skb
->data
+ 2, skb
->data
, hdrlen
- 2);
1243 static void ieee80211_handle_filtered_frame(struct ieee80211_local
*local
,
1244 struct sta_info
*sta
,
1245 struct sk_buff
*skb
,
1246 struct ieee80211_tx_status
*status
)
1248 sta
->tx_filtered_count
++;
1251 * Clear the TX filter mask for this STA when sending the next
1252 * packet. If the STA went to power save mode, this will happen
1253 * happen when it wakes up for the next time.
1255 sta
->flags
|= WLAN_STA_CLEAR_PS_FILT
;
1258 * This code races in the following way:
1260 * (1) STA sends frame indicating it will go to sleep and does so
1261 * (2) hardware/firmware adds STA to filter list, passes frame up
1262 * (3) hardware/firmware processes TX fifo and suppresses a frame
1263 * (4) we get TX status before having processed the frame and
1264 * knowing that the STA has gone to sleep.
1266 * This is actually quite unlikely even when both those events are
1267 * processed from interrupts coming in quickly after one another or
1268 * even at the same time because we queue both TX status events and
1269 * RX frames to be processed by a tasklet and process them in the
1270 * same order that they were received or TX status last. Hence, there
1271 * is no race as long as the frame RX is processed before the next TX
1272 * status, which drivers can ensure, see below.
1274 * Note that this can only happen if the hardware or firmware can
1275 * actually add STAs to the filter list, if this is done by the
1276 * driver in response to set_tim() (which will only reduce the race
1277 * this whole filtering tries to solve, not completely solve it)
1278 * this situation cannot happen.
1280 * To completely solve this race drivers need to make sure that they
1281 * (a) don't mix the irq-safe/not irq-safe TX status/RX processing
1283 * (b) always process RX events before TX status events if ordering
1284 * can be unknown, for example with different interrupt status
1287 if (sta
->flags
& WLAN_STA_PS
&&
1288 skb_queue_len(&sta
->tx_filtered
) < STA_MAX_TX_BUFFER
) {
1289 ieee80211_remove_tx_extra(local
, sta
->key
, skb
,
1291 skb_queue_tail(&sta
->tx_filtered
, skb
);
1295 if (!(sta
->flags
& WLAN_STA_PS
) &&
1296 !(status
->control
.flags
& IEEE80211_TXCTL_REQUEUE
)) {
1297 /* Software retry the packet once */
1298 status
->control
.flags
|= IEEE80211_TXCTL_REQUEUE
;
1299 ieee80211_remove_tx_extra(local
, sta
->key
, skb
,
1301 dev_queue_xmit(skb
);
1305 if (net_ratelimit())
1306 printk(KERN_DEBUG
"%s: dropped TX filtered frame, "
1307 "queue_len=%d PS=%d @%lu\n",
1308 wiphy_name(local
->hw
.wiphy
),
1309 skb_queue_len(&sta
->tx_filtered
),
1310 !!(sta
->flags
& WLAN_STA_PS
), jiffies
);
1314 void ieee80211_tx_status(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
1315 struct ieee80211_tx_status
*status
)
1317 struct sk_buff
*skb2
;
1318 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1319 struct ieee80211_local
*local
= hw_to_local(hw
);
1321 struct ieee80211_tx_status_rtap_hdr
*rthdr
;
1322 struct ieee80211_sub_if_data
*sdata
;
1323 struct net_device
*prev_dev
= NULL
;
1327 "%s: ieee80211_tx_status called with NULL status\n",
1328 wiphy_name(local
->hw
.wiphy
));
1333 if (status
->excessive_retries
) {
1334 struct sta_info
*sta
;
1335 sta
= sta_info_get(local
, hdr
->addr1
);
1337 if (sta
->flags
& WLAN_STA_PS
) {
1339 * The STA is in power save mode, so assume
1340 * that this TX packet failed because of that.
1342 status
->excessive_retries
= 0;
1343 status
->flags
|= IEEE80211_TX_STATUS_TX_FILTERED
;
1344 ieee80211_handle_filtered_frame(local
, sta
,
1353 if (status
->flags
& IEEE80211_TX_STATUS_TX_FILTERED
) {
1354 struct sta_info
*sta
;
1355 sta
= sta_info_get(local
, hdr
->addr1
);
1357 ieee80211_handle_filtered_frame(local
, sta
, skb
,
1363 rate_control_tx_status(local
->mdev
, skb
, status
);
1365 ieee80211_led_tx(local
, 0);
1368 * Fragments are passed to low-level drivers as separate skbs, so these
1369 * are actually fragments, not frames. Update frame counters only for
1370 * the first fragment of the frame. */
1372 frag
= le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_FRAG
;
1373 type
= le16_to_cpu(hdr
->frame_control
) & IEEE80211_FCTL_FTYPE
;
1375 if (status
->flags
& IEEE80211_TX_STATUS_ACK
) {
1377 local
->dot11TransmittedFrameCount
++;
1378 if (is_multicast_ether_addr(hdr
->addr1
))
1379 local
->dot11MulticastTransmittedFrameCount
++;
1380 if (status
->retry_count
> 0)
1381 local
->dot11RetryCount
++;
1382 if (status
->retry_count
> 1)
1383 local
->dot11MultipleRetryCount
++;
1386 /* This counter shall be incremented for an acknowledged MPDU
1387 * with an individual address in the address 1 field or an MPDU
1388 * with a multicast address in the address 1 field of type Data
1390 if (!is_multicast_ether_addr(hdr
->addr1
) ||
1391 type
== IEEE80211_FTYPE_DATA
||
1392 type
== IEEE80211_FTYPE_MGMT
)
1393 local
->dot11TransmittedFragmentCount
++;
1396 local
->dot11FailedCount
++;
1399 /* this was a transmitted frame, but now we want to reuse it */
1403 * This is a bit racy but we can avoid a lot of work
1406 if (!local
->monitors
&& !local
->cooked_mntrs
) {
1411 /* send frame to monitor interfaces now */
1413 if (skb_headroom(skb
) < sizeof(*rthdr
)) {
1414 printk(KERN_ERR
"ieee80211_tx_status: headroom too small\n");
1419 rthdr
= (struct ieee80211_tx_status_rtap_hdr
*)
1420 skb_push(skb
, sizeof(*rthdr
));
1422 memset(rthdr
, 0, sizeof(*rthdr
));
1423 rthdr
->hdr
.it_len
= cpu_to_le16(sizeof(*rthdr
));
1424 rthdr
->hdr
.it_present
=
1425 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS
) |
1426 (1 << IEEE80211_RADIOTAP_DATA_RETRIES
));
1428 if (!(status
->flags
& IEEE80211_TX_STATUS_ACK
) &&
1429 !is_multicast_ether_addr(hdr
->addr1
))
1430 rthdr
->tx_flags
|= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL
);
1432 if ((status
->control
.flags
& IEEE80211_TXCTL_USE_RTS_CTS
) &&
1433 (status
->control
.flags
& IEEE80211_TXCTL_USE_CTS_PROTECT
))
1434 rthdr
->tx_flags
|= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS
);
1435 else if (status
->control
.flags
& IEEE80211_TXCTL_USE_RTS_CTS
)
1436 rthdr
->tx_flags
|= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS
);
1438 rthdr
->data_retries
= status
->retry_count
;
1440 /* XXX: is this sufficient for BPF? */
1441 skb_set_mac_header(skb
, 0);
1442 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1443 skb
->pkt_type
= PACKET_OTHERHOST
;
1444 skb
->protocol
= htons(ETH_P_802_2
);
1445 memset(skb
->cb
, 0, sizeof(skb
->cb
));
1448 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
1449 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_MNTR
) {
1450 if (!netif_running(sdata
->dev
))
1454 skb2
= skb_clone(skb
, GFP_ATOMIC
);
1456 skb2
->dev
= prev_dev
;
1461 prev_dev
= sdata
->dev
;
1465 skb
->dev
= prev_dev
;
1472 EXPORT_SYMBOL(ieee80211_tx_status
);
1474 struct ieee80211_hw
*ieee80211_alloc_hw(size_t priv_data_len
,
1475 const struct ieee80211_ops
*ops
)
1477 struct ieee80211_local
*local
;
1479 struct wiphy
*wiphy
;
1481 /* Ensure 32-byte alignment of our private data and hw private data.
1482 * We use the wiphy priv data for both our ieee80211_local and for
1483 * the driver's private data
1485 * In memory it'll be like this:
1487 * +-------------------------+
1489 * +-------------------------+
1490 * | struct ieee80211_local |
1491 * +-------------------------+
1492 * | driver's private data |
1493 * +-------------------------+
1496 priv_size
= ((sizeof(struct ieee80211_local
) +
1497 NETDEV_ALIGN_CONST
) & ~NETDEV_ALIGN_CONST
) +
1500 wiphy
= wiphy_new(&mac80211_config_ops
, priv_size
);
1505 wiphy
->privid
= mac80211_wiphy_privid
;
1507 local
= wiphy_priv(wiphy
);
1508 local
->hw
.wiphy
= wiphy
;
1510 local
->hw
.priv
= (char *)local
+
1511 ((sizeof(struct ieee80211_local
) +
1512 NETDEV_ALIGN_CONST
) & ~NETDEV_ALIGN_CONST
);
1515 BUG_ON(!ops
->start
);
1517 BUG_ON(!ops
->config
);
1518 BUG_ON(!ops
->add_interface
);
1519 BUG_ON(!ops
->remove_interface
);
1520 BUG_ON(!ops
->configure_filter
);
1523 local
->hw
.queues
= 1; /* default */
1525 local
->bridge_packets
= 1;
1527 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
1528 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
1529 local
->short_retry_limit
= 7;
1530 local
->long_retry_limit
= 4;
1531 local
->hw
.conf
.radio_enabled
= 1;
1533 INIT_LIST_HEAD(&local
->interfaces
);
1535 INIT_DELAYED_WORK(&local
->scan_work
, ieee80211_sta_scan_work
);
1537 sta_info_init(local
);
1539 tasklet_init(&local
->tx_pending_tasklet
, ieee80211_tx_pending
,
1540 (unsigned long)local
);
1541 tasklet_disable(&local
->tx_pending_tasklet
);
1543 tasklet_init(&local
->tasklet
,
1544 ieee80211_tasklet_handler
,
1545 (unsigned long) local
);
1546 tasklet_disable(&local
->tasklet
);
1548 skb_queue_head_init(&local
->skb_queue
);
1549 skb_queue_head_init(&local
->skb_queue_unreliable
);
1551 return local_to_hw(local
);
1553 EXPORT_SYMBOL(ieee80211_alloc_hw
);
1555 int ieee80211_register_hw(struct ieee80211_hw
*hw
)
1557 struct ieee80211_local
*local
= hw_to_local(hw
);
1560 enum ieee80211_band band
;
1561 struct net_device
*mdev
;
1562 struct ieee80211_sub_if_data
*sdata
;
1565 * generic code guarantees at least one band,
1566 * set this very early because much code assumes
1567 * that hw.conf.channel is assigned
1569 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1570 struct ieee80211_supported_band
*sband
;
1572 sband
= local
->hw
.wiphy
->bands
[band
];
1574 /* init channel we're on */
1575 local
->hw
.conf
.channel
=
1576 local
->oper_channel
=
1577 local
->scan_channel
= &sband
->channels
[0];
1582 result
= wiphy_register(local
->hw
.wiphy
);
1586 /* for now, mdev needs sub_if_data :/ */
1587 mdev
= alloc_netdev(sizeof(struct ieee80211_sub_if_data
),
1588 "wmaster%d", ether_setup
);
1590 goto fail_mdev_alloc
;
1592 sdata
= IEEE80211_DEV_TO_SUB_IF(mdev
);
1593 mdev
->ieee80211_ptr
= &sdata
->wdev
;
1594 sdata
->wdev
.wiphy
= local
->hw
.wiphy
;
1598 ieee80211_rx_bss_list_init(mdev
);
1600 mdev
->hard_start_xmit
= ieee80211_master_start_xmit
;
1601 mdev
->open
= ieee80211_master_open
;
1602 mdev
->stop
= ieee80211_master_stop
;
1603 mdev
->type
= ARPHRD_IEEE80211
;
1604 mdev
->header_ops
= &ieee80211_header_ops
;
1605 mdev
->set_multicast_list
= ieee80211_master_set_multicast_list
;
1607 sdata
->vif
.type
= IEEE80211_IF_TYPE_AP
;
1609 sdata
->local
= local
;
1610 sdata
->u
.ap
.force_unicast_rateidx
= -1;
1611 sdata
->u
.ap
.max_ratectrl_rateidx
= -1;
1612 ieee80211_if_sdata_init(sdata
);
1614 /* no RCU needed since we're still during init phase */
1615 list_add_tail(&sdata
->list
, &local
->interfaces
);
1617 name
= wiphy_dev(local
->hw
.wiphy
)->driver
->name
;
1618 local
->hw
.workqueue
= create_singlethread_workqueue(name
);
1619 if (!local
->hw
.workqueue
) {
1621 goto fail_workqueue
;
1625 * The hardware needs headroom for sending the frame,
1626 * and we need some headroom for passing the frame to monitor
1627 * interfaces, but never both at the same time.
1629 local
->tx_headroom
= max_t(unsigned int , local
->hw
.extra_tx_headroom
,
1630 sizeof(struct ieee80211_tx_status_rtap_hdr
));
1632 debugfs_hw_add(local
);
1634 local
->hw
.conf
.beacon_int
= 1000;
1636 local
->wstats_flags
|= local
->hw
.max_rssi
?
1637 IW_QUAL_LEVEL_UPDATED
: IW_QUAL_LEVEL_INVALID
;
1638 local
->wstats_flags
|= local
->hw
.max_signal
?
1639 IW_QUAL_QUAL_UPDATED
: IW_QUAL_QUAL_INVALID
;
1640 local
->wstats_flags
|= local
->hw
.max_noise
?
1641 IW_QUAL_NOISE_UPDATED
: IW_QUAL_NOISE_INVALID
;
1642 if (local
->hw
.max_rssi
< 0 || local
->hw
.max_noise
< 0)
1643 local
->wstats_flags
|= IW_QUAL_DBM
;
1645 result
= sta_info_start(local
);
1650 result
= dev_alloc_name(local
->mdev
, local
->mdev
->name
);
1654 memcpy(local
->mdev
->dev_addr
, local
->hw
.wiphy
->perm_addr
, ETH_ALEN
);
1655 SET_NETDEV_DEV(local
->mdev
, wiphy_dev(local
->hw
.wiphy
));
1657 result
= register_netdevice(local
->mdev
);
1661 ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local
->mdev
));
1662 ieee80211_if_set_type(local
->mdev
, IEEE80211_IF_TYPE_AP
);
1664 result
= ieee80211_init_rate_ctrl_alg(local
,
1665 hw
->rate_control_algorithm
);
1667 printk(KERN_DEBUG
"%s: Failed to initialize rate control "
1668 "algorithm\n", wiphy_name(local
->hw
.wiphy
));
1672 result
= ieee80211_wep_init(local
);
1675 printk(KERN_DEBUG
"%s: Failed to initialize wep\n",
1676 wiphy_name(local
->hw
.wiphy
));
1680 ieee80211_install_qdisc(local
->mdev
);
1682 /* add one default STA interface */
1683 result
= ieee80211_if_add(local
->mdev
, "wlan%d", NULL
,
1684 IEEE80211_IF_TYPE_STA
, NULL
);
1686 printk(KERN_WARNING
"%s: Failed to add default virtual iface\n",
1687 wiphy_name(local
->hw
.wiphy
));
1689 local
->reg_state
= IEEE80211_DEV_REGISTERED
;
1692 ieee80211_led_init(local
);
1697 rate_control_deinitialize(local
);
1699 ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local
->mdev
));
1700 unregister_netdevice(local
->mdev
);
1703 sta_info_stop(local
);
1705 debugfs_hw_del(local
);
1706 destroy_workqueue(local
->hw
.workqueue
);
1708 ieee80211_if_free(local
->mdev
);
1711 wiphy_unregister(local
->hw
.wiphy
);
1714 EXPORT_SYMBOL(ieee80211_register_hw
);
1716 void ieee80211_unregister_hw(struct ieee80211_hw
*hw
)
1718 struct ieee80211_local
*local
= hw_to_local(hw
);
1719 struct ieee80211_sub_if_data
*sdata
, *tmp
;
1721 tasklet_kill(&local
->tx_pending_tasklet
);
1722 tasklet_kill(&local
->tasklet
);
1726 BUG_ON(local
->reg_state
!= IEEE80211_DEV_REGISTERED
);
1728 local
->reg_state
= IEEE80211_DEV_UNREGISTERED
;
1731 * At this point, interface list manipulations are fine
1732 * because the driver cannot be handing us frames any
1733 * more and the tasklet is killed.
1737 * First, we remove all non-master interfaces. Do this because they
1738 * may have bss pointer dependency on the master, and when we free
1739 * the master these would be freed as well, breaking our list
1740 * iteration completely.
1742 list_for_each_entry_safe(sdata
, tmp
, &local
->interfaces
, list
) {
1743 if (sdata
->dev
== local
->mdev
)
1745 list_del(&sdata
->list
);
1746 __ieee80211_if_del(local
, sdata
);
1749 /* then, finally, remove the master interface */
1750 __ieee80211_if_del(local
, IEEE80211_DEV_TO_SUB_IF(local
->mdev
));
1754 ieee80211_rx_bss_list_deinit(local
->mdev
);
1755 ieee80211_clear_tx_pending(local
);
1756 sta_info_stop(local
);
1757 rate_control_deinitialize(local
);
1758 debugfs_hw_del(local
);
1760 if (skb_queue_len(&local
->skb_queue
)
1761 || skb_queue_len(&local
->skb_queue_unreliable
))
1762 printk(KERN_WARNING
"%s: skb_queue not empty\n",
1763 wiphy_name(local
->hw
.wiphy
));
1764 skb_queue_purge(&local
->skb_queue
);
1765 skb_queue_purge(&local
->skb_queue_unreliable
);
1767 destroy_workqueue(local
->hw
.workqueue
);
1768 wiphy_unregister(local
->hw
.wiphy
);
1769 ieee80211_wep_free(local
);
1770 ieee80211_led_exit(local
);
1771 ieee80211_if_free(local
->mdev
);
1774 EXPORT_SYMBOL(ieee80211_unregister_hw
);
1776 void ieee80211_free_hw(struct ieee80211_hw
*hw
)
1778 struct ieee80211_local
*local
= hw_to_local(hw
);
1780 wiphy_free(local
->hw
.wiphy
);
1782 EXPORT_SYMBOL(ieee80211_free_hw
);
1784 static int __init
ieee80211_init(void)
1786 struct sk_buff
*skb
;
1789 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data
) > sizeof(skb
->cb
));
1791 ret
= rc80211_simple_init();
1795 ret
= rc80211_pid_init();
1797 goto out_cleanup_simple
;
1799 ret
= ieee80211_wme_register();
1801 printk(KERN_DEBUG
"ieee80211_init: failed to "
1802 "initialize WME (err=%d)\n", ret
);
1803 goto out_cleanup_pid
;
1806 ieee80211_debugfs_netdev_init();
1813 rc80211_simple_exit();
1818 static void __exit
ieee80211_exit(void)
1820 rc80211_simple_exit();
1826 ieee80211_wme_unregister();
1827 ieee80211_debugfs_netdev_exit();
1831 subsys_initcall(ieee80211_init
);
1832 module_exit(ieee80211_exit
);
1834 MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1835 MODULE_LICENSE("GPL");