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
) &&
187 compare_ether_addr(dev
->dev_addr
, ndev
->dev_addr
) == 0) {
189 * check whether it may have the same address
191 if (!identical_mac_addr_allowed(sdata
->vif
.type
,
196 * can only add VLANs to enabled APs
198 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_VLAN
&&
199 nsdata
->vif
.type
== IEEE80211_IF_TYPE_AP
&&
200 netif_running(nsdata
->dev
))
201 sdata
->u
.vlan
.ap
= nsdata
;
205 switch (sdata
->vif
.type
) {
206 case IEEE80211_IF_TYPE_WDS
:
207 if (is_zero_ether_addr(sdata
->u
.wds
.remote_addr
))
210 case IEEE80211_IF_TYPE_VLAN
:
211 if (!sdata
->u
.vlan
.ap
)
214 case IEEE80211_IF_TYPE_AP
:
215 case IEEE80211_IF_TYPE_STA
:
216 case IEEE80211_IF_TYPE_MNTR
:
217 case IEEE80211_IF_TYPE_IBSS
:
218 /* no special treatment */
220 case IEEE80211_IF_TYPE_INVALID
:
226 if (local
->open_count
== 0) {
228 if (local
->ops
->start
)
229 res
= local
->ops
->start(local_to_hw(local
));
232 need_hw_reconfig
= 1;
233 ieee80211_led_radio(local
, local
->hw
.conf
.radio_enabled
);
236 switch (sdata
->vif
.type
) {
237 case IEEE80211_IF_TYPE_VLAN
:
238 list_add(&sdata
->u
.vlan
.list
, &sdata
->u
.vlan
.ap
->u
.ap
.vlans
);
239 /* no need to tell driver */
241 case IEEE80211_IF_TYPE_MNTR
:
242 /* must be before the call to ieee80211_configure_filter */
244 if (local
->monitors
== 1)
245 local
->hw
.conf
.flags
|= IEEE80211_CONF_RADIOTAP
;
247 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_FCSFAIL
)
248 local
->fif_fcsfail
++;
249 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_PLCPFAIL
)
250 local
->fif_plcpfail
++;
251 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_CONTROL
)
252 local
->fif_control
++;
253 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_OTHER_BSS
)
254 local
->fif_other_bss
++;
256 netif_tx_lock_bh(local
->mdev
);
257 ieee80211_configure_filter(local
);
258 netif_tx_unlock_bh(local
->mdev
);
260 case IEEE80211_IF_TYPE_STA
:
261 case IEEE80211_IF_TYPE_IBSS
:
262 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
265 conf
.vif
= &sdata
->vif
;
266 conf
.type
= sdata
->vif
.type
;
267 conf
.mac_addr
= dev
->dev_addr
;
268 res
= local
->ops
->add_interface(local_to_hw(local
), &conf
);
269 if (res
&& !local
->open_count
&& local
->ops
->stop
)
270 local
->ops
->stop(local_to_hw(local
));
274 ieee80211_if_config(dev
);
275 ieee80211_reset_erp_info(dev
);
276 ieee80211_enable_keys(sdata
);
278 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
&&
279 !(sdata
->flags
& IEEE80211_SDATA_USERSPACE_MLME
))
280 netif_carrier_off(dev
);
282 netif_carrier_on(dev
);
285 if (local
->open_count
== 0) {
286 res
= dev_open(local
->mdev
);
288 tasklet_enable(&local
->tx_pending_tasklet
);
289 tasklet_enable(&local
->tasklet
);
293 * set_multicast_list will be invoked by the networking core
294 * which will check whether any increments here were done in
295 * error and sync them down to the hardware as filter flags.
297 if (sdata
->flags
& IEEE80211_SDATA_ALLMULTI
)
298 atomic_inc(&local
->iff_allmultis
);
300 if (sdata
->flags
& IEEE80211_SDATA_PROMISC
)
301 atomic_inc(&local
->iff_promiscs
);
304 if (need_hw_reconfig
)
305 ieee80211_hw_config(local
);
307 netif_start_queue(dev
);
312 static int ieee80211_stop(struct net_device
*dev
)
314 struct ieee80211_sub_if_data
*sdata
;
315 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
316 struct ieee80211_if_init_conf conf
;
317 struct sta_info
*sta
;
320 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
322 list_for_each_entry(sta
, &local
->sta_list
, list
) {
324 for (i
= 0; i
< STA_TID_NUM
; i
++)
325 ieee80211_sta_stop_rx_ba_session(sta
->dev
,
328 WLAN_REASON_QSTA_LEAVE_QBSS
);
331 netif_stop_queue(dev
);
334 * Don't count this interface for promisc/allmulti while it
335 * is down. dev_mc_unsync() will invoke set_multicast_list
336 * on the master interface which will sync these down to the
337 * hardware as filter flags.
339 if (sdata
->flags
& IEEE80211_SDATA_ALLMULTI
)
340 atomic_dec(&local
->iff_allmultis
);
342 if (sdata
->flags
& IEEE80211_SDATA_PROMISC
)
343 atomic_dec(&local
->iff_promiscs
);
345 dev_mc_unsync(local
->mdev
, dev
);
347 /* APs need special treatment */
348 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
) {
349 struct ieee80211_sub_if_data
*vlan
, *tmp
;
350 struct beacon_data
*old_beacon
= sdata
->u
.ap
.beacon
;
353 rcu_assign_pointer(sdata
->u
.ap
.beacon
, NULL
);
357 /* down all dependent devices, that is VLANs */
358 list_for_each_entry_safe(vlan
, tmp
, &sdata
->u
.ap
.vlans
,
360 dev_close(vlan
->dev
);
361 WARN_ON(!list_empty(&sdata
->u
.ap
.vlans
));
366 switch (sdata
->vif
.type
) {
367 case IEEE80211_IF_TYPE_VLAN
:
368 list_del(&sdata
->u
.vlan
.list
);
369 sdata
->u
.vlan
.ap
= NULL
;
370 /* no need to tell driver */
372 case IEEE80211_IF_TYPE_MNTR
:
374 if (local
->monitors
== 0)
375 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_RADIOTAP
;
377 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_FCSFAIL
)
378 local
->fif_fcsfail
--;
379 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_PLCPFAIL
)
380 local
->fif_plcpfail
--;
381 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_CONTROL
)
382 local
->fif_control
--;
383 if (sdata
->u
.mntr_flags
& MONITOR_FLAG_OTHER_BSS
)
384 local
->fif_other_bss
--;
386 netif_tx_lock_bh(local
->mdev
);
387 ieee80211_configure_filter(local
);
388 netif_tx_unlock_bh(local
->mdev
);
390 case IEEE80211_IF_TYPE_STA
:
391 case IEEE80211_IF_TYPE_IBSS
:
392 sdata
->u
.sta
.state
= IEEE80211_DISABLED
;
393 del_timer_sync(&sdata
->u
.sta
.timer
);
395 * When we get here, the interface is marked down.
396 * Call synchronize_rcu() to wait for the RX path
397 * should it be using the interface and enqueuing
398 * frames at this very time on another CPU.
401 skb_queue_purge(&sdata
->u
.sta
.skb_queue
);
403 if (local
->scan_dev
== sdata
->dev
) {
404 if (!local
->ops
->hw_scan
) {
405 local
->sta_sw_scanning
= 0;
406 cancel_delayed_work(&local
->scan_work
);
408 local
->sta_hw_scanning
= 0;
411 flush_workqueue(local
->hw
.workqueue
);
413 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_PRIVACY_INVOKED
;
414 kfree(sdata
->u
.sta
.extra_ie
);
415 sdata
->u
.sta
.extra_ie
= NULL
;
416 sdata
->u
.sta
.extra_ie_len
= 0;
419 conf
.vif
= &sdata
->vif
;
420 conf
.type
= sdata
->vif
.type
;
421 conf
.mac_addr
= dev
->dev_addr
;
422 /* disable all keys for as long as this netdev is down */
423 ieee80211_disable_keys(sdata
);
424 local
->ops
->remove_interface(local_to_hw(local
), &conf
);
427 if (local
->open_count
== 0) {
428 if (netif_running(local
->mdev
))
429 dev_close(local
->mdev
);
431 if (local
->ops
->stop
)
432 local
->ops
->stop(local_to_hw(local
));
434 ieee80211_led_radio(local
, 0);
436 tasklet_disable(&local
->tx_pending_tasklet
);
437 tasklet_disable(&local
->tasklet
);
443 int ieee80211_start_tx_ba_session(struct ieee80211_hw
*hw
, u8
*ra
, u16 tid
)
445 struct ieee80211_local
*local
= hw_to_local(hw
);
446 struct sta_info
*sta
;
447 struct ieee80211_sub_if_data
*sdata
;
448 u16 start_seq_num
= 0;
451 DECLARE_MAC_BUF(mac
);
453 if (tid
>= STA_TID_NUM
)
456 #ifdef CONFIG_MAC80211_HT_DEBUG
457 printk(KERN_DEBUG
"Open BA session requested for %s tid %u\n",
458 print_mac(mac
, ra
), tid
);
459 #endif /* CONFIG_MAC80211_HT_DEBUG */
461 sta
= sta_info_get(local
, ra
);
463 printk(KERN_DEBUG
"Could not find the station\n");
467 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
469 /* we have tried too many times, receiver does not want A-MPDU */
470 if (sta
->ampdu_mlme
.tid_tx
[tid
].addba_req_num
> HT_AGG_MAX_RETRIES
) {
475 state
= &sta
->ampdu_mlme
.tid_tx
[tid
].state
;
476 /* check if the TID is not in aggregation flow already */
477 if (*state
!= HT_AGG_STATE_IDLE
) {
478 #ifdef CONFIG_MAC80211_HT_DEBUG
479 printk(KERN_DEBUG
"BA request denied - session is not "
480 "idle on tid %u\n", tid
);
481 #endif /* CONFIG_MAC80211_HT_DEBUG */
486 /* ensure that TX flow won't interrupt us
487 * until the end of the call to requeue function */
488 spin_lock_bh(&local
->mdev
->queue_lock
);
490 /* create a new queue for this aggregation */
491 ret
= ieee80211_ht_agg_queue_add(local
, sta
, tid
);
493 /* case no queue is available to aggregation
494 * don't switch to aggregation */
496 #ifdef CONFIG_MAC80211_HT_DEBUG
497 printk(KERN_DEBUG
"BA request denied - no queue available for"
499 #endif /* CONFIG_MAC80211_HT_DEBUG */
500 spin_unlock_bh(&local
->mdev
->queue_lock
);
503 sdata
= IEEE80211_DEV_TO_SUB_IF(sta
->dev
);
505 /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
506 * call back right away, it must see that the flow has begun */
507 *state
|= HT_ADDBA_REQUESTED_MSK
;
509 if (local
->ops
->ampdu_action
)
510 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_TX_START
,
511 ra
, tid
, &start_seq_num
);
514 /* No need to requeue the packets in the agg queue, since we
515 * held the tx lock: no packet could be enqueued to the newly
517 ieee80211_ht_agg_queue_remove(local
, sta
, tid
, 0);
518 #ifdef CONFIG_MAC80211_HT_DEBUG
519 printk(KERN_DEBUG
"BA request denied - HW or queue unavailable"
520 " for tid %d\n", tid
);
521 #endif /* CONFIG_MAC80211_HT_DEBUG */
522 spin_unlock_bh(&local
->mdev
->queue_lock
);
523 *state
= HT_AGG_STATE_IDLE
;
527 /* Will put all the packets in the new SW queue */
528 ieee80211_requeue(local
, ieee802_1d_to_ac
[tid
]);
529 spin_unlock_bh(&local
->mdev
->queue_lock
);
531 /* We have most probably almost emptied the legacy queue */
532 /* ieee80211_wake_queue(local_to_hw(local), ieee802_1d_to_ac[tid]); */
534 /* send an addBA request */
535 sta
->ampdu_mlme
.dialog_token_allocator
++;
536 sta
->ampdu_mlme
.tid_tx
[tid
].dialog_token
=
537 sta
->ampdu_mlme
.dialog_token_allocator
;
538 sta
->ampdu_mlme
.tid_tx
[tid
].ssn
= start_seq_num
;
540 ieee80211_send_addba_request(sta
->dev
, ra
, tid
,
541 sta
->ampdu_mlme
.tid_tx
[tid
].dialog_token
,
542 sta
->ampdu_mlme
.tid_tx
[tid
].ssn
,
545 /* activate the timer for the recipient's addBA response */
546 sta
->ampdu_mlme
.tid_tx
[tid
].addba_resp_timer
.expires
=
547 jiffies
+ ADDBA_RESP_INTERVAL
;
548 add_timer(&sta
->ampdu_mlme
.tid_tx
[tid
].addba_resp_timer
);
549 printk(KERN_DEBUG
"activated addBA response timer on tid %d\n", tid
);
552 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
556 EXPORT_SYMBOL(ieee80211_start_tx_ba_session
);
558 int ieee80211_stop_tx_ba_session(struct ieee80211_hw
*hw
,
560 enum ieee80211_back_parties initiator
)
562 struct ieee80211_local
*local
= hw_to_local(hw
);
563 struct sta_info
*sta
;
566 DECLARE_MAC_BUF(mac
);
568 if (tid
>= STA_TID_NUM
)
571 #ifdef CONFIG_MAC80211_HT_DEBUG
572 printk(KERN_DEBUG
"Stop a BA session requested for %s tid %u\n",
573 print_mac(mac
, ra
), tid
);
574 #endif /* CONFIG_MAC80211_HT_DEBUG */
576 sta
= sta_info_get(local
, ra
);
580 /* check if the TID is in aggregation */
581 state
= &sta
->ampdu_mlme
.tid_tx
[tid
].state
;
582 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
584 if (*state
!= HT_AGG_STATE_OPERATIONAL
) {
585 #ifdef CONFIG_MAC80211_HT_DEBUG
586 printk(KERN_DEBUG
"Try to stop Tx aggregation on"
587 " non active TID\n");
588 #endif /* CONFIG_MAC80211_HT_DEBUG */
593 ieee80211_stop_queue(hw
, sta
->tid_to_tx_q
[tid
]);
595 *state
= HT_AGG_STATE_REQ_STOP_BA_MSK
|
596 (initiator
<< HT_AGG_STATE_INITIATOR_SHIFT
);
598 if (local
->ops
->ampdu_action
)
599 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_TX_STOP
,
602 /* case HW denied going back to legacy */
604 WARN_ON(ret
!= -EBUSY
);
605 *state
= HT_AGG_STATE_OPERATIONAL
;
606 ieee80211_wake_queue(hw
, sta
->tid_to_tx_q
[tid
]);
611 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
615 EXPORT_SYMBOL(ieee80211_stop_tx_ba_session
);
617 void ieee80211_start_tx_ba_cb(struct ieee80211_hw
*hw
, u8
*ra
, u16 tid
)
619 struct ieee80211_local
*local
= hw_to_local(hw
);
620 struct sta_info
*sta
;
622 DECLARE_MAC_BUF(mac
);
624 if (tid
>= STA_TID_NUM
) {
625 printk(KERN_DEBUG
"Bad TID value: tid = %d (>= %d)\n",
630 sta
= sta_info_get(local
, ra
);
632 printk(KERN_DEBUG
"Could not find station: %s\n",
637 state
= &sta
->ampdu_mlme
.tid_tx
[tid
].state
;
638 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
640 if (!(*state
& HT_ADDBA_REQUESTED_MSK
)) {
641 printk(KERN_DEBUG
"addBA was not requested yet, state is %d\n",
643 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
648 WARN_ON_ONCE(*state
& HT_ADDBA_DRV_READY_MSK
);
650 *state
|= HT_ADDBA_DRV_READY_MSK
;
652 if (*state
== HT_AGG_STATE_OPERATIONAL
) {
653 printk(KERN_DEBUG
"Aggregation is on for tid %d \n", tid
);
654 ieee80211_wake_queue(hw
, sta
->tid_to_tx_q
[tid
]);
656 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
659 EXPORT_SYMBOL(ieee80211_start_tx_ba_cb
);
661 void ieee80211_stop_tx_ba_cb(struct ieee80211_hw
*hw
, u8
*ra
, u8 tid
)
663 struct ieee80211_local
*local
= hw_to_local(hw
);
664 struct sta_info
*sta
;
667 DECLARE_MAC_BUF(mac
);
669 if (tid
>= STA_TID_NUM
) {
670 printk(KERN_DEBUG
"Bad TID value: tid = %d (>= %d)\n",
675 printk(KERN_DEBUG
"Stop a BA session requested on DA %s tid %d\n",
676 print_mac(mac
, ra
), tid
);
678 sta
= sta_info_get(local
, ra
);
680 printk(KERN_DEBUG
"Could not find station: %s\n",
684 state
= &sta
->ampdu_mlme
.tid_tx
[tid
].state
;
686 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
687 if ((*state
& HT_AGG_STATE_REQ_STOP_BA_MSK
) == 0) {
688 printk(KERN_DEBUG
"unexpected callback to A-MPDU stop\n");
690 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
694 if (*state
& HT_AGG_STATE_INITIATOR_MSK
)
695 ieee80211_send_delba(sta
->dev
, ra
, tid
,
696 WLAN_BACK_INITIATOR
, WLAN_REASON_QSTA_NOT_USE
);
698 agg_queue
= sta
->tid_to_tx_q
[tid
];
700 /* avoid ordering issues: we are the only one that can modify
701 * the content of the qdiscs */
702 spin_lock_bh(&local
->mdev
->queue_lock
);
703 /* remove the queue for this aggregation */
704 ieee80211_ht_agg_queue_remove(local
, sta
, tid
, 1);
705 spin_unlock_bh(&local
->mdev
->queue_lock
);
707 /* we just requeued the all the frames that were in the removed
708 * queue, and since we might miss a softirq we do netif_schedule.
709 * ieee80211_wake_queue is not used here as this queue is not
710 * necessarily stopped */
711 netif_schedule(local
->mdev
);
712 *state
= HT_AGG_STATE_IDLE
;
713 sta
->ampdu_mlme
.tid_tx
[tid
].addba_req_num
= 0;
714 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
718 EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb
);
720 void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw
*hw
,
721 const u8
*ra
, u16 tid
)
723 struct ieee80211_local
*local
= hw_to_local(hw
);
724 struct ieee80211_ra_tid
*ra_tid
;
725 struct sk_buff
*skb
= dev_alloc_skb(0);
727 if (unlikely(!skb
)) {
729 printk(KERN_WARNING
"%s: Not enough memory, "
730 "dropping start BA session", skb
->dev
->name
);
733 ra_tid
= (struct ieee80211_ra_tid
*) &skb
->cb
;
734 memcpy(&ra_tid
->ra
, ra
, ETH_ALEN
);
737 skb
->pkt_type
= IEEE80211_ADDBA_MSG
;
738 skb_queue_tail(&local
->skb_queue
, skb
);
739 tasklet_schedule(&local
->tasklet
);
741 EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe
);
743 void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw
*hw
,
744 const u8
*ra
, u16 tid
)
746 struct ieee80211_local
*local
= hw_to_local(hw
);
747 struct ieee80211_ra_tid
*ra_tid
;
748 struct sk_buff
*skb
= dev_alloc_skb(0);
750 if (unlikely(!skb
)) {
752 printk(KERN_WARNING
"%s: Not enough memory, "
753 "dropping stop BA session", skb
->dev
->name
);
756 ra_tid
= (struct ieee80211_ra_tid
*) &skb
->cb
;
757 memcpy(&ra_tid
->ra
, ra
, ETH_ALEN
);
760 skb
->pkt_type
= IEEE80211_DELBA_MSG
;
761 skb_queue_tail(&local
->skb_queue
, skb
);
762 tasklet_schedule(&local
->tasklet
);
764 EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe
);
766 static void ieee80211_set_multicast_list(struct net_device
*dev
)
768 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
769 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
770 int allmulti
, promisc
, sdata_allmulti
, sdata_promisc
;
772 allmulti
= !!(dev
->flags
& IFF_ALLMULTI
);
773 promisc
= !!(dev
->flags
& IFF_PROMISC
);
774 sdata_allmulti
= !!(sdata
->flags
& IEEE80211_SDATA_ALLMULTI
);
775 sdata_promisc
= !!(sdata
->flags
& IEEE80211_SDATA_PROMISC
);
777 if (allmulti
!= sdata_allmulti
) {
778 if (dev
->flags
& IFF_ALLMULTI
)
779 atomic_inc(&local
->iff_allmultis
);
781 atomic_dec(&local
->iff_allmultis
);
782 sdata
->flags
^= IEEE80211_SDATA_ALLMULTI
;
785 if (promisc
!= sdata_promisc
) {
786 if (dev
->flags
& IFF_PROMISC
)
787 atomic_inc(&local
->iff_promiscs
);
789 atomic_dec(&local
->iff_promiscs
);
790 sdata
->flags
^= IEEE80211_SDATA_PROMISC
;
793 dev_mc_sync(local
->mdev
, dev
);
796 static const struct header_ops ieee80211_header_ops
= {
797 .create
= eth_header
,
798 .parse
= header_parse_80211
,
799 .rebuild
= eth_rebuild_header
,
800 .cache
= eth_header_cache
,
801 .cache_update
= eth_header_cache_update
,
804 /* Must not be called for mdev */
805 void ieee80211_if_setup(struct net_device
*dev
)
808 dev
->hard_start_xmit
= ieee80211_subif_start_xmit
;
809 dev
->wireless_handlers
= &ieee80211_iw_handler_def
;
810 dev
->set_multicast_list
= ieee80211_set_multicast_list
;
811 dev
->change_mtu
= ieee80211_change_mtu
;
812 dev
->open
= ieee80211_open
;
813 dev
->stop
= ieee80211_stop
;
814 dev
->destructor
= ieee80211_if_free
;
817 /* WDS specialties */
819 int ieee80211_if_update_wds(struct net_device
*dev
, u8
*remote_addr
)
821 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
822 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
823 struct sta_info
*sta
;
824 DECLARE_MAC_BUF(mac
);
826 if (compare_ether_addr(remote_addr
, sdata
->u
.wds
.remote_addr
) == 0)
829 /* Create STA entry for the new peer */
830 sta
= sta_info_add(local
, dev
, remote_addr
, GFP_KERNEL
);
834 sta
->flags
|= WLAN_STA_AUTHORIZED
;
838 /* Remove STA entry for the old peer */
839 sta
= sta_info_get(local
, sdata
->u
.wds
.remote_addr
);
844 printk(KERN_DEBUG
"%s: could not find STA entry for WDS link "
846 dev
->name
, print_mac(mac
, sdata
->u
.wds
.remote_addr
));
849 /* Update WDS link data */
850 memcpy(&sdata
->u
.wds
.remote_addr
, remote_addr
, ETH_ALEN
);
855 /* everything else */
857 static int __ieee80211_if_config(struct net_device
*dev
,
858 struct sk_buff
*beacon
,
859 struct ieee80211_tx_control
*control
)
861 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
862 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
863 struct ieee80211_if_conf conf
;
865 if (!local
->ops
->config_interface
|| !netif_running(dev
))
868 memset(&conf
, 0, sizeof(conf
));
869 conf
.type
= sdata
->vif
.type
;
870 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
871 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
872 conf
.bssid
= sdata
->u
.sta
.bssid
;
873 conf
.ssid
= sdata
->u
.sta
.ssid
;
874 conf
.ssid_len
= sdata
->u
.sta
.ssid_len
;
875 } else if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
) {
876 conf
.ssid
= sdata
->u
.ap
.ssid
;
877 conf
.ssid_len
= sdata
->u
.ap
.ssid_len
;
878 conf
.beacon
= beacon
;
879 conf
.beacon_control
= control
;
881 return local
->ops
->config_interface(local_to_hw(local
),
885 int ieee80211_if_config(struct net_device
*dev
)
887 return __ieee80211_if_config(dev
, NULL
, NULL
);
890 int ieee80211_if_config_beacon(struct net_device
*dev
)
892 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
893 struct ieee80211_tx_control control
;
894 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
897 if (!(local
->hw
.flags
& IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE
))
899 skb
= ieee80211_beacon_get(local_to_hw(local
), &sdata
->vif
,
903 return __ieee80211_if_config(dev
, skb
, &control
);
906 int ieee80211_hw_config(struct ieee80211_local
*local
)
908 struct ieee80211_channel
*chan
;
911 if (local
->sta_sw_scanning
)
912 chan
= local
->scan_channel
;
914 chan
= local
->oper_channel
;
916 local
->hw
.conf
.channel
= chan
;
918 if (!local
->hw
.conf
.power_level
)
919 local
->hw
.conf
.power_level
= chan
->max_power
;
921 local
->hw
.conf
.power_level
= min(chan
->max_power
,
922 local
->hw
.conf
.power_level
);
924 local
->hw
.conf
.max_antenna_gain
= chan
->max_antenna_gain
;
926 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
927 printk(KERN_DEBUG
"%s: HW CONFIG: freq=%d\n",
928 wiphy_name(local
->hw
.wiphy
), chan
->center_freq
);
931 if (local
->open_count
)
932 ret
= local
->ops
->config(local_to_hw(local
), &local
->hw
.conf
);
938 * ieee80211_hw_config_ht should be used only after legacy configuration
939 * has been determined, as ht configuration depends upon the hardware's
940 * HT abilities for a _specific_ band.
942 int ieee80211_hw_config_ht(struct ieee80211_local
*local
, int enable_ht
,
943 struct ieee80211_ht_info
*req_ht_cap
,
944 struct ieee80211_ht_bss_info
*req_bss_cap
)
946 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
947 struct ieee80211_supported_band
*sband
;
950 sband
= local
->hw
.wiphy
->bands
[conf
->channel
->band
];
952 /* HT is not supported */
953 if (!sband
->ht_info
.ht_supported
) {
954 conf
->flags
&= ~IEEE80211_CONF_SUPPORT_HT_MODE
;
960 conf
->flags
&= ~IEEE80211_CONF_SUPPORT_HT_MODE
;
962 conf
->flags
|= IEEE80211_CONF_SUPPORT_HT_MODE
;
963 conf
->ht_conf
.cap
= req_ht_cap
->cap
& sband
->ht_info
.cap
;
964 conf
->ht_conf
.cap
&= ~(IEEE80211_HT_CAP_MIMO_PS
);
966 sband
->ht_info
.cap
& IEEE80211_HT_CAP_MIMO_PS
;
967 conf
->ht_bss_conf
.primary_channel
=
968 req_bss_cap
->primary_channel
;
969 conf
->ht_bss_conf
.bss_cap
= req_bss_cap
->bss_cap
;
970 conf
->ht_bss_conf
.bss_op_mode
= req_bss_cap
->bss_op_mode
;
971 for (i
= 0; i
< SUPP_MCS_SET_LEN
; i
++)
972 conf
->ht_conf
.supp_mcs_set
[i
] =
973 sband
->ht_info
.supp_mcs_set
[i
] &
974 req_ht_cap
->supp_mcs_set
[i
];
976 /* In STA mode, this gives us indication
977 * to the AP's mode of operation */
978 conf
->ht_conf
.ht_supported
= 1;
979 conf
->ht_conf
.ampdu_factor
= req_ht_cap
->ampdu_factor
;
980 conf
->ht_conf
.ampdu_density
= req_ht_cap
->ampdu_density
;
983 local
->ops
->conf_ht(local_to_hw(local
), &local
->hw
.conf
);
988 void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data
*sdata
,
991 struct ieee80211_local
*local
= sdata
->local
;
996 if (local
->ops
->bss_info_changed
)
997 local
->ops
->bss_info_changed(local_to_hw(local
),
1003 void ieee80211_reset_erp_info(struct net_device
*dev
)
1005 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1007 sdata
->bss_conf
.use_cts_prot
= 0;
1008 sdata
->bss_conf
.use_short_preamble
= 0;
1009 ieee80211_bss_info_change_notify(sdata
,
1010 BSS_CHANGED_ERP_CTS_PROT
|
1011 BSS_CHANGED_ERP_PREAMBLE
);
1014 void ieee80211_tx_status_irqsafe(struct ieee80211_hw
*hw
,
1015 struct sk_buff
*skb
,
1016 struct ieee80211_tx_status
*status
)
1018 struct ieee80211_local
*local
= hw_to_local(hw
);
1019 struct ieee80211_tx_status
*saved
;
1022 skb
->dev
= local
->mdev
;
1023 saved
= kmalloc(sizeof(struct ieee80211_tx_status
), GFP_ATOMIC
);
1024 if (unlikely(!saved
)) {
1025 if (net_ratelimit())
1026 printk(KERN_WARNING
"%s: Not enough memory, "
1027 "dropping tx status", skb
->dev
->name
);
1028 /* should be dev_kfree_skb_irq, but due to this function being
1029 * named _irqsafe instead of just _irq we can't be sure that
1030 * people won't call it from non-irq contexts */
1031 dev_kfree_skb_any(skb
);
1034 memcpy(saved
, status
, sizeof(struct ieee80211_tx_status
));
1035 /* copy pointer to saved status into skb->cb for use by tasklet */
1036 memcpy(skb
->cb
, &saved
, sizeof(saved
));
1038 skb
->pkt_type
= IEEE80211_TX_STATUS_MSG
;
1039 skb_queue_tail(status
->control
.flags
& IEEE80211_TXCTL_REQ_TX_STATUS
?
1040 &local
->skb_queue
: &local
->skb_queue_unreliable
, skb
);
1041 tmp
= skb_queue_len(&local
->skb_queue
) +
1042 skb_queue_len(&local
->skb_queue_unreliable
);
1043 while (tmp
> IEEE80211_IRQSAFE_QUEUE_LIMIT
&&
1044 (skb
= skb_dequeue(&local
->skb_queue_unreliable
))) {
1045 memcpy(&saved
, skb
->cb
, sizeof(saved
));
1047 dev_kfree_skb_irq(skb
);
1049 I802_DEBUG_INC(local
->tx_status_drop
);
1051 tasklet_schedule(&local
->tasklet
);
1053 EXPORT_SYMBOL(ieee80211_tx_status_irqsafe
);
1055 static void ieee80211_tasklet_handler(unsigned long data
)
1057 struct ieee80211_local
*local
= (struct ieee80211_local
*) data
;
1058 struct sk_buff
*skb
;
1059 struct ieee80211_rx_status rx_status
;
1060 struct ieee80211_tx_status
*tx_status
;
1061 struct ieee80211_ra_tid
*ra_tid
;
1063 while ((skb
= skb_dequeue(&local
->skb_queue
)) ||
1064 (skb
= skb_dequeue(&local
->skb_queue_unreliable
))) {
1065 switch (skb
->pkt_type
) {
1066 case IEEE80211_RX_MSG
:
1067 /* status is in skb->cb */
1068 memcpy(&rx_status
, skb
->cb
, sizeof(rx_status
));
1069 /* Clear skb->pkt_type in order to not confuse kernel
1072 __ieee80211_rx(local_to_hw(local
), skb
, &rx_status
);
1074 case IEEE80211_TX_STATUS_MSG
:
1075 /* get pointer to saved status out of skb->cb */
1076 memcpy(&tx_status
, skb
->cb
, sizeof(tx_status
));
1078 ieee80211_tx_status(local_to_hw(local
),
1082 case IEEE80211_DELBA_MSG
:
1083 ra_tid
= (struct ieee80211_ra_tid
*) &skb
->cb
;
1084 ieee80211_stop_tx_ba_cb(local_to_hw(local
),
1085 ra_tid
->ra
, ra_tid
->tid
);
1088 case IEEE80211_ADDBA_MSG
:
1089 ra_tid
= (struct ieee80211_ra_tid
*) &skb
->cb
;
1090 ieee80211_start_tx_ba_cb(local_to_hw(local
),
1091 ra_tid
->ra
, ra_tid
->tid
);
1094 default: /* should never get here! */
1095 printk(KERN_ERR
"%s: Unknown message type (%d)\n",
1096 wiphy_name(local
->hw
.wiphy
), skb
->pkt_type
);
1103 /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
1104 * make a prepared TX frame (one that has been given to hw) to look like brand
1105 * new IEEE 802.11 frame that is ready to go through TX processing again.
1106 * Also, tx_packet_data in cb is restored from tx_control. */
1107 static void ieee80211_remove_tx_extra(struct ieee80211_local
*local
,
1108 struct ieee80211_key
*key
,
1109 struct sk_buff
*skb
,
1110 struct ieee80211_tx_control
*control
)
1112 int hdrlen
, iv_len
, mic_len
;
1113 struct ieee80211_tx_packet_data
*pkt_data
;
1115 pkt_data
= (struct ieee80211_tx_packet_data
*)skb
->cb
;
1116 pkt_data
->ifindex
= vif_to_sdata(control
->vif
)->dev
->ifindex
;
1117 pkt_data
->flags
= 0;
1118 if (control
->flags
& IEEE80211_TXCTL_REQ_TX_STATUS
)
1119 pkt_data
->flags
|= IEEE80211_TXPD_REQ_TX_STATUS
;
1120 if (control
->flags
& IEEE80211_TXCTL_DO_NOT_ENCRYPT
)
1121 pkt_data
->flags
|= IEEE80211_TXPD_DO_NOT_ENCRYPT
;
1122 if (control
->flags
& IEEE80211_TXCTL_REQUEUE
)
1123 pkt_data
->flags
|= IEEE80211_TXPD_REQUEUE
;
1124 if (control
->flags
& IEEE80211_TXCTL_EAPOL_FRAME
)
1125 pkt_data
->flags
|= IEEE80211_TXPD_EAPOL_FRAME
;
1126 pkt_data
->queue
= control
->queue
;
1128 hdrlen
= ieee80211_get_hdrlen_from_skb(skb
);
1133 switch (key
->conf
.alg
) {
1135 iv_len
= WEP_IV_LEN
;
1136 mic_len
= WEP_ICV_LEN
;
1139 iv_len
= TKIP_IV_LEN
;
1140 mic_len
= TKIP_ICV_LEN
;
1143 iv_len
= CCMP_HDR_LEN
;
1144 mic_len
= CCMP_MIC_LEN
;
1150 if (skb
->len
>= mic_len
&&
1151 !(key
->flags
& KEY_FLAG_UPLOADED_TO_HARDWARE
))
1152 skb_trim(skb
, skb
->len
- mic_len
);
1153 if (skb
->len
>= iv_len
&& skb
->len
> hdrlen
) {
1154 memmove(skb
->data
+ iv_len
, skb
->data
, hdrlen
);
1155 skb_pull(skb
, iv_len
);
1160 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1161 u16 fc
= le16_to_cpu(hdr
->frame_control
);
1162 if ((fc
& 0x8C) == 0x88) /* QoS Control Field */ {
1163 fc
&= ~IEEE80211_STYPE_QOS_DATA
;
1164 hdr
->frame_control
= cpu_to_le16(fc
);
1165 memmove(skb
->data
+ 2, skb
->data
, hdrlen
- 2);
1171 void ieee80211_tx_status(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
1172 struct ieee80211_tx_status
*status
)
1174 struct sk_buff
*skb2
;
1175 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1176 struct ieee80211_local
*local
= hw_to_local(hw
);
1178 struct ieee80211_tx_status_rtap_hdr
*rthdr
;
1179 struct ieee80211_sub_if_data
*sdata
;
1184 "%s: ieee80211_tx_status called with NULL status\n",
1185 wiphy_name(local
->hw
.wiphy
));
1190 if (status
->excessive_retries
) {
1191 struct sta_info
*sta
;
1192 sta
= sta_info_get(local
, hdr
->addr1
);
1194 if (sta
->flags
& WLAN_STA_PS
) {
1195 /* The STA is in power save mode, so assume
1196 * that this TX packet failed because of that.
1198 status
->excessive_retries
= 0;
1199 status
->flags
|= IEEE80211_TX_STATUS_TX_FILTERED
;
1205 if (status
->flags
& IEEE80211_TX_STATUS_TX_FILTERED
) {
1206 struct sta_info
*sta
;
1207 sta
= sta_info_get(local
, hdr
->addr1
);
1209 sta
->tx_filtered_count
++;
1211 /* Clear the TX filter mask for this STA when sending
1212 * the next packet. If the STA went to power save mode,
1213 * this will happen when it is waking up for the next
1215 sta
->clear_dst_mask
= 1;
1217 /* TODO: Is the WLAN_STA_PS flag always set here or is
1218 * the race between RX and TX status causing some
1219 * packets to be filtered out before 80211.o gets an
1220 * update for PS status? This seems to be the case, so
1221 * no changes are likely to be needed. */
1222 if (sta
->flags
& WLAN_STA_PS
&&
1223 skb_queue_len(&sta
->tx_filtered
) <
1224 STA_MAX_TX_BUFFER
) {
1225 ieee80211_remove_tx_extra(local
, sta
->key
,
1228 skb_queue_tail(&sta
->tx_filtered
, skb
);
1229 } else if (!(sta
->flags
& WLAN_STA_PS
) &&
1230 !(status
->control
.flags
& IEEE80211_TXCTL_REQUEUE
)) {
1231 /* Software retry the packet once */
1232 status
->control
.flags
|= IEEE80211_TXCTL_REQUEUE
;
1233 ieee80211_remove_tx_extra(local
, sta
->key
,
1236 dev_queue_xmit(skb
);
1238 if (net_ratelimit()) {
1239 printk(KERN_DEBUG
"%s: dropped TX "
1240 "filtered frame queue_len=%d "
1242 wiphy_name(local
->hw
.wiphy
),
1245 !!(sta
->flags
& WLAN_STA_PS
),
1254 rate_control_tx_status(local
->mdev
, skb
, status
);
1256 ieee80211_led_tx(local
, 0);
1259 * Fragments are passed to low-level drivers as separate skbs, so these
1260 * are actually fragments, not frames. Update frame counters only for
1261 * the first fragment of the frame. */
1263 frag
= le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_FRAG
;
1264 type
= le16_to_cpu(hdr
->frame_control
) & IEEE80211_FCTL_FTYPE
;
1266 if (status
->flags
& IEEE80211_TX_STATUS_ACK
) {
1268 local
->dot11TransmittedFrameCount
++;
1269 if (is_multicast_ether_addr(hdr
->addr1
))
1270 local
->dot11MulticastTransmittedFrameCount
++;
1271 if (status
->retry_count
> 0)
1272 local
->dot11RetryCount
++;
1273 if (status
->retry_count
> 1)
1274 local
->dot11MultipleRetryCount
++;
1277 /* This counter shall be incremented for an acknowledged MPDU
1278 * with an individual address in the address 1 field or an MPDU
1279 * with a multicast address in the address 1 field of type Data
1281 if (!is_multicast_ether_addr(hdr
->addr1
) ||
1282 type
== IEEE80211_FTYPE_DATA
||
1283 type
== IEEE80211_FTYPE_MGMT
)
1284 local
->dot11TransmittedFragmentCount
++;
1287 local
->dot11FailedCount
++;
1290 /* this was a transmitted frame, but now we want to reuse it */
1293 if (!local
->monitors
) {
1298 /* send frame to monitor interfaces now */
1300 if (skb_headroom(skb
) < sizeof(*rthdr
)) {
1301 printk(KERN_ERR
"ieee80211_tx_status: headroom too small\n");
1306 rthdr
= (struct ieee80211_tx_status_rtap_hdr
*)
1307 skb_push(skb
, sizeof(*rthdr
));
1309 memset(rthdr
, 0, sizeof(*rthdr
));
1310 rthdr
->hdr
.it_len
= cpu_to_le16(sizeof(*rthdr
));
1311 rthdr
->hdr
.it_present
=
1312 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS
) |
1313 (1 << IEEE80211_RADIOTAP_DATA_RETRIES
));
1315 if (!(status
->flags
& IEEE80211_TX_STATUS_ACK
) &&
1316 !is_multicast_ether_addr(hdr
->addr1
))
1317 rthdr
->tx_flags
|= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL
);
1319 if ((status
->control
.flags
& IEEE80211_TXCTL_USE_RTS_CTS
) &&
1320 (status
->control
.flags
& IEEE80211_TXCTL_USE_CTS_PROTECT
))
1321 rthdr
->tx_flags
|= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS
);
1322 else if (status
->control
.flags
& IEEE80211_TXCTL_USE_RTS_CTS
)
1323 rthdr
->tx_flags
|= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS
);
1325 rthdr
->data_retries
= status
->retry_count
;
1328 monitors
= local
->monitors
;
1329 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
1331 * Using the monitors counter is possibly racy, but
1332 * if the value is wrong we simply either clone the skb
1333 * once too much or forget sending it to one monitor iface
1334 * The latter case isn't nice but fixing the race is much
1337 if (!monitors
|| !skb
)
1340 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_MNTR
) {
1341 if (!netif_running(sdata
->dev
))
1345 skb2
= skb_clone(skb
, GFP_ATOMIC
);
1348 skb
->dev
= sdata
->dev
;
1349 /* XXX: is this sufficient for BPF? */
1350 skb_set_mac_header(skb
, 0);
1351 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1352 skb
->pkt_type
= PACKET_OTHERHOST
;
1353 skb
->protocol
= htons(ETH_P_802_2
);
1354 memset(skb
->cb
, 0, sizeof(skb
->cb
));
1364 EXPORT_SYMBOL(ieee80211_tx_status
);
1366 struct ieee80211_hw
*ieee80211_alloc_hw(size_t priv_data_len
,
1367 const struct ieee80211_ops
*ops
)
1369 struct net_device
*mdev
;
1370 struct ieee80211_local
*local
;
1371 struct ieee80211_sub_if_data
*sdata
;
1373 struct wiphy
*wiphy
;
1375 /* Ensure 32-byte alignment of our private data and hw private data.
1376 * We use the wiphy priv data for both our ieee80211_local and for
1377 * the driver's private data
1379 * In memory it'll be like this:
1381 * +-------------------------+
1383 * +-------------------------+
1384 * | struct ieee80211_local |
1385 * +-------------------------+
1386 * | driver's private data |
1387 * +-------------------------+
1390 priv_size
= ((sizeof(struct ieee80211_local
) +
1391 NETDEV_ALIGN_CONST
) & ~NETDEV_ALIGN_CONST
) +
1394 wiphy
= wiphy_new(&mac80211_config_ops
, priv_size
);
1399 wiphy
->privid
= mac80211_wiphy_privid
;
1401 local
= wiphy_priv(wiphy
);
1402 local
->hw
.wiphy
= wiphy
;
1404 local
->hw
.priv
= (char *)local
+
1405 ((sizeof(struct ieee80211_local
) +
1406 NETDEV_ALIGN_CONST
) & ~NETDEV_ALIGN_CONST
);
1409 BUG_ON(!ops
->start
);
1411 BUG_ON(!ops
->config
);
1412 BUG_ON(!ops
->add_interface
);
1413 BUG_ON(!ops
->remove_interface
);
1414 BUG_ON(!ops
->configure_filter
);
1417 /* for now, mdev needs sub_if_data :/ */
1418 mdev
= alloc_netdev(sizeof(struct ieee80211_sub_if_data
),
1419 "wmaster%d", ether_setup
);
1425 sdata
= IEEE80211_DEV_TO_SUB_IF(mdev
);
1426 mdev
->ieee80211_ptr
= &sdata
->wdev
;
1427 sdata
->wdev
.wiphy
= wiphy
;
1429 local
->hw
.queues
= 1; /* default */
1432 local
->rx_handlers
= ieee80211_rx_handlers
;
1433 local
->tx_handlers
= ieee80211_tx_handlers
;
1435 local
->bridge_packets
= 1;
1437 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
1438 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
1439 local
->short_retry_limit
= 7;
1440 local
->long_retry_limit
= 4;
1441 local
->hw
.conf
.radio_enabled
= 1;
1443 INIT_LIST_HEAD(&local
->interfaces
);
1445 INIT_DELAYED_WORK(&local
->scan_work
, ieee80211_sta_scan_work
);
1446 ieee80211_rx_bss_list_init(mdev
);
1448 sta_info_init(local
);
1450 mdev
->hard_start_xmit
= ieee80211_master_start_xmit
;
1451 mdev
->open
= ieee80211_master_open
;
1452 mdev
->stop
= ieee80211_master_stop
;
1453 mdev
->type
= ARPHRD_IEEE80211
;
1454 mdev
->header_ops
= &ieee80211_header_ops
;
1455 mdev
->set_multicast_list
= ieee80211_master_set_multicast_list
;
1457 sdata
->vif
.type
= IEEE80211_IF_TYPE_AP
;
1459 sdata
->local
= local
;
1460 sdata
->u
.ap
.force_unicast_rateidx
= -1;
1461 sdata
->u
.ap
.max_ratectrl_rateidx
= -1;
1462 ieee80211_if_sdata_init(sdata
);
1463 /* no RCU needed since we're still during init phase */
1464 list_add_tail(&sdata
->list
, &local
->interfaces
);
1466 tasklet_init(&local
->tx_pending_tasklet
, ieee80211_tx_pending
,
1467 (unsigned long)local
);
1468 tasklet_disable(&local
->tx_pending_tasklet
);
1470 tasklet_init(&local
->tasklet
,
1471 ieee80211_tasklet_handler
,
1472 (unsigned long) local
);
1473 tasklet_disable(&local
->tasklet
);
1475 skb_queue_head_init(&local
->skb_queue
);
1476 skb_queue_head_init(&local
->skb_queue_unreliable
);
1478 return local_to_hw(local
);
1480 EXPORT_SYMBOL(ieee80211_alloc_hw
);
1482 int ieee80211_register_hw(struct ieee80211_hw
*hw
)
1484 struct ieee80211_local
*local
= hw_to_local(hw
);
1487 enum ieee80211_band band
;
1490 * generic code guarantees at least one band,
1491 * set this very early because much code assumes
1492 * that hw.conf.channel is assigned
1494 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1495 struct ieee80211_supported_band
*sband
;
1497 sband
= local
->hw
.wiphy
->bands
[band
];
1499 /* init channel we're on */
1500 local
->hw
.conf
.channel
=
1501 local
->oper_channel
=
1502 local
->scan_channel
= &sband
->channels
[0];
1507 result
= wiphy_register(local
->hw
.wiphy
);
1511 name
= wiphy_dev(local
->hw
.wiphy
)->driver
->name
;
1512 local
->hw
.workqueue
= create_singlethread_workqueue(name
);
1513 if (!local
->hw
.workqueue
) {
1515 goto fail_workqueue
;
1519 * The hardware needs headroom for sending the frame,
1520 * and we need some headroom for passing the frame to monitor
1521 * interfaces, but never both at the same time.
1523 local
->tx_headroom
= max_t(unsigned int , local
->hw
.extra_tx_headroom
,
1524 sizeof(struct ieee80211_tx_status_rtap_hdr
));
1526 debugfs_hw_add(local
);
1528 local
->hw
.conf
.beacon_int
= 1000;
1530 local
->wstats_flags
|= local
->hw
.max_rssi
?
1531 IW_QUAL_LEVEL_UPDATED
: IW_QUAL_LEVEL_INVALID
;
1532 local
->wstats_flags
|= local
->hw
.max_signal
?
1533 IW_QUAL_QUAL_UPDATED
: IW_QUAL_QUAL_INVALID
;
1534 local
->wstats_flags
|= local
->hw
.max_noise
?
1535 IW_QUAL_NOISE_UPDATED
: IW_QUAL_NOISE_INVALID
;
1536 if (local
->hw
.max_rssi
< 0 || local
->hw
.max_noise
< 0)
1537 local
->wstats_flags
|= IW_QUAL_DBM
;
1539 result
= sta_info_start(local
);
1544 result
= dev_alloc_name(local
->mdev
, local
->mdev
->name
);
1548 memcpy(local
->mdev
->dev_addr
, local
->hw
.wiphy
->perm_addr
, ETH_ALEN
);
1549 SET_NETDEV_DEV(local
->mdev
, wiphy_dev(local
->hw
.wiphy
));
1551 result
= register_netdevice(local
->mdev
);
1555 ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local
->mdev
));
1556 ieee80211_if_set_type(local
->mdev
, IEEE80211_IF_TYPE_AP
);
1558 result
= ieee80211_init_rate_ctrl_alg(local
,
1559 hw
->rate_control_algorithm
);
1561 printk(KERN_DEBUG
"%s: Failed to initialize rate control "
1562 "algorithm\n", wiphy_name(local
->hw
.wiphy
));
1566 result
= ieee80211_wep_init(local
);
1569 printk(KERN_DEBUG
"%s: Failed to initialize wep\n",
1570 wiphy_name(local
->hw
.wiphy
));
1574 ieee80211_install_qdisc(local
->mdev
);
1576 /* add one default STA interface */
1577 result
= ieee80211_if_add(local
->mdev
, "wlan%d", NULL
,
1578 IEEE80211_IF_TYPE_STA
);
1580 printk(KERN_WARNING
"%s: Failed to add default virtual iface\n",
1581 wiphy_name(local
->hw
.wiphy
));
1583 local
->reg_state
= IEEE80211_DEV_REGISTERED
;
1586 ieee80211_led_init(local
);
1591 rate_control_deinitialize(local
);
1593 ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local
->mdev
));
1594 unregister_netdevice(local
->mdev
);
1597 sta_info_stop(local
);
1599 debugfs_hw_del(local
);
1600 destroy_workqueue(local
->hw
.workqueue
);
1602 wiphy_unregister(local
->hw
.wiphy
);
1605 EXPORT_SYMBOL(ieee80211_register_hw
);
1607 void ieee80211_unregister_hw(struct ieee80211_hw
*hw
)
1609 struct ieee80211_local
*local
= hw_to_local(hw
);
1610 struct ieee80211_sub_if_data
*sdata
, *tmp
;
1612 tasklet_kill(&local
->tx_pending_tasklet
);
1613 tasklet_kill(&local
->tasklet
);
1617 BUG_ON(local
->reg_state
!= IEEE80211_DEV_REGISTERED
);
1619 local
->reg_state
= IEEE80211_DEV_UNREGISTERED
;
1622 * At this point, interface list manipulations are fine
1623 * because the driver cannot be handing us frames any
1624 * more and the tasklet is killed.
1628 * First, we remove all non-master interfaces. Do this because they
1629 * may have bss pointer dependency on the master, and when we free
1630 * the master these would be freed as well, breaking our list
1631 * iteration completely.
1633 list_for_each_entry_safe(sdata
, tmp
, &local
->interfaces
, list
) {
1634 if (sdata
->dev
== local
->mdev
)
1636 list_del(&sdata
->list
);
1637 __ieee80211_if_del(local
, sdata
);
1640 /* then, finally, remove the master interface */
1641 __ieee80211_if_del(local
, IEEE80211_DEV_TO_SUB_IF(local
->mdev
));
1645 ieee80211_rx_bss_list_deinit(local
->mdev
);
1646 ieee80211_clear_tx_pending(local
);
1647 sta_info_stop(local
);
1648 rate_control_deinitialize(local
);
1649 debugfs_hw_del(local
);
1651 if (skb_queue_len(&local
->skb_queue
)
1652 || skb_queue_len(&local
->skb_queue_unreliable
))
1653 printk(KERN_WARNING
"%s: skb_queue not empty\n",
1654 wiphy_name(local
->hw
.wiphy
));
1655 skb_queue_purge(&local
->skb_queue
);
1656 skb_queue_purge(&local
->skb_queue_unreliable
);
1658 destroy_workqueue(local
->hw
.workqueue
);
1659 wiphy_unregister(local
->hw
.wiphy
);
1660 ieee80211_wep_free(local
);
1661 ieee80211_led_exit(local
);
1663 EXPORT_SYMBOL(ieee80211_unregister_hw
);
1665 void ieee80211_free_hw(struct ieee80211_hw
*hw
)
1667 struct ieee80211_local
*local
= hw_to_local(hw
);
1669 ieee80211_if_free(local
->mdev
);
1670 wiphy_free(local
->hw
.wiphy
);
1672 EXPORT_SYMBOL(ieee80211_free_hw
);
1674 static int __init
ieee80211_init(void)
1676 struct sk_buff
*skb
;
1679 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data
) > sizeof(skb
->cb
));
1681 ret
= rc80211_simple_init();
1685 ret
= rc80211_pid_init();
1687 goto out_cleanup_simple
;
1689 ret
= ieee80211_wme_register();
1691 printk(KERN_DEBUG
"ieee80211_init: failed to "
1692 "initialize WME (err=%d)\n", ret
);
1693 goto out_cleanup_pid
;
1696 ieee80211_debugfs_netdev_init();
1703 rc80211_simple_exit();
1708 static void __exit
ieee80211_exit(void)
1710 rc80211_simple_exit();
1713 ieee80211_wme_unregister();
1714 ieee80211_debugfs_netdev_exit();
1718 subsys_initcall(ieee80211_init
);
1719 module_exit(ieee80211_exit
);
1721 MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1722 MODULE_LICENSE("GPL");