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;
179 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
181 /* we hold the RTNL here so can safely walk the list */
182 list_for_each_entry(nsdata, &local->interfaces, list) {
183 struct net_device *ndev = nsdata->dev;
185 if (ndev != dev && ndev != local->mdev && netif_running(ndev) &&
186 compare_ether_addr(dev->dev_addr, ndev->dev_addr) == 0) {
188 * check whether it may have the same address
190 if (!identical_mac_addr_allowed(sdata->vif.type,
195 * can only add VLANs to enabled APs
197 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN &&
198 nsdata->vif.type == IEEE80211_IF_TYPE_AP &&
199 netif_running(nsdata->dev))
200 sdata->u.vlan.ap = nsdata;
204 switch (sdata->vif.type) {
205 case IEEE80211_IF_TYPE_WDS:
206 if (is_zero_ether_addr(sdata->u.wds.remote_addr))
209 case IEEE80211_IF_TYPE_VLAN:
210 if (!sdata->u.vlan.ap)
213 case IEEE80211_IF_TYPE_AP:
214 case IEEE80211_IF_TYPE_STA:
215 case IEEE80211_IF_TYPE_MNTR:
216 case IEEE80211_IF_TYPE_IBSS:
217 /* no special treatment */
219 case IEEE80211_IF_TYPE_INVALID:
225 if (local->open_count == 0) {
227 if (local->ops->start)
228 res = local->ops->start(local_to_hw(local));
231 ieee80211_hw_config(local);
232 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
235 switch (sdata->vif.type) {
236 case IEEE80211_IF_TYPE_VLAN:
237 list_add(&sdata->u.vlan.list, &sdata->u.vlan.ap->u.ap.vlans);
238 /* no need to tell driver */
240 case IEEE80211_IF_TYPE_MNTR:
241 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
242 local->cooked_mntrs++;
246 /* must be before the call to ieee80211_configure_filter */
248 if (local->monitors == 1)
249 local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
251 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
252 local->fif_fcsfail++;
253 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
254 local->fif_plcpfail++;
255 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
256 local->fif_control++;
257 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
258 local->fif_other_bss++;
260 netif_tx_lock_bh(local->mdev);
261 ieee80211_configure_filter(local);
262 netif_tx_unlock_bh(local->mdev);
264 case IEEE80211_IF_TYPE_STA:
265 case IEEE80211_IF_TYPE_IBSS:
266 sdata->u.sta.flags &= ~IEEE80211_STA_PREV_BSSID_SET;
269 conf.vif = &sdata->vif;
270 conf.type = sdata->vif.type;
271 conf.mac_addr = dev->dev_addr;
272 res = local->ops->add_interface(local_to_hw(local), &conf);
273 if (res && !local->open_count && local->ops->stop)
274 local->ops->stop(local_to_hw(local));
278 ieee80211_if_config(dev);
279 ieee80211_reset_erp_info(dev);
280 ieee80211_enable_keys(sdata);
282 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
283 !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME))
284 netif_carrier_off(dev);
286 netif_carrier_on(dev);
289 if (local->open_count == 0) {
290 res = dev_open(local->mdev);
292 tasklet_enable(&local->tx_pending_tasklet);
293 tasklet_enable(&local->tasklet);
297 * set_multicast_list will be invoked by the networking core
298 * which will check whether any increments here were done in
299 * error and sync them down to the hardware as filter flags.
301 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
302 atomic_inc(&local->iff_allmultis);
304 if (sdata->flags & IEEE80211_SDATA_PROMISC)
305 atomic_inc(&local->iff_promiscs);
309 netif_start_queue(dev);
314 static int ieee80211_stop(struct net_device *dev)
316 struct ieee80211_sub_if_data *sdata;
317 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
318 struct ieee80211_if_init_conf conf;
319 struct sta_info *sta;
322 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
324 list_for_each_entry(sta, &local->sta_list, list) {
326 for (i = 0; i < STA_TID_NUM; i++)
327 ieee80211_sta_stop_rx_ba_session(sta->dev,
330 WLAN_REASON_QSTA_LEAVE_QBSS);
333 netif_stop_queue(dev);
336 * Don't count this interface for promisc/allmulti while it
337 * is down. dev_mc_unsync() will invoke set_multicast_list
338 * on the master interface which will sync these down to the
339 * hardware as filter flags.
341 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
342 atomic_dec(&local->iff_allmultis);
344 if (sdata->flags & IEEE80211_SDATA_PROMISC)
345 atomic_dec(&local->iff_promiscs);
347 dev_mc_unsync(local->mdev, dev);
349 /* APs need special treatment */
350 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
351 struct ieee80211_sub_if_data *vlan, *tmp;
352 struct beacon_data *old_beacon = sdata->u.ap.beacon;
355 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
359 /* down all dependent devices, that is VLANs */
360 list_for_each_entry_safe(vlan, tmp, &sdata->u.ap.vlans,
362 dev_close(vlan->dev);
363 WARN_ON(!list_empty(&sdata->u.ap.vlans));
368 switch (sdata->vif.type) {
369 case IEEE80211_IF_TYPE_VLAN:
370 list_del(&sdata->u.vlan.list);
371 sdata->u.vlan.ap = NULL;
372 /* no need to tell driver */
374 case IEEE80211_IF_TYPE_MNTR:
375 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
376 local->cooked_mntrs--;
381 if (local->monitors == 0)
382 local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
384 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
385 local->fif_fcsfail--;
386 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
387 local->fif_plcpfail--;
388 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
389 local->fif_control--;
390 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
391 local->fif_other_bss--;
393 netif_tx_lock_bh(local->mdev);
394 ieee80211_configure_filter(local);
395 netif_tx_unlock_bh(local->mdev);
397 case IEEE80211_IF_TYPE_STA:
398 case IEEE80211_IF_TYPE_IBSS:
399 sdata->u.sta.state = IEEE80211_DISABLED;
400 del_timer_sync(&sdata->u.sta.timer);
402 * When we get here, the interface is marked down.
403 * Call synchronize_rcu() to wait for the RX path
404 * should it be using the interface and enqueuing
405 * frames at this very time on another CPU.
408 skb_queue_purge(&sdata->u.sta.skb_queue);
410 if (local->scan_dev == sdata->dev) {
411 if (!local->ops->hw_scan) {
412 local->sta_sw_scanning = 0;
413 cancel_delayed_work(&local->scan_work);
415 local->sta_hw_scanning = 0;
418 flush_workqueue(local->hw.workqueue);
420 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
421 kfree(sdata->u.sta.extra_ie);
422 sdata->u.sta.extra_ie = NULL;
423 sdata->u.sta.extra_ie_len = 0;
426 conf.vif = &sdata->vif;
427 conf.type = sdata->vif.type;
428 conf.mac_addr = dev->dev_addr;
429 /* disable all keys for as long as this netdev is down */
430 ieee80211_disable_keys(sdata);
431 local->ops->remove_interface(local_to_hw(local), &conf);
434 if (local->open_count == 0) {
435 if (netif_running(local->mdev))
436 dev_close(local->mdev);
438 if (local->ops->stop)
439 local->ops->stop(local_to_hw(local));
441 ieee80211_led_radio(local, 0);
443 tasklet_disable(&local->tx_pending_tasklet);
444 tasklet_disable(&local->tasklet);
450 int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
452 struct ieee80211_local *local = hw_to_local(hw);
453 struct sta_info *sta;
454 struct ieee80211_sub_if_data *sdata;
455 u16 start_seq_num = 0;
458 DECLARE_MAC_BUF(mac);
460 if (tid >= STA_TID_NUM)
463 #ifdef CONFIG_MAC80211_HT_DEBUG
464 printk(KERN_DEBUG "Open BA session requested for %s tid %u\n",
465 print_mac(mac, ra), tid);
466 #endif /* CONFIG_MAC80211_HT_DEBUG */
468 sta = sta_info_get(local, ra);
470 printk(KERN_DEBUG "Could not find the station\n");
474 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
476 /* we have tried too many times, receiver does not want A-MPDU */
477 if (sta->ampdu_mlme.tid_tx[tid].addba_req_num > HT_AGG_MAX_RETRIES) {
482 state = &sta->ampdu_mlme.tid_tx[tid].state;
483 /* check if the TID is not in aggregation flow already */
484 if (*state != HT_AGG_STATE_IDLE) {
485 #ifdef CONFIG_MAC80211_HT_DEBUG
486 printk(KERN_DEBUG "BA request denied - session is not "
487 "idle on tid %u\n", tid);
488 #endif /* CONFIG_MAC80211_HT_DEBUG */
493 /* ensure that TX flow won't interrupt us
494 * until the end of the call to requeue function */
495 spin_lock_bh(&local->mdev->queue_lock);
497 /* create a new queue for this aggregation */
498 ret = ieee80211_ht_agg_queue_add(local, sta, tid);
500 /* case no queue is available to aggregation
501 * don't switch to aggregation */
503 #ifdef CONFIG_MAC80211_HT_DEBUG
504 printk(KERN_DEBUG "BA request denied - no queue available for"
506 #endif /* CONFIG_MAC80211_HT_DEBUG */
507 spin_unlock_bh(&local->mdev->queue_lock);
510 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
512 /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
513 * call back right away, it must see that the flow has begun */
514 *state |= HT_ADDBA_REQUESTED_MSK;
516 if (local->ops->ampdu_action)
517 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START,
518 ra, tid, &start_seq_num);
521 /* No need to requeue the packets in the agg queue, since we
522 * held the tx lock: no packet could be enqueued to the newly
524 ieee80211_ht_agg_queue_remove(local, sta, tid, 0);
525 #ifdef CONFIG_MAC80211_HT_DEBUG
526 printk(KERN_DEBUG "BA request denied - HW or queue unavailable"
527 " for tid %d\n", tid);
528 #endif /* CONFIG_MAC80211_HT_DEBUG */
529 spin_unlock_bh(&local->mdev->queue_lock);
530 *state = HT_AGG_STATE_IDLE;
534 /* Will put all the packets in the new SW queue */
535 ieee80211_requeue(local, ieee802_1d_to_ac[tid]);
536 spin_unlock_bh(&local->mdev->queue_lock);
538 /* We have most probably almost emptied the legacy queue */
539 /* ieee80211_wake_queue(local_to_hw(local), ieee802_1d_to_ac[tid]); */
541 /* send an addBA request */
542 sta->ampdu_mlme.dialog_token_allocator++;
543 sta->ampdu_mlme.tid_tx[tid].dialog_token =
544 sta->ampdu_mlme.dialog_token_allocator;
545 sta->ampdu_mlme.tid_tx[tid].ssn = start_seq_num;
547 ieee80211_send_addba_request(sta->dev, ra, tid,
548 sta->ampdu_mlme.tid_tx[tid].dialog_token,
549 sta->ampdu_mlme.tid_tx[tid].ssn,
552 /* activate the timer for the recipient's addBA response */
553 sta->ampdu_mlme.tid_tx[tid].addba_resp_timer.expires =
554 jiffies + ADDBA_RESP_INTERVAL;
555 add_timer(&sta->ampdu_mlme.tid_tx[tid].addba_resp_timer);
556 printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
559 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
563 EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
565 int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
567 enum ieee80211_back_parties initiator)
569 struct ieee80211_local *local = hw_to_local(hw);
570 struct sta_info *sta;
573 DECLARE_MAC_BUF(mac);
575 if (tid >= STA_TID_NUM)
578 #ifdef CONFIG_MAC80211_HT_DEBUG
579 printk(KERN_DEBUG "Stop a BA session requested for %s tid %u\n",
580 print_mac(mac, ra), tid);
581 #endif /* CONFIG_MAC80211_HT_DEBUG */
583 sta = sta_info_get(local, ra);
587 /* check if the TID is in aggregation */
588 state = &sta->ampdu_mlme.tid_tx[tid].state;
589 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
591 if (*state != HT_AGG_STATE_OPERATIONAL) {
592 #ifdef CONFIG_MAC80211_HT_DEBUG
593 printk(KERN_DEBUG "Try to stop Tx aggregation on"
594 " non active TID\n");
595 #endif /* CONFIG_MAC80211_HT_DEBUG */
600 ieee80211_stop_queue(hw, sta->tid_to_tx_q[tid]);
602 *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
603 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
605 if (local->ops->ampdu_action)
606 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_STOP,
609 /* case HW denied going back to legacy */
611 WARN_ON(ret != -EBUSY);
612 *state = HT_AGG_STATE_OPERATIONAL;
613 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
618 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
622 EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
624 void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
626 struct ieee80211_local *local = hw_to_local(hw);
627 struct sta_info *sta;
629 DECLARE_MAC_BUF(mac);
631 if (tid >= STA_TID_NUM) {
632 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
637 sta = sta_info_get(local, ra);
639 printk(KERN_DEBUG "Could not find station: %s\n",
644 state = &sta->ampdu_mlme.tid_tx[tid].state;
645 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
647 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
648 printk(KERN_DEBUG "addBA was not requested yet, state is %d\n",
650 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
655 WARN_ON_ONCE(*state & HT_ADDBA_DRV_READY_MSK);
657 *state |= HT_ADDBA_DRV_READY_MSK;
659 if (*state == HT_AGG_STATE_OPERATIONAL) {
660 printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid);
661 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
663 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
666 EXPORT_SYMBOL(ieee80211_start_tx_ba_cb);
668 void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
670 struct ieee80211_local *local = hw_to_local(hw);
671 struct sta_info *sta;
674 DECLARE_MAC_BUF(mac);
676 if (tid >= STA_TID_NUM) {
677 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
682 printk(KERN_DEBUG "Stop a BA session requested on DA %s tid %d\n",
683 print_mac(mac, ra), tid);
685 sta = sta_info_get(local, ra);
687 printk(KERN_DEBUG "Could not find station: %s\n",
691 state = &sta->ampdu_mlme.tid_tx[tid].state;
693 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
694 if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) {
695 printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
697 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
701 if (*state & HT_AGG_STATE_INITIATOR_MSK)
702 ieee80211_send_delba(sta->dev, ra, tid,
703 WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
705 agg_queue = sta->tid_to_tx_q[tid];
707 /* avoid ordering issues: we are the only one that can modify
708 * the content of the qdiscs */
709 spin_lock_bh(&local->mdev->queue_lock);
710 /* remove the queue for this aggregation */
711 ieee80211_ht_agg_queue_remove(local, sta, tid, 1);
712 spin_unlock_bh(&local->mdev->queue_lock);
714 /* we just requeued the all the frames that were in the removed
715 * queue, and since we might miss a softirq we do netif_schedule.
716 * ieee80211_wake_queue is not used here as this queue is not
717 * necessarily stopped */
718 netif_schedule(local->mdev);
719 *state = HT_AGG_STATE_IDLE;
720 sta->ampdu_mlme.tid_tx[tid].addba_req_num = 0;
721 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
725 EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb);
727 void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
728 const u8 *ra, u16 tid)
730 struct ieee80211_local *local = hw_to_local(hw);
731 struct ieee80211_ra_tid *ra_tid;
732 struct sk_buff *skb = dev_alloc_skb(0);
734 if (unlikely(!skb)) {
736 printk(KERN_WARNING "%s: Not enough memory, "
737 "dropping start BA session", skb->dev->name);
740 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
741 memcpy(&ra_tid->ra, ra, ETH_ALEN);
744 skb->pkt_type = IEEE80211_ADDBA_MSG;
745 skb_queue_tail(&local->skb_queue, skb);
746 tasklet_schedule(&local->tasklet);
748 EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
750 void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
751 const u8 *ra, u16 tid)
753 struct ieee80211_local *local = hw_to_local(hw);
754 struct ieee80211_ra_tid *ra_tid;
755 struct sk_buff *skb = dev_alloc_skb(0);
757 if (unlikely(!skb)) {
759 printk(KERN_WARNING "%s: Not enough memory, "
760 "dropping stop BA session", skb->dev->name);
763 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
764 memcpy(&ra_tid->ra, ra, ETH_ALEN);
767 skb->pkt_type = IEEE80211_DELBA_MSG;
768 skb_queue_tail(&local->skb_queue, skb);
769 tasklet_schedule(&local->tasklet);
771 EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
773 static void ieee80211_set_multicast_list(struct net_device *dev)
775 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
776 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
777 int allmulti, promisc, sdata_allmulti, sdata_promisc;
779 allmulti = !!(dev->flags & IFF_ALLMULTI);
780 promisc = !!(dev->flags & IFF_PROMISC);
781 sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
782 sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC);
784 if (allmulti != sdata_allmulti) {
785 if (dev->flags & IFF_ALLMULTI)
786 atomic_inc(&local->iff_allmultis);
788 atomic_dec(&local->iff_allmultis);
789 sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
792 if (promisc != sdata_promisc) {
793 if (dev->flags & IFF_PROMISC)
794 atomic_inc(&local->iff_promiscs);
796 atomic_dec(&local->iff_promiscs);
797 sdata->flags ^= IEEE80211_SDATA_PROMISC;
800 dev_mc_sync(local->mdev, dev);
803 static const struct header_ops ieee80211_header_ops = {
804 .create = eth_header,
805 .parse = header_parse_80211,
806 .rebuild = eth_rebuild_header,
807 .cache = eth_header_cache,
808 .cache_update = eth_header_cache_update,
811 /* Must not be called for mdev */
812 void ieee80211_if_setup(struct net_device *dev)
815 dev->hard_start_xmit = ieee80211_subif_start_xmit;
816 dev->wireless_handlers = &ieee80211_iw_handler_def;
817 dev->set_multicast_list = ieee80211_set_multicast_list;
818 dev->change_mtu = ieee80211_change_mtu;
819 dev->open = ieee80211_open;
820 dev->stop = ieee80211_stop;
821 dev->destructor = ieee80211_if_free;
824 /* WDS specialties */
826 int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr)
828 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
829 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
830 struct sta_info *sta;
831 DECLARE_MAC_BUF(mac);
833 if (compare_ether_addr(remote_addr, sdata->u.wds.remote_addr) == 0)
836 /* Create STA entry for the new peer */
837 sta = sta_info_add(local, dev, remote_addr, GFP_KERNEL);
841 sta->flags |= WLAN_STA_AUTHORIZED;
845 /* Remove STA entry for the old peer */
846 sta = sta_info_get(local, sdata->u.wds.remote_addr);
851 printk(KERN_DEBUG "%s: could not find STA entry for WDS link "
853 dev->name, print_mac(mac, sdata->u.wds.remote_addr));
856 /* Update WDS link data */
857 memcpy(&sdata->u.wds.remote_addr, remote_addr, ETH_ALEN);
862 /* everything else */
864 static int __ieee80211_if_config(struct net_device *dev,
865 struct sk_buff *beacon,
866 struct ieee80211_tx_control *control)
868 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
869 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
870 struct ieee80211_if_conf conf;
872 if (!local->ops->config_interface || !netif_running(dev))
875 memset(&conf, 0, sizeof(conf));
876 conf.type = sdata->vif.type;
877 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
878 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
879 conf.bssid = sdata->u.sta.bssid;
880 conf.ssid = sdata->u.sta.ssid;
881 conf.ssid_len = sdata->u.sta.ssid_len;
882 } else if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
883 conf.ssid = sdata->u.ap.ssid;
884 conf.ssid_len = sdata->u.ap.ssid_len;
885 conf.beacon = beacon;
886 conf.beacon_control = control;
888 return local->ops->config_interface(local_to_hw(local),
892 int ieee80211_if_config(struct net_device *dev)
894 return __ieee80211_if_config(dev, NULL, NULL);
897 int ieee80211_if_config_beacon(struct net_device *dev)
899 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
900 struct ieee80211_tx_control control;
901 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
904 if (!(local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE))
906 skb = ieee80211_beacon_get(local_to_hw(local), &sdata->vif,
910 return __ieee80211_if_config(dev, skb, &control);
913 int ieee80211_hw_config(struct ieee80211_local *local)
915 struct ieee80211_channel *chan;
918 if (local->sta_sw_scanning)
919 chan = local->scan_channel;
921 chan = local->oper_channel;
923 local->hw.conf.channel = chan;
925 if (!local->hw.conf.power_level)
926 local->hw.conf.power_level = chan->max_power;
928 local->hw.conf.power_level = min(chan->max_power,
929 local->hw.conf.power_level);
931 local->hw.conf.max_antenna_gain = chan->max_antenna_gain;
933 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
934 printk(KERN_DEBUG "%s: HW CONFIG: freq=%d\n",
935 wiphy_name(local->hw.wiphy), chan->center_freq);
938 if (local->open_count)
939 ret = local->ops->config(local_to_hw(local), &local->hw.conf);
945 * ieee80211_hw_config_ht should be used only after legacy configuration
946 * has been determined, as ht configuration depends upon the hardware's
947 * HT abilities for a _specific_ band.
949 int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht,
950 struct ieee80211_ht_info *req_ht_cap,
951 struct ieee80211_ht_bss_info *req_bss_cap)
953 struct ieee80211_conf *conf = &local->hw.conf;
954 struct ieee80211_supported_band *sband;
957 sband = local->hw.wiphy->bands[conf->channel->band];
959 /* HT is not supported */
960 if (!sband->ht_info.ht_supported) {
961 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
967 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
969 conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE;
970 conf->ht_conf.cap = req_ht_cap->cap & sband->ht_info.cap;
971 conf->ht_conf.cap &= ~(IEEE80211_HT_CAP_MIMO_PS);
973 sband->ht_info.cap & IEEE80211_HT_CAP_MIMO_PS;
974 conf->ht_bss_conf.primary_channel =
975 req_bss_cap->primary_channel;
976 conf->ht_bss_conf.bss_cap = req_bss_cap->bss_cap;
977 conf->ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode;
978 for (i = 0; i < SUPP_MCS_SET_LEN; i++)
979 conf->ht_conf.supp_mcs_set[i] =
980 sband->ht_info.supp_mcs_set[i] &
981 req_ht_cap->supp_mcs_set[i];
983 /* In STA mode, this gives us indication
984 * to the AP's mode of operation */
985 conf->ht_conf.ht_supported = 1;
986 conf->ht_conf.ampdu_factor = req_ht_cap->ampdu_factor;
987 conf->ht_conf.ampdu_density = req_ht_cap->ampdu_density;
990 local->ops->conf_ht(local_to_hw(local), &local->hw.conf);
995 void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
998 struct ieee80211_local *local = sdata->local;
1003 if (local->ops->bss_info_changed)
1004 local->ops->bss_info_changed(local_to_hw(local),
1010 void ieee80211_reset_erp_info(struct net_device *dev)
1012 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1014 sdata->bss_conf.use_cts_prot = 0;
1015 sdata->bss_conf.use_short_preamble = 0;
1016 ieee80211_bss_info_change_notify(sdata,
1017 BSS_CHANGED_ERP_CTS_PROT |
1018 BSS_CHANGED_ERP_PREAMBLE);
1021 void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
1022 struct sk_buff *skb,
1023 struct ieee80211_tx_status *status)
1025 struct ieee80211_local *local = hw_to_local(hw);
1026 struct ieee80211_tx_status *saved;
1029 skb->dev = local->mdev;
1030 saved = kmalloc(sizeof(struct ieee80211_tx_status), GFP_ATOMIC);
1031 if (unlikely(!saved)) {
1032 if (net_ratelimit())
1033 printk(KERN_WARNING "%s: Not enough memory, "
1034 "dropping tx status", skb->dev->name);
1035 /* should be dev_kfree_skb_irq, but due to this function being
1036 * named _irqsafe instead of just _irq we can't be sure that
1037 * people won't call it from non-irq contexts */
1038 dev_kfree_skb_any(skb);
1041 memcpy(saved, status, sizeof(struct ieee80211_tx_status));
1042 /* copy pointer to saved status into skb->cb for use by tasklet */
1043 memcpy(skb->cb, &saved, sizeof(saved));
1045 skb->pkt_type = IEEE80211_TX_STATUS_MSG;
1046 skb_queue_tail(status->control.flags & IEEE80211_TXCTL_REQ_TX_STATUS ?
1047 &local->skb_queue : &local->skb_queue_unreliable, skb);
1048 tmp = skb_queue_len(&local->skb_queue) +
1049 skb_queue_len(&local->skb_queue_unreliable);
1050 while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
1051 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
1052 memcpy(&saved, skb->cb, sizeof(saved));
1054 dev_kfree_skb_irq(skb);
1056 I802_DEBUG_INC(local->tx_status_drop);
1058 tasklet_schedule(&local->tasklet);
1060 EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
1062 static void ieee80211_tasklet_handler(unsigned long data)
1064 struct ieee80211_local *local = (struct ieee80211_local *) data;
1065 struct sk_buff *skb;
1066 struct ieee80211_rx_status rx_status;
1067 struct ieee80211_tx_status *tx_status;
1068 struct ieee80211_ra_tid *ra_tid;
1070 while ((skb = skb_dequeue(&local->skb_queue)) ||
1071 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
1072 switch (skb->pkt_type) {
1073 case IEEE80211_RX_MSG:
1074 /* status is in skb->cb */
1075 memcpy(&rx_status, skb->cb, sizeof(rx_status));
1076 /* Clear skb->pkt_type in order to not confuse kernel
1079 __ieee80211_rx(local_to_hw(local), skb, &rx_status);
1081 case IEEE80211_TX_STATUS_MSG:
1082 /* get pointer to saved status out of skb->cb */
1083 memcpy(&tx_status, skb->cb, sizeof(tx_status));
1085 ieee80211_tx_status(local_to_hw(local),
1089 case IEEE80211_DELBA_MSG:
1090 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
1091 ieee80211_stop_tx_ba_cb(local_to_hw(local),
1092 ra_tid->ra, ra_tid->tid);
1095 case IEEE80211_ADDBA_MSG:
1096 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
1097 ieee80211_start_tx_ba_cb(local_to_hw(local),
1098 ra_tid->ra, ra_tid->tid);
1101 default: /* should never get here! */
1102 printk(KERN_ERR "%s: Unknown message type (%d)\n",
1103 wiphy_name(local->hw.wiphy), skb->pkt_type);
1110 /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
1111 * make a prepared TX frame (one that has been given to hw) to look like brand
1112 * new IEEE 802.11 frame that is ready to go through TX processing again.
1113 * Also, tx_packet_data in cb is restored from tx_control. */
1114 static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
1115 struct ieee80211_key *key,
1116 struct sk_buff *skb,
1117 struct ieee80211_tx_control *control)
1119 int hdrlen, iv_len, mic_len;
1120 struct ieee80211_tx_packet_data *pkt_data;
1122 pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
1123 pkt_data->ifindex = vif_to_sdata(control->vif)->dev->ifindex;
1124 pkt_data->flags = 0;
1125 if (control->flags & IEEE80211_TXCTL_REQ_TX_STATUS)
1126 pkt_data->flags |= IEEE80211_TXPD_REQ_TX_STATUS;
1127 if (control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)
1128 pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT;
1129 if (control->flags & IEEE80211_TXCTL_REQUEUE)
1130 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
1131 if (control->flags & IEEE80211_TXCTL_EAPOL_FRAME)
1132 pkt_data->flags |= IEEE80211_TXPD_EAPOL_FRAME;
1133 pkt_data->queue = control->queue;
1135 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1140 switch (key->conf.alg) {
1142 iv_len = WEP_IV_LEN;
1143 mic_len = WEP_ICV_LEN;
1146 iv_len = TKIP_IV_LEN;
1147 mic_len = TKIP_ICV_LEN;
1150 iv_len = CCMP_HDR_LEN;
1151 mic_len = CCMP_MIC_LEN;
1157 if (skb->len >= mic_len &&
1158 !(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
1159 skb_trim(skb, skb->len - mic_len);
1160 if (skb->len >= iv_len && skb->len > hdrlen) {
1161 memmove(skb->data + iv_len, skb->data, hdrlen);
1162 skb_pull(skb, iv_len);
1167 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1168 u16 fc = le16_to_cpu(hdr->frame_control);
1169 if ((fc & 0x8C) == 0x88) /* QoS Control Field */ {
1170 fc &= ~IEEE80211_STYPE_QOS_DATA;
1171 hdr->frame_control = cpu_to_le16(fc);
1172 memmove(skb->data + 2, skb->data, hdrlen - 2);
1178 void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
1179 struct ieee80211_tx_status *status)
1181 struct sk_buff *skb2;
1182 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1183 struct ieee80211_local *local = hw_to_local(hw);
1185 struct ieee80211_tx_status_rtap_hdr *rthdr;
1186 struct ieee80211_sub_if_data *sdata;
1187 struct net_device *prev_dev = NULL;
1191 "%s: ieee80211_tx_status called with NULL status\n",
1192 wiphy_name(local->hw.wiphy));
1197 if (status->excessive_retries) {
1198 struct sta_info *sta;
1199 sta = sta_info_get(local, hdr->addr1);
1201 if (sta->flags & WLAN_STA_PS) {
1202 /* The STA is in power save mode, so assume
1203 * that this TX packet failed because of that.
1205 status->excessive_retries = 0;
1206 status->flags |= IEEE80211_TX_STATUS_TX_FILTERED;
1212 if (status->flags & IEEE80211_TX_STATUS_TX_FILTERED) {
1213 struct sta_info *sta;
1214 sta = sta_info_get(local, hdr->addr1);
1216 sta->tx_filtered_count++;
1218 /* Clear the TX filter mask for this STA when sending
1219 * the next packet. If the STA went to power save mode,
1220 * this will happen when it is waking up for the next
1222 sta->clear_dst_mask = 1;
1224 /* TODO: Is the WLAN_STA_PS flag always set here or is
1225 * the race between RX and TX status causing some
1226 * packets to be filtered out before 80211.o gets an
1227 * update for PS status? This seems to be the case, so
1228 * no changes are likely to be needed. */
1229 if (sta->flags & WLAN_STA_PS &&
1230 skb_queue_len(&sta->tx_filtered) <
1231 STA_MAX_TX_BUFFER) {
1232 ieee80211_remove_tx_extra(local, sta->key,
1235 skb_queue_tail(&sta->tx_filtered, skb);
1236 } else if (!(sta->flags & WLAN_STA_PS) &&
1237 !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) {
1238 /* Software retry the packet once */
1239 status->control.flags |= IEEE80211_TXCTL_REQUEUE;
1240 ieee80211_remove_tx_extra(local, sta->key,
1243 dev_queue_xmit(skb);
1245 if (net_ratelimit()) {
1246 printk(KERN_DEBUG "%s: dropped TX "
1247 "filtered frame queue_len=%d "
1249 wiphy_name(local->hw.wiphy),
1252 !!(sta->flags & WLAN_STA_PS),
1261 rate_control_tx_status(local->mdev, skb, status);
1263 ieee80211_led_tx(local, 0);
1266 * Fragments are passed to low-level drivers as separate skbs, so these
1267 * are actually fragments, not frames. Update frame counters only for
1268 * the first fragment of the frame. */
1270 frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
1271 type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
1273 if (status->flags & IEEE80211_TX_STATUS_ACK) {
1275 local->dot11TransmittedFrameCount++;
1276 if (is_multicast_ether_addr(hdr->addr1))
1277 local->dot11MulticastTransmittedFrameCount++;
1278 if (status->retry_count > 0)
1279 local->dot11RetryCount++;
1280 if (status->retry_count > 1)
1281 local->dot11MultipleRetryCount++;
1284 /* This counter shall be incremented for an acknowledged MPDU
1285 * with an individual address in the address 1 field or an MPDU
1286 * with a multicast address in the address 1 field of type Data
1288 if (!is_multicast_ether_addr(hdr->addr1) ||
1289 type == IEEE80211_FTYPE_DATA ||
1290 type == IEEE80211_FTYPE_MGMT)
1291 local->dot11TransmittedFragmentCount++;
1294 local->dot11FailedCount++;
1297 /* this was a transmitted frame, but now we want to reuse it */
1301 * This is a bit racy but we can avoid a lot of work
1304 if (!local->monitors && !local->cooked_mntrs) {
1309 /* send frame to monitor interfaces now */
1311 if (skb_headroom(skb) < sizeof(*rthdr)) {
1312 printk(KERN_ERR "ieee80211_tx_status: headroom too small\n");
1317 rthdr = (struct ieee80211_tx_status_rtap_hdr*)
1318 skb_push(skb, sizeof(*rthdr));
1320 memset(rthdr, 0, sizeof(*rthdr));
1321 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
1322 rthdr->hdr.it_present =
1323 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
1324 (1 << IEEE80211_RADIOTAP_DATA_RETRIES));
1326 if (!(status->flags & IEEE80211_TX_STATUS_ACK) &&
1327 !is_multicast_ether_addr(hdr->addr1))
1328 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL);
1330 if ((status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS) &&
1331 (status->control.flags & IEEE80211_TXCTL_USE_CTS_PROTECT))
1332 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS);
1333 else if (status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS)
1334 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS);
1336 rthdr->data_retries = status->retry_count;
1338 /* XXX: is this sufficient for BPF? */
1339 skb_set_mac_header(skb, 0);
1340 skb->ip_summed = CHECKSUM_UNNECESSARY;
1341 skb->pkt_type = PACKET_OTHERHOST;
1342 skb->protocol = htons(ETH_P_802_2);
1343 memset(skb->cb, 0, sizeof(skb->cb));
1346 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1347 if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR) {
1348 if (!netif_running(sdata->dev))
1352 skb2 = skb_clone(skb, GFP_ATOMIC);
1354 skb2->dev = prev_dev;
1359 prev_dev = sdata->dev;
1363 skb->dev = prev_dev;
1370 EXPORT_SYMBOL(ieee80211_tx_status);
1372 struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
1373 const struct ieee80211_ops *ops)
1375 struct net_device *mdev;
1376 struct ieee80211_local *local;
1377 struct ieee80211_sub_if_data *sdata;
1379 struct wiphy *wiphy;
1381 /* Ensure 32-byte alignment of our private data and hw private data.
1382 * We use the wiphy priv data for both our ieee80211_local and for
1383 * the driver's private data
1385 * In memory it'll be like this:
1387 * +-------------------------+
1389 * +-------------------------+
1390 * | struct ieee80211_local |
1391 * +-------------------------+
1392 * | driver's private data |
1393 * +-------------------------+
1396 priv_size = ((sizeof(struct ieee80211_local) +
1397 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) +
1400 wiphy = wiphy_new(&mac80211_config_ops, priv_size);
1405 wiphy->privid = mac80211_wiphy_privid;
1407 local = wiphy_priv(wiphy);
1408 local->hw.wiphy = wiphy;
1410 local->hw.priv = (char *)local +
1411 ((sizeof(struct ieee80211_local) +
1412 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
1415 BUG_ON(!ops->start);
1417 BUG_ON(!ops->config);
1418 BUG_ON(!ops->add_interface);
1419 BUG_ON(!ops->remove_interface);
1420 BUG_ON(!ops->configure_filter);
1423 /* for now, mdev needs sub_if_data :/ */
1424 mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
1425 "wmaster%d", ether_setup);
1431 sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
1432 mdev->ieee80211_ptr = &sdata->wdev;
1433 sdata->wdev.wiphy = wiphy;
1435 local->hw.queues = 1; /* default */
1439 local->bridge_packets = 1;
1441 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
1442 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
1443 local->short_retry_limit = 7;
1444 local->long_retry_limit = 4;
1445 local->hw.conf.radio_enabled = 1;
1447 INIT_LIST_HEAD(&local->interfaces);
1449 INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work);
1450 ieee80211_rx_bss_list_init(mdev);
1452 sta_info_init(local);
1454 mdev->hard_start_xmit = ieee80211_master_start_xmit;
1455 mdev->open = ieee80211_master_open;
1456 mdev->stop = ieee80211_master_stop;
1457 mdev->type = ARPHRD_IEEE80211;
1458 mdev->header_ops = &ieee80211_header_ops;
1459 mdev->set_multicast_list = ieee80211_master_set_multicast_list;
1461 sdata->vif.type = IEEE80211_IF_TYPE_AP;
1463 sdata->local = local;
1464 sdata->u.ap.force_unicast_rateidx = -1;
1465 sdata->u.ap.max_ratectrl_rateidx = -1;
1466 ieee80211_if_sdata_init(sdata);
1467 /* no RCU needed since we're still during init phase */
1468 list_add_tail(&sdata->list, &local->interfaces);
1470 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
1471 (unsigned long)local);
1472 tasklet_disable(&local->tx_pending_tasklet);
1474 tasklet_init(&local->tasklet,
1475 ieee80211_tasklet_handler,
1476 (unsigned long) local);
1477 tasklet_disable(&local->tasklet);
1479 skb_queue_head_init(&local->skb_queue);
1480 skb_queue_head_init(&local->skb_queue_unreliable);
1482 return local_to_hw(local);
1484 EXPORT_SYMBOL(ieee80211_alloc_hw);
1486 int ieee80211_register_hw(struct ieee80211_hw *hw)
1488 struct ieee80211_local *local = hw_to_local(hw);
1491 enum ieee80211_band band;
1494 * generic code guarantees at least one band,
1495 * set this very early because much code assumes
1496 * that hw.conf.channel is assigned
1498 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1499 struct ieee80211_supported_band *sband;
1501 sband = local->hw.wiphy->bands[band];
1503 /* init channel we're on */
1504 local->hw.conf.channel =
1505 local->oper_channel =
1506 local->scan_channel = &sband->channels[0];
1511 result = wiphy_register(local->hw.wiphy);
1515 name = wiphy_dev(local->hw.wiphy)->driver->name;
1516 local->hw.workqueue = create_singlethread_workqueue(name);
1517 if (!local->hw.workqueue) {
1519 goto fail_workqueue;
1523 * The hardware needs headroom for sending the frame,
1524 * and we need some headroom for passing the frame to monitor
1525 * interfaces, but never both at the same time.
1527 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
1528 sizeof(struct ieee80211_tx_status_rtap_hdr));
1530 debugfs_hw_add(local);
1532 local->hw.conf.beacon_int = 1000;
1534 local->wstats_flags |= local->hw.max_rssi ?
1535 IW_QUAL_LEVEL_UPDATED : IW_QUAL_LEVEL_INVALID;
1536 local->wstats_flags |= local->hw.max_signal ?
1537 IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
1538 local->wstats_flags |= local->hw.max_noise ?
1539 IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
1540 if (local->hw.max_rssi < 0 || local->hw.max_noise < 0)
1541 local->wstats_flags |= IW_QUAL_DBM;
1543 result = sta_info_start(local);
1548 result = dev_alloc_name(local->mdev, local->mdev->name);
1552 memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
1553 SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy));
1555 result = register_netdevice(local->mdev);
1559 ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
1560 ieee80211_if_set_type(local->mdev, IEEE80211_IF_TYPE_AP);
1562 result = ieee80211_init_rate_ctrl_alg(local,
1563 hw->rate_control_algorithm);
1565 printk(KERN_DEBUG "%s: Failed to initialize rate control "
1566 "algorithm\n", wiphy_name(local->hw.wiphy));
1570 result = ieee80211_wep_init(local);
1573 printk(KERN_DEBUG "%s: Failed to initialize wep\n",
1574 wiphy_name(local->hw.wiphy));
1578 ieee80211_install_qdisc(local->mdev);
1580 /* add one default STA interface */
1581 result = ieee80211_if_add(local->mdev, "wlan%d", NULL,
1582 IEEE80211_IF_TYPE_STA);
1584 printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
1585 wiphy_name(local->hw.wiphy));
1587 local->reg_state = IEEE80211_DEV_REGISTERED;
1590 ieee80211_led_init(local);
1595 rate_control_deinitialize(local);
1597 ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
1598 unregister_netdevice(local->mdev);
1601 sta_info_stop(local);
1603 debugfs_hw_del(local);
1604 destroy_workqueue(local->hw.workqueue);
1606 wiphy_unregister(local->hw.wiphy);
1609 EXPORT_SYMBOL(ieee80211_register_hw);
1611 void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1613 struct ieee80211_local *local = hw_to_local(hw);
1614 struct ieee80211_sub_if_data *sdata, *tmp;
1616 tasklet_kill(&local->tx_pending_tasklet);
1617 tasklet_kill(&local->tasklet);
1621 BUG_ON(local->reg_state != IEEE80211_DEV_REGISTERED);
1623 local->reg_state = IEEE80211_DEV_UNREGISTERED;
1626 * At this point, interface list manipulations are fine
1627 * because the driver cannot be handing us frames any
1628 * more and the tasklet is killed.
1632 * First, we remove all non-master interfaces. Do this because they
1633 * may have bss pointer dependency on the master, and when we free
1634 * the master these would be freed as well, breaking our list
1635 * iteration completely.
1637 list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
1638 if (sdata->dev == local->mdev)
1640 list_del(&sdata->list);
1641 __ieee80211_if_del(local, sdata);
1644 /* then, finally, remove the master interface */
1645 __ieee80211_if_del(local, IEEE80211_DEV_TO_SUB_IF(local->mdev));
1649 ieee80211_rx_bss_list_deinit(local->mdev);
1650 ieee80211_clear_tx_pending(local);
1651 sta_info_stop(local);
1652 rate_control_deinitialize(local);
1653 debugfs_hw_del(local);
1655 if (skb_queue_len(&local->skb_queue)
1656 || skb_queue_len(&local->skb_queue_unreliable))
1657 printk(KERN_WARNING "%s: skb_queue not empty\n",
1658 wiphy_name(local->hw.wiphy));
1659 skb_queue_purge(&local->skb_queue);
1660 skb_queue_purge(&local->skb_queue_unreliable);
1662 destroy_workqueue(local->hw.workqueue);
1663 wiphy_unregister(local->hw.wiphy);
1664 ieee80211_wep_free(local);
1665 ieee80211_led_exit(local);
1667 EXPORT_SYMBOL(ieee80211_unregister_hw);
1669 void ieee80211_free_hw(struct ieee80211_hw *hw)
1671 struct ieee80211_local *local = hw_to_local(hw);
1673 ieee80211_if_free(local->mdev);
1674 wiphy_free(local->hw.wiphy);
1676 EXPORT_SYMBOL(ieee80211_free_hw);
1678 static int __init ieee80211_init(void)
1680 struct sk_buff *skb;
1683 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb));
1685 ret = rc80211_simple_init();
1689 ret = rc80211_pid_init();
1691 goto out_cleanup_simple;
1693 ret = ieee80211_wme_register();
1695 printk(KERN_DEBUG "ieee80211_init: failed to "
1696 "initialize WME (err=%d)\n", ret);
1697 goto out_cleanup_pid;
1700 ieee80211_debugfs_netdev_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");