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;
186 struct sta_info
*sta
;
188 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
190 /* we hold the RTNL here so can safely walk the list */
191 list_for_each_entry(nsdata
, &local
->interfaces
, list
) {
192 struct net_device
*ndev
= nsdata
->dev
;
194 if (ndev
!= dev
&& ndev
!= local
->mdev
&& netif_running(ndev
)) {
196 * Allow only a single IBSS interface to be up at any
197 * time. This is restricted because beacon distribution
198 * cannot work properly if both are in the same IBSS.
200 * To remove this restriction we'd have to disallow them
201 * from setting the same SSID on different IBSS interfaces
202 * belonging to the same hardware. Then, however, we're
203 * faced with having to adopt two different TSF timers...
205 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&&
206 nsdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
)
210 * Disallow multiple IBSS/STA mode interfaces.
212 * This is a technical restriction, it is possible although
213 * most likely not IEEE 802.11 compliant to have multiple
214 * STAs with just a single hardware (the TSF timer will not
215 * be adjusted properly.)
217 * However, because mac80211 uses the master device's BSS
218 * information for each STA/IBSS interface, doing this will
219 * currently corrupt that BSS information completely, unless,
220 * a not very useful case, both STAs are associated to the
223 * To remove this restriction, the BSS information needs to
224 * be embedded in the STA/IBSS mode sdata instead of using
225 * the master device's BSS structure.
227 if ((sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
228 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) &&
229 (nsdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
230 nsdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
))
234 * The remaining checks are only performed for interfaces
235 * with the same MAC address.
237 if (compare_ether_addr(dev
->dev_addr
, ndev
->dev_addr
))
241 * check whether it may have the same address
243 if (!identical_mac_addr_allowed(sdata
->vif
.type
,
248 * can only add VLANs to enabled APs
250 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_VLAN
&&
251 nsdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
252 sdata
->u
.vlan
.ap
= nsdata
;
256 switch (sdata
->vif
.type
) {
257 case IEEE80211_IF_TYPE_WDS
:
258 if (is_zero_ether_addr(sdata
->u
.wds
.remote_addr
))
261 /* Create STA entry for the WDS peer */
262 sta
= sta_info_alloc(sdata
, sdata
->u
.wds
.remote_addr
,
267 sta
->flags
|= WLAN_STA_AUTHORIZED
;
269 res
= sta_info_insert(sta
);
271 /* STA has been freed */
275 case IEEE80211_IF_TYPE_VLAN
:
276 if (!sdata
->u
.vlan
.ap
)
279 case IEEE80211_IF_TYPE_AP
:
280 case IEEE80211_IF_TYPE_STA
:
281 case IEEE80211_IF_TYPE_MNTR
:
282 case IEEE80211_IF_TYPE_IBSS
:
283 case IEEE80211_IF_TYPE_MESH_POINT
:
284 /* no special treatment */
286 case IEEE80211_IF_TYPE_INVALID
:
292 if (local
->open_count
== 0) {
294 if (local
->ops
->start
)
295 res
= local
->ops
->start(local_to_hw(local
));
298 need_hw_reconfig
= 1;
299 ieee80211_led_radio(local
, local
->hw
.conf
.radio_enabled
);
302 switch (sdata
->vif
.type
) {
303 case IEEE80211_IF_TYPE_VLAN
:
304 list_add(&sdata
->u
.vlan
.list
, &sdata
->u
.vlan
.ap
->u
.ap
.vlans
);
305 /* no need to tell driver */
307 case IEEE80211_IF_TYPE_MNTR
:
308 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_COOK_FRAMES
) {
309 local
->cooked_mntrs
++;
313 /* must be before the call to ieee80211_configure_filter */
315 if (local
->monitors
== 1)
316 local
->hw
.conf
.flags
|= IEEE80211_CONF_RADIOTAP
;
318 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_FCSFAIL
)
319 local
->fif_fcsfail
++;
320 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_PLCPFAIL
)
321 local
->fif_plcpfail
++;
322 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_CONTROL
)
323 local
->fif_control
++;
324 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_OTHER_BSS
)
325 local
->fif_other_bss
++;
327 netif_tx_lock_bh(local
->mdev
);
328 ieee80211_configure_filter(local
);
329 netif_tx_unlock_bh(local
->mdev
);
331 case IEEE80211_IF_TYPE_STA
:
332 case IEEE80211_IF_TYPE_IBSS
:
333 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
336 conf
.vif
= &sdata
->vif
;
337 conf
.type
= sdata
->vif
.type
;
338 conf
.mac_addr
= dev
->dev_addr
;
339 res
= local
->ops
->add_interface(local_to_hw(local
), &conf
);
340 if (res
&& !local
->open_count
&& local
->ops
->stop
)
341 local
->ops
->stop(local_to_hw(local
));
345 ieee80211_if_config(dev
);
346 ieee80211_reset_erp_info(dev
);
347 ieee80211_enable_keys(sdata
);
349 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
&&
350 !(sdata
->flags
& IEEE80211_SDATA_USERSPACE_MLME
))
351 netif_carrier_off(dev
);
353 netif_carrier_on(dev
);
356 if (local
->open_count
== 0) {
357 res
= dev_open(local
->mdev
);
359 tasklet_enable(&local
->tx_pending_tasklet
);
360 tasklet_enable(&local
->tasklet
);
364 * set_multicast_list will be invoked by the networking core
365 * which will check whether any increments here were done in
366 * error and sync them down to the hardware as filter flags.
368 if (sdata
->flags
& IEEE80211_SDATA_ALLMULTI
)
369 atomic_inc(&local
->iff_allmultis
);
371 if (sdata
->flags
& IEEE80211_SDATA_PROMISC
)
372 atomic_inc(&local
->iff_promiscs
);
375 if (need_hw_reconfig
)
376 ieee80211_hw_config(local
);
379 * ieee80211_sta_work is disabled while network interface
380 * is down. Therefore, some configuration changes may not
381 * yet be effective. Trigger execution of ieee80211_sta_work
384 if(sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
385 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
386 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
387 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
390 netif_start_queue(dev
);
395 static int ieee80211_stop(struct net_device
*dev
)
397 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
398 struct ieee80211_local
*local
= sdata
->local
;
399 struct ieee80211_if_init_conf conf
;
400 struct sta_info
*sta
;
403 * Stop TX on this interface first.
405 netif_stop_queue(dev
);
408 * Now delete all active aggregation sessions.
412 list_for_each_entry_rcu(sta
, &local
->sta_list
, list
) {
413 if (sta
->sdata
== sdata
)
414 ieee80211_sta_tear_down_BA_sessions(dev
, sta
->addr
);
420 * Remove all stations associated with this interface.
422 * This must be done before calling ops->remove_interface()
423 * because otherwise we can later invoke ops->sta_notify()
424 * whenever the STAs are removed, and that invalidates driver
425 * assumptions about always getting a vif pointer that is valid
426 * (because if we remove a STA after ops->remove_interface()
427 * the driver will have removed the vif info already!)
429 * We could relax this and only unlink the stations from the
430 * hash table and list but keep them on a per-sdata list that
431 * will be inserted back again when the interface is brought
432 * up again, but I don't currently see a use case for that,
433 * except with WDS which gets a STA entry created when it is
436 sta_info_flush(local
, sdata
);
439 * Don't count this interface for promisc/allmulti while it
440 * is down. dev_mc_unsync() will invoke set_multicast_list
441 * on the master interface which will sync these down to the
442 * hardware as filter flags.
444 if (sdata
->flags
& IEEE80211_SDATA_ALLMULTI
)
445 atomic_dec(&local
->iff_allmultis
);
447 if (sdata
->flags
& IEEE80211_SDATA_PROMISC
)
448 atomic_dec(&local
->iff_promiscs
);
450 dev_mc_unsync(local
->mdev
, dev
);
452 /* APs need special treatment */
453 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
) {
454 struct ieee80211_sub_if_data
*vlan
, *tmp
;
455 struct beacon_data
*old_beacon
= sdata
->u
.ap
.beacon
;
458 rcu_assign_pointer(sdata
->u
.ap
.beacon
, NULL
);
462 /* down all dependent devices, that is VLANs */
463 list_for_each_entry_safe(vlan
, tmp
, &sdata
->u
.ap
.vlans
,
465 dev_close(vlan
->dev
);
466 WARN_ON(!list_empty(&sdata
->u
.ap
.vlans
));
471 switch (sdata
->vif
.type
) {
472 case IEEE80211_IF_TYPE_VLAN
:
473 list_del(&sdata
->u
.vlan
.list
);
474 sdata
->u
.vlan
.ap
= NULL
;
475 /* no need to tell driver */
477 case IEEE80211_IF_TYPE_MNTR
:
478 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_COOK_FRAMES
) {
479 local
->cooked_mntrs
--;
484 if (local
->monitors
== 0)
485 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_RADIOTAP
;
487 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_FCSFAIL
)
488 local
->fif_fcsfail
--;
489 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_PLCPFAIL
)
490 local
->fif_plcpfail
--;
491 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_CONTROL
)
492 local
->fif_control
--;
493 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_OTHER_BSS
)
494 local
->fif_other_bss
--;
496 netif_tx_lock_bh(local
->mdev
);
497 ieee80211_configure_filter(local
);
498 netif_tx_unlock_bh(local
->mdev
);
500 case IEEE80211_IF_TYPE_MESH_POINT
:
501 case IEEE80211_IF_TYPE_STA
:
502 case IEEE80211_IF_TYPE_IBSS
:
503 sdata
->u
.sta
.state
= IEEE80211_DISABLED
;
504 del_timer_sync(&sdata
->u
.sta
.timer
);
506 * When we get here, the interface is marked down.
507 * Call synchronize_rcu() to wait for the RX path
508 * should it be using the interface and enqueuing
509 * frames at this very time on another CPU.
512 skb_queue_purge(&sdata
->u
.sta
.skb_queue
);
514 if (local
->scan_dev
== sdata
->dev
) {
515 if (!local
->ops
->hw_scan
) {
516 local
->sta_sw_scanning
= 0;
517 cancel_delayed_work(&local
->scan_work
);
519 local
->sta_hw_scanning
= 0;
522 flush_workqueue(local
->hw
.workqueue
);
524 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_PRIVACY_INVOKED
;
525 kfree(sdata
->u
.sta
.extra_ie
);
526 sdata
->u
.sta
.extra_ie
= NULL
;
527 sdata
->u
.sta
.extra_ie_len
= 0;
530 conf
.vif
= &sdata
->vif
;
531 conf
.type
= sdata
->vif
.type
;
532 conf
.mac_addr
= dev
->dev_addr
;
533 /* disable all keys for as long as this netdev is down */
534 ieee80211_disable_keys(sdata
);
535 local
->ops
->remove_interface(local_to_hw(local
), &conf
);
538 if (local
->open_count
== 0) {
539 if (netif_running(local
->mdev
))
540 dev_close(local
->mdev
);
542 if (local
->ops
->stop
)
543 local
->ops
->stop(local_to_hw(local
));
545 ieee80211_led_radio(local
, 0);
547 tasklet_disable(&local
->tx_pending_tasklet
);
548 tasklet_disable(&local
->tasklet
);
554 int ieee80211_start_tx_ba_session(struct ieee80211_hw
*hw
, u8
*ra
, u16 tid
)
556 struct ieee80211_local
*local
= hw_to_local(hw
);
557 struct sta_info
*sta
;
558 struct ieee80211_sub_if_data
*sdata
;
559 u16 start_seq_num
= 0;
562 DECLARE_MAC_BUF(mac
);
564 if (tid
>= STA_TID_NUM
)
567 #ifdef CONFIG_MAC80211_HT_DEBUG
568 printk(KERN_DEBUG
"Open BA session requested for %s tid %u\n",
569 print_mac(mac
, ra
), tid
);
570 #endif /* CONFIG_MAC80211_HT_DEBUG */
574 sta
= sta_info_get(local
, ra
);
576 printk(KERN_DEBUG
"Could not find the station\n");
581 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
583 /* we have tried too many times, receiver does not want A-MPDU */
584 if (sta
->ampdu_mlme
.addba_req_num
[tid
] > HT_AGG_MAX_RETRIES
) {
589 state
= &sta
->ampdu_mlme
.tid_state_tx
[tid
];
590 /* check if the TID is not in aggregation flow already */
591 if (*state
!= HT_AGG_STATE_IDLE
) {
592 #ifdef CONFIG_MAC80211_HT_DEBUG
593 printk(KERN_DEBUG
"BA request denied - session is not "
594 "idle on tid %u\n", tid
);
595 #endif /* CONFIG_MAC80211_HT_DEBUG */
600 /* prepare A-MPDU MLME for Tx aggregation */
601 sta
->ampdu_mlme
.tid_tx
[tid
] =
602 kmalloc(sizeof(struct tid_ampdu_tx
), GFP_ATOMIC
);
603 if (!sta
->ampdu_mlme
.tid_tx
[tid
]) {
605 printk(KERN_ERR
"allocate tx mlme to tid %d failed\n",
611 sta
->ampdu_mlme
.tid_tx
[tid
]->addba_resp_timer
.function
=
612 sta_addba_resp_timer_expired
;
613 sta
->ampdu_mlme
.tid_tx
[tid
]->addba_resp_timer
.data
=
614 (unsigned long)&sta
->timer_to_tid
[tid
];
615 init_timer(&sta
->ampdu_mlme
.tid_tx
[tid
]->addba_resp_timer
);
617 /* ensure that TX flow won't interrupt us
618 * until the end of the call to requeue function */
619 spin_lock_bh(&local
->mdev
->queue_lock
);
621 /* create a new queue for this aggregation */
622 ret
= ieee80211_ht_agg_queue_add(local
, sta
, tid
);
624 /* case no queue is available to aggregation
625 * don't switch to aggregation */
627 #ifdef CONFIG_MAC80211_HT_DEBUG
628 printk(KERN_DEBUG
"BA request denied - queue unavailable for"
630 #endif /* CONFIG_MAC80211_HT_DEBUG */
635 /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
636 * call back right away, it must see that the flow has begun */
637 *state
|= HT_ADDBA_REQUESTED_MSK
;
639 if (local
->ops
->ampdu_action
)
640 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_TX_START
,
641 ra
, tid
, &start_seq_num
);
644 /* No need to requeue the packets in the agg queue, since we
645 * held the tx lock: no packet could be enqueued to the newly
647 ieee80211_ht_agg_queue_remove(local
, sta
, tid
, 0);
648 #ifdef CONFIG_MAC80211_HT_DEBUG
649 printk(KERN_DEBUG
"BA request denied - HW unavailable for"
651 #endif /* CONFIG_MAC80211_HT_DEBUG */
652 *state
= HT_AGG_STATE_IDLE
;
656 /* Will put all the packets in the new SW queue */
657 ieee80211_requeue(local
, ieee802_1d_to_ac
[tid
]);
658 spin_unlock_bh(&local
->mdev
->queue_lock
);
660 /* send an addBA request */
661 sta
->ampdu_mlme
.dialog_token_allocator
++;
662 sta
->ampdu_mlme
.tid_tx
[tid
]->dialog_token
=
663 sta
->ampdu_mlme
.dialog_token_allocator
;
664 sta
->ampdu_mlme
.tid_tx
[tid
]->ssn
= start_seq_num
;
666 ieee80211_send_addba_request(sta
->sdata
->dev
, ra
, tid
,
667 sta
->ampdu_mlme
.tid_tx
[tid
]->dialog_token
,
668 sta
->ampdu_mlme
.tid_tx
[tid
]->ssn
,
671 /* activate the timer for the recipient's addBA response */
672 sta
->ampdu_mlme
.tid_tx
[tid
]->addba_resp_timer
.expires
=
673 jiffies
+ ADDBA_RESP_INTERVAL
;
674 add_timer(&sta
->ampdu_mlme
.tid_tx
[tid
]->addba_resp_timer
);
675 printk(KERN_DEBUG
"activated addBA response timer on tid %d\n", tid
);
679 kfree(sta
->ampdu_mlme
.tid_tx
[tid
]);
680 sta
->ampdu_mlme
.tid_tx
[tid
] = NULL
;
681 spin_unlock_bh(&local
->mdev
->queue_lock
);
684 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
688 EXPORT_SYMBOL(ieee80211_start_tx_ba_session
);
690 int ieee80211_stop_tx_ba_session(struct ieee80211_hw
*hw
,
692 enum ieee80211_back_parties initiator
)
694 struct ieee80211_local
*local
= hw_to_local(hw
);
695 struct sta_info
*sta
;
698 DECLARE_MAC_BUF(mac
);
700 if (tid
>= STA_TID_NUM
)
703 #ifdef CONFIG_MAC80211_HT_DEBUG
704 printk(KERN_DEBUG
"Stop a BA session requested for %s tid %u\n",
705 print_mac(mac
, ra
), tid
);
706 #endif /* CONFIG_MAC80211_HT_DEBUG */
709 sta
= sta_info_get(local
, ra
);
715 /* check if the TID is in aggregation */
716 state
= &sta
->ampdu_mlme
.tid_state_tx
[tid
];
717 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
719 if (*state
!= HT_AGG_STATE_OPERATIONAL
) {
720 #ifdef CONFIG_MAC80211_HT_DEBUG
721 printk(KERN_DEBUG
"Try to stop Tx aggregation on"
722 " non active TID\n");
723 #endif /* CONFIG_MAC80211_HT_DEBUG */
728 ieee80211_stop_queue(hw
, sta
->tid_to_tx_q
[tid
]);
730 *state
= HT_AGG_STATE_REQ_STOP_BA_MSK
|
731 (initiator
<< HT_AGG_STATE_INITIATOR_SHIFT
);
733 if (local
->ops
->ampdu_action
)
734 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_TX_STOP
,
737 /* case HW denied going back to legacy */
739 WARN_ON(ret
!= -EBUSY
);
740 *state
= HT_AGG_STATE_OPERATIONAL
;
741 ieee80211_wake_queue(hw
, sta
->tid_to_tx_q
[tid
]);
746 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
750 EXPORT_SYMBOL(ieee80211_stop_tx_ba_session
);
752 void ieee80211_start_tx_ba_cb(struct ieee80211_hw
*hw
, u8
*ra
, u16 tid
)
754 struct ieee80211_local
*local
= hw_to_local(hw
);
755 struct sta_info
*sta
;
757 DECLARE_MAC_BUF(mac
);
759 if (tid
>= STA_TID_NUM
) {
760 printk(KERN_DEBUG
"Bad TID value: tid = %d (>= %d)\n",
766 sta
= sta_info_get(local
, ra
);
769 printk(KERN_DEBUG
"Could not find station: %s\n",
774 state
= &sta
->ampdu_mlme
.tid_state_tx
[tid
];
775 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
777 if (!(*state
& HT_ADDBA_REQUESTED_MSK
)) {
778 printk(KERN_DEBUG
"addBA was not requested yet, state is %d\n",
780 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
785 WARN_ON_ONCE(*state
& HT_ADDBA_DRV_READY_MSK
);
787 *state
|= HT_ADDBA_DRV_READY_MSK
;
789 if (*state
== HT_AGG_STATE_OPERATIONAL
) {
790 printk(KERN_DEBUG
"Aggregation is on for tid %d \n", tid
);
791 ieee80211_wake_queue(hw
, sta
->tid_to_tx_q
[tid
]);
793 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
796 EXPORT_SYMBOL(ieee80211_start_tx_ba_cb
);
798 void ieee80211_stop_tx_ba_cb(struct ieee80211_hw
*hw
, u8
*ra
, u8 tid
)
800 struct ieee80211_local
*local
= hw_to_local(hw
);
801 struct sta_info
*sta
;
804 DECLARE_MAC_BUF(mac
);
806 if (tid
>= STA_TID_NUM
) {
807 printk(KERN_DEBUG
"Bad TID value: tid = %d (>= %d)\n",
812 printk(KERN_DEBUG
"Stop a BA session requested on DA %s tid %d\n",
813 print_mac(mac
, ra
), tid
);
816 sta
= sta_info_get(local
, ra
);
818 printk(KERN_DEBUG
"Could not find station: %s\n",
823 state
= &sta
->ampdu_mlme
.tid_state_tx
[tid
];
825 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
826 if ((*state
& HT_AGG_STATE_REQ_STOP_BA_MSK
) == 0) {
827 printk(KERN_DEBUG
"unexpected callback to A-MPDU stop\n");
828 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
833 if (*state
& HT_AGG_STATE_INITIATOR_MSK
)
834 ieee80211_send_delba(sta
->sdata
->dev
, ra
, tid
,
835 WLAN_BACK_INITIATOR
, WLAN_REASON_QSTA_NOT_USE
);
837 agg_queue
= sta
->tid_to_tx_q
[tid
];
839 /* avoid ordering issues: we are the only one that can modify
840 * the content of the qdiscs */
841 spin_lock_bh(&local
->mdev
->queue_lock
);
842 /* remove the queue for this aggregation */
843 ieee80211_ht_agg_queue_remove(local
, sta
, tid
, 1);
844 spin_unlock_bh(&local
->mdev
->queue_lock
);
846 /* we just requeued the all the frames that were in the removed
847 * queue, and since we might miss a softirq we do netif_schedule.
848 * ieee80211_wake_queue is not used here as this queue is not
849 * necessarily stopped */
850 netif_schedule(local
->mdev
);
851 *state
= HT_AGG_STATE_IDLE
;
852 sta
->ampdu_mlme
.addba_req_num
[tid
] = 0;
853 kfree(sta
->ampdu_mlme
.tid_tx
[tid
]);
854 sta
->ampdu_mlme
.tid_tx
[tid
] = NULL
;
855 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
859 EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb
);
861 void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw
*hw
,
862 const u8
*ra
, u16 tid
)
864 struct ieee80211_local
*local
= hw_to_local(hw
);
865 struct ieee80211_ra_tid
*ra_tid
;
866 struct sk_buff
*skb
= dev_alloc_skb(0);
868 if (unlikely(!skb
)) {
870 printk(KERN_WARNING
"%s: Not enough memory, "
871 "dropping start BA session", skb
->dev
->name
);
874 ra_tid
= (struct ieee80211_ra_tid
*) &skb
->cb
;
875 memcpy(&ra_tid
->ra
, ra
, ETH_ALEN
);
878 skb
->pkt_type
= IEEE80211_ADDBA_MSG
;
879 skb_queue_tail(&local
->skb_queue
, skb
);
880 tasklet_schedule(&local
->tasklet
);
882 EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe
);
884 void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw
*hw
,
885 const u8
*ra
, u16 tid
)
887 struct ieee80211_local
*local
= hw_to_local(hw
);
888 struct ieee80211_ra_tid
*ra_tid
;
889 struct sk_buff
*skb
= dev_alloc_skb(0);
891 if (unlikely(!skb
)) {
893 printk(KERN_WARNING
"%s: Not enough memory, "
894 "dropping stop BA session", skb
->dev
->name
);
897 ra_tid
= (struct ieee80211_ra_tid
*) &skb
->cb
;
898 memcpy(&ra_tid
->ra
, ra
, ETH_ALEN
);
901 skb
->pkt_type
= IEEE80211_DELBA_MSG
;
902 skb_queue_tail(&local
->skb_queue
, skb
);
903 tasklet_schedule(&local
->tasklet
);
905 EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe
);
907 static void ieee80211_set_multicast_list(struct net_device
*dev
)
909 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
910 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
911 int allmulti
, promisc
, sdata_allmulti
, sdata_promisc
;
913 allmulti
= !!(dev
->flags
& IFF_ALLMULTI
);
914 promisc
= !!(dev
->flags
& IFF_PROMISC
);
915 sdata_allmulti
= !!(sdata
->flags
& IEEE80211_SDATA_ALLMULTI
);
916 sdata_promisc
= !!(sdata
->flags
& IEEE80211_SDATA_PROMISC
);
918 if (allmulti
!= sdata_allmulti
) {
919 if (dev
->flags
& IFF_ALLMULTI
)
920 atomic_inc(&local
->iff_allmultis
);
922 atomic_dec(&local
->iff_allmultis
);
923 sdata
->flags
^= IEEE80211_SDATA_ALLMULTI
;
926 if (promisc
!= sdata_promisc
) {
927 if (dev
->flags
& IFF_PROMISC
)
928 atomic_inc(&local
->iff_promiscs
);
930 atomic_dec(&local
->iff_promiscs
);
931 sdata
->flags
^= IEEE80211_SDATA_PROMISC
;
934 dev_mc_sync(local
->mdev
, dev
);
937 static const struct header_ops ieee80211_header_ops
= {
938 .create
= eth_header
,
939 .parse
= header_parse_80211
,
940 .rebuild
= eth_rebuild_header
,
941 .cache
= eth_header_cache
,
942 .cache_update
= eth_header_cache_update
,
945 /* Must not be called for mdev */
946 void ieee80211_if_setup(struct net_device
*dev
)
949 dev
->hard_start_xmit
= ieee80211_subif_start_xmit
;
950 dev
->wireless_handlers
= &ieee80211_iw_handler_def
;
951 dev
->set_multicast_list
= ieee80211_set_multicast_list
;
952 dev
->change_mtu
= ieee80211_change_mtu
;
953 dev
->open
= ieee80211_open
;
954 dev
->stop
= ieee80211_stop
;
955 dev
->destructor
= ieee80211_if_free
;
958 /* everything else */
960 static int __ieee80211_if_config(struct net_device
*dev
,
961 struct sk_buff
*beacon
,
962 struct ieee80211_tx_control
*control
)
964 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
965 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
966 struct ieee80211_if_conf conf
;
968 if (!local
->ops
->config_interface
|| !netif_running(dev
))
971 memset(&conf
, 0, sizeof(conf
));
972 conf
.type
= sdata
->vif
.type
;
973 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
974 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
975 conf
.bssid
= sdata
->u
.sta
.bssid
;
976 conf
.ssid
= sdata
->u
.sta
.ssid
;
977 conf
.ssid_len
= sdata
->u
.sta
.ssid_len
;
978 } else if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
979 conf
.beacon
= beacon
;
980 ieee80211_start_mesh(dev
);
981 } else if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
) {
982 conf
.ssid
= sdata
->u
.ap
.ssid
;
983 conf
.ssid_len
= sdata
->u
.ap
.ssid_len
;
984 conf
.beacon
= beacon
;
985 conf
.beacon_control
= control
;
987 return local
->ops
->config_interface(local_to_hw(local
),
991 int ieee80211_if_config(struct net_device
*dev
)
993 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
994 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
995 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_MESH_POINT
&&
996 (local
->hw
.flags
& IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE
))
997 return ieee80211_if_config_beacon(dev
);
998 return __ieee80211_if_config(dev
, NULL
, NULL
);
1001 int ieee80211_if_config_beacon(struct net_device
*dev
)
1003 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1004 struct ieee80211_tx_control control
;
1005 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1006 struct sk_buff
*skb
;
1008 if (!(local
->hw
.flags
& IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE
))
1010 skb
= ieee80211_beacon_get(local_to_hw(local
), &sdata
->vif
,
1014 return __ieee80211_if_config(dev
, skb
, &control
);
1017 int ieee80211_hw_config(struct ieee80211_local
*local
)
1019 struct ieee80211_channel
*chan
;
1022 if (local
->sta_sw_scanning
)
1023 chan
= local
->scan_channel
;
1025 chan
= local
->oper_channel
;
1027 local
->hw
.conf
.channel
= chan
;
1029 if (!local
->hw
.conf
.power_level
)
1030 local
->hw
.conf
.power_level
= chan
->max_power
;
1032 local
->hw
.conf
.power_level
= min(chan
->max_power
,
1033 local
->hw
.conf
.power_level
);
1035 local
->hw
.conf
.max_antenna_gain
= chan
->max_antenna_gain
;
1037 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1038 printk(KERN_DEBUG
"%s: HW CONFIG: freq=%d\n",
1039 wiphy_name(local
->hw
.wiphy
), chan
->center_freq
);
1042 if (local
->open_count
)
1043 ret
= local
->ops
->config(local_to_hw(local
), &local
->hw
.conf
);
1049 * ieee80211_hw_config_ht should be used only after legacy configuration
1050 * has been determined, as ht configuration depends upon the hardware's
1051 * HT abilities for a _specific_ band.
1053 int ieee80211_hw_config_ht(struct ieee80211_local
*local
, int enable_ht
,
1054 struct ieee80211_ht_info
*req_ht_cap
,
1055 struct ieee80211_ht_bss_info
*req_bss_cap
)
1057 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1058 struct ieee80211_supported_band
*sband
;
1061 sband
= local
->hw
.wiphy
->bands
[conf
->channel
->band
];
1063 /* HT is not supported */
1064 if (!sband
->ht_info
.ht_supported
) {
1065 conf
->flags
&= ~IEEE80211_CONF_SUPPORT_HT_MODE
;
1071 conf
->flags
&= ~IEEE80211_CONF_SUPPORT_HT_MODE
;
1073 conf
->flags
|= IEEE80211_CONF_SUPPORT_HT_MODE
;
1074 conf
->ht_conf
.cap
= req_ht_cap
->cap
& sband
->ht_info
.cap
;
1075 conf
->ht_conf
.cap
&= ~(IEEE80211_HT_CAP_MIMO_PS
);
1076 conf
->ht_conf
.cap
|=
1077 sband
->ht_info
.cap
& IEEE80211_HT_CAP_MIMO_PS
;
1078 conf
->ht_bss_conf
.primary_channel
=
1079 req_bss_cap
->primary_channel
;
1080 conf
->ht_bss_conf
.bss_cap
= req_bss_cap
->bss_cap
;
1081 conf
->ht_bss_conf
.bss_op_mode
= req_bss_cap
->bss_op_mode
;
1082 for (i
= 0; i
< SUPP_MCS_SET_LEN
; i
++)
1083 conf
->ht_conf
.supp_mcs_set
[i
] =
1084 sband
->ht_info
.supp_mcs_set
[i
] &
1085 req_ht_cap
->supp_mcs_set
[i
];
1087 /* In STA mode, this gives us indication
1088 * to the AP's mode of operation */
1089 conf
->ht_conf
.ht_supported
= 1;
1090 conf
->ht_conf
.ampdu_factor
= req_ht_cap
->ampdu_factor
;
1091 conf
->ht_conf
.ampdu_density
= req_ht_cap
->ampdu_density
;
1094 local
->ops
->conf_ht(local_to_hw(local
), &local
->hw
.conf
);
1099 void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data
*sdata
,
1102 struct ieee80211_local
*local
= sdata
->local
;
1107 if (local
->ops
->bss_info_changed
)
1108 local
->ops
->bss_info_changed(local_to_hw(local
),
1114 void ieee80211_reset_erp_info(struct net_device
*dev
)
1116 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1118 sdata
->bss_conf
.use_cts_prot
= 0;
1119 sdata
->bss_conf
.use_short_preamble
= 0;
1120 ieee80211_bss_info_change_notify(sdata
,
1121 BSS_CHANGED_ERP_CTS_PROT
|
1122 BSS_CHANGED_ERP_PREAMBLE
);
1125 void ieee80211_tx_status_irqsafe(struct ieee80211_hw
*hw
,
1126 struct sk_buff
*skb
,
1127 struct ieee80211_tx_status
*status
)
1129 struct ieee80211_local
*local
= hw_to_local(hw
);
1130 struct ieee80211_tx_status
*saved
;
1133 skb
->dev
= local
->mdev
;
1134 saved
= kmalloc(sizeof(struct ieee80211_tx_status
), GFP_ATOMIC
);
1135 if (unlikely(!saved
)) {
1136 if (net_ratelimit())
1137 printk(KERN_WARNING
"%s: Not enough memory, "
1138 "dropping tx status", skb
->dev
->name
);
1139 /* should be dev_kfree_skb_irq, but due to this function being
1140 * named _irqsafe instead of just _irq we can't be sure that
1141 * people won't call it from non-irq contexts */
1142 dev_kfree_skb_any(skb
);
1145 memcpy(saved
, status
, sizeof(struct ieee80211_tx_status
));
1146 /* copy pointer to saved status into skb->cb for use by tasklet */
1147 memcpy(skb
->cb
, &saved
, sizeof(saved
));
1149 skb
->pkt_type
= IEEE80211_TX_STATUS_MSG
;
1150 skb_queue_tail(status
->control
.flags
& IEEE80211_TXCTL_REQ_TX_STATUS
?
1151 &local
->skb_queue
: &local
->skb_queue_unreliable
, skb
);
1152 tmp
= skb_queue_len(&local
->skb_queue
) +
1153 skb_queue_len(&local
->skb_queue_unreliable
);
1154 while (tmp
> IEEE80211_IRQSAFE_QUEUE_LIMIT
&&
1155 (skb
= skb_dequeue(&local
->skb_queue_unreliable
))) {
1156 memcpy(&saved
, skb
->cb
, sizeof(saved
));
1158 dev_kfree_skb_irq(skb
);
1160 I802_DEBUG_INC(local
->tx_status_drop
);
1162 tasklet_schedule(&local
->tasklet
);
1164 EXPORT_SYMBOL(ieee80211_tx_status_irqsafe
);
1166 static void ieee80211_tasklet_handler(unsigned long data
)
1168 struct ieee80211_local
*local
= (struct ieee80211_local
*) data
;
1169 struct sk_buff
*skb
;
1170 struct ieee80211_rx_status rx_status
;
1171 struct ieee80211_tx_status
*tx_status
;
1172 struct ieee80211_ra_tid
*ra_tid
;
1174 while ((skb
= skb_dequeue(&local
->skb_queue
)) ||
1175 (skb
= skb_dequeue(&local
->skb_queue_unreliable
))) {
1176 switch (skb
->pkt_type
) {
1177 case IEEE80211_RX_MSG
:
1178 /* status is in skb->cb */
1179 memcpy(&rx_status
, skb
->cb
, sizeof(rx_status
));
1180 /* Clear skb->pkt_type in order to not confuse kernel
1183 __ieee80211_rx(local_to_hw(local
), skb
, &rx_status
);
1185 case IEEE80211_TX_STATUS_MSG
:
1186 /* get pointer to saved status out of skb->cb */
1187 memcpy(&tx_status
, skb
->cb
, sizeof(tx_status
));
1189 ieee80211_tx_status(local_to_hw(local
),
1193 case IEEE80211_DELBA_MSG
:
1194 ra_tid
= (struct ieee80211_ra_tid
*) &skb
->cb
;
1195 ieee80211_stop_tx_ba_cb(local_to_hw(local
),
1196 ra_tid
->ra
, ra_tid
->tid
);
1199 case IEEE80211_ADDBA_MSG
:
1200 ra_tid
= (struct ieee80211_ra_tid
*) &skb
->cb
;
1201 ieee80211_start_tx_ba_cb(local_to_hw(local
),
1202 ra_tid
->ra
, ra_tid
->tid
);
1205 default: /* should never get here! */
1206 printk(KERN_ERR
"%s: Unknown message type (%d)\n",
1207 wiphy_name(local
->hw
.wiphy
), skb
->pkt_type
);
1214 /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
1215 * make a prepared TX frame (one that has been given to hw) to look like brand
1216 * new IEEE 802.11 frame that is ready to go through TX processing again.
1217 * Also, tx_packet_data in cb is restored from tx_control. */
1218 static void ieee80211_remove_tx_extra(struct ieee80211_local
*local
,
1219 struct ieee80211_key
*key
,
1220 struct sk_buff
*skb
,
1221 struct ieee80211_tx_control
*control
)
1223 int hdrlen
, iv_len
, mic_len
;
1224 struct ieee80211_tx_packet_data
*pkt_data
;
1226 pkt_data
= (struct ieee80211_tx_packet_data
*)skb
->cb
;
1227 pkt_data
->ifindex
= vif_to_sdata(control
->vif
)->dev
->ifindex
;
1228 pkt_data
->flags
= 0;
1229 if (control
->flags
& IEEE80211_TXCTL_REQ_TX_STATUS
)
1230 pkt_data
->flags
|= IEEE80211_TXPD_REQ_TX_STATUS
;
1231 if (control
->flags
& IEEE80211_TXCTL_DO_NOT_ENCRYPT
)
1232 pkt_data
->flags
|= IEEE80211_TXPD_DO_NOT_ENCRYPT
;
1233 if (control
->flags
& IEEE80211_TXCTL_REQUEUE
)
1234 pkt_data
->flags
|= IEEE80211_TXPD_REQUEUE
;
1235 if (control
->flags
& IEEE80211_TXCTL_EAPOL_FRAME
)
1236 pkt_data
->flags
|= IEEE80211_TXPD_EAPOL_FRAME
;
1237 pkt_data
->queue
= control
->queue
;
1239 hdrlen
= ieee80211_get_hdrlen_from_skb(skb
);
1244 switch (key
->conf
.alg
) {
1246 iv_len
= WEP_IV_LEN
;
1247 mic_len
= WEP_ICV_LEN
;
1250 iv_len
= TKIP_IV_LEN
;
1251 mic_len
= TKIP_ICV_LEN
;
1254 iv_len
= CCMP_HDR_LEN
;
1255 mic_len
= CCMP_MIC_LEN
;
1261 if (skb
->len
>= mic_len
&&
1262 !(key
->flags
& KEY_FLAG_UPLOADED_TO_HARDWARE
))
1263 skb_trim(skb
, skb
->len
- mic_len
);
1264 if (skb
->len
>= iv_len
&& skb
->len
> hdrlen
) {
1265 memmove(skb
->data
+ iv_len
, skb
->data
, hdrlen
);
1266 skb_pull(skb
, iv_len
);
1271 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1272 u16 fc
= le16_to_cpu(hdr
->frame_control
);
1273 if ((fc
& 0x8C) == 0x88) /* QoS Control Field */ {
1274 fc
&= ~IEEE80211_STYPE_QOS_DATA
;
1275 hdr
->frame_control
= cpu_to_le16(fc
);
1276 memmove(skb
->data
+ 2, skb
->data
, hdrlen
- 2);
1282 static void ieee80211_handle_filtered_frame(struct ieee80211_local
*local
,
1283 struct sta_info
*sta
,
1284 struct sk_buff
*skb
,
1285 struct ieee80211_tx_status
*status
)
1287 sta
->tx_filtered_count
++;
1290 * Clear the TX filter mask for this STA when sending the next
1291 * packet. If the STA went to power save mode, this will happen
1292 * happen when it wakes up for the next time.
1294 sta
->flags
|= WLAN_STA_CLEAR_PS_FILT
;
1297 * This code races in the following way:
1299 * (1) STA sends frame indicating it will go to sleep and does so
1300 * (2) hardware/firmware adds STA to filter list, passes frame up
1301 * (3) hardware/firmware processes TX fifo and suppresses a frame
1302 * (4) we get TX status before having processed the frame and
1303 * knowing that the STA has gone to sleep.
1305 * This is actually quite unlikely even when both those events are
1306 * processed from interrupts coming in quickly after one another or
1307 * even at the same time because we queue both TX status events and
1308 * RX frames to be processed by a tasklet and process them in the
1309 * same order that they were received or TX status last. Hence, there
1310 * is no race as long as the frame RX is processed before the next TX
1311 * status, which drivers can ensure, see below.
1313 * Note that this can only happen if the hardware or firmware can
1314 * actually add STAs to the filter list, if this is done by the
1315 * driver in response to set_tim() (which will only reduce the race
1316 * this whole filtering tries to solve, not completely solve it)
1317 * this situation cannot happen.
1319 * To completely solve this race drivers need to make sure that they
1320 * (a) don't mix the irq-safe/not irq-safe TX status/RX processing
1322 * (b) always process RX events before TX status events if ordering
1323 * can be unknown, for example with different interrupt status
1326 if (sta
->flags
& WLAN_STA_PS
&&
1327 skb_queue_len(&sta
->tx_filtered
) < STA_MAX_TX_BUFFER
) {
1328 ieee80211_remove_tx_extra(local
, sta
->key
, skb
,
1330 skb_queue_tail(&sta
->tx_filtered
, skb
);
1334 if (!(sta
->flags
& WLAN_STA_PS
) &&
1335 !(status
->control
.flags
& IEEE80211_TXCTL_REQUEUE
)) {
1336 /* Software retry the packet once */
1337 status
->control
.flags
|= IEEE80211_TXCTL_REQUEUE
;
1338 ieee80211_remove_tx_extra(local
, sta
->key
, skb
,
1340 dev_queue_xmit(skb
);
1344 if (net_ratelimit())
1345 printk(KERN_DEBUG
"%s: dropped TX filtered frame, "
1346 "queue_len=%d PS=%d @%lu\n",
1347 wiphy_name(local
->hw
.wiphy
),
1348 skb_queue_len(&sta
->tx_filtered
),
1349 !!(sta
->flags
& WLAN_STA_PS
), jiffies
);
1353 void ieee80211_tx_status(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
1354 struct ieee80211_tx_status
*status
)
1356 struct sk_buff
*skb2
;
1357 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1358 struct ieee80211_local
*local
= hw_to_local(hw
);
1360 struct ieee80211_tx_status_rtap_hdr
*rthdr
;
1361 struct ieee80211_sub_if_data
*sdata
;
1362 struct net_device
*prev_dev
= NULL
;
1366 "%s: ieee80211_tx_status called with NULL status\n",
1367 wiphy_name(local
->hw
.wiphy
));
1374 if (status
->excessive_retries
) {
1375 struct sta_info
*sta
;
1376 sta
= sta_info_get(local
, hdr
->addr1
);
1378 if (sta
->flags
& WLAN_STA_PS
) {
1380 * The STA is in power save mode, so assume
1381 * that this TX packet failed because of that.
1383 status
->excessive_retries
= 0;
1384 status
->flags
|= IEEE80211_TX_STATUS_TX_FILTERED
;
1385 ieee80211_handle_filtered_frame(local
, sta
,
1393 if (status
->flags
& IEEE80211_TX_STATUS_TX_FILTERED
) {
1394 struct sta_info
*sta
;
1395 sta
= sta_info_get(local
, hdr
->addr1
);
1397 ieee80211_handle_filtered_frame(local
, sta
, skb
,
1403 rate_control_tx_status(local
->mdev
, skb
, status
);
1407 ieee80211_led_tx(local
, 0);
1410 * Fragments are passed to low-level drivers as separate skbs, so these
1411 * are actually fragments, not frames. Update frame counters only for
1412 * the first fragment of the frame. */
1414 frag
= le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_FRAG
;
1415 type
= le16_to_cpu(hdr
->frame_control
) & IEEE80211_FCTL_FTYPE
;
1417 if (status
->flags
& IEEE80211_TX_STATUS_ACK
) {
1419 local
->dot11TransmittedFrameCount
++;
1420 if (is_multicast_ether_addr(hdr
->addr1
))
1421 local
->dot11MulticastTransmittedFrameCount
++;
1422 if (status
->retry_count
> 0)
1423 local
->dot11RetryCount
++;
1424 if (status
->retry_count
> 1)
1425 local
->dot11MultipleRetryCount
++;
1428 /* This counter shall be incremented for an acknowledged MPDU
1429 * with an individual address in the address 1 field or an MPDU
1430 * with a multicast address in the address 1 field of type Data
1432 if (!is_multicast_ether_addr(hdr
->addr1
) ||
1433 type
== IEEE80211_FTYPE_DATA
||
1434 type
== IEEE80211_FTYPE_MGMT
)
1435 local
->dot11TransmittedFragmentCount
++;
1438 local
->dot11FailedCount
++;
1441 /* this was a transmitted frame, but now we want to reuse it */
1445 * This is a bit racy but we can avoid a lot of work
1448 if (!local
->monitors
&& !local
->cooked_mntrs
) {
1453 /* send frame to monitor interfaces now */
1455 if (skb_headroom(skb
) < sizeof(*rthdr
)) {
1456 printk(KERN_ERR
"ieee80211_tx_status: headroom too small\n");
1461 rthdr
= (struct ieee80211_tx_status_rtap_hdr
*)
1462 skb_push(skb
, sizeof(*rthdr
));
1464 memset(rthdr
, 0, sizeof(*rthdr
));
1465 rthdr
->hdr
.it_len
= cpu_to_le16(sizeof(*rthdr
));
1466 rthdr
->hdr
.it_present
=
1467 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS
) |
1468 (1 << IEEE80211_RADIOTAP_DATA_RETRIES
));
1470 if (!(status
->flags
& IEEE80211_TX_STATUS_ACK
) &&
1471 !is_multicast_ether_addr(hdr
->addr1
))
1472 rthdr
->tx_flags
|= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL
);
1474 if ((status
->control
.flags
& IEEE80211_TXCTL_USE_RTS_CTS
) &&
1475 (status
->control
.flags
& IEEE80211_TXCTL_USE_CTS_PROTECT
))
1476 rthdr
->tx_flags
|= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS
);
1477 else if (status
->control
.flags
& IEEE80211_TXCTL_USE_RTS_CTS
)
1478 rthdr
->tx_flags
|= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS
);
1480 rthdr
->data_retries
= status
->retry_count
;
1482 /* XXX: is this sufficient for BPF? */
1483 skb_set_mac_header(skb
, 0);
1484 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1485 skb
->pkt_type
= PACKET_OTHERHOST
;
1486 skb
->protocol
= htons(ETH_P_802_2
);
1487 memset(skb
->cb
, 0, sizeof(skb
->cb
));
1490 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
1491 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_MNTR
) {
1492 if (!netif_running(sdata
->dev
))
1496 skb2
= skb_clone(skb
, GFP_ATOMIC
);
1498 skb2
->dev
= prev_dev
;
1503 prev_dev
= sdata
->dev
;
1507 skb
->dev
= prev_dev
;
1514 EXPORT_SYMBOL(ieee80211_tx_status
);
1516 struct ieee80211_hw
*ieee80211_alloc_hw(size_t priv_data_len
,
1517 const struct ieee80211_ops
*ops
)
1519 struct ieee80211_local
*local
;
1521 struct wiphy
*wiphy
;
1523 /* Ensure 32-byte alignment of our private data and hw private data.
1524 * We use the wiphy priv data for both our ieee80211_local and for
1525 * the driver's private data
1527 * In memory it'll be like this:
1529 * +-------------------------+
1531 * +-------------------------+
1532 * | struct ieee80211_local |
1533 * +-------------------------+
1534 * | driver's private data |
1535 * +-------------------------+
1538 priv_size
= ((sizeof(struct ieee80211_local
) +
1539 NETDEV_ALIGN_CONST
) & ~NETDEV_ALIGN_CONST
) +
1542 wiphy
= wiphy_new(&mac80211_config_ops
, priv_size
);
1547 wiphy
->privid
= mac80211_wiphy_privid
;
1549 local
= wiphy_priv(wiphy
);
1550 local
->hw
.wiphy
= wiphy
;
1552 local
->hw
.priv
= (char *)local
+
1553 ((sizeof(struct ieee80211_local
) +
1554 NETDEV_ALIGN_CONST
) & ~NETDEV_ALIGN_CONST
);
1557 BUG_ON(!ops
->start
);
1559 BUG_ON(!ops
->config
);
1560 BUG_ON(!ops
->add_interface
);
1561 BUG_ON(!ops
->remove_interface
);
1562 BUG_ON(!ops
->configure_filter
);
1565 local
->hw
.queues
= 1; /* default */
1567 local
->bridge_packets
= 1;
1569 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
1570 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
1571 local
->short_retry_limit
= 7;
1572 local
->long_retry_limit
= 4;
1573 local
->hw
.conf
.radio_enabled
= 1;
1575 INIT_LIST_HEAD(&local
->interfaces
);
1577 INIT_DELAYED_WORK(&local
->scan_work
, ieee80211_sta_scan_work
);
1579 sta_info_init(local
);
1581 tasklet_init(&local
->tx_pending_tasklet
, ieee80211_tx_pending
,
1582 (unsigned long)local
);
1583 tasklet_disable(&local
->tx_pending_tasklet
);
1585 tasklet_init(&local
->tasklet
,
1586 ieee80211_tasklet_handler
,
1587 (unsigned long) local
);
1588 tasklet_disable(&local
->tasklet
);
1590 skb_queue_head_init(&local
->skb_queue
);
1591 skb_queue_head_init(&local
->skb_queue_unreliable
);
1593 return local_to_hw(local
);
1595 EXPORT_SYMBOL(ieee80211_alloc_hw
);
1597 int ieee80211_register_hw(struct ieee80211_hw
*hw
)
1599 struct ieee80211_local
*local
= hw_to_local(hw
);
1602 enum ieee80211_band band
;
1603 struct net_device
*mdev
;
1604 struct ieee80211_sub_if_data
*sdata
;
1607 * generic code guarantees at least one band,
1608 * set this very early because much code assumes
1609 * that hw.conf.channel is assigned
1611 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1612 struct ieee80211_supported_band
*sband
;
1614 sband
= local
->hw
.wiphy
->bands
[band
];
1616 /* init channel we're on */
1617 local
->hw
.conf
.channel
=
1618 local
->oper_channel
=
1619 local
->scan_channel
= &sband
->channels
[0];
1624 result
= wiphy_register(local
->hw
.wiphy
);
1628 /* for now, mdev needs sub_if_data :/ */
1629 mdev
= alloc_netdev(sizeof(struct ieee80211_sub_if_data
),
1630 "wmaster%d", ether_setup
);
1632 goto fail_mdev_alloc
;
1634 sdata
= IEEE80211_DEV_TO_SUB_IF(mdev
);
1635 mdev
->ieee80211_ptr
= &sdata
->wdev
;
1636 sdata
->wdev
.wiphy
= local
->hw
.wiphy
;
1640 ieee80211_rx_bss_list_init(mdev
);
1642 mdev
->hard_start_xmit
= ieee80211_master_start_xmit
;
1643 mdev
->open
= ieee80211_master_open
;
1644 mdev
->stop
= ieee80211_master_stop
;
1645 mdev
->type
= ARPHRD_IEEE80211
;
1646 mdev
->header_ops
= &ieee80211_header_ops
;
1647 mdev
->set_multicast_list
= ieee80211_master_set_multicast_list
;
1649 sdata
->vif
.type
= IEEE80211_IF_TYPE_AP
;
1651 sdata
->local
= local
;
1652 sdata
->u
.ap
.force_unicast_rateidx
= -1;
1653 sdata
->u
.ap
.max_ratectrl_rateidx
= -1;
1654 ieee80211_if_sdata_init(sdata
);
1656 /* no RCU needed since we're still during init phase */
1657 list_add_tail(&sdata
->list
, &local
->interfaces
);
1659 name
= wiphy_dev(local
->hw
.wiphy
)->driver
->name
;
1660 local
->hw
.workqueue
= create_singlethread_workqueue(name
);
1661 if (!local
->hw
.workqueue
) {
1663 goto fail_workqueue
;
1667 * The hardware needs headroom for sending the frame,
1668 * and we need some headroom for passing the frame to monitor
1669 * interfaces, but never both at the same time.
1671 local
->tx_headroom
= max_t(unsigned int , local
->hw
.extra_tx_headroom
,
1672 sizeof(struct ieee80211_tx_status_rtap_hdr
));
1674 debugfs_hw_add(local
);
1676 local
->hw
.conf
.beacon_int
= 1000;
1678 local
->wstats_flags
|= local
->hw
.max_rssi
?
1679 IW_QUAL_LEVEL_UPDATED
: IW_QUAL_LEVEL_INVALID
;
1680 local
->wstats_flags
|= local
->hw
.max_signal
?
1681 IW_QUAL_QUAL_UPDATED
: IW_QUAL_QUAL_INVALID
;
1682 local
->wstats_flags
|= local
->hw
.max_noise
?
1683 IW_QUAL_NOISE_UPDATED
: IW_QUAL_NOISE_INVALID
;
1684 if (local
->hw
.max_rssi
< 0 || local
->hw
.max_noise
< 0)
1685 local
->wstats_flags
|= IW_QUAL_DBM
;
1687 result
= sta_info_start(local
);
1692 result
= dev_alloc_name(local
->mdev
, local
->mdev
->name
);
1696 memcpy(local
->mdev
->dev_addr
, local
->hw
.wiphy
->perm_addr
, ETH_ALEN
);
1697 SET_NETDEV_DEV(local
->mdev
, wiphy_dev(local
->hw
.wiphy
));
1699 result
= register_netdevice(local
->mdev
);
1703 ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local
->mdev
));
1704 ieee80211_if_set_type(local
->mdev
, IEEE80211_IF_TYPE_AP
);
1706 result
= ieee80211_init_rate_ctrl_alg(local
,
1707 hw
->rate_control_algorithm
);
1709 printk(KERN_DEBUG
"%s: Failed to initialize rate control "
1710 "algorithm\n", wiphy_name(local
->hw
.wiphy
));
1714 result
= ieee80211_wep_init(local
);
1717 printk(KERN_DEBUG
"%s: Failed to initialize wep\n",
1718 wiphy_name(local
->hw
.wiphy
));
1722 ieee80211_install_qdisc(local
->mdev
);
1724 /* add one default STA interface */
1725 result
= ieee80211_if_add(local
->mdev
, "wlan%d", NULL
,
1726 IEEE80211_IF_TYPE_STA
, NULL
);
1728 printk(KERN_WARNING
"%s: Failed to add default virtual iface\n",
1729 wiphy_name(local
->hw
.wiphy
));
1731 local
->reg_state
= IEEE80211_DEV_REGISTERED
;
1734 ieee80211_led_init(local
);
1739 rate_control_deinitialize(local
);
1741 ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local
->mdev
));
1742 unregister_netdevice(local
->mdev
);
1745 sta_info_stop(local
);
1747 debugfs_hw_del(local
);
1748 destroy_workqueue(local
->hw
.workqueue
);
1750 ieee80211_if_free(local
->mdev
);
1753 wiphy_unregister(local
->hw
.wiphy
);
1756 EXPORT_SYMBOL(ieee80211_register_hw
);
1758 void ieee80211_unregister_hw(struct ieee80211_hw
*hw
)
1760 struct ieee80211_local
*local
= hw_to_local(hw
);
1761 struct ieee80211_sub_if_data
*sdata
, *tmp
;
1763 tasklet_kill(&local
->tx_pending_tasklet
);
1764 tasklet_kill(&local
->tasklet
);
1768 BUG_ON(local
->reg_state
!= IEEE80211_DEV_REGISTERED
);
1770 local
->reg_state
= IEEE80211_DEV_UNREGISTERED
;
1773 * At this point, interface list manipulations are fine
1774 * because the driver cannot be handing us frames any
1775 * more and the tasklet is killed.
1779 * First, we remove all non-master interfaces. Do this because they
1780 * may have bss pointer dependency on the master, and when we free
1781 * the master these would be freed as well, breaking our list
1782 * iteration completely.
1784 list_for_each_entry_safe(sdata
, tmp
, &local
->interfaces
, list
) {
1785 if (sdata
->dev
== local
->mdev
)
1787 list_del(&sdata
->list
);
1788 __ieee80211_if_del(local
, sdata
);
1791 /* then, finally, remove the master interface */
1792 __ieee80211_if_del(local
, IEEE80211_DEV_TO_SUB_IF(local
->mdev
));
1796 ieee80211_rx_bss_list_deinit(local
->mdev
);
1797 ieee80211_clear_tx_pending(local
);
1798 sta_info_stop(local
);
1799 rate_control_deinitialize(local
);
1800 debugfs_hw_del(local
);
1802 if (skb_queue_len(&local
->skb_queue
)
1803 || skb_queue_len(&local
->skb_queue_unreliable
))
1804 printk(KERN_WARNING
"%s: skb_queue not empty\n",
1805 wiphy_name(local
->hw
.wiphy
));
1806 skb_queue_purge(&local
->skb_queue
);
1807 skb_queue_purge(&local
->skb_queue_unreliable
);
1809 destroy_workqueue(local
->hw
.workqueue
);
1810 wiphy_unregister(local
->hw
.wiphy
);
1811 ieee80211_wep_free(local
);
1812 ieee80211_led_exit(local
);
1813 ieee80211_if_free(local
->mdev
);
1816 EXPORT_SYMBOL(ieee80211_unregister_hw
);
1818 void ieee80211_free_hw(struct ieee80211_hw
*hw
)
1820 struct ieee80211_local
*local
= hw_to_local(hw
);
1822 wiphy_free(local
->hw
.wiphy
);
1824 EXPORT_SYMBOL(ieee80211_free_hw
);
1826 static int __init
ieee80211_init(void)
1828 struct sk_buff
*skb
;
1831 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data
) > sizeof(skb
->cb
));
1833 ret
= rc80211_pid_init();
1837 ret
= ieee80211_wme_register();
1839 printk(KERN_DEBUG
"ieee80211_init: failed to "
1840 "initialize WME (err=%d)\n", ret
);
1841 goto out_cleanup_pid
;
1844 ieee80211_debugfs_netdev_init();
1854 static void __exit
ieee80211_exit(void)
1861 ieee80211_wme_unregister();
1862 ieee80211_debugfs_netdev_exit();
1866 subsys_initcall(ieee80211_init
);
1867 module_exit(ieee80211_exit
);
1869 MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1870 MODULE_LICENSE("GPL");