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"
32 #include "ieee80211_led.h"
35 #include "debugfs_netdev.h"
37 #define SUPP_MCS_SET_LEN 16
40 * For seeing transmitted packets on monitor interfaces
41 * we have a radiotap header too.
43 struct ieee80211_tx_status_rtap_hdr
{
44 struct ieee80211_radiotap_header hdr
;
47 } __attribute__ ((packed
));
49 /* common interface routines */
51 static int header_parse_80211(const struct sk_buff
*skb
, unsigned char *haddr
)
53 memcpy(haddr
, skb_mac_header(skb
) + 10, ETH_ALEN
); /* addr2 */
57 /* must be called under mdev tx lock */
58 static void ieee80211_configure_filter(struct ieee80211_local
*local
)
60 unsigned int changed_flags
;
61 unsigned int new_flags
= 0;
63 if (atomic_read(&local
->iff_promiscs
))
64 new_flags
|= FIF_PROMISC_IN_BSS
;
66 if (atomic_read(&local
->iff_allmultis
))
67 new_flags
|= FIF_ALLMULTI
;
70 new_flags
|= FIF_BCN_PRBRESP_PROMISC
;
72 if (local
->fif_fcsfail
)
73 new_flags
|= FIF_FCSFAIL
;
75 if (local
->fif_plcpfail
)
76 new_flags
|= FIF_PLCPFAIL
;
78 if (local
->fif_control
)
79 new_flags
|= FIF_CONTROL
;
81 if (local
->fif_other_bss
)
82 new_flags
|= FIF_OTHER_BSS
;
84 changed_flags
= local
->filter_flags
^ new_flags
;
89 local
->ops
->configure_filter(local_to_hw(local
),
90 changed_flags
, &new_flags
,
91 local
->mdev
->mc_count
,
92 local
->mdev
->mc_list
);
94 WARN_ON(new_flags
& (1<<31));
96 local
->filter_flags
= new_flags
& ~(1<<31);
99 /* master interface */
101 static int ieee80211_master_open(struct net_device
*dev
)
103 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
104 struct ieee80211_sub_if_data
*sdata
;
105 int res
= -EOPNOTSUPP
;
107 /* we hold the RTNL here so can safely walk the list */
108 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
109 if (sdata
->dev
!= dev
&& netif_running(sdata
->dev
)) {
117 static int ieee80211_master_stop(struct net_device
*dev
)
119 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
120 struct ieee80211_sub_if_data
*sdata
;
122 /* we hold the RTNL here so can safely walk the list */
123 list_for_each_entry(sdata
, &local
->interfaces
, list
)
124 if (sdata
->dev
!= dev
&& netif_running(sdata
->dev
))
125 dev_close(sdata
->dev
);
130 static void ieee80211_master_set_multicast_list(struct net_device
*dev
)
132 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
134 ieee80211_configure_filter(local
);
137 /* regular interfaces */
139 static int ieee80211_change_mtu(struct net_device
*dev
, int new_mtu
)
141 /* FIX: what would be proper limits for MTU?
142 * This interface uses 802.3 frames. */
143 if (new_mtu
< 256 || new_mtu
> IEEE80211_MAX_DATA_LEN
- 24 - 6) {
144 printk(KERN_WARNING
"%s: invalid MTU %d\n",
149 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
150 printk(KERN_DEBUG
"%s: setting MTU %d\n", dev
->name
, new_mtu
);
151 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
156 static inline int identical_mac_addr_allowed(int type1
, int type2
)
158 return (type1
== IEEE80211_IF_TYPE_MNTR
||
159 type2
== IEEE80211_IF_TYPE_MNTR
||
160 (type1
== IEEE80211_IF_TYPE_AP
&&
161 type2
== IEEE80211_IF_TYPE_WDS
) ||
162 (type1
== IEEE80211_IF_TYPE_WDS
&&
163 (type2
== IEEE80211_IF_TYPE_WDS
||
164 type2
== IEEE80211_IF_TYPE_AP
)) ||
165 (type1
== IEEE80211_IF_TYPE_AP
&&
166 type2
== IEEE80211_IF_TYPE_VLAN
) ||
167 (type1
== IEEE80211_IF_TYPE_VLAN
&&
168 (type2
== IEEE80211_IF_TYPE_AP
||
169 type2
== IEEE80211_IF_TYPE_VLAN
)));
172 static int ieee80211_open(struct net_device
*dev
)
174 struct ieee80211_sub_if_data
*sdata
, *nsdata
;
175 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
176 struct ieee80211_if_init_conf conf
;
178 bool need_hw_reconfig
= 0;
180 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
182 /* we hold the RTNL here so can safely walk the list */
183 list_for_each_entry(nsdata
, &local
->interfaces
, list
) {
184 struct net_device
*ndev
= nsdata
->dev
;
186 if (ndev
!= dev
&& ndev
!= local
->mdev
&& netif_running(ndev
)) {
188 * Allow only a single IBSS interface to be up at any
189 * time. This is restricted because beacon distribution
190 * cannot work properly if both are in the same IBSS.
192 * To remove this restriction we'd have to disallow them
193 * from setting the same SSID on different IBSS interfaces
194 * belonging to the same hardware. Then, however, we're
195 * faced with having to adopt two different TSF timers...
197 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&&
198 nsdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
)
202 * Disallow multiple IBSS/STA mode interfaces.
204 * This is a technical restriction, it is possible although
205 * most likely not IEEE 802.11 compliant to have multiple
206 * STAs with just a single hardware (the TSF timer will not
207 * be adjusted properly.)
209 * However, because mac80211 uses the master device's BSS
210 * information for each STA/IBSS interface, doing this will
211 * currently corrupt that BSS information completely, unless,
212 * a not very useful case, both STAs are associated to the
215 * To remove this restriction, the BSS information needs to
216 * be embedded in the STA/IBSS mode sdata instead of using
217 * the master device's BSS structure.
219 if ((sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
220 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) &&
221 (nsdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
222 nsdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
))
226 * The remaining checks are only performed for interfaces
227 * with the same MAC address.
229 if (compare_ether_addr(dev
->dev_addr
, ndev
->dev_addr
))
233 * check whether it may have the same address
235 if (!identical_mac_addr_allowed(sdata
->vif
.type
,
240 * can only add VLANs to enabled APs
242 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_VLAN
&&
243 nsdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
244 sdata
->u
.vlan
.ap
= nsdata
;
248 switch (sdata
->vif
.type
) {
249 case IEEE80211_IF_TYPE_WDS
:
250 if (is_zero_ether_addr(sdata
->u
.wds
.remote_addr
))
253 case IEEE80211_IF_TYPE_VLAN
:
254 if (!sdata
->u
.vlan
.ap
)
257 case IEEE80211_IF_TYPE_AP
:
258 case IEEE80211_IF_TYPE_STA
:
259 case IEEE80211_IF_TYPE_MNTR
:
260 case IEEE80211_IF_TYPE_IBSS
:
261 case IEEE80211_IF_TYPE_MESH_POINT
:
262 /* no special treatment */
264 case IEEE80211_IF_TYPE_INVALID
:
270 if (local
->open_count
== 0) {
272 if (local
->ops
->start
)
273 res
= local
->ops
->start(local_to_hw(local
));
276 need_hw_reconfig
= 1;
277 ieee80211_led_radio(local
, local
->hw
.conf
.radio_enabled
);
280 switch (sdata
->vif
.type
) {
281 case IEEE80211_IF_TYPE_VLAN
:
282 list_add(&sdata
->u
.vlan
.list
, &sdata
->u
.vlan
.ap
->u
.ap
.vlans
);
283 /* no need to tell driver */
285 case IEEE80211_IF_TYPE_MNTR
:
286 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_COOK_FRAMES
) {
287 local
->cooked_mntrs
++;
291 /* must be before the call to ieee80211_configure_filter */
293 if (local
->monitors
== 1)
294 local
->hw
.conf
.flags
|= IEEE80211_CONF_RADIOTAP
;
296 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_FCSFAIL
)
297 local
->fif_fcsfail
++;
298 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_PLCPFAIL
)
299 local
->fif_plcpfail
++;
300 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_CONTROL
)
301 local
->fif_control
++;
302 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_OTHER_BSS
)
303 local
->fif_other_bss
++;
305 netif_tx_lock_bh(local
->mdev
);
306 ieee80211_configure_filter(local
);
307 netif_tx_unlock_bh(local
->mdev
);
309 case IEEE80211_IF_TYPE_STA
:
310 case IEEE80211_IF_TYPE_IBSS
:
311 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
314 conf
.vif
= &sdata
->vif
;
315 conf
.type
= sdata
->vif
.type
;
316 conf
.mac_addr
= dev
->dev_addr
;
317 res
= local
->ops
->add_interface(local_to_hw(local
), &conf
);
318 if (res
&& !local
->open_count
&& local
->ops
->stop
)
319 local
->ops
->stop(local_to_hw(local
));
323 ieee80211_if_config(dev
);
324 ieee80211_reset_erp_info(dev
);
325 ieee80211_enable_keys(sdata
);
327 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
&&
328 !(sdata
->flags
& IEEE80211_SDATA_USERSPACE_MLME
))
329 netif_carrier_off(dev
);
331 netif_carrier_on(dev
);
334 if (local
->open_count
== 0) {
335 res
= dev_open(local
->mdev
);
337 tasklet_enable(&local
->tx_pending_tasklet
);
338 tasklet_enable(&local
->tasklet
);
342 * set_multicast_list will be invoked by the networking core
343 * which will check whether any increments here were done in
344 * error and sync them down to the hardware as filter flags.
346 if (sdata
->flags
& IEEE80211_SDATA_ALLMULTI
)
347 atomic_inc(&local
->iff_allmultis
);
349 if (sdata
->flags
& IEEE80211_SDATA_PROMISC
)
350 atomic_inc(&local
->iff_promiscs
);
353 if (need_hw_reconfig
)
354 ieee80211_hw_config(local
);
356 netif_start_queue(dev
);
361 static int ieee80211_stop(struct net_device
*dev
)
363 struct ieee80211_sub_if_data
*sdata
;
364 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
365 struct ieee80211_if_init_conf conf
;
366 struct sta_info
*sta
;
369 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
371 list_for_each_entry(sta
, &local
->sta_list
, list
) {
373 for (i
= 0; i
< STA_TID_NUM
; i
++)
374 ieee80211_sta_stop_rx_ba_session(sta
->dev
,
377 WLAN_REASON_QSTA_LEAVE_QBSS
);
380 netif_stop_queue(dev
);
383 * Don't count this interface for promisc/allmulti while it
384 * is down. dev_mc_unsync() will invoke set_multicast_list
385 * on the master interface which will sync these down to the
386 * hardware as filter flags.
388 if (sdata
->flags
& IEEE80211_SDATA_ALLMULTI
)
389 atomic_dec(&local
->iff_allmultis
);
391 if (sdata
->flags
& IEEE80211_SDATA_PROMISC
)
392 atomic_dec(&local
->iff_promiscs
);
394 dev_mc_unsync(local
->mdev
, dev
);
396 /* APs need special treatment */
397 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
) {
398 struct ieee80211_sub_if_data
*vlan
, *tmp
;
399 struct beacon_data
*old_beacon
= sdata
->u
.ap
.beacon
;
402 rcu_assign_pointer(sdata
->u
.ap
.beacon
, NULL
);
406 /* down all dependent devices, that is VLANs */
407 list_for_each_entry_safe(vlan
, tmp
, &sdata
->u
.ap
.vlans
,
409 dev_close(vlan
->dev
);
410 WARN_ON(!list_empty(&sdata
->u
.ap
.vlans
));
415 switch (sdata
->vif
.type
) {
416 case IEEE80211_IF_TYPE_VLAN
:
417 list_del(&sdata
->u
.vlan
.list
);
418 sdata
->u
.vlan
.ap
= NULL
;
419 /* no need to tell driver */
421 case IEEE80211_IF_TYPE_MNTR
:
422 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_COOK_FRAMES
) {
423 local
->cooked_mntrs
--;
428 if (local
->monitors
== 0)
429 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_RADIOTAP
;
431 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_FCSFAIL
)
432 local
->fif_fcsfail
--;
433 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_PLCPFAIL
)
434 local
->fif_plcpfail
--;
435 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_CONTROL
)
436 local
->fif_control
--;
437 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_OTHER_BSS
)
438 local
->fif_other_bss
--;
440 netif_tx_lock_bh(local
->mdev
);
441 ieee80211_configure_filter(local
);
442 netif_tx_unlock_bh(local
->mdev
);
444 case IEEE80211_IF_TYPE_STA
:
445 case IEEE80211_IF_TYPE_IBSS
:
446 sdata
->u
.sta
.state
= IEEE80211_DISABLED
;
447 del_timer_sync(&sdata
->u
.sta
.timer
);
449 * When we get here, the interface is marked down.
450 * Call synchronize_rcu() to wait for the RX path
451 * should it be using the interface and enqueuing
452 * frames at this very time on another CPU.
455 skb_queue_purge(&sdata
->u
.sta
.skb_queue
);
457 if (local
->scan_dev
== sdata
->dev
) {
458 if (!local
->ops
->hw_scan
) {
459 local
->sta_sw_scanning
= 0;
460 cancel_delayed_work(&local
->scan_work
);
462 local
->sta_hw_scanning
= 0;
465 flush_workqueue(local
->hw
.workqueue
);
467 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_PRIVACY_INVOKED
;
468 kfree(sdata
->u
.sta
.extra_ie
);
469 sdata
->u
.sta
.extra_ie
= NULL
;
470 sdata
->u
.sta
.extra_ie_len
= 0;
473 conf
.vif
= &sdata
->vif
;
474 conf
.type
= sdata
->vif
.type
;
475 conf
.mac_addr
= dev
->dev_addr
;
476 /* disable all keys for as long as this netdev is down */
477 ieee80211_disable_keys(sdata
);
478 local
->ops
->remove_interface(local_to_hw(local
), &conf
);
481 if (local
->open_count
== 0) {
482 if (netif_running(local
->mdev
))
483 dev_close(local
->mdev
);
485 if (local
->ops
->stop
)
486 local
->ops
->stop(local_to_hw(local
));
488 ieee80211_led_radio(local
, 0);
490 tasklet_disable(&local
->tx_pending_tasklet
);
491 tasklet_disable(&local
->tasklet
);
497 int ieee80211_start_tx_ba_session(struct ieee80211_hw
*hw
, u8
*ra
, u16 tid
)
499 struct ieee80211_local
*local
= hw_to_local(hw
);
500 struct sta_info
*sta
;
501 struct ieee80211_sub_if_data
*sdata
;
502 u16 start_seq_num
= 0;
505 DECLARE_MAC_BUF(mac
);
507 if (tid
>= STA_TID_NUM
)
510 #ifdef CONFIG_MAC80211_HT_DEBUG
511 printk(KERN_DEBUG
"Open BA session requested for %s tid %u\n",
512 print_mac(mac
, ra
), tid
);
513 #endif /* CONFIG_MAC80211_HT_DEBUG */
515 sta
= sta_info_get(local
, ra
);
517 printk(KERN_DEBUG
"Could not find the station\n");
521 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
523 /* we have tried too many times, receiver does not want A-MPDU */
524 if (sta
->ampdu_mlme
.tid_tx
[tid
].addba_req_num
> HT_AGG_MAX_RETRIES
) {
529 state
= &sta
->ampdu_mlme
.tid_tx
[tid
].state
;
530 /* check if the TID is not in aggregation flow already */
531 if (*state
!= HT_AGG_STATE_IDLE
) {
532 #ifdef CONFIG_MAC80211_HT_DEBUG
533 printk(KERN_DEBUG
"BA request denied - session is not "
534 "idle on tid %u\n", tid
);
535 #endif /* CONFIG_MAC80211_HT_DEBUG */
540 /* ensure that TX flow won't interrupt us
541 * until the end of the call to requeue function */
542 spin_lock_bh(&local
->mdev
->queue_lock
);
544 /* create a new queue for this aggregation */
545 ret
= ieee80211_ht_agg_queue_add(local
, sta
, tid
);
547 /* case no queue is available to aggregation
548 * don't switch to aggregation */
550 #ifdef CONFIG_MAC80211_HT_DEBUG
551 printk(KERN_DEBUG
"BA request denied - no queue available for"
553 #endif /* CONFIG_MAC80211_HT_DEBUG */
554 spin_unlock_bh(&local
->mdev
->queue_lock
);
557 sdata
= IEEE80211_DEV_TO_SUB_IF(sta
->dev
);
559 /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
560 * call back right away, it must see that the flow has begun */
561 *state
|= HT_ADDBA_REQUESTED_MSK
;
563 if (local
->ops
->ampdu_action
)
564 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_TX_START
,
565 ra
, tid
, &start_seq_num
);
568 /* No need to requeue the packets in the agg queue, since we
569 * held the tx lock: no packet could be enqueued to the newly
571 ieee80211_ht_agg_queue_remove(local
, sta
, tid
, 0);
572 #ifdef CONFIG_MAC80211_HT_DEBUG
573 printk(KERN_DEBUG
"BA request denied - HW or queue unavailable"
574 " for tid %d\n", tid
);
575 #endif /* CONFIG_MAC80211_HT_DEBUG */
576 spin_unlock_bh(&local
->mdev
->queue_lock
);
577 *state
= HT_AGG_STATE_IDLE
;
581 /* Will put all the packets in the new SW queue */
582 ieee80211_requeue(local
, ieee802_1d_to_ac
[tid
]);
583 spin_unlock_bh(&local
->mdev
->queue_lock
);
585 /* We have most probably almost emptied the legacy queue */
586 /* ieee80211_wake_queue(local_to_hw(local), ieee802_1d_to_ac[tid]); */
588 /* send an addBA request */
589 sta
->ampdu_mlme
.dialog_token_allocator
++;
590 sta
->ampdu_mlme
.tid_tx
[tid
].dialog_token
=
591 sta
->ampdu_mlme
.dialog_token_allocator
;
592 sta
->ampdu_mlme
.tid_tx
[tid
].ssn
= start_seq_num
;
594 ieee80211_send_addba_request(sta
->dev
, ra
, tid
,
595 sta
->ampdu_mlme
.tid_tx
[tid
].dialog_token
,
596 sta
->ampdu_mlme
.tid_tx
[tid
].ssn
,
599 /* activate the timer for the recipient's addBA response */
600 sta
->ampdu_mlme
.tid_tx
[tid
].addba_resp_timer
.expires
=
601 jiffies
+ ADDBA_RESP_INTERVAL
;
602 add_timer(&sta
->ampdu_mlme
.tid_tx
[tid
].addba_resp_timer
);
603 printk(KERN_DEBUG
"activated addBA response timer on tid %d\n", tid
);
606 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
610 EXPORT_SYMBOL(ieee80211_start_tx_ba_session
);
612 int ieee80211_stop_tx_ba_session(struct ieee80211_hw
*hw
,
614 enum ieee80211_back_parties initiator
)
616 struct ieee80211_local
*local
= hw_to_local(hw
);
617 struct sta_info
*sta
;
620 DECLARE_MAC_BUF(mac
);
622 if (tid
>= STA_TID_NUM
)
625 #ifdef CONFIG_MAC80211_HT_DEBUG
626 printk(KERN_DEBUG
"Stop a BA session requested for %s tid %u\n",
627 print_mac(mac
, ra
), tid
);
628 #endif /* CONFIG_MAC80211_HT_DEBUG */
630 sta
= sta_info_get(local
, ra
);
634 /* check if the TID is in aggregation */
635 state
= &sta
->ampdu_mlme
.tid_tx
[tid
].state
;
636 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
638 if (*state
!= HT_AGG_STATE_OPERATIONAL
) {
639 #ifdef CONFIG_MAC80211_HT_DEBUG
640 printk(KERN_DEBUG
"Try to stop Tx aggregation on"
641 " non active TID\n");
642 #endif /* CONFIG_MAC80211_HT_DEBUG */
647 ieee80211_stop_queue(hw
, sta
->tid_to_tx_q
[tid
]);
649 *state
= HT_AGG_STATE_REQ_STOP_BA_MSK
|
650 (initiator
<< HT_AGG_STATE_INITIATOR_SHIFT
);
652 if (local
->ops
->ampdu_action
)
653 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_TX_STOP
,
656 /* case HW denied going back to legacy */
658 WARN_ON(ret
!= -EBUSY
);
659 *state
= HT_AGG_STATE_OPERATIONAL
;
660 ieee80211_wake_queue(hw
, sta
->tid_to_tx_q
[tid
]);
665 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
669 EXPORT_SYMBOL(ieee80211_stop_tx_ba_session
);
671 void ieee80211_start_tx_ba_cb(struct ieee80211_hw
*hw
, u8
*ra
, u16 tid
)
673 struct ieee80211_local
*local
= hw_to_local(hw
);
674 struct sta_info
*sta
;
676 DECLARE_MAC_BUF(mac
);
678 if (tid
>= STA_TID_NUM
) {
679 printk(KERN_DEBUG
"Bad TID value: tid = %d (>= %d)\n",
684 sta
= sta_info_get(local
, ra
);
686 printk(KERN_DEBUG
"Could not find station: %s\n",
691 state
= &sta
->ampdu_mlme
.tid_tx
[tid
].state
;
692 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
694 if (!(*state
& HT_ADDBA_REQUESTED_MSK
)) {
695 printk(KERN_DEBUG
"addBA was not requested yet, state is %d\n",
697 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
702 WARN_ON_ONCE(*state
& HT_ADDBA_DRV_READY_MSK
);
704 *state
|= HT_ADDBA_DRV_READY_MSK
;
706 if (*state
== HT_AGG_STATE_OPERATIONAL
) {
707 printk(KERN_DEBUG
"Aggregation is on for tid %d \n", tid
);
708 ieee80211_wake_queue(hw
, sta
->tid_to_tx_q
[tid
]);
710 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
713 EXPORT_SYMBOL(ieee80211_start_tx_ba_cb
);
715 void ieee80211_stop_tx_ba_cb(struct ieee80211_hw
*hw
, u8
*ra
, u8 tid
)
717 struct ieee80211_local
*local
= hw_to_local(hw
);
718 struct sta_info
*sta
;
721 DECLARE_MAC_BUF(mac
);
723 if (tid
>= STA_TID_NUM
) {
724 printk(KERN_DEBUG
"Bad TID value: tid = %d (>= %d)\n",
729 printk(KERN_DEBUG
"Stop a BA session requested on DA %s tid %d\n",
730 print_mac(mac
, ra
), tid
);
732 sta
= sta_info_get(local
, ra
);
734 printk(KERN_DEBUG
"Could not find station: %s\n",
738 state
= &sta
->ampdu_mlme
.tid_tx
[tid
].state
;
740 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
741 if ((*state
& HT_AGG_STATE_REQ_STOP_BA_MSK
) == 0) {
742 printk(KERN_DEBUG
"unexpected callback to A-MPDU stop\n");
744 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
748 if (*state
& HT_AGG_STATE_INITIATOR_MSK
)
749 ieee80211_send_delba(sta
->dev
, ra
, tid
,
750 WLAN_BACK_INITIATOR
, WLAN_REASON_QSTA_NOT_USE
);
752 agg_queue
= sta
->tid_to_tx_q
[tid
];
754 /* avoid ordering issues: we are the only one that can modify
755 * the content of the qdiscs */
756 spin_lock_bh(&local
->mdev
->queue_lock
);
757 /* remove the queue for this aggregation */
758 ieee80211_ht_agg_queue_remove(local
, sta
, tid
, 1);
759 spin_unlock_bh(&local
->mdev
->queue_lock
);
761 /* we just requeued the all the frames that were in the removed
762 * queue, and since we might miss a softirq we do netif_schedule.
763 * ieee80211_wake_queue is not used here as this queue is not
764 * necessarily stopped */
765 netif_schedule(local
->mdev
);
766 *state
= HT_AGG_STATE_IDLE
;
767 sta
->ampdu_mlme
.tid_tx
[tid
].addba_req_num
= 0;
768 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
772 EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb
);
774 void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw
*hw
,
775 const u8
*ra
, u16 tid
)
777 struct ieee80211_local
*local
= hw_to_local(hw
);
778 struct ieee80211_ra_tid
*ra_tid
;
779 struct sk_buff
*skb
= dev_alloc_skb(0);
781 if (unlikely(!skb
)) {
783 printk(KERN_WARNING
"%s: Not enough memory, "
784 "dropping start BA session", skb
->dev
->name
);
787 ra_tid
= (struct ieee80211_ra_tid
*) &skb
->cb
;
788 memcpy(&ra_tid
->ra
, ra
, ETH_ALEN
);
791 skb
->pkt_type
= IEEE80211_ADDBA_MSG
;
792 skb_queue_tail(&local
->skb_queue
, skb
);
793 tasklet_schedule(&local
->tasklet
);
795 EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe
);
797 void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw
*hw
,
798 const u8
*ra
, u16 tid
)
800 struct ieee80211_local
*local
= hw_to_local(hw
);
801 struct ieee80211_ra_tid
*ra_tid
;
802 struct sk_buff
*skb
= dev_alloc_skb(0);
804 if (unlikely(!skb
)) {
806 printk(KERN_WARNING
"%s: Not enough memory, "
807 "dropping stop BA session", skb
->dev
->name
);
810 ra_tid
= (struct ieee80211_ra_tid
*) &skb
->cb
;
811 memcpy(&ra_tid
->ra
, ra
, ETH_ALEN
);
814 skb
->pkt_type
= IEEE80211_DELBA_MSG
;
815 skb_queue_tail(&local
->skb_queue
, skb
);
816 tasklet_schedule(&local
->tasklet
);
818 EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe
);
820 static void ieee80211_set_multicast_list(struct net_device
*dev
)
822 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
823 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
824 int allmulti
, promisc
, sdata_allmulti
, sdata_promisc
;
826 allmulti
= !!(dev
->flags
& IFF_ALLMULTI
);
827 promisc
= !!(dev
->flags
& IFF_PROMISC
);
828 sdata_allmulti
= !!(sdata
->flags
& IEEE80211_SDATA_ALLMULTI
);
829 sdata_promisc
= !!(sdata
->flags
& IEEE80211_SDATA_PROMISC
);
831 if (allmulti
!= sdata_allmulti
) {
832 if (dev
->flags
& IFF_ALLMULTI
)
833 atomic_inc(&local
->iff_allmultis
);
835 atomic_dec(&local
->iff_allmultis
);
836 sdata
->flags
^= IEEE80211_SDATA_ALLMULTI
;
839 if (promisc
!= sdata_promisc
) {
840 if (dev
->flags
& IFF_PROMISC
)
841 atomic_inc(&local
->iff_promiscs
);
843 atomic_dec(&local
->iff_promiscs
);
844 sdata
->flags
^= IEEE80211_SDATA_PROMISC
;
847 dev_mc_sync(local
->mdev
, dev
);
850 static const struct header_ops ieee80211_header_ops
= {
851 .create
= eth_header
,
852 .parse
= header_parse_80211
,
853 .rebuild
= eth_rebuild_header
,
854 .cache
= eth_header_cache
,
855 .cache_update
= eth_header_cache_update
,
858 /* Must not be called for mdev */
859 void ieee80211_if_setup(struct net_device
*dev
)
862 dev
->hard_start_xmit
= ieee80211_subif_start_xmit
;
863 dev
->wireless_handlers
= &ieee80211_iw_handler_def
;
864 dev
->set_multicast_list
= ieee80211_set_multicast_list
;
865 dev
->change_mtu
= ieee80211_change_mtu
;
866 dev
->open
= ieee80211_open
;
867 dev
->stop
= ieee80211_stop
;
868 dev
->destructor
= ieee80211_if_free
;
871 /* WDS specialties */
873 int ieee80211_if_update_wds(struct net_device
*dev
, u8
*remote_addr
)
875 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
876 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
877 struct sta_info
*sta
;
878 DECLARE_MAC_BUF(mac
);
880 if (compare_ether_addr(remote_addr
, sdata
->u
.wds
.remote_addr
) == 0)
883 /* Create STA entry for the new peer */
884 sta
= sta_info_add(local
, dev
, remote_addr
, GFP_KERNEL
);
888 sta
->flags
|= WLAN_STA_AUTHORIZED
;
892 /* Remove STA entry for the old peer */
893 sta
= sta_info_get(local
, sdata
->u
.wds
.remote_addr
);
898 printk(KERN_DEBUG
"%s: could not find STA entry for WDS link "
900 dev
->name
, print_mac(mac
, sdata
->u
.wds
.remote_addr
));
903 /* Update WDS link data */
904 memcpy(&sdata
->u
.wds
.remote_addr
, remote_addr
, ETH_ALEN
);
909 /* everything else */
911 static int __ieee80211_if_config(struct net_device
*dev
,
912 struct sk_buff
*beacon
,
913 struct ieee80211_tx_control
*control
)
915 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
916 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
917 struct ieee80211_if_conf conf
;
919 if (!local
->ops
->config_interface
|| !netif_running(dev
))
922 memset(&conf
, 0, sizeof(conf
));
923 conf
.type
= sdata
->vif
.type
;
924 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
925 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
926 conf
.bssid
= sdata
->u
.sta
.bssid
;
927 conf
.ssid
= sdata
->u
.sta
.ssid
;
928 conf
.ssid_len
= sdata
->u
.sta
.ssid_len
;
929 } else if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
) {
930 conf
.ssid
= sdata
->u
.ap
.ssid
;
931 conf
.ssid_len
= sdata
->u
.ap
.ssid_len
;
932 conf
.beacon
= beacon
;
933 conf
.beacon_control
= control
;
935 return local
->ops
->config_interface(local_to_hw(local
),
939 int ieee80211_if_config(struct net_device
*dev
)
941 return __ieee80211_if_config(dev
, NULL
, NULL
);
944 int ieee80211_if_config_beacon(struct net_device
*dev
)
946 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
947 struct ieee80211_tx_control control
;
948 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
951 if (!(local
->hw
.flags
& IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE
))
953 skb
= ieee80211_beacon_get(local_to_hw(local
), &sdata
->vif
,
957 return __ieee80211_if_config(dev
, skb
, &control
);
960 int ieee80211_hw_config(struct ieee80211_local
*local
)
962 struct ieee80211_channel
*chan
;
965 if (local
->sta_sw_scanning
)
966 chan
= local
->scan_channel
;
968 chan
= local
->oper_channel
;
970 local
->hw
.conf
.channel
= chan
;
972 if (!local
->hw
.conf
.power_level
)
973 local
->hw
.conf
.power_level
= chan
->max_power
;
975 local
->hw
.conf
.power_level
= min(chan
->max_power
,
976 local
->hw
.conf
.power_level
);
978 local
->hw
.conf
.max_antenna_gain
= chan
->max_antenna_gain
;
980 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
981 printk(KERN_DEBUG
"%s: HW CONFIG: freq=%d\n",
982 wiphy_name(local
->hw
.wiphy
), chan
->center_freq
);
985 if (local
->open_count
)
986 ret
= local
->ops
->config(local_to_hw(local
), &local
->hw
.conf
);
992 * ieee80211_hw_config_ht should be used only after legacy configuration
993 * has been determined, as ht configuration depends upon the hardware's
994 * HT abilities for a _specific_ band.
996 int ieee80211_hw_config_ht(struct ieee80211_local
*local
, int enable_ht
,
997 struct ieee80211_ht_info
*req_ht_cap
,
998 struct ieee80211_ht_bss_info
*req_bss_cap
)
1000 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1001 struct ieee80211_supported_band
*sband
;
1004 sband
= local
->hw
.wiphy
->bands
[conf
->channel
->band
];
1006 /* HT is not supported */
1007 if (!sband
->ht_info
.ht_supported
) {
1008 conf
->flags
&= ~IEEE80211_CONF_SUPPORT_HT_MODE
;
1014 conf
->flags
&= ~IEEE80211_CONF_SUPPORT_HT_MODE
;
1016 conf
->flags
|= IEEE80211_CONF_SUPPORT_HT_MODE
;
1017 conf
->ht_conf
.cap
= req_ht_cap
->cap
& sband
->ht_info
.cap
;
1018 conf
->ht_conf
.cap
&= ~(IEEE80211_HT_CAP_MIMO_PS
);
1019 conf
->ht_conf
.cap
|=
1020 sband
->ht_info
.cap
& IEEE80211_HT_CAP_MIMO_PS
;
1021 conf
->ht_bss_conf
.primary_channel
=
1022 req_bss_cap
->primary_channel
;
1023 conf
->ht_bss_conf
.bss_cap
= req_bss_cap
->bss_cap
;
1024 conf
->ht_bss_conf
.bss_op_mode
= req_bss_cap
->bss_op_mode
;
1025 for (i
= 0; i
< SUPP_MCS_SET_LEN
; i
++)
1026 conf
->ht_conf
.supp_mcs_set
[i
] =
1027 sband
->ht_info
.supp_mcs_set
[i
] &
1028 req_ht_cap
->supp_mcs_set
[i
];
1030 /* In STA mode, this gives us indication
1031 * to the AP's mode of operation */
1032 conf
->ht_conf
.ht_supported
= 1;
1033 conf
->ht_conf
.ampdu_factor
= req_ht_cap
->ampdu_factor
;
1034 conf
->ht_conf
.ampdu_density
= req_ht_cap
->ampdu_density
;
1037 local
->ops
->conf_ht(local_to_hw(local
), &local
->hw
.conf
);
1042 void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data
*sdata
,
1045 struct ieee80211_local
*local
= sdata
->local
;
1050 if (local
->ops
->bss_info_changed
)
1051 local
->ops
->bss_info_changed(local_to_hw(local
),
1057 void ieee80211_reset_erp_info(struct net_device
*dev
)
1059 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1061 sdata
->bss_conf
.use_cts_prot
= 0;
1062 sdata
->bss_conf
.use_short_preamble
= 0;
1063 ieee80211_bss_info_change_notify(sdata
,
1064 BSS_CHANGED_ERP_CTS_PROT
|
1065 BSS_CHANGED_ERP_PREAMBLE
);
1068 void ieee80211_tx_status_irqsafe(struct ieee80211_hw
*hw
,
1069 struct sk_buff
*skb
,
1070 struct ieee80211_tx_status
*status
)
1072 struct ieee80211_local
*local
= hw_to_local(hw
);
1073 struct ieee80211_tx_status
*saved
;
1076 skb
->dev
= local
->mdev
;
1077 saved
= kmalloc(sizeof(struct ieee80211_tx_status
), GFP_ATOMIC
);
1078 if (unlikely(!saved
)) {
1079 if (net_ratelimit())
1080 printk(KERN_WARNING
"%s: Not enough memory, "
1081 "dropping tx status", skb
->dev
->name
);
1082 /* should be dev_kfree_skb_irq, but due to this function being
1083 * named _irqsafe instead of just _irq we can't be sure that
1084 * people won't call it from non-irq contexts */
1085 dev_kfree_skb_any(skb
);
1088 memcpy(saved
, status
, sizeof(struct ieee80211_tx_status
));
1089 /* copy pointer to saved status into skb->cb for use by tasklet */
1090 memcpy(skb
->cb
, &saved
, sizeof(saved
));
1092 skb
->pkt_type
= IEEE80211_TX_STATUS_MSG
;
1093 skb_queue_tail(status
->control
.flags
& IEEE80211_TXCTL_REQ_TX_STATUS
?
1094 &local
->skb_queue
: &local
->skb_queue_unreliable
, skb
);
1095 tmp
= skb_queue_len(&local
->skb_queue
) +
1096 skb_queue_len(&local
->skb_queue_unreliable
);
1097 while (tmp
> IEEE80211_IRQSAFE_QUEUE_LIMIT
&&
1098 (skb
= skb_dequeue(&local
->skb_queue_unreliable
))) {
1099 memcpy(&saved
, skb
->cb
, sizeof(saved
));
1101 dev_kfree_skb_irq(skb
);
1103 I802_DEBUG_INC(local
->tx_status_drop
);
1105 tasklet_schedule(&local
->tasklet
);
1107 EXPORT_SYMBOL(ieee80211_tx_status_irqsafe
);
1109 static void ieee80211_tasklet_handler(unsigned long data
)
1111 struct ieee80211_local
*local
= (struct ieee80211_local
*) data
;
1112 struct sk_buff
*skb
;
1113 struct ieee80211_rx_status rx_status
;
1114 struct ieee80211_tx_status
*tx_status
;
1115 struct ieee80211_ra_tid
*ra_tid
;
1117 while ((skb
= skb_dequeue(&local
->skb_queue
)) ||
1118 (skb
= skb_dequeue(&local
->skb_queue_unreliable
))) {
1119 switch (skb
->pkt_type
) {
1120 case IEEE80211_RX_MSG
:
1121 /* status is in skb->cb */
1122 memcpy(&rx_status
, skb
->cb
, sizeof(rx_status
));
1123 /* Clear skb->pkt_type in order to not confuse kernel
1126 __ieee80211_rx(local_to_hw(local
), skb
, &rx_status
);
1128 case IEEE80211_TX_STATUS_MSG
:
1129 /* get pointer to saved status out of skb->cb */
1130 memcpy(&tx_status
, skb
->cb
, sizeof(tx_status
));
1132 ieee80211_tx_status(local_to_hw(local
),
1136 case IEEE80211_DELBA_MSG
:
1137 ra_tid
= (struct ieee80211_ra_tid
*) &skb
->cb
;
1138 ieee80211_stop_tx_ba_cb(local_to_hw(local
),
1139 ra_tid
->ra
, ra_tid
->tid
);
1142 case IEEE80211_ADDBA_MSG
:
1143 ra_tid
= (struct ieee80211_ra_tid
*) &skb
->cb
;
1144 ieee80211_start_tx_ba_cb(local_to_hw(local
),
1145 ra_tid
->ra
, ra_tid
->tid
);
1148 default: /* should never get here! */
1149 printk(KERN_ERR
"%s: Unknown message type (%d)\n",
1150 wiphy_name(local
->hw
.wiphy
), skb
->pkt_type
);
1157 /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
1158 * make a prepared TX frame (one that has been given to hw) to look like brand
1159 * new IEEE 802.11 frame that is ready to go through TX processing again.
1160 * Also, tx_packet_data in cb is restored from tx_control. */
1161 static void ieee80211_remove_tx_extra(struct ieee80211_local
*local
,
1162 struct ieee80211_key
*key
,
1163 struct sk_buff
*skb
,
1164 struct ieee80211_tx_control
*control
)
1166 int hdrlen
, iv_len
, mic_len
;
1167 struct ieee80211_tx_packet_data
*pkt_data
;
1169 pkt_data
= (struct ieee80211_tx_packet_data
*)skb
->cb
;
1170 pkt_data
->ifindex
= vif_to_sdata(control
->vif
)->dev
->ifindex
;
1171 pkt_data
->flags
= 0;
1172 if (control
->flags
& IEEE80211_TXCTL_REQ_TX_STATUS
)
1173 pkt_data
->flags
|= IEEE80211_TXPD_REQ_TX_STATUS
;
1174 if (control
->flags
& IEEE80211_TXCTL_DO_NOT_ENCRYPT
)
1175 pkt_data
->flags
|= IEEE80211_TXPD_DO_NOT_ENCRYPT
;
1176 if (control
->flags
& IEEE80211_TXCTL_REQUEUE
)
1177 pkt_data
->flags
|= IEEE80211_TXPD_REQUEUE
;
1178 if (control
->flags
& IEEE80211_TXCTL_EAPOL_FRAME
)
1179 pkt_data
->flags
|= IEEE80211_TXPD_EAPOL_FRAME
;
1180 pkt_data
->queue
= control
->queue
;
1182 hdrlen
= ieee80211_get_hdrlen_from_skb(skb
);
1187 switch (key
->conf
.alg
) {
1189 iv_len
= WEP_IV_LEN
;
1190 mic_len
= WEP_ICV_LEN
;
1193 iv_len
= TKIP_IV_LEN
;
1194 mic_len
= TKIP_ICV_LEN
;
1197 iv_len
= CCMP_HDR_LEN
;
1198 mic_len
= CCMP_MIC_LEN
;
1204 if (skb
->len
>= mic_len
&&
1205 !(key
->flags
& KEY_FLAG_UPLOADED_TO_HARDWARE
))
1206 skb_trim(skb
, skb
->len
- mic_len
);
1207 if (skb
->len
>= iv_len
&& skb
->len
> hdrlen
) {
1208 memmove(skb
->data
+ iv_len
, skb
->data
, hdrlen
);
1209 skb_pull(skb
, iv_len
);
1214 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1215 u16 fc
= le16_to_cpu(hdr
->frame_control
);
1216 if ((fc
& 0x8C) == 0x88) /* QoS Control Field */ {
1217 fc
&= ~IEEE80211_STYPE_QOS_DATA
;
1218 hdr
->frame_control
= cpu_to_le16(fc
);
1219 memmove(skb
->data
+ 2, skb
->data
, hdrlen
- 2);
1225 static void ieee80211_handle_filtered_frame(struct ieee80211_local
*local
,
1226 struct sta_info
*sta
,
1227 struct sk_buff
*skb
,
1228 struct ieee80211_tx_status
*status
)
1230 sta
->tx_filtered_count
++;
1233 * Clear the TX filter mask for this STA when sending the next
1234 * packet. If the STA went to power save mode, this will happen
1235 * happen when it wakes up for the next time.
1237 sta
->flags
|= WLAN_STA_CLEAR_PS_FILT
;
1240 * This code races in the following way:
1242 * (1) STA sends frame indicating it will go to sleep and does so
1243 * (2) hardware/firmware adds STA to filter list, passes frame up
1244 * (3) hardware/firmware processes TX fifo and suppresses a frame
1245 * (4) we get TX status before having processed the frame and
1246 * knowing that the STA has gone to sleep.
1248 * This is actually quite unlikely even when both those events are
1249 * processed from interrupts coming in quickly after one another or
1250 * even at the same time because we queue both TX status events and
1251 * RX frames to be processed by a tasklet and process them in the
1252 * same order that they were received or TX status last. Hence, there
1253 * is no race as long as the frame RX is processed before the next TX
1254 * status, which drivers can ensure, see below.
1256 * Note that this can only happen if the hardware or firmware can
1257 * actually add STAs to the filter list, if this is done by the
1258 * driver in response to set_tim() (which will only reduce the race
1259 * this whole filtering tries to solve, not completely solve it)
1260 * this situation cannot happen.
1262 * To completely solve this race drivers need to make sure that they
1263 * (a) don't mix the irq-safe/not irq-safe TX status/RX processing
1265 * (b) always process RX events before TX status events if ordering
1266 * can be unknown, for example with different interrupt status
1269 if (sta
->flags
& WLAN_STA_PS
&&
1270 skb_queue_len(&sta
->tx_filtered
) < STA_MAX_TX_BUFFER
) {
1271 ieee80211_remove_tx_extra(local
, sta
->key
, skb
,
1273 skb_queue_tail(&sta
->tx_filtered
, skb
);
1277 if (!(sta
->flags
& WLAN_STA_PS
) &&
1278 !(status
->control
.flags
& IEEE80211_TXCTL_REQUEUE
)) {
1279 /* Software retry the packet once */
1280 status
->control
.flags
|= IEEE80211_TXCTL_REQUEUE
;
1281 ieee80211_remove_tx_extra(local
, sta
->key
, skb
,
1283 dev_queue_xmit(skb
);
1287 if (net_ratelimit())
1288 printk(KERN_DEBUG
"%s: dropped TX filtered frame, "
1289 "queue_len=%d PS=%d @%lu\n",
1290 wiphy_name(local
->hw
.wiphy
),
1291 skb_queue_len(&sta
->tx_filtered
),
1292 !!(sta
->flags
& WLAN_STA_PS
), jiffies
);
1296 void ieee80211_tx_status(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
1297 struct ieee80211_tx_status
*status
)
1299 struct sk_buff
*skb2
;
1300 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1301 struct ieee80211_local
*local
= hw_to_local(hw
);
1303 struct ieee80211_tx_status_rtap_hdr
*rthdr
;
1304 struct ieee80211_sub_if_data
*sdata
;
1305 struct net_device
*prev_dev
= NULL
;
1309 "%s: ieee80211_tx_status called with NULL status\n",
1310 wiphy_name(local
->hw
.wiphy
));
1315 if (status
->excessive_retries
) {
1316 struct sta_info
*sta
;
1317 sta
= sta_info_get(local
, hdr
->addr1
);
1319 if (sta
->flags
& WLAN_STA_PS
) {
1321 * The STA is in power save mode, so assume
1322 * that this TX packet failed because of that.
1324 status
->excessive_retries
= 0;
1325 status
->flags
|= IEEE80211_TX_STATUS_TX_FILTERED
;
1326 ieee80211_handle_filtered_frame(local
, sta
,
1335 if (status
->flags
& IEEE80211_TX_STATUS_TX_FILTERED
) {
1336 struct sta_info
*sta
;
1337 sta
= sta_info_get(local
, hdr
->addr1
);
1339 ieee80211_handle_filtered_frame(local
, sta
, skb
,
1345 rate_control_tx_status(local
->mdev
, skb
, status
);
1347 ieee80211_led_tx(local
, 0);
1350 * Fragments are passed to low-level drivers as separate skbs, so these
1351 * are actually fragments, not frames. Update frame counters only for
1352 * the first fragment of the frame. */
1354 frag
= le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_FRAG
;
1355 type
= le16_to_cpu(hdr
->frame_control
) & IEEE80211_FCTL_FTYPE
;
1357 if (status
->flags
& IEEE80211_TX_STATUS_ACK
) {
1359 local
->dot11TransmittedFrameCount
++;
1360 if (is_multicast_ether_addr(hdr
->addr1
))
1361 local
->dot11MulticastTransmittedFrameCount
++;
1362 if (status
->retry_count
> 0)
1363 local
->dot11RetryCount
++;
1364 if (status
->retry_count
> 1)
1365 local
->dot11MultipleRetryCount
++;
1368 /* This counter shall be incremented for an acknowledged MPDU
1369 * with an individual address in the address 1 field or an MPDU
1370 * with a multicast address in the address 1 field of type Data
1372 if (!is_multicast_ether_addr(hdr
->addr1
) ||
1373 type
== IEEE80211_FTYPE_DATA
||
1374 type
== IEEE80211_FTYPE_MGMT
)
1375 local
->dot11TransmittedFragmentCount
++;
1378 local
->dot11FailedCount
++;
1381 /* this was a transmitted frame, but now we want to reuse it */
1385 * This is a bit racy but we can avoid a lot of work
1388 if (!local
->monitors
&& !local
->cooked_mntrs
) {
1393 /* send frame to monitor interfaces now */
1395 if (skb_headroom(skb
) < sizeof(*rthdr
)) {
1396 printk(KERN_ERR
"ieee80211_tx_status: headroom too small\n");
1401 rthdr
= (struct ieee80211_tx_status_rtap_hdr
*)
1402 skb_push(skb
, sizeof(*rthdr
));
1404 memset(rthdr
, 0, sizeof(*rthdr
));
1405 rthdr
->hdr
.it_len
= cpu_to_le16(sizeof(*rthdr
));
1406 rthdr
->hdr
.it_present
=
1407 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS
) |
1408 (1 << IEEE80211_RADIOTAP_DATA_RETRIES
));
1410 if (!(status
->flags
& IEEE80211_TX_STATUS_ACK
) &&
1411 !is_multicast_ether_addr(hdr
->addr1
))
1412 rthdr
->tx_flags
|= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL
);
1414 if ((status
->control
.flags
& IEEE80211_TXCTL_USE_RTS_CTS
) &&
1415 (status
->control
.flags
& IEEE80211_TXCTL_USE_CTS_PROTECT
))
1416 rthdr
->tx_flags
|= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS
);
1417 else if (status
->control
.flags
& IEEE80211_TXCTL_USE_RTS_CTS
)
1418 rthdr
->tx_flags
|= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS
);
1420 rthdr
->data_retries
= status
->retry_count
;
1422 /* XXX: is this sufficient for BPF? */
1423 skb_set_mac_header(skb
, 0);
1424 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1425 skb
->pkt_type
= PACKET_OTHERHOST
;
1426 skb
->protocol
= htons(ETH_P_802_2
);
1427 memset(skb
->cb
, 0, sizeof(skb
->cb
));
1430 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
1431 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_MNTR
) {
1432 if (!netif_running(sdata
->dev
))
1436 skb2
= skb_clone(skb
, GFP_ATOMIC
);
1438 skb2
->dev
= prev_dev
;
1443 prev_dev
= sdata
->dev
;
1447 skb
->dev
= prev_dev
;
1454 EXPORT_SYMBOL(ieee80211_tx_status
);
1456 struct ieee80211_hw
*ieee80211_alloc_hw(size_t priv_data_len
,
1457 const struct ieee80211_ops
*ops
)
1459 struct ieee80211_local
*local
;
1461 struct wiphy
*wiphy
;
1463 /* Ensure 32-byte alignment of our private data and hw private data.
1464 * We use the wiphy priv data for both our ieee80211_local and for
1465 * the driver's private data
1467 * In memory it'll be like this:
1469 * +-------------------------+
1471 * +-------------------------+
1472 * | struct ieee80211_local |
1473 * +-------------------------+
1474 * | driver's private data |
1475 * +-------------------------+
1478 priv_size
= ((sizeof(struct ieee80211_local
) +
1479 NETDEV_ALIGN_CONST
) & ~NETDEV_ALIGN_CONST
) +
1482 wiphy
= wiphy_new(&mac80211_config_ops
, priv_size
);
1487 wiphy
->privid
= mac80211_wiphy_privid
;
1489 local
= wiphy_priv(wiphy
);
1490 local
->hw
.wiphy
= wiphy
;
1492 local
->hw
.priv
= (char *)local
+
1493 ((sizeof(struct ieee80211_local
) +
1494 NETDEV_ALIGN_CONST
) & ~NETDEV_ALIGN_CONST
);
1497 BUG_ON(!ops
->start
);
1499 BUG_ON(!ops
->config
);
1500 BUG_ON(!ops
->add_interface
);
1501 BUG_ON(!ops
->remove_interface
);
1502 BUG_ON(!ops
->configure_filter
);
1505 local
->hw
.queues
= 1; /* default */
1507 local
->bridge_packets
= 1;
1509 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
1510 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
1511 local
->short_retry_limit
= 7;
1512 local
->long_retry_limit
= 4;
1513 local
->hw
.conf
.radio_enabled
= 1;
1515 INIT_LIST_HEAD(&local
->interfaces
);
1517 INIT_DELAYED_WORK(&local
->scan_work
, ieee80211_sta_scan_work
);
1519 sta_info_init(local
);
1521 tasklet_init(&local
->tx_pending_tasklet
, ieee80211_tx_pending
,
1522 (unsigned long)local
);
1523 tasklet_disable(&local
->tx_pending_tasklet
);
1525 tasklet_init(&local
->tasklet
,
1526 ieee80211_tasklet_handler
,
1527 (unsigned long) local
);
1528 tasklet_disable(&local
->tasklet
);
1530 skb_queue_head_init(&local
->skb_queue
);
1531 skb_queue_head_init(&local
->skb_queue_unreliable
);
1533 return local_to_hw(local
);
1535 EXPORT_SYMBOL(ieee80211_alloc_hw
);
1537 int ieee80211_register_hw(struct ieee80211_hw
*hw
)
1539 struct ieee80211_local
*local
= hw_to_local(hw
);
1542 enum ieee80211_band band
;
1543 struct net_device
*mdev
;
1544 struct ieee80211_sub_if_data
*sdata
;
1547 * generic code guarantees at least one band,
1548 * set this very early because much code assumes
1549 * that hw.conf.channel is assigned
1551 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1552 struct ieee80211_supported_band
*sband
;
1554 sband
= local
->hw
.wiphy
->bands
[band
];
1556 /* init channel we're on */
1557 local
->hw
.conf
.channel
=
1558 local
->oper_channel
=
1559 local
->scan_channel
= &sband
->channels
[0];
1564 result
= wiphy_register(local
->hw
.wiphy
);
1568 /* for now, mdev needs sub_if_data :/ */
1569 mdev
= alloc_netdev(sizeof(struct ieee80211_sub_if_data
),
1570 "wmaster%d", ether_setup
);
1572 goto fail_mdev_alloc
;
1574 sdata
= IEEE80211_DEV_TO_SUB_IF(mdev
);
1575 mdev
->ieee80211_ptr
= &sdata
->wdev
;
1576 sdata
->wdev
.wiphy
= local
->hw
.wiphy
;
1580 ieee80211_rx_bss_list_init(mdev
);
1582 mdev
->hard_start_xmit
= ieee80211_master_start_xmit
;
1583 mdev
->open
= ieee80211_master_open
;
1584 mdev
->stop
= ieee80211_master_stop
;
1585 mdev
->type
= ARPHRD_IEEE80211
;
1586 mdev
->header_ops
= &ieee80211_header_ops
;
1587 mdev
->set_multicast_list
= ieee80211_master_set_multicast_list
;
1589 sdata
->vif
.type
= IEEE80211_IF_TYPE_AP
;
1591 sdata
->local
= local
;
1592 sdata
->u
.ap
.force_unicast_rateidx
= -1;
1593 sdata
->u
.ap
.max_ratectrl_rateidx
= -1;
1594 ieee80211_if_sdata_init(sdata
);
1596 /* no RCU needed since we're still during init phase */
1597 list_add_tail(&sdata
->list
, &local
->interfaces
);
1599 name
= wiphy_dev(local
->hw
.wiphy
)->driver
->name
;
1600 local
->hw
.workqueue
= create_singlethread_workqueue(name
);
1601 if (!local
->hw
.workqueue
) {
1603 goto fail_workqueue
;
1607 * The hardware needs headroom for sending the frame,
1608 * and we need some headroom for passing the frame to monitor
1609 * interfaces, but never both at the same time.
1611 local
->tx_headroom
= max_t(unsigned int , local
->hw
.extra_tx_headroom
,
1612 sizeof(struct ieee80211_tx_status_rtap_hdr
));
1614 debugfs_hw_add(local
);
1616 local
->hw
.conf
.beacon_int
= 1000;
1618 local
->wstats_flags
|= local
->hw
.max_rssi
?
1619 IW_QUAL_LEVEL_UPDATED
: IW_QUAL_LEVEL_INVALID
;
1620 local
->wstats_flags
|= local
->hw
.max_signal
?
1621 IW_QUAL_QUAL_UPDATED
: IW_QUAL_QUAL_INVALID
;
1622 local
->wstats_flags
|= local
->hw
.max_noise
?
1623 IW_QUAL_NOISE_UPDATED
: IW_QUAL_NOISE_INVALID
;
1624 if (local
->hw
.max_rssi
< 0 || local
->hw
.max_noise
< 0)
1625 local
->wstats_flags
|= IW_QUAL_DBM
;
1627 result
= sta_info_start(local
);
1632 result
= dev_alloc_name(local
->mdev
, local
->mdev
->name
);
1636 memcpy(local
->mdev
->dev_addr
, local
->hw
.wiphy
->perm_addr
, ETH_ALEN
);
1637 SET_NETDEV_DEV(local
->mdev
, wiphy_dev(local
->hw
.wiphy
));
1639 result
= register_netdevice(local
->mdev
);
1643 ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local
->mdev
));
1644 ieee80211_if_set_type(local
->mdev
, IEEE80211_IF_TYPE_AP
);
1646 result
= ieee80211_init_rate_ctrl_alg(local
,
1647 hw
->rate_control_algorithm
);
1649 printk(KERN_DEBUG
"%s: Failed to initialize rate control "
1650 "algorithm\n", wiphy_name(local
->hw
.wiphy
));
1654 result
= ieee80211_wep_init(local
);
1657 printk(KERN_DEBUG
"%s: Failed to initialize wep\n",
1658 wiphy_name(local
->hw
.wiphy
));
1662 ieee80211_install_qdisc(local
->mdev
);
1664 /* add one default STA interface */
1665 result
= ieee80211_if_add(local
->mdev
, "wlan%d", NULL
,
1666 IEEE80211_IF_TYPE_STA
, NULL
);
1668 printk(KERN_WARNING
"%s: Failed to add default virtual iface\n",
1669 wiphy_name(local
->hw
.wiphy
));
1671 local
->reg_state
= IEEE80211_DEV_REGISTERED
;
1674 ieee80211_led_init(local
);
1679 rate_control_deinitialize(local
);
1681 ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local
->mdev
));
1682 unregister_netdevice(local
->mdev
);
1685 sta_info_stop(local
);
1687 debugfs_hw_del(local
);
1688 destroy_workqueue(local
->hw
.workqueue
);
1690 ieee80211_if_free(local
->mdev
);
1693 wiphy_unregister(local
->hw
.wiphy
);
1696 EXPORT_SYMBOL(ieee80211_register_hw
);
1698 void ieee80211_unregister_hw(struct ieee80211_hw
*hw
)
1700 struct ieee80211_local
*local
= hw_to_local(hw
);
1701 struct ieee80211_sub_if_data
*sdata
, *tmp
;
1703 tasklet_kill(&local
->tx_pending_tasklet
);
1704 tasklet_kill(&local
->tasklet
);
1708 BUG_ON(local
->reg_state
!= IEEE80211_DEV_REGISTERED
);
1710 local
->reg_state
= IEEE80211_DEV_UNREGISTERED
;
1713 * At this point, interface list manipulations are fine
1714 * because the driver cannot be handing us frames any
1715 * more and the tasklet is killed.
1719 * First, we remove all non-master interfaces. Do this because they
1720 * may have bss pointer dependency on the master, and when we free
1721 * the master these would be freed as well, breaking our list
1722 * iteration completely.
1724 list_for_each_entry_safe(sdata
, tmp
, &local
->interfaces
, list
) {
1725 if (sdata
->dev
== local
->mdev
)
1727 list_del(&sdata
->list
);
1728 __ieee80211_if_del(local
, sdata
);
1731 /* then, finally, remove the master interface */
1732 __ieee80211_if_del(local
, IEEE80211_DEV_TO_SUB_IF(local
->mdev
));
1736 ieee80211_rx_bss_list_deinit(local
->mdev
);
1737 ieee80211_clear_tx_pending(local
);
1738 sta_info_stop(local
);
1739 rate_control_deinitialize(local
);
1740 debugfs_hw_del(local
);
1742 if (skb_queue_len(&local
->skb_queue
)
1743 || skb_queue_len(&local
->skb_queue_unreliable
))
1744 printk(KERN_WARNING
"%s: skb_queue not empty\n",
1745 wiphy_name(local
->hw
.wiphy
));
1746 skb_queue_purge(&local
->skb_queue
);
1747 skb_queue_purge(&local
->skb_queue_unreliable
);
1749 destroy_workqueue(local
->hw
.workqueue
);
1750 wiphy_unregister(local
->hw
.wiphy
);
1751 ieee80211_wep_free(local
);
1752 ieee80211_led_exit(local
);
1753 ieee80211_if_free(local
->mdev
);
1756 EXPORT_SYMBOL(ieee80211_unregister_hw
);
1758 void ieee80211_free_hw(struct ieee80211_hw
*hw
)
1760 struct ieee80211_local
*local
= hw_to_local(hw
);
1762 wiphy_free(local
->hw
.wiphy
);
1764 EXPORT_SYMBOL(ieee80211_free_hw
);
1766 static int __init
ieee80211_init(void)
1768 struct sk_buff
*skb
;
1771 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data
) > sizeof(skb
->cb
));
1773 ret
= rc80211_simple_init();
1777 ret
= rc80211_pid_init();
1779 goto out_cleanup_simple
;
1781 ret
= ieee80211_wme_register();
1783 printk(KERN_DEBUG
"ieee80211_init: failed to "
1784 "initialize WME (err=%d)\n", ret
);
1785 goto out_cleanup_pid
;
1788 ieee80211_debugfs_netdev_init();
1795 rc80211_simple_exit();
1800 static void __exit
ieee80211_exit(void)
1802 rc80211_simple_exit();
1805 ieee80211_wme_unregister();
1806 ieee80211_debugfs_netdev_exit();
1810 subsys_initcall(ieee80211_init
);
1811 module_exit(ieee80211_exit
);
1813 MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1814 MODULE_LICENSE("GPL");