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_CONTROL
|
72 FIF_BCN_PRBRESP_PROMISC
;
74 changed_flags
= local
->filter_flags
^ new_flags
;
79 local
->ops
->configure_filter(local_to_hw(local
),
80 changed_flags
, &new_flags
,
81 local
->mdev
->mc_count
,
82 local
->mdev
->mc_list
);
84 WARN_ON(new_flags
& (1<<31));
86 local
->filter_flags
= new_flags
& ~(1<<31);
89 /* master interface */
91 static int ieee80211_master_open(struct net_device
*dev
)
93 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
94 struct ieee80211_sub_if_data
*sdata
;
95 int res
= -EOPNOTSUPP
;
97 /* we hold the RTNL here so can safely walk the list */
98 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
99 if (sdata
->dev
!= dev
&& netif_running(sdata
->dev
)) {
107 static int ieee80211_master_stop(struct net_device
*dev
)
109 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
110 struct ieee80211_sub_if_data
*sdata
;
112 /* we hold the RTNL here so can safely walk the list */
113 list_for_each_entry(sdata
, &local
->interfaces
, list
)
114 if (sdata
->dev
!= dev
&& netif_running(sdata
->dev
))
115 dev_close(sdata
->dev
);
120 static void ieee80211_master_set_multicast_list(struct net_device
*dev
)
122 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
124 ieee80211_configure_filter(local
);
127 /* regular interfaces */
129 static int ieee80211_change_mtu(struct net_device
*dev
, int new_mtu
)
131 /* FIX: what would be proper limits for MTU?
132 * This interface uses 802.3 frames. */
133 if (new_mtu
< 256 || new_mtu
> IEEE80211_MAX_DATA_LEN
- 24 - 6) {
134 printk(KERN_WARNING
"%s: invalid MTU %d\n",
139 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
140 printk(KERN_DEBUG
"%s: setting MTU %d\n", dev
->name
, new_mtu
);
141 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
146 static inline int identical_mac_addr_allowed(int type1
, int type2
)
148 return (type1
== IEEE80211_IF_TYPE_MNTR
||
149 type2
== IEEE80211_IF_TYPE_MNTR
||
150 (type1
== IEEE80211_IF_TYPE_AP
&&
151 type2
== IEEE80211_IF_TYPE_WDS
) ||
152 (type1
== IEEE80211_IF_TYPE_WDS
&&
153 (type2
== IEEE80211_IF_TYPE_WDS
||
154 type2
== IEEE80211_IF_TYPE_AP
)) ||
155 (type1
== IEEE80211_IF_TYPE_AP
&&
156 type2
== IEEE80211_IF_TYPE_VLAN
) ||
157 (type1
== IEEE80211_IF_TYPE_VLAN
&&
158 (type2
== IEEE80211_IF_TYPE_AP
||
159 type2
== IEEE80211_IF_TYPE_VLAN
)));
162 static int ieee80211_open(struct net_device
*dev
)
164 struct ieee80211_sub_if_data
*sdata
, *nsdata
;
165 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
166 struct ieee80211_if_init_conf conf
;
168 bool need_hw_reconfig
= 0;
170 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
172 /* we hold the RTNL here so can safely walk the list */
173 list_for_each_entry(nsdata
, &local
->interfaces
, list
) {
174 struct net_device
*ndev
= nsdata
->dev
;
176 if (ndev
!= dev
&& ndev
!= local
->mdev
&& netif_running(ndev
) &&
177 compare_ether_addr(dev
->dev_addr
, ndev
->dev_addr
) == 0) {
179 * check whether it may have the same address
181 if (!identical_mac_addr_allowed(sdata
->vif
.type
,
186 * can only add VLANs to enabled APs
188 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_VLAN
&&
189 nsdata
->vif
.type
== IEEE80211_IF_TYPE_AP
&&
190 netif_running(nsdata
->dev
))
191 sdata
->u
.vlan
.ap
= nsdata
;
195 switch (sdata
->vif
.type
) {
196 case IEEE80211_IF_TYPE_WDS
:
197 if (is_zero_ether_addr(sdata
->u
.wds
.remote_addr
))
200 case IEEE80211_IF_TYPE_VLAN
:
201 if (!sdata
->u
.vlan
.ap
)
204 case IEEE80211_IF_TYPE_AP
:
205 case IEEE80211_IF_TYPE_STA
:
206 case IEEE80211_IF_TYPE_MNTR
:
207 case IEEE80211_IF_TYPE_IBSS
:
208 /* no special treatment */
210 case IEEE80211_IF_TYPE_INVALID
:
216 if (local
->open_count
== 0) {
218 if (local
->ops
->start
)
219 res
= local
->ops
->start(local_to_hw(local
));
222 need_hw_reconfig
= 1;
223 ieee80211_led_radio(local
, local
->hw
.conf
.radio_enabled
);
226 switch (sdata
->vif
.type
) {
227 case IEEE80211_IF_TYPE_VLAN
:
228 list_add(&sdata
->u
.vlan
.list
, &sdata
->u
.vlan
.ap
->u
.ap
.vlans
);
229 /* no need to tell driver */
231 case IEEE80211_IF_TYPE_MNTR
:
232 /* must be before the call to ieee80211_configure_filter */
234 if (local
->monitors
== 1) {
235 netif_tx_lock_bh(local
->mdev
);
236 ieee80211_configure_filter(local
);
237 netif_tx_unlock_bh(local
->mdev
);
239 local
->hw
.conf
.flags
|= IEEE80211_CONF_RADIOTAP
;
242 case IEEE80211_IF_TYPE_STA
:
243 case IEEE80211_IF_TYPE_IBSS
:
244 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
247 conf
.vif
= &sdata
->vif
;
248 conf
.type
= sdata
->vif
.type
;
249 conf
.mac_addr
= dev
->dev_addr
;
250 res
= local
->ops
->add_interface(local_to_hw(local
), &conf
);
251 if (res
&& !local
->open_count
&& local
->ops
->stop
)
252 local
->ops
->stop(local_to_hw(local
));
256 ieee80211_if_config(dev
);
257 ieee80211_reset_erp_info(dev
);
258 ieee80211_enable_keys(sdata
);
260 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
&&
261 !(sdata
->flags
& IEEE80211_SDATA_USERSPACE_MLME
))
262 netif_carrier_off(dev
);
264 netif_carrier_on(dev
);
267 if (local
->open_count
== 0) {
268 res
= dev_open(local
->mdev
);
270 tasklet_enable(&local
->tx_pending_tasklet
);
271 tasklet_enable(&local
->tasklet
);
275 * set_multicast_list will be invoked by the networking core
276 * which will check whether any increments here were done in
277 * error and sync them down to the hardware as filter flags.
279 if (sdata
->flags
& IEEE80211_SDATA_ALLMULTI
)
280 atomic_inc(&local
->iff_allmultis
);
282 if (sdata
->flags
& IEEE80211_SDATA_PROMISC
)
283 atomic_inc(&local
->iff_promiscs
);
286 if (need_hw_reconfig
)
287 ieee80211_hw_config(local
);
289 netif_start_queue(dev
);
294 static int ieee80211_stop(struct net_device
*dev
)
296 struct ieee80211_sub_if_data
*sdata
;
297 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
298 struct ieee80211_if_init_conf conf
;
299 struct sta_info
*sta
;
302 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
304 list_for_each_entry(sta
, &local
->sta_list
, list
) {
306 for (i
= 0; i
< STA_TID_NUM
; i
++)
307 ieee80211_sta_stop_rx_ba_session(sta
->dev
,
310 WLAN_REASON_QSTA_LEAVE_QBSS
);
313 netif_stop_queue(dev
);
316 * Don't count this interface for promisc/allmulti while it
317 * is down. dev_mc_unsync() will invoke set_multicast_list
318 * on the master interface which will sync these down to the
319 * hardware as filter flags.
321 if (sdata
->flags
& IEEE80211_SDATA_ALLMULTI
)
322 atomic_dec(&local
->iff_allmultis
);
324 if (sdata
->flags
& IEEE80211_SDATA_PROMISC
)
325 atomic_dec(&local
->iff_promiscs
);
327 dev_mc_unsync(local
->mdev
, dev
);
329 /* APs need special treatment */
330 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
) {
331 struct ieee80211_sub_if_data
*vlan
, *tmp
;
332 struct beacon_data
*old_beacon
= sdata
->u
.ap
.beacon
;
335 rcu_assign_pointer(sdata
->u
.ap
.beacon
, NULL
);
339 /* down all dependent devices, that is VLANs */
340 list_for_each_entry_safe(vlan
, tmp
, &sdata
->u
.ap
.vlans
,
342 dev_close(vlan
->dev
);
343 WARN_ON(!list_empty(&sdata
->u
.ap
.vlans
));
348 switch (sdata
->vif
.type
) {
349 case IEEE80211_IF_TYPE_VLAN
:
350 list_del(&sdata
->u
.vlan
.list
);
351 sdata
->u
.vlan
.ap
= NULL
;
352 /* no need to tell driver */
354 case IEEE80211_IF_TYPE_MNTR
:
356 if (local
->monitors
== 0) {
357 netif_tx_lock_bh(local
->mdev
);
358 ieee80211_configure_filter(local
);
359 netif_tx_unlock_bh(local
->mdev
);
361 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_RADIOTAP
;
364 case IEEE80211_IF_TYPE_STA
:
365 case IEEE80211_IF_TYPE_IBSS
:
366 sdata
->u
.sta
.state
= IEEE80211_DISABLED
;
367 del_timer_sync(&sdata
->u
.sta
.timer
);
369 * When we get here, the interface is marked down.
370 * Call synchronize_rcu() to wait for the RX path
371 * should it be using the interface and enqueuing
372 * frames at this very time on another CPU.
375 skb_queue_purge(&sdata
->u
.sta
.skb_queue
);
377 if (local
->scan_dev
== sdata
->dev
) {
378 if (!local
->ops
->hw_scan
) {
379 local
->sta_sw_scanning
= 0;
380 cancel_delayed_work(&local
->scan_work
);
382 local
->sta_hw_scanning
= 0;
385 flush_workqueue(local
->hw
.workqueue
);
387 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_PRIVACY_INVOKED
;
388 kfree(sdata
->u
.sta
.extra_ie
);
389 sdata
->u
.sta
.extra_ie
= NULL
;
390 sdata
->u
.sta
.extra_ie_len
= 0;
393 conf
.vif
= &sdata
->vif
;
394 conf
.type
= sdata
->vif
.type
;
395 conf
.mac_addr
= dev
->dev_addr
;
396 /* disable all keys for as long as this netdev is down */
397 ieee80211_disable_keys(sdata
);
398 local
->ops
->remove_interface(local_to_hw(local
), &conf
);
401 if (local
->open_count
== 0) {
402 if (netif_running(local
->mdev
))
403 dev_close(local
->mdev
);
405 if (local
->ops
->stop
)
406 local
->ops
->stop(local_to_hw(local
));
408 ieee80211_led_radio(local
, 0);
410 tasklet_disable(&local
->tx_pending_tasklet
);
411 tasklet_disable(&local
->tasklet
);
417 int ieee80211_start_tx_ba_session(struct ieee80211_hw
*hw
, u8
*ra
, u16 tid
)
419 struct ieee80211_local
*local
= hw_to_local(hw
);
420 struct sta_info
*sta
;
421 struct ieee80211_sub_if_data
*sdata
;
422 u16 start_seq_num
= 0;
425 DECLARE_MAC_BUF(mac
);
427 if (tid
>= STA_TID_NUM
)
430 #ifdef CONFIG_MAC80211_HT_DEBUG
431 printk(KERN_DEBUG
"Open BA session requested for %s tid %u\n",
432 print_mac(mac
, ra
), tid
);
433 #endif /* CONFIG_MAC80211_HT_DEBUG */
435 sta
= sta_info_get(local
, ra
);
437 printk(KERN_DEBUG
"Could not find the station\n");
441 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
443 /* we have tried too many times, receiver does not want A-MPDU */
444 if (sta
->ampdu_mlme
.tid_tx
[tid
].addba_req_num
> HT_AGG_MAX_RETRIES
) {
449 state
= &sta
->ampdu_mlme
.tid_tx
[tid
].state
;
450 /* check if the TID is not in aggregation flow already */
451 if (*state
!= HT_AGG_STATE_IDLE
) {
452 #ifdef CONFIG_MAC80211_HT_DEBUG
453 printk(KERN_DEBUG
"BA request denied - session is not "
454 "idle on tid %u\n", tid
);
455 #endif /* CONFIG_MAC80211_HT_DEBUG */
460 /* ensure that TX flow won't interrupt us
461 * until the end of the call to requeue function */
462 spin_lock_bh(&local
->mdev
->queue_lock
);
464 /* create a new queue for this aggregation */
465 /* ret = ieee80211_ht_agg_queue_add(local, sta, tid); */
467 /* case no queue is available to aggregation
468 * don't switch to aggregation */
470 #ifdef CONFIG_MAC80211_HT_DEBUG
471 printk(KERN_DEBUG
"BA request denied - no queue available for"
473 #endif /* CONFIG_MAC80211_HT_DEBUG */
474 spin_unlock_bh(&local
->mdev
->queue_lock
);
477 sdata
= IEEE80211_DEV_TO_SUB_IF(sta
->dev
);
479 /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
480 * call back right away, it must see that the flow has begun */
481 *state
|= HT_ADDBA_REQUESTED_MSK
;
483 if (local
->ops
->ampdu_action
)
484 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_TX_START
,
485 ra
, tid
, &start_seq_num
);
488 /* No need to requeue the packets in the agg queue, since we
489 * held the tx lock: no packet could be enqueued to the newly
491 /* ieee80211_ht_agg_queue_remove(local, sta, tid, 0); */
492 #ifdef CONFIG_MAC80211_HT_DEBUG
493 printk(KERN_DEBUG
"BA request denied - HW or queue unavailable"
494 " for tid %d\n", tid
);
495 #endif /* CONFIG_MAC80211_HT_DEBUG */
496 spin_unlock_bh(&local
->mdev
->queue_lock
);
497 *state
= HT_AGG_STATE_IDLE
;
501 /* Will put all the packets in the new SW queue */
502 /* ieee80211_requeue(local, ieee802_1d_to_ac[tid]); */
503 spin_unlock_bh(&local
->mdev
->queue_lock
);
505 /* We have most probably almost emptied the legacy queue */
506 /* ieee80211_wake_queue(local_to_hw(local), ieee802_1d_to_ac[tid]); */
508 /* send an addBA request */
509 sta
->ampdu_mlme
.dialog_token_allocator
++;
510 sta
->ampdu_mlme
.tid_tx
[tid
].dialog_token
=
511 sta
->ampdu_mlme
.dialog_token_allocator
;
512 sta
->ampdu_mlme
.tid_tx
[tid
].ssn
= start_seq_num
;
514 ieee80211_send_addba_request(sta
->dev
, ra
, tid
,
515 sta
->ampdu_mlme
.tid_tx
[tid
].dialog_token
,
516 sta
->ampdu_mlme
.tid_tx
[tid
].ssn
,
519 /* activate the timer for the recipient's addBA response */
520 sta
->ampdu_mlme
.tid_tx
[tid
].addba_resp_timer
.expires
=
521 jiffies
+ ADDBA_RESP_INTERVAL
;
522 add_timer(&sta
->ampdu_mlme
.tid_tx
[tid
].addba_resp_timer
);
523 printk(KERN_DEBUG
"activated addBA response timer on tid %d\n", tid
);
526 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
530 EXPORT_SYMBOL(ieee80211_start_tx_ba_session
);
532 int ieee80211_stop_tx_ba_session(struct ieee80211_hw
*hw
,
534 enum ieee80211_back_parties initiator
)
536 struct ieee80211_local
*local
= hw_to_local(hw
);
537 struct sta_info
*sta
;
540 DECLARE_MAC_BUF(mac
);
542 if (tid
>= STA_TID_NUM
)
545 #ifdef CONFIG_MAC80211_HT_DEBUG
546 printk(KERN_DEBUG
"Stop a BA session requested for %s tid %u\n",
547 print_mac(mac
, ra
), tid
);
548 #endif /* CONFIG_MAC80211_HT_DEBUG */
550 sta
= sta_info_get(local
, ra
);
554 /* check if the TID is in aggregation */
555 state
= &sta
->ampdu_mlme
.tid_tx
[tid
].state
;
556 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
558 if (*state
!= HT_AGG_STATE_OPERATIONAL
) {
559 #ifdef CONFIG_MAC80211_HT_DEBUG
560 printk(KERN_DEBUG
"Try to stop Tx aggregation on"
561 " non active TID\n");
562 #endif /* CONFIG_MAC80211_HT_DEBUG */
567 ieee80211_stop_queue(hw
, sta
->tid_to_tx_q
[tid
]);
569 *state
= HT_AGG_STATE_REQ_STOP_BA_MSK
|
570 (initiator
<< HT_AGG_STATE_INITIATOR_SHIFT
);
572 if (local
->ops
->ampdu_action
)
573 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_TX_STOP
,
576 /* case HW denied going back to legacy */
578 WARN_ON(ret
!= -EBUSY
);
579 *state
= HT_AGG_STATE_OPERATIONAL
;
580 ieee80211_wake_queue(hw
, sta
->tid_to_tx_q
[tid
]);
585 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
589 EXPORT_SYMBOL(ieee80211_stop_tx_ba_session
);
591 void ieee80211_start_tx_ba_cb(struct ieee80211_hw
*hw
, u8
*ra
, u16 tid
)
593 struct ieee80211_local
*local
= hw_to_local(hw
);
594 struct sta_info
*sta
;
596 DECLARE_MAC_BUF(mac
);
598 if (tid
>= STA_TID_NUM
) {
599 printk(KERN_DEBUG
"Bad TID value: tid = %d (>= %d)\n",
604 sta
= sta_info_get(local
, ra
);
606 printk(KERN_DEBUG
"Could not find station: %s\n",
611 state
= &sta
->ampdu_mlme
.tid_tx
[tid
].state
;
612 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
614 if (!(*state
& HT_ADDBA_REQUESTED_MSK
)) {
615 printk(KERN_DEBUG
"addBA was not requested yet, state is %d\n",
617 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
622 WARN_ON_ONCE(*state
& HT_ADDBA_DRV_READY_MSK
);
624 *state
|= HT_ADDBA_DRV_READY_MSK
;
626 if (*state
== HT_AGG_STATE_OPERATIONAL
) {
627 printk(KERN_DEBUG
"Aggregation is on for tid %d \n", tid
);
628 ieee80211_wake_queue(hw
, sta
->tid_to_tx_q
[tid
]);
630 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
633 EXPORT_SYMBOL(ieee80211_start_tx_ba_cb
);
635 void ieee80211_stop_tx_ba_cb(struct ieee80211_hw
*hw
, u8
*ra
, u8 tid
)
637 struct ieee80211_local
*local
= hw_to_local(hw
);
638 struct sta_info
*sta
;
641 DECLARE_MAC_BUF(mac
);
643 if (tid
>= STA_TID_NUM
) {
644 printk(KERN_DEBUG
"Bad TID value: tid = %d (>= %d)\n",
649 printk(KERN_DEBUG
"Stop a BA session requested on DA %s tid %d\n",
650 print_mac(mac
, ra
), tid
);
652 sta
= sta_info_get(local
, ra
);
654 printk(KERN_DEBUG
"Could not find station: %s\n",
658 state
= &sta
->ampdu_mlme
.tid_tx
[tid
].state
;
660 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
661 if ((*state
& HT_AGG_STATE_REQ_STOP_BA_MSK
) == 0) {
662 printk(KERN_DEBUG
"unexpected callback to A-MPDU stop\n");
664 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
668 if (*state
& HT_AGG_STATE_INITIATOR_MSK
)
669 ieee80211_send_delba(sta
->dev
, ra
, tid
,
670 WLAN_BACK_INITIATOR
, WLAN_REASON_QSTA_NOT_USE
);
672 agg_queue
= sta
->tid_to_tx_q
[tid
];
674 /* avoid ordering issues: we are the only one that can modify
675 * the content of the qdiscs */
676 spin_lock_bh(&local
->mdev
->queue_lock
);
677 /* remove the queue for this aggregation */
678 /* ieee80211_ht_agg_queue_remove(local, sta, tid, 1); */
679 spin_unlock_bh(&local
->mdev
->queue_lock
);
681 /* we just requeued the all the frames that were in the removed
682 * queue, and since we might miss a softirq we do netif_schedule.
683 * ieee80211_wake_queue is not used here as this queue is not
684 * necessarily stopped */
685 netif_schedule(local
->mdev
);
686 *state
= HT_AGG_STATE_IDLE
;
687 sta
->ampdu_mlme
.tid_tx
[tid
].addba_req_num
= 0;
688 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
692 EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb
);
694 void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw
*hw
,
695 const u8
*ra
, u16 tid
)
697 struct ieee80211_local
*local
= hw_to_local(hw
);
698 struct ieee80211_ra_tid
*ra_tid
;
699 struct sk_buff
*skb
= dev_alloc_skb(0);
701 if (unlikely(!skb
)) {
703 printk(KERN_WARNING
"%s: Not enough memory, "
704 "dropping start BA session", skb
->dev
->name
);
707 ra_tid
= (struct ieee80211_ra_tid
*) &skb
->cb
;
708 memcpy(&ra_tid
->ra
, ra
, ETH_ALEN
);
711 skb
->pkt_type
= IEEE80211_ADDBA_MSG
;
712 skb_queue_tail(&local
->skb_queue
, skb
);
713 tasklet_schedule(&local
->tasklet
);
715 EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe
);
717 void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw
*hw
,
718 const u8
*ra
, u16 tid
)
720 struct ieee80211_local
*local
= hw_to_local(hw
);
721 struct ieee80211_ra_tid
*ra_tid
;
722 struct sk_buff
*skb
= dev_alloc_skb(0);
724 if (unlikely(!skb
)) {
726 printk(KERN_WARNING
"%s: Not enough memory, "
727 "dropping stop BA session", skb
->dev
->name
);
730 ra_tid
= (struct ieee80211_ra_tid
*) &skb
->cb
;
731 memcpy(&ra_tid
->ra
, ra
, ETH_ALEN
);
734 skb
->pkt_type
= IEEE80211_DELBA_MSG
;
735 skb_queue_tail(&local
->skb_queue
, skb
);
736 tasklet_schedule(&local
->tasklet
);
738 EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe
);
740 static void ieee80211_set_multicast_list(struct net_device
*dev
)
742 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
743 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
744 int allmulti
, promisc
, sdata_allmulti
, sdata_promisc
;
746 allmulti
= !!(dev
->flags
& IFF_ALLMULTI
);
747 promisc
= !!(dev
->flags
& IFF_PROMISC
);
748 sdata_allmulti
= !!(sdata
->flags
& IEEE80211_SDATA_ALLMULTI
);
749 sdata_promisc
= !!(sdata
->flags
& IEEE80211_SDATA_PROMISC
);
751 if (allmulti
!= sdata_allmulti
) {
752 if (dev
->flags
& IFF_ALLMULTI
)
753 atomic_inc(&local
->iff_allmultis
);
755 atomic_dec(&local
->iff_allmultis
);
756 sdata
->flags
^= IEEE80211_SDATA_ALLMULTI
;
759 if (promisc
!= sdata_promisc
) {
760 if (dev
->flags
& IFF_PROMISC
)
761 atomic_inc(&local
->iff_promiscs
);
763 atomic_dec(&local
->iff_promiscs
);
764 sdata
->flags
^= IEEE80211_SDATA_PROMISC
;
767 dev_mc_sync(local
->mdev
, dev
);
770 static const struct header_ops ieee80211_header_ops
= {
771 .create
= eth_header
,
772 .parse
= header_parse_80211
,
773 .rebuild
= eth_rebuild_header
,
774 .cache
= eth_header_cache
,
775 .cache_update
= eth_header_cache_update
,
778 /* Must not be called for mdev */
779 void ieee80211_if_setup(struct net_device
*dev
)
782 dev
->hard_start_xmit
= ieee80211_subif_start_xmit
;
783 dev
->wireless_handlers
= &ieee80211_iw_handler_def
;
784 dev
->set_multicast_list
= ieee80211_set_multicast_list
;
785 dev
->change_mtu
= ieee80211_change_mtu
;
786 dev
->open
= ieee80211_open
;
787 dev
->stop
= ieee80211_stop
;
788 dev
->destructor
= ieee80211_if_free
;
791 /* WDS specialties */
793 int ieee80211_if_update_wds(struct net_device
*dev
, u8
*remote_addr
)
795 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
796 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
797 struct sta_info
*sta
;
798 DECLARE_MAC_BUF(mac
);
800 if (compare_ether_addr(remote_addr
, sdata
->u
.wds
.remote_addr
) == 0)
803 /* Create STA entry for the new peer */
804 sta
= sta_info_add(local
, dev
, remote_addr
, GFP_KERNEL
);
809 /* Remove STA entry for the old peer */
810 sta
= sta_info_get(local
, sdata
->u
.wds
.remote_addr
);
815 printk(KERN_DEBUG
"%s: could not find STA entry for WDS link "
817 dev
->name
, print_mac(mac
, sdata
->u
.wds
.remote_addr
));
820 /* Update WDS link data */
821 memcpy(&sdata
->u
.wds
.remote_addr
, remote_addr
, ETH_ALEN
);
826 /* everything else */
828 static int __ieee80211_if_config(struct net_device
*dev
,
829 struct sk_buff
*beacon
,
830 struct ieee80211_tx_control
*control
)
832 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
833 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
834 struct ieee80211_if_conf conf
;
836 if (!local
->ops
->config_interface
|| !netif_running(dev
))
839 memset(&conf
, 0, sizeof(conf
));
840 conf
.type
= sdata
->vif
.type
;
841 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
842 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
843 conf
.bssid
= sdata
->u
.sta
.bssid
;
844 conf
.ssid
= sdata
->u
.sta
.ssid
;
845 conf
.ssid_len
= sdata
->u
.sta
.ssid_len
;
846 } else if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
) {
847 conf
.ssid
= sdata
->u
.ap
.ssid
;
848 conf
.ssid_len
= sdata
->u
.ap
.ssid_len
;
849 conf
.beacon
= beacon
;
850 conf
.beacon_control
= control
;
852 return local
->ops
->config_interface(local_to_hw(local
),
856 int ieee80211_if_config(struct net_device
*dev
)
858 return __ieee80211_if_config(dev
, NULL
, NULL
);
861 int ieee80211_if_config_beacon(struct net_device
*dev
)
863 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
864 struct ieee80211_tx_control control
;
865 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
868 if (!(local
->hw
.flags
& IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE
))
870 skb
= ieee80211_beacon_get(local_to_hw(local
), &sdata
->vif
,
874 return __ieee80211_if_config(dev
, skb
, &control
);
877 int ieee80211_hw_config(struct ieee80211_local
*local
)
879 struct ieee80211_hw_mode
*mode
;
880 struct ieee80211_channel
*chan
;
883 if (local
->sta_sw_scanning
) {
884 chan
= local
->scan_channel
;
885 mode
= local
->scan_hw_mode
;
887 chan
= local
->oper_channel
;
888 mode
= local
->oper_hw_mode
;
891 local
->hw
.conf
.channel
= chan
->chan
;
892 local
->hw
.conf
.channel_val
= chan
->val
;
893 if (!local
->hw
.conf
.power_level
) {
894 local
->hw
.conf
.power_level
= chan
->power_level
;
896 local
->hw
.conf
.power_level
= min(chan
->power_level
,
897 local
->hw
.conf
.power_level
);
899 local
->hw
.conf
.freq
= chan
->freq
;
900 local
->hw
.conf
.phymode
= mode
->mode
;
901 local
->hw
.conf
.antenna_max
= chan
->antenna_max
;
902 local
->hw
.conf
.chan
= chan
;
903 local
->hw
.conf
.mode
= mode
;
905 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
906 printk(KERN_DEBUG
"HW CONFIG: channel=%d freq=%d "
907 "phymode=%d\n", local
->hw
.conf
.channel
, local
->hw
.conf
.freq
,
908 local
->hw
.conf
.phymode
);
909 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
911 if (local
->open_count
)
912 ret
= local
->ops
->config(local_to_hw(local
), &local
->hw
.conf
);
918 * ieee80211_hw_config_ht should be used only after legacy configuration
919 * has been determined, as ht configuration depends upon the hardware's
920 * HT abilities for a _specific_ band.
922 int ieee80211_hw_config_ht(struct ieee80211_local
*local
, int enable_ht
,
923 struct ieee80211_ht_info
*req_ht_cap
,
924 struct ieee80211_ht_bss_info
*req_bss_cap
)
926 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
927 struct ieee80211_hw_mode
*mode
= conf
->mode
;
930 /* HT is not supported */
931 if (!mode
->ht_info
.ht_supported
) {
932 conf
->flags
&= ~IEEE80211_CONF_SUPPORT_HT_MODE
;
938 conf
->flags
&= ~IEEE80211_CONF_SUPPORT_HT_MODE
;
940 conf
->flags
|= IEEE80211_CONF_SUPPORT_HT_MODE
;
941 conf
->ht_conf
.cap
= req_ht_cap
->cap
& mode
->ht_info
.cap
;
942 conf
->ht_conf
.cap
&= ~(IEEE80211_HT_CAP_MIMO_PS
);
944 mode
->ht_info
.cap
& IEEE80211_HT_CAP_MIMO_PS
;
945 conf
->ht_bss_conf
.primary_channel
=
946 req_bss_cap
->primary_channel
;
947 conf
->ht_bss_conf
.bss_cap
= req_bss_cap
->bss_cap
;
948 conf
->ht_bss_conf
.bss_op_mode
= req_bss_cap
->bss_op_mode
;
949 for (i
= 0; i
< SUPP_MCS_SET_LEN
; i
++)
950 conf
->ht_conf
.supp_mcs_set
[i
] =
951 mode
->ht_info
.supp_mcs_set
[i
] &
952 req_ht_cap
->supp_mcs_set
[i
];
954 /* In STA mode, this gives us indication
955 * to the AP's mode of operation */
956 conf
->ht_conf
.ht_supported
= 1;
957 conf
->ht_conf
.ampdu_factor
= req_ht_cap
->ampdu_factor
;
958 conf
->ht_conf
.ampdu_density
= req_ht_cap
->ampdu_density
;
961 local
->ops
->conf_ht(local_to_hw(local
), &local
->hw
.conf
);
966 void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data
*sdata
,
969 struct ieee80211_local
*local
= sdata
->local
;
974 if (local
->ops
->bss_info_changed
)
975 local
->ops
->bss_info_changed(local_to_hw(local
),
981 void ieee80211_reset_erp_info(struct net_device
*dev
)
983 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
985 sdata
->bss_conf
.use_cts_prot
= 0;
986 sdata
->bss_conf
.use_short_preamble
= 0;
987 ieee80211_bss_info_change_notify(sdata
,
988 BSS_CHANGED_ERP_CTS_PROT
|
989 BSS_CHANGED_ERP_PREAMBLE
);
992 void ieee80211_tx_status_irqsafe(struct ieee80211_hw
*hw
,
994 struct ieee80211_tx_status
*status
)
996 struct ieee80211_local
*local
= hw_to_local(hw
);
997 struct ieee80211_tx_status
*saved
;
1000 skb
->dev
= local
->mdev
;
1001 saved
= kmalloc(sizeof(struct ieee80211_tx_status
), GFP_ATOMIC
);
1002 if (unlikely(!saved
)) {
1003 if (net_ratelimit())
1004 printk(KERN_WARNING
"%s: Not enough memory, "
1005 "dropping tx status", skb
->dev
->name
);
1006 /* should be dev_kfree_skb_irq, but due to this function being
1007 * named _irqsafe instead of just _irq we can't be sure that
1008 * people won't call it from non-irq contexts */
1009 dev_kfree_skb_any(skb
);
1012 memcpy(saved
, status
, sizeof(struct ieee80211_tx_status
));
1013 /* copy pointer to saved status into skb->cb for use by tasklet */
1014 memcpy(skb
->cb
, &saved
, sizeof(saved
));
1016 skb
->pkt_type
= IEEE80211_TX_STATUS_MSG
;
1017 skb_queue_tail(status
->control
.flags
& IEEE80211_TXCTL_REQ_TX_STATUS
?
1018 &local
->skb_queue
: &local
->skb_queue_unreliable
, skb
);
1019 tmp
= skb_queue_len(&local
->skb_queue
) +
1020 skb_queue_len(&local
->skb_queue_unreliable
);
1021 while (tmp
> IEEE80211_IRQSAFE_QUEUE_LIMIT
&&
1022 (skb
= skb_dequeue(&local
->skb_queue_unreliable
))) {
1023 memcpy(&saved
, skb
->cb
, sizeof(saved
));
1025 dev_kfree_skb_irq(skb
);
1027 I802_DEBUG_INC(local
->tx_status_drop
);
1029 tasklet_schedule(&local
->tasklet
);
1031 EXPORT_SYMBOL(ieee80211_tx_status_irqsafe
);
1033 static void ieee80211_tasklet_handler(unsigned long data
)
1035 struct ieee80211_local
*local
= (struct ieee80211_local
*) data
;
1036 struct sk_buff
*skb
;
1037 struct ieee80211_rx_status rx_status
;
1038 struct ieee80211_tx_status
*tx_status
;
1039 struct ieee80211_ra_tid
*ra_tid
;
1041 while ((skb
= skb_dequeue(&local
->skb_queue
)) ||
1042 (skb
= skb_dequeue(&local
->skb_queue_unreliable
))) {
1043 switch (skb
->pkt_type
) {
1044 case IEEE80211_RX_MSG
:
1045 /* status is in skb->cb */
1046 memcpy(&rx_status
, skb
->cb
, sizeof(rx_status
));
1047 /* Clear skb->pkt_type in order to not confuse kernel
1050 __ieee80211_rx(local_to_hw(local
), skb
, &rx_status
);
1052 case IEEE80211_TX_STATUS_MSG
:
1053 /* get pointer to saved status out of skb->cb */
1054 memcpy(&tx_status
, skb
->cb
, sizeof(tx_status
));
1056 ieee80211_tx_status(local_to_hw(local
),
1060 case IEEE80211_DELBA_MSG
:
1061 ra_tid
= (struct ieee80211_ra_tid
*) &skb
->cb
;
1062 ieee80211_stop_tx_ba_cb(local_to_hw(local
),
1063 ra_tid
->ra
, ra_tid
->tid
);
1066 case IEEE80211_ADDBA_MSG
:
1067 ra_tid
= (struct ieee80211_ra_tid
*) &skb
->cb
;
1068 ieee80211_start_tx_ba_cb(local_to_hw(local
),
1069 ra_tid
->ra
, ra_tid
->tid
);
1072 default: /* should never get here! */
1073 printk(KERN_ERR
"%s: Unknown message type (%d)\n",
1074 wiphy_name(local
->hw
.wiphy
), skb
->pkt_type
);
1081 /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
1082 * make a prepared TX frame (one that has been given to hw) to look like brand
1083 * new IEEE 802.11 frame that is ready to go through TX processing again.
1084 * Also, tx_packet_data in cb is restored from tx_control. */
1085 static void ieee80211_remove_tx_extra(struct ieee80211_local
*local
,
1086 struct ieee80211_key
*key
,
1087 struct sk_buff
*skb
,
1088 struct ieee80211_tx_control
*control
)
1090 int hdrlen
, iv_len
, mic_len
;
1091 struct ieee80211_tx_packet_data
*pkt_data
;
1093 pkt_data
= (struct ieee80211_tx_packet_data
*)skb
->cb
;
1094 pkt_data
->ifindex
= vif_to_sdata(control
->vif
)->dev
->ifindex
;
1095 pkt_data
->flags
= 0;
1096 if (control
->flags
& IEEE80211_TXCTL_REQ_TX_STATUS
)
1097 pkt_data
->flags
|= IEEE80211_TXPD_REQ_TX_STATUS
;
1098 if (control
->flags
& IEEE80211_TXCTL_DO_NOT_ENCRYPT
)
1099 pkt_data
->flags
|= IEEE80211_TXPD_DO_NOT_ENCRYPT
;
1100 if (control
->flags
& IEEE80211_TXCTL_REQUEUE
)
1101 pkt_data
->flags
|= IEEE80211_TXPD_REQUEUE
;
1102 if (control
->flags
& IEEE80211_TXCTL_EAPOL_FRAME
)
1103 pkt_data
->flags
|= IEEE80211_TXPD_EAPOL_FRAME
;
1104 pkt_data
->queue
= control
->queue
;
1106 hdrlen
= ieee80211_get_hdrlen_from_skb(skb
);
1111 switch (key
->conf
.alg
) {
1113 iv_len
= WEP_IV_LEN
;
1114 mic_len
= WEP_ICV_LEN
;
1117 iv_len
= TKIP_IV_LEN
;
1118 mic_len
= TKIP_ICV_LEN
;
1121 iv_len
= CCMP_HDR_LEN
;
1122 mic_len
= CCMP_MIC_LEN
;
1128 if (skb
->len
>= mic_len
&&
1129 !(key
->flags
& KEY_FLAG_UPLOADED_TO_HARDWARE
))
1130 skb_trim(skb
, skb
->len
- mic_len
);
1131 if (skb
->len
>= iv_len
&& skb
->len
> hdrlen
) {
1132 memmove(skb
->data
+ iv_len
, skb
->data
, hdrlen
);
1133 skb_pull(skb
, iv_len
);
1138 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1139 u16 fc
= le16_to_cpu(hdr
->frame_control
);
1140 if ((fc
& 0x8C) == 0x88) /* QoS Control Field */ {
1141 fc
&= ~IEEE80211_STYPE_QOS_DATA
;
1142 hdr
->frame_control
= cpu_to_le16(fc
);
1143 memmove(skb
->data
+ 2, skb
->data
, hdrlen
- 2);
1149 void ieee80211_tx_status(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
1150 struct ieee80211_tx_status
*status
)
1152 struct sk_buff
*skb2
;
1153 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1154 struct ieee80211_local
*local
= hw_to_local(hw
);
1156 struct ieee80211_tx_status_rtap_hdr
*rthdr
;
1157 struct ieee80211_sub_if_data
*sdata
;
1162 "%s: ieee80211_tx_status called with NULL status\n",
1163 wiphy_name(local
->hw
.wiphy
));
1168 if (status
->excessive_retries
) {
1169 struct sta_info
*sta
;
1170 sta
= sta_info_get(local
, hdr
->addr1
);
1172 if (sta
->flags
& WLAN_STA_PS
) {
1173 /* The STA is in power save mode, so assume
1174 * that this TX packet failed because of that.
1176 status
->excessive_retries
= 0;
1177 status
->flags
|= IEEE80211_TX_STATUS_TX_FILTERED
;
1183 if (status
->flags
& IEEE80211_TX_STATUS_TX_FILTERED
) {
1184 struct sta_info
*sta
;
1185 sta
= sta_info_get(local
, hdr
->addr1
);
1187 sta
->tx_filtered_count
++;
1189 /* Clear the TX filter mask for this STA when sending
1190 * the next packet. If the STA went to power save mode,
1191 * this will happen when it is waking up for the next
1193 sta
->clear_dst_mask
= 1;
1195 /* TODO: Is the WLAN_STA_PS flag always set here or is
1196 * the race between RX and TX status causing some
1197 * packets to be filtered out before 80211.o gets an
1198 * update for PS status? This seems to be the case, so
1199 * no changes are likely to be needed. */
1200 if (sta
->flags
& WLAN_STA_PS
&&
1201 skb_queue_len(&sta
->tx_filtered
) <
1202 STA_MAX_TX_BUFFER
) {
1203 ieee80211_remove_tx_extra(local
, sta
->key
,
1206 skb_queue_tail(&sta
->tx_filtered
, skb
);
1207 } else if (!(sta
->flags
& WLAN_STA_PS
) &&
1208 !(status
->control
.flags
& IEEE80211_TXCTL_REQUEUE
)) {
1209 /* Software retry the packet once */
1210 status
->control
.flags
|= IEEE80211_TXCTL_REQUEUE
;
1211 ieee80211_remove_tx_extra(local
, sta
->key
,
1214 dev_queue_xmit(skb
);
1216 if (net_ratelimit()) {
1217 printk(KERN_DEBUG
"%s: dropped TX "
1218 "filtered frame queue_len=%d "
1220 wiphy_name(local
->hw
.wiphy
),
1223 !!(sta
->flags
& WLAN_STA_PS
),
1232 rate_control_tx_status(local
->mdev
, skb
, status
);
1234 ieee80211_led_tx(local
, 0);
1237 * Fragments are passed to low-level drivers as separate skbs, so these
1238 * are actually fragments, not frames. Update frame counters only for
1239 * the first fragment of the frame. */
1241 frag
= le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_FRAG
;
1242 type
= le16_to_cpu(hdr
->frame_control
) & IEEE80211_FCTL_FTYPE
;
1244 if (status
->flags
& IEEE80211_TX_STATUS_ACK
) {
1246 local
->dot11TransmittedFrameCount
++;
1247 if (is_multicast_ether_addr(hdr
->addr1
))
1248 local
->dot11MulticastTransmittedFrameCount
++;
1249 if (status
->retry_count
> 0)
1250 local
->dot11RetryCount
++;
1251 if (status
->retry_count
> 1)
1252 local
->dot11MultipleRetryCount
++;
1255 /* This counter shall be incremented for an acknowledged MPDU
1256 * with an individual address in the address 1 field or an MPDU
1257 * with a multicast address in the address 1 field of type Data
1259 if (!is_multicast_ether_addr(hdr
->addr1
) ||
1260 type
== IEEE80211_FTYPE_DATA
||
1261 type
== IEEE80211_FTYPE_MGMT
)
1262 local
->dot11TransmittedFragmentCount
++;
1265 local
->dot11FailedCount
++;
1268 /* this was a transmitted frame, but now we want to reuse it */
1271 if (!local
->monitors
) {
1276 /* send frame to monitor interfaces now */
1278 if (skb_headroom(skb
) < sizeof(*rthdr
)) {
1279 printk(KERN_ERR
"ieee80211_tx_status: headroom too small\n");
1284 rthdr
= (struct ieee80211_tx_status_rtap_hdr
*)
1285 skb_push(skb
, sizeof(*rthdr
));
1287 memset(rthdr
, 0, sizeof(*rthdr
));
1288 rthdr
->hdr
.it_len
= cpu_to_le16(sizeof(*rthdr
));
1289 rthdr
->hdr
.it_present
=
1290 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS
) |
1291 (1 << IEEE80211_RADIOTAP_DATA_RETRIES
));
1293 if (!(status
->flags
& IEEE80211_TX_STATUS_ACK
) &&
1294 !is_multicast_ether_addr(hdr
->addr1
))
1295 rthdr
->tx_flags
|= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL
);
1297 if ((status
->control
.flags
& IEEE80211_TXCTL_USE_RTS_CTS
) &&
1298 (status
->control
.flags
& IEEE80211_TXCTL_USE_CTS_PROTECT
))
1299 rthdr
->tx_flags
|= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS
);
1300 else if (status
->control
.flags
& IEEE80211_TXCTL_USE_RTS_CTS
)
1301 rthdr
->tx_flags
|= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS
);
1303 rthdr
->data_retries
= status
->retry_count
;
1306 monitors
= local
->monitors
;
1307 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
1309 * Using the monitors counter is possibly racy, but
1310 * if the value is wrong we simply either clone the skb
1311 * once too much or forget sending it to one monitor iface
1312 * The latter case isn't nice but fixing the race is much
1315 if (!monitors
|| !skb
)
1318 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_MNTR
) {
1319 if (!netif_running(sdata
->dev
))
1323 skb2
= skb_clone(skb
, GFP_ATOMIC
);
1326 skb
->dev
= sdata
->dev
;
1327 /* XXX: is this sufficient for BPF? */
1328 skb_set_mac_header(skb
, 0);
1329 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1330 skb
->pkt_type
= PACKET_OTHERHOST
;
1331 skb
->protocol
= htons(ETH_P_802_2
);
1332 memset(skb
->cb
, 0, sizeof(skb
->cb
));
1342 EXPORT_SYMBOL(ieee80211_tx_status
);
1344 struct ieee80211_hw
*ieee80211_alloc_hw(size_t priv_data_len
,
1345 const struct ieee80211_ops
*ops
)
1347 struct net_device
*mdev
;
1348 struct ieee80211_local
*local
;
1349 struct ieee80211_sub_if_data
*sdata
;
1351 struct wiphy
*wiphy
;
1353 /* Ensure 32-byte alignment of our private data and hw private data.
1354 * We use the wiphy priv data for both our ieee80211_local and for
1355 * the driver's private data
1357 * In memory it'll be like this:
1359 * +-------------------------+
1361 * +-------------------------+
1362 * | struct ieee80211_local |
1363 * +-------------------------+
1364 * | driver's private data |
1365 * +-------------------------+
1368 priv_size
= ((sizeof(struct ieee80211_local
) +
1369 NETDEV_ALIGN_CONST
) & ~NETDEV_ALIGN_CONST
) +
1372 wiphy
= wiphy_new(&mac80211_config_ops
, priv_size
);
1377 wiphy
->privid
= mac80211_wiphy_privid
;
1379 local
= wiphy_priv(wiphy
);
1380 local
->hw
.wiphy
= wiphy
;
1382 local
->hw
.priv
= (char *)local
+
1383 ((sizeof(struct ieee80211_local
) +
1384 NETDEV_ALIGN_CONST
) & ~NETDEV_ALIGN_CONST
);
1387 BUG_ON(!ops
->start
);
1389 BUG_ON(!ops
->config
);
1390 BUG_ON(!ops
->add_interface
);
1391 BUG_ON(!ops
->remove_interface
);
1392 BUG_ON(!ops
->configure_filter
);
1395 /* for now, mdev needs sub_if_data :/ */
1396 mdev
= alloc_netdev(sizeof(struct ieee80211_sub_if_data
),
1397 "wmaster%d", ether_setup
);
1403 sdata
= IEEE80211_DEV_TO_SUB_IF(mdev
);
1404 mdev
->ieee80211_ptr
= &sdata
->wdev
;
1405 sdata
->wdev
.wiphy
= wiphy
;
1407 local
->hw
.queues
= 1; /* default */
1410 local
->rx_pre_handlers
= ieee80211_rx_pre_handlers
;
1411 local
->rx_handlers
= ieee80211_rx_handlers
;
1412 local
->tx_handlers
= ieee80211_tx_handlers
;
1414 local
->bridge_packets
= 1;
1416 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
1417 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
1418 local
->short_retry_limit
= 7;
1419 local
->long_retry_limit
= 4;
1420 local
->hw
.conf
.radio_enabled
= 1;
1422 local
->enabled_modes
= ~0;
1424 INIT_LIST_HEAD(&local
->modes_list
);
1426 INIT_LIST_HEAD(&local
->interfaces
);
1428 INIT_DELAYED_WORK(&local
->scan_work
, ieee80211_sta_scan_work
);
1429 ieee80211_rx_bss_list_init(mdev
);
1431 sta_info_init(local
);
1433 mdev
->hard_start_xmit
= ieee80211_master_start_xmit
;
1434 mdev
->open
= ieee80211_master_open
;
1435 mdev
->stop
= ieee80211_master_stop
;
1436 mdev
->type
= ARPHRD_IEEE80211
;
1437 mdev
->header_ops
= &ieee80211_header_ops
;
1438 mdev
->set_multicast_list
= ieee80211_master_set_multicast_list
;
1440 sdata
->vif
.type
= IEEE80211_IF_TYPE_AP
;
1442 sdata
->local
= local
;
1443 sdata
->u
.ap
.force_unicast_rateidx
= -1;
1444 sdata
->u
.ap
.max_ratectrl_rateidx
= -1;
1445 ieee80211_if_sdata_init(sdata
);
1446 /* no RCU needed since we're still during init phase */
1447 list_add_tail(&sdata
->list
, &local
->interfaces
);
1449 tasklet_init(&local
->tx_pending_tasklet
, ieee80211_tx_pending
,
1450 (unsigned long)local
);
1451 tasklet_disable(&local
->tx_pending_tasklet
);
1453 tasklet_init(&local
->tasklet
,
1454 ieee80211_tasklet_handler
,
1455 (unsigned long) local
);
1456 tasklet_disable(&local
->tasklet
);
1458 skb_queue_head_init(&local
->skb_queue
);
1459 skb_queue_head_init(&local
->skb_queue_unreliable
);
1461 return local_to_hw(local
);
1463 EXPORT_SYMBOL(ieee80211_alloc_hw
);
1465 int ieee80211_register_hw(struct ieee80211_hw
*hw
)
1467 struct ieee80211_local
*local
= hw_to_local(hw
);
1471 result
= wiphy_register(local
->hw
.wiphy
);
1475 name
= wiphy_dev(local
->hw
.wiphy
)->driver
->name
;
1476 local
->hw
.workqueue
= create_singlethread_workqueue(name
);
1477 if (!local
->hw
.workqueue
) {
1479 goto fail_workqueue
;
1483 * The hardware needs headroom for sending the frame,
1484 * and we need some headroom for passing the frame to monitor
1485 * interfaces, but never both at the same time.
1487 local
->tx_headroom
= max_t(unsigned int , local
->hw
.extra_tx_headroom
,
1488 sizeof(struct ieee80211_tx_status_rtap_hdr
));
1490 debugfs_hw_add(local
);
1492 local
->hw
.conf
.beacon_int
= 1000;
1494 local
->wstats_flags
|= local
->hw
.max_rssi
?
1495 IW_QUAL_LEVEL_UPDATED
: IW_QUAL_LEVEL_INVALID
;
1496 local
->wstats_flags
|= local
->hw
.max_signal
?
1497 IW_QUAL_QUAL_UPDATED
: IW_QUAL_QUAL_INVALID
;
1498 local
->wstats_flags
|= local
->hw
.max_noise
?
1499 IW_QUAL_NOISE_UPDATED
: IW_QUAL_NOISE_INVALID
;
1500 if (local
->hw
.max_rssi
< 0 || local
->hw
.max_noise
< 0)
1501 local
->wstats_flags
|= IW_QUAL_DBM
;
1503 result
= sta_info_start(local
);
1508 result
= dev_alloc_name(local
->mdev
, local
->mdev
->name
);
1512 memcpy(local
->mdev
->dev_addr
, local
->hw
.wiphy
->perm_addr
, ETH_ALEN
);
1513 SET_NETDEV_DEV(local
->mdev
, wiphy_dev(local
->hw
.wiphy
));
1515 result
= register_netdevice(local
->mdev
);
1519 ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local
->mdev
));
1520 ieee80211_if_set_type(local
->mdev
, IEEE80211_IF_TYPE_AP
);
1522 result
= ieee80211_init_rate_ctrl_alg(local
,
1523 hw
->rate_control_algorithm
);
1525 printk(KERN_DEBUG
"%s: Failed to initialize rate control "
1526 "algorithm\n", wiphy_name(local
->hw
.wiphy
));
1530 result
= ieee80211_wep_init(local
);
1533 printk(KERN_DEBUG
"%s: Failed to initialize wep\n",
1534 wiphy_name(local
->hw
.wiphy
));
1538 ieee80211_install_qdisc(local
->mdev
);
1540 /* add one default STA interface */
1541 result
= ieee80211_if_add(local
->mdev
, "wlan%d", NULL
,
1542 IEEE80211_IF_TYPE_STA
);
1544 printk(KERN_WARNING
"%s: Failed to add default virtual iface\n",
1545 wiphy_name(local
->hw
.wiphy
));
1547 local
->reg_state
= IEEE80211_DEV_REGISTERED
;
1550 ieee80211_led_init(local
);
1555 rate_control_deinitialize(local
);
1557 ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local
->mdev
));
1558 unregister_netdevice(local
->mdev
);
1561 sta_info_stop(local
);
1563 debugfs_hw_del(local
);
1564 destroy_workqueue(local
->hw
.workqueue
);
1566 wiphy_unregister(local
->hw
.wiphy
);
1569 EXPORT_SYMBOL(ieee80211_register_hw
);
1571 int ieee80211_register_hwmode(struct ieee80211_hw
*hw
,
1572 struct ieee80211_hw_mode
*mode
)
1574 struct ieee80211_local
*local
= hw_to_local(hw
);
1575 struct ieee80211_rate
*rate
;
1578 INIT_LIST_HEAD(&mode
->list
);
1579 list_add_tail(&mode
->list
, &local
->modes_list
);
1581 local
->hw_modes
|= (1 << mode
->mode
);
1582 for (i
= 0; i
< mode
->num_rates
; i
++) {
1583 rate
= &(mode
->rates
[i
]);
1584 rate
->rate_inv
= CHAN_UTIL_RATE_LCM
/ rate
->rate
;
1586 ieee80211_prepare_rates(local
, mode
);
1588 if (!local
->oper_hw_mode
) {
1589 /* Default to this mode */
1590 local
->hw
.conf
.phymode
= mode
->mode
;
1591 local
->oper_hw_mode
= local
->scan_hw_mode
= mode
;
1592 local
->oper_channel
= local
->scan_channel
= &mode
->channels
[0];
1593 local
->hw
.conf
.mode
= local
->oper_hw_mode
;
1594 local
->hw
.conf
.chan
= local
->oper_channel
;
1597 if (!(hw
->flags
& IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED
))
1598 ieee80211_set_default_regdomain(mode
);
1602 EXPORT_SYMBOL(ieee80211_register_hwmode
);
1604 void ieee80211_unregister_hw(struct ieee80211_hw
*hw
)
1606 struct ieee80211_local
*local
= hw_to_local(hw
);
1607 struct ieee80211_sub_if_data
*sdata
, *tmp
;
1610 tasklet_kill(&local
->tx_pending_tasklet
);
1611 tasklet_kill(&local
->tasklet
);
1615 BUG_ON(local
->reg_state
!= IEEE80211_DEV_REGISTERED
);
1617 local
->reg_state
= IEEE80211_DEV_UNREGISTERED
;
1620 * At this point, interface list manipulations are fine
1621 * because the driver cannot be handing us frames any
1622 * more and the tasklet is killed.
1626 * First, we remove all non-master interfaces. Do this because they
1627 * may have bss pointer dependency on the master, and when we free
1628 * the master these would be freed as well, breaking our list
1629 * iteration completely.
1631 list_for_each_entry_safe(sdata
, tmp
, &local
->interfaces
, list
) {
1632 if (sdata
->dev
== local
->mdev
)
1634 list_del(&sdata
->list
);
1635 __ieee80211_if_del(local
, sdata
);
1638 /* then, finally, remove the master interface */
1639 __ieee80211_if_del(local
, IEEE80211_DEV_TO_SUB_IF(local
->mdev
));
1643 ieee80211_rx_bss_list_deinit(local
->mdev
);
1644 ieee80211_clear_tx_pending(local
);
1645 sta_info_stop(local
);
1646 rate_control_deinitialize(local
);
1647 debugfs_hw_del(local
);
1649 for (i
= 0; i
< NUM_IEEE80211_MODES
; i
++) {
1650 kfree(local
->supp_rates
[i
]);
1651 kfree(local
->basic_rates
[i
]);
1654 if (skb_queue_len(&local
->skb_queue
)
1655 || skb_queue_len(&local
->skb_queue_unreliable
))
1656 printk(KERN_WARNING
"%s: skb_queue not empty\n",
1657 wiphy_name(local
->hw
.wiphy
));
1658 skb_queue_purge(&local
->skb_queue
);
1659 skb_queue_purge(&local
->skb_queue_unreliable
);
1661 destroy_workqueue(local
->hw
.workqueue
);
1662 wiphy_unregister(local
->hw
.wiphy
);
1663 ieee80211_wep_free(local
);
1664 ieee80211_led_exit(local
);
1666 EXPORT_SYMBOL(ieee80211_unregister_hw
);
1668 void ieee80211_free_hw(struct ieee80211_hw
*hw
)
1670 struct ieee80211_local
*local
= hw_to_local(hw
);
1672 ieee80211_if_free(local
->mdev
);
1673 wiphy_free(local
->hw
.wiphy
);
1675 EXPORT_SYMBOL(ieee80211_free_hw
);
1677 static int __init
ieee80211_init(void)
1679 struct sk_buff
*skb
;
1682 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data
) > sizeof(skb
->cb
));
1684 ret
= rc80211_simple_init();
1688 ret
= rc80211_pid_init();
1690 goto out_cleanup_simple
;
1692 ret
= ieee80211_wme_register();
1694 printk(KERN_DEBUG
"ieee80211_init: failed to "
1695 "initialize WME (err=%d)\n", ret
);
1696 goto out_cleanup_pid
;
1699 ieee80211_debugfs_netdev_init();
1700 ieee80211_regdomain_init();
1707 rc80211_simple_exit();
1712 static void __exit
ieee80211_exit(void)
1714 rc80211_simple_exit();
1717 ieee80211_wme_unregister();
1718 ieee80211_debugfs_netdev_exit();
1722 subsys_initcall(ieee80211_init
);
1723 module_exit(ieee80211_exit
);
1725 MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1726 MODULE_LICENSE("GPL");