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 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
243 local->cooked_mntrs++;
247 /* must be before the call to ieee80211_configure_filter */
249 if (local->monitors == 1)
250 local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
252 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
253 local->fif_fcsfail++;
254 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
255 local->fif_plcpfail++;
256 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
257 local->fif_control++;
258 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
259 local->fif_other_bss++;
261 netif_tx_lock_bh(local->mdev);
262 ieee80211_configure_filter(local);
263 netif_tx_unlock_bh(local->mdev);
265 case IEEE80211_IF_TYPE_STA:
266 case IEEE80211_IF_TYPE_IBSS:
267 sdata->u.sta.flags &= ~IEEE80211_STA_PREV_BSSID_SET;
270 conf.vif = &sdata->vif;
271 conf.type = sdata->vif.type;
272 conf.mac_addr = dev->dev_addr;
273 res = local->ops->add_interface(local_to_hw(local), &conf);
274 if (res && !local->open_count && local->ops->stop)
275 local->ops->stop(local_to_hw(local));
279 ieee80211_if_config(dev);
280 ieee80211_reset_erp_info(dev);
281 ieee80211_enable_keys(sdata);
283 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
284 !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME))
285 netif_carrier_off(dev);
287 netif_carrier_on(dev);
290 if (local->open_count == 0) {
291 res = dev_open(local->mdev);
293 tasklet_enable(&local->tx_pending_tasklet);
294 tasklet_enable(&local->tasklet);
298 * set_multicast_list will be invoked by the networking core
299 * which will check whether any increments here were done in
300 * error and sync them down to the hardware as filter flags.
302 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
303 atomic_inc(&local->iff_allmultis);
305 if (sdata->flags & IEEE80211_SDATA_PROMISC)
306 atomic_inc(&local->iff_promiscs);
309 if (need_hw_reconfig)
310 ieee80211_hw_config(local);
312 netif_start_queue(dev);
317 static int ieee80211_stop(struct net_device *dev)
319 struct ieee80211_sub_if_data *sdata;
320 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
321 struct ieee80211_if_init_conf conf;
322 struct sta_info *sta;
325 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
327 list_for_each_entry(sta, &local->sta_list, list) {
329 for (i = 0; i < STA_TID_NUM; i++)
330 ieee80211_sta_stop_rx_ba_session(sta->dev,
333 WLAN_REASON_QSTA_LEAVE_QBSS);
336 netif_stop_queue(dev);
339 * Don't count this interface for promisc/allmulti while it
340 * is down. dev_mc_unsync() will invoke set_multicast_list
341 * on the master interface which will sync these down to the
342 * hardware as filter flags.
344 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
345 atomic_dec(&local->iff_allmultis);
347 if (sdata->flags & IEEE80211_SDATA_PROMISC)
348 atomic_dec(&local->iff_promiscs);
350 dev_mc_unsync(local->mdev, dev);
352 /* APs need special treatment */
353 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
354 struct ieee80211_sub_if_data *vlan, *tmp;
355 struct beacon_data *old_beacon = sdata->u.ap.beacon;
358 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
362 /* down all dependent devices, that is VLANs */
363 list_for_each_entry_safe(vlan, tmp, &sdata->u.ap.vlans,
365 dev_close(vlan->dev);
366 WARN_ON(!list_empty(&sdata->u.ap.vlans));
371 switch (sdata->vif.type) {
372 case IEEE80211_IF_TYPE_VLAN:
373 list_del(&sdata->u.vlan.list);
374 sdata->u.vlan.ap = NULL;
375 /* no need to tell driver */
377 case IEEE80211_IF_TYPE_MNTR:
378 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
379 local->cooked_mntrs--;
384 if (local->monitors == 0)
385 local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
387 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
388 local->fif_fcsfail--;
389 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
390 local->fif_plcpfail--;
391 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
392 local->fif_control--;
393 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
394 local->fif_other_bss--;
396 netif_tx_lock_bh(local->mdev);
397 ieee80211_configure_filter(local);
398 netif_tx_unlock_bh(local->mdev);
400 case IEEE80211_IF_TYPE_STA:
401 case IEEE80211_IF_TYPE_IBSS:
402 sdata->u.sta.state = IEEE80211_DISABLED;
403 del_timer_sync(&sdata->u.sta.timer);
405 * When we get here, the interface is marked down.
406 * Call synchronize_rcu() to wait for the RX path
407 * should it be using the interface and enqueuing
408 * frames at this very time on another CPU.
411 skb_queue_purge(&sdata->u.sta.skb_queue);
413 if (local->scan_dev == sdata->dev) {
414 if (!local->ops->hw_scan) {
415 local->sta_sw_scanning = 0;
416 cancel_delayed_work(&local->scan_work);
418 local->sta_hw_scanning = 0;
421 flush_workqueue(local->hw.workqueue);
423 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
424 kfree(sdata->u.sta.extra_ie);
425 sdata->u.sta.extra_ie = NULL;
426 sdata->u.sta.extra_ie_len = 0;
429 conf.vif = &sdata->vif;
430 conf.type = sdata->vif.type;
431 conf.mac_addr = dev->dev_addr;
432 /* disable all keys for as long as this netdev is down */
433 ieee80211_disable_keys(sdata);
434 local->ops->remove_interface(local_to_hw(local), &conf);
437 if (local->open_count == 0) {
438 if (netif_running(local->mdev))
439 dev_close(local->mdev);
441 if (local->ops->stop)
442 local->ops->stop(local_to_hw(local));
444 ieee80211_led_radio(local, 0);
446 tasklet_disable(&local->tx_pending_tasklet);
447 tasklet_disable(&local->tasklet);
453 int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
455 struct ieee80211_local *local = hw_to_local(hw);
456 struct sta_info *sta;
457 struct ieee80211_sub_if_data *sdata;
458 u16 start_seq_num = 0;
461 DECLARE_MAC_BUF(mac);
463 if (tid >= STA_TID_NUM)
466 #ifdef CONFIG_MAC80211_HT_DEBUG
467 printk(KERN_DEBUG "Open BA session requested for %s tid %u\n",
468 print_mac(mac, ra), tid);
469 #endif /* CONFIG_MAC80211_HT_DEBUG */
471 sta = sta_info_get(local, ra);
473 printk(KERN_DEBUG "Could not find the station\n");
477 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
479 /* we have tried too many times, receiver does not want A-MPDU */
480 if (sta->ampdu_mlme.tid_tx[tid].addba_req_num > HT_AGG_MAX_RETRIES) {
485 state = &sta->ampdu_mlme.tid_tx[tid].state;
486 /* check if the TID is not in aggregation flow already */
487 if (*state != HT_AGG_STATE_IDLE) {
488 #ifdef CONFIG_MAC80211_HT_DEBUG
489 printk(KERN_DEBUG "BA request denied - session is not "
490 "idle on tid %u\n", tid);
491 #endif /* CONFIG_MAC80211_HT_DEBUG */
496 /* ensure that TX flow won't interrupt us
497 * until the end of the call to requeue function */
498 spin_lock_bh(&local->mdev->queue_lock);
500 /* create a new queue for this aggregation */
501 ret = ieee80211_ht_agg_queue_add(local, sta, tid);
503 /* case no queue is available to aggregation
504 * don't switch to aggregation */
506 #ifdef CONFIG_MAC80211_HT_DEBUG
507 printk(KERN_DEBUG "BA request denied - no queue available for"
509 #endif /* CONFIG_MAC80211_HT_DEBUG */
510 spin_unlock_bh(&local->mdev->queue_lock);
513 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
515 /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
516 * call back right away, it must see that the flow has begun */
517 *state |= HT_ADDBA_REQUESTED_MSK;
519 if (local->ops->ampdu_action)
520 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START,
521 ra, tid, &start_seq_num);
524 /* No need to requeue the packets in the agg queue, since we
525 * held the tx lock: no packet could be enqueued to the newly
527 ieee80211_ht_agg_queue_remove(local, sta, tid, 0);
528 #ifdef CONFIG_MAC80211_HT_DEBUG
529 printk(KERN_DEBUG "BA request denied - HW or queue unavailable"
530 " for tid %d\n", tid);
531 #endif /* CONFIG_MAC80211_HT_DEBUG */
532 spin_unlock_bh(&local->mdev->queue_lock);
533 *state = HT_AGG_STATE_IDLE;
537 /* Will put all the packets in the new SW queue */
538 ieee80211_requeue(local, ieee802_1d_to_ac[tid]);
539 spin_unlock_bh(&local->mdev->queue_lock);
541 /* We have most probably almost emptied the legacy queue */
542 /* ieee80211_wake_queue(local_to_hw(local), ieee802_1d_to_ac[tid]); */
544 /* send an addBA request */
545 sta->ampdu_mlme.dialog_token_allocator++;
546 sta->ampdu_mlme.tid_tx[tid].dialog_token =
547 sta->ampdu_mlme.dialog_token_allocator;
548 sta->ampdu_mlme.tid_tx[tid].ssn = start_seq_num;
550 ieee80211_send_addba_request(sta->dev, ra, tid,
551 sta->ampdu_mlme.tid_tx[tid].dialog_token,
552 sta->ampdu_mlme.tid_tx[tid].ssn,
555 /* activate the timer for the recipient's addBA response */
556 sta->ampdu_mlme.tid_tx[tid].addba_resp_timer.expires =
557 jiffies + ADDBA_RESP_INTERVAL;
558 add_timer(&sta->ampdu_mlme.tid_tx[tid].addba_resp_timer);
559 printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
562 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
566 EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
568 int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
570 enum ieee80211_back_parties initiator)
572 struct ieee80211_local *local = hw_to_local(hw);
573 struct sta_info *sta;
576 DECLARE_MAC_BUF(mac);
578 if (tid >= STA_TID_NUM)
581 #ifdef CONFIG_MAC80211_HT_DEBUG
582 printk(KERN_DEBUG "Stop a BA session requested for %s tid %u\n",
583 print_mac(mac, ra), tid);
584 #endif /* CONFIG_MAC80211_HT_DEBUG */
586 sta = sta_info_get(local, ra);
590 /* check if the TID is in aggregation */
591 state = &sta->ampdu_mlme.tid_tx[tid].state;
592 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
594 if (*state != HT_AGG_STATE_OPERATIONAL) {
595 #ifdef CONFIG_MAC80211_HT_DEBUG
596 printk(KERN_DEBUG "Try to stop Tx aggregation on"
597 " non active TID\n");
598 #endif /* CONFIG_MAC80211_HT_DEBUG */
603 ieee80211_stop_queue(hw, sta->tid_to_tx_q[tid]);
605 *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
606 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
608 if (local->ops->ampdu_action)
609 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_STOP,
612 /* case HW denied going back to legacy */
614 WARN_ON(ret != -EBUSY);
615 *state = HT_AGG_STATE_OPERATIONAL;
616 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
621 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
625 EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
627 void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
629 struct ieee80211_local *local = hw_to_local(hw);
630 struct sta_info *sta;
632 DECLARE_MAC_BUF(mac);
634 if (tid >= STA_TID_NUM) {
635 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
640 sta = sta_info_get(local, ra);
642 printk(KERN_DEBUG "Could not find station: %s\n",
647 state = &sta->ampdu_mlme.tid_tx[tid].state;
648 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
650 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
651 printk(KERN_DEBUG "addBA was not requested yet, state is %d\n",
653 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
658 WARN_ON_ONCE(*state & HT_ADDBA_DRV_READY_MSK);
660 *state |= HT_ADDBA_DRV_READY_MSK;
662 if (*state == HT_AGG_STATE_OPERATIONAL) {
663 printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid);
664 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
666 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
669 EXPORT_SYMBOL(ieee80211_start_tx_ba_cb);
671 void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
673 struct ieee80211_local *local = hw_to_local(hw);
674 struct sta_info *sta;
677 DECLARE_MAC_BUF(mac);
679 if (tid >= STA_TID_NUM) {
680 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
685 printk(KERN_DEBUG "Stop a BA session requested on DA %s tid %d\n",
686 print_mac(mac, ra), tid);
688 sta = sta_info_get(local, ra);
690 printk(KERN_DEBUG "Could not find station: %s\n",
694 state = &sta->ampdu_mlme.tid_tx[tid].state;
696 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
697 if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) {
698 printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
700 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
704 if (*state & HT_AGG_STATE_INITIATOR_MSK)
705 ieee80211_send_delba(sta->dev, ra, tid,
706 WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
708 agg_queue = sta->tid_to_tx_q[tid];
710 /* avoid ordering issues: we are the only one that can modify
711 * the content of the qdiscs */
712 spin_lock_bh(&local->mdev->queue_lock);
713 /* remove the queue for this aggregation */
714 ieee80211_ht_agg_queue_remove(local, sta, tid, 1);
715 spin_unlock_bh(&local->mdev->queue_lock);
717 /* we just requeued the all the frames that were in the removed
718 * queue, and since we might miss a softirq we do netif_schedule.
719 * ieee80211_wake_queue is not used here as this queue is not
720 * necessarily stopped */
721 netif_schedule(local->mdev);
722 *state = HT_AGG_STATE_IDLE;
723 sta->ampdu_mlme.tid_tx[tid].addba_req_num = 0;
724 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
728 EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb);
730 void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
731 const u8 *ra, u16 tid)
733 struct ieee80211_local *local = hw_to_local(hw);
734 struct ieee80211_ra_tid *ra_tid;
735 struct sk_buff *skb = dev_alloc_skb(0);
737 if (unlikely(!skb)) {
739 printk(KERN_WARNING "%s: Not enough memory, "
740 "dropping start BA session", skb->dev->name);
743 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
744 memcpy(&ra_tid->ra, ra, ETH_ALEN);
747 skb->pkt_type = IEEE80211_ADDBA_MSG;
748 skb_queue_tail(&local->skb_queue, skb);
749 tasklet_schedule(&local->tasklet);
751 EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
753 void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
754 const u8 *ra, u16 tid)
756 struct ieee80211_local *local = hw_to_local(hw);
757 struct ieee80211_ra_tid *ra_tid;
758 struct sk_buff *skb = dev_alloc_skb(0);
760 if (unlikely(!skb)) {
762 printk(KERN_WARNING "%s: Not enough memory, "
763 "dropping stop BA session", skb->dev->name);
766 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
767 memcpy(&ra_tid->ra, ra, ETH_ALEN);
770 skb->pkt_type = IEEE80211_DELBA_MSG;
771 skb_queue_tail(&local->skb_queue, skb);
772 tasklet_schedule(&local->tasklet);
774 EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
776 static void ieee80211_set_multicast_list(struct net_device *dev)
778 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
779 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
780 int allmulti, promisc, sdata_allmulti, sdata_promisc;
782 allmulti = !!(dev->flags & IFF_ALLMULTI);
783 promisc = !!(dev->flags & IFF_PROMISC);
784 sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
785 sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC);
787 if (allmulti != sdata_allmulti) {
788 if (dev->flags & IFF_ALLMULTI)
789 atomic_inc(&local->iff_allmultis);
791 atomic_dec(&local->iff_allmultis);
792 sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
795 if (promisc != sdata_promisc) {
796 if (dev->flags & IFF_PROMISC)
797 atomic_inc(&local->iff_promiscs);
799 atomic_dec(&local->iff_promiscs);
800 sdata->flags ^= IEEE80211_SDATA_PROMISC;
803 dev_mc_sync(local->mdev, dev);
806 static const struct header_ops ieee80211_header_ops = {
807 .create = eth_header,
808 .parse = header_parse_80211,
809 .rebuild = eth_rebuild_header,
810 .cache = eth_header_cache,
811 .cache_update = eth_header_cache_update,
814 /* Must not be called for mdev */
815 void ieee80211_if_setup(struct net_device *dev)
818 dev->hard_start_xmit = ieee80211_subif_start_xmit;
819 dev->wireless_handlers = &ieee80211_iw_handler_def;
820 dev->set_multicast_list = ieee80211_set_multicast_list;
821 dev->change_mtu = ieee80211_change_mtu;
822 dev->open = ieee80211_open;
823 dev->stop = ieee80211_stop;
824 dev->destructor = ieee80211_if_free;
827 /* WDS specialties */
829 int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr)
831 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
832 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
833 struct sta_info *sta;
834 DECLARE_MAC_BUF(mac);
836 if (compare_ether_addr(remote_addr, sdata->u.wds.remote_addr) == 0)
839 /* Create STA entry for the new peer */
840 sta = sta_info_add(local, dev, remote_addr, GFP_KERNEL);
844 sta->flags |= WLAN_STA_AUTHORIZED;
848 /* Remove STA entry for the old peer */
849 sta = sta_info_get(local, sdata->u.wds.remote_addr);
854 printk(KERN_DEBUG "%s: could not find STA entry for WDS link "
856 dev->name, print_mac(mac, sdata->u.wds.remote_addr));
859 /* Update WDS link data */
860 memcpy(&sdata->u.wds.remote_addr, remote_addr, ETH_ALEN);
865 /* everything else */
867 static int __ieee80211_if_config(struct net_device *dev,
868 struct sk_buff *beacon,
869 struct ieee80211_tx_control *control)
871 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
872 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
873 struct ieee80211_if_conf conf;
875 if (!local->ops->config_interface || !netif_running(dev))
878 memset(&conf, 0, sizeof(conf));
879 conf.type = sdata->vif.type;
880 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
881 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
882 conf.bssid = sdata->u.sta.bssid;
883 conf.ssid = sdata->u.sta.ssid;
884 conf.ssid_len = sdata->u.sta.ssid_len;
885 } else if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
886 conf.ssid = sdata->u.ap.ssid;
887 conf.ssid_len = sdata->u.ap.ssid_len;
888 conf.beacon = beacon;
889 conf.beacon_control = control;
891 return local->ops->config_interface(local_to_hw(local),
895 int ieee80211_if_config(struct net_device *dev)
897 return __ieee80211_if_config(dev, NULL, NULL);
900 int ieee80211_if_config_beacon(struct net_device *dev)
902 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
903 struct ieee80211_tx_control control;
904 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
907 if (!(local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE))
909 skb = ieee80211_beacon_get(local_to_hw(local), &sdata->vif,
913 return __ieee80211_if_config(dev, skb, &control);
916 int ieee80211_hw_config(struct ieee80211_local *local)
918 struct ieee80211_channel *chan;
921 if (local->sta_sw_scanning)
922 chan = local->scan_channel;
924 chan = local->oper_channel;
926 local->hw.conf.channel = chan;
928 if (!local->hw.conf.power_level)
929 local->hw.conf.power_level = chan->max_power;
931 local->hw.conf.power_level = min(chan->max_power,
932 local->hw.conf.power_level);
934 local->hw.conf.max_antenna_gain = chan->max_antenna_gain;
936 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
937 printk(KERN_DEBUG "%s: HW CONFIG: freq=%d\n",
938 wiphy_name(local->hw.wiphy), chan->center_freq);
941 if (local->open_count)
942 ret = local->ops->config(local_to_hw(local), &local->hw.conf);
948 * ieee80211_hw_config_ht should be used only after legacy configuration
949 * has been determined, as ht configuration depends upon the hardware's
950 * HT abilities for a _specific_ band.
952 int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht,
953 struct ieee80211_ht_info *req_ht_cap,
954 struct ieee80211_ht_bss_info *req_bss_cap)
956 struct ieee80211_conf *conf = &local->hw.conf;
957 struct ieee80211_supported_band *sband;
960 sband = local->hw.wiphy->bands[conf->channel->band];
962 /* HT is not supported */
963 if (!sband->ht_info.ht_supported) {
964 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
970 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
972 conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE;
973 conf->ht_conf.cap = req_ht_cap->cap & sband->ht_info.cap;
974 conf->ht_conf.cap &= ~(IEEE80211_HT_CAP_MIMO_PS);
976 sband->ht_info.cap & IEEE80211_HT_CAP_MIMO_PS;
977 conf->ht_bss_conf.primary_channel =
978 req_bss_cap->primary_channel;
979 conf->ht_bss_conf.bss_cap = req_bss_cap->bss_cap;
980 conf->ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode;
981 for (i = 0; i < SUPP_MCS_SET_LEN; i++)
982 conf->ht_conf.supp_mcs_set[i] =
983 sband->ht_info.supp_mcs_set[i] &
984 req_ht_cap->supp_mcs_set[i];
986 /* In STA mode, this gives us indication
987 * to the AP's mode of operation */
988 conf->ht_conf.ht_supported = 1;
989 conf->ht_conf.ampdu_factor = req_ht_cap->ampdu_factor;
990 conf->ht_conf.ampdu_density = req_ht_cap->ampdu_density;
993 local->ops->conf_ht(local_to_hw(local), &local->hw.conf);
998 void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
1001 struct ieee80211_local *local = sdata->local;
1006 if (local->ops->bss_info_changed)
1007 local->ops->bss_info_changed(local_to_hw(local),
1013 void ieee80211_reset_erp_info(struct net_device *dev)
1015 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1017 sdata->bss_conf.use_cts_prot = 0;
1018 sdata->bss_conf.use_short_preamble = 0;
1019 ieee80211_bss_info_change_notify(sdata,
1020 BSS_CHANGED_ERP_CTS_PROT |
1021 BSS_CHANGED_ERP_PREAMBLE);
1024 void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
1025 struct sk_buff *skb,
1026 struct ieee80211_tx_status *status)
1028 struct ieee80211_local *local = hw_to_local(hw);
1029 struct ieee80211_tx_status *saved;
1032 skb->dev = local->mdev;
1033 saved = kmalloc(sizeof(struct ieee80211_tx_status), GFP_ATOMIC);
1034 if (unlikely(!saved)) {
1035 if (net_ratelimit())
1036 printk(KERN_WARNING "%s: Not enough memory, "
1037 "dropping tx status", skb->dev->name);
1038 /* should be dev_kfree_skb_irq, but due to this function being
1039 * named _irqsafe instead of just _irq we can't be sure that
1040 * people won't call it from non-irq contexts */
1041 dev_kfree_skb_any(skb);
1044 memcpy(saved, status, sizeof(struct ieee80211_tx_status));
1045 /* copy pointer to saved status into skb->cb for use by tasklet */
1046 memcpy(skb->cb, &saved, sizeof(saved));
1048 skb->pkt_type = IEEE80211_TX_STATUS_MSG;
1049 skb_queue_tail(status->control.flags & IEEE80211_TXCTL_REQ_TX_STATUS ?
1050 &local->skb_queue : &local->skb_queue_unreliable, skb);
1051 tmp = skb_queue_len(&local->skb_queue) +
1052 skb_queue_len(&local->skb_queue_unreliable);
1053 while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
1054 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
1055 memcpy(&saved, skb->cb, sizeof(saved));
1057 dev_kfree_skb_irq(skb);
1059 I802_DEBUG_INC(local->tx_status_drop);
1061 tasklet_schedule(&local->tasklet);
1063 EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
1065 static void ieee80211_tasklet_handler(unsigned long data)
1067 struct ieee80211_local *local = (struct ieee80211_local *) data;
1068 struct sk_buff *skb;
1069 struct ieee80211_rx_status rx_status;
1070 struct ieee80211_tx_status *tx_status;
1071 struct ieee80211_ra_tid *ra_tid;
1073 while ((skb = skb_dequeue(&local->skb_queue)) ||
1074 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
1075 switch (skb->pkt_type) {
1076 case IEEE80211_RX_MSG:
1077 /* status is in skb->cb */
1078 memcpy(&rx_status, skb->cb, sizeof(rx_status));
1079 /* Clear skb->pkt_type in order to not confuse kernel
1082 __ieee80211_rx(local_to_hw(local), skb, &rx_status);
1084 case IEEE80211_TX_STATUS_MSG:
1085 /* get pointer to saved status out of skb->cb */
1086 memcpy(&tx_status, skb->cb, sizeof(tx_status));
1088 ieee80211_tx_status(local_to_hw(local),
1092 case IEEE80211_DELBA_MSG:
1093 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
1094 ieee80211_stop_tx_ba_cb(local_to_hw(local),
1095 ra_tid->ra, ra_tid->tid);
1098 case IEEE80211_ADDBA_MSG:
1099 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
1100 ieee80211_start_tx_ba_cb(local_to_hw(local),
1101 ra_tid->ra, ra_tid->tid);
1104 default: /* should never get here! */
1105 printk(KERN_ERR "%s: Unknown message type (%d)\n",
1106 wiphy_name(local->hw.wiphy), skb->pkt_type);
1113 /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
1114 * make a prepared TX frame (one that has been given to hw) to look like brand
1115 * new IEEE 802.11 frame that is ready to go through TX processing again.
1116 * Also, tx_packet_data in cb is restored from tx_control. */
1117 static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
1118 struct ieee80211_key *key,
1119 struct sk_buff *skb,
1120 struct ieee80211_tx_control *control)
1122 int hdrlen, iv_len, mic_len;
1123 struct ieee80211_tx_packet_data *pkt_data;
1125 pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
1126 pkt_data->ifindex = vif_to_sdata(control->vif)->dev->ifindex;
1127 pkt_data->flags = 0;
1128 if (control->flags & IEEE80211_TXCTL_REQ_TX_STATUS)
1129 pkt_data->flags |= IEEE80211_TXPD_REQ_TX_STATUS;
1130 if (control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)
1131 pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT;
1132 if (control->flags & IEEE80211_TXCTL_REQUEUE)
1133 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
1134 if (control->flags & IEEE80211_TXCTL_EAPOL_FRAME)
1135 pkt_data->flags |= IEEE80211_TXPD_EAPOL_FRAME;
1136 pkt_data->queue = control->queue;
1138 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1143 switch (key->conf.alg) {
1145 iv_len = WEP_IV_LEN;
1146 mic_len = WEP_ICV_LEN;
1149 iv_len = TKIP_IV_LEN;
1150 mic_len = TKIP_ICV_LEN;
1153 iv_len = CCMP_HDR_LEN;
1154 mic_len = CCMP_MIC_LEN;
1160 if (skb->len >= mic_len &&
1161 !(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
1162 skb_trim(skb, skb->len - mic_len);
1163 if (skb->len >= iv_len && skb->len > hdrlen) {
1164 memmove(skb->data + iv_len, skb->data, hdrlen);
1165 skb_pull(skb, iv_len);
1170 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1171 u16 fc = le16_to_cpu(hdr->frame_control);
1172 if ((fc & 0x8C) == 0x88) /* QoS Control Field */ {
1173 fc &= ~IEEE80211_STYPE_QOS_DATA;
1174 hdr->frame_control = cpu_to_le16(fc);
1175 memmove(skb->data + 2, skb->data, hdrlen - 2);
1181 void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
1182 struct ieee80211_tx_status *status)
1184 struct sk_buff *skb2;
1185 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1186 struct ieee80211_local *local = hw_to_local(hw);
1188 struct ieee80211_tx_status_rtap_hdr *rthdr;
1189 struct ieee80211_sub_if_data *sdata;
1190 struct net_device *prev_dev = NULL;
1194 "%s: ieee80211_tx_status called with NULL status\n",
1195 wiphy_name(local->hw.wiphy));
1200 if (status->excessive_retries) {
1201 struct sta_info *sta;
1202 sta = sta_info_get(local, hdr->addr1);
1204 if (sta->flags & WLAN_STA_PS) {
1205 /* The STA is in power save mode, so assume
1206 * that this TX packet failed because of that.
1208 status->excessive_retries = 0;
1209 status->flags |= IEEE80211_TX_STATUS_TX_FILTERED;
1215 if (status->flags & IEEE80211_TX_STATUS_TX_FILTERED) {
1216 struct sta_info *sta;
1217 sta = sta_info_get(local, hdr->addr1);
1219 sta->tx_filtered_count++;
1221 /* Clear the TX filter mask for this STA when sending
1222 * the next packet. If the STA went to power save mode,
1223 * this will happen when it is waking up for the next
1225 sta->clear_dst_mask = 1;
1227 /* TODO: Is the WLAN_STA_PS flag always set here or is
1228 * the race between RX and TX status causing some
1229 * packets to be filtered out before 80211.o gets an
1230 * update for PS status? This seems to be the case, so
1231 * no changes are likely to be needed. */
1232 if (sta->flags & WLAN_STA_PS &&
1233 skb_queue_len(&sta->tx_filtered) <
1234 STA_MAX_TX_BUFFER) {
1235 ieee80211_remove_tx_extra(local, sta->key,
1238 skb_queue_tail(&sta->tx_filtered, skb);
1239 } else if (!(sta->flags & WLAN_STA_PS) &&
1240 !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) {
1241 /* Software retry the packet once */
1242 status->control.flags |= IEEE80211_TXCTL_REQUEUE;
1243 ieee80211_remove_tx_extra(local, sta->key,
1246 dev_queue_xmit(skb);
1248 if (net_ratelimit()) {
1249 printk(KERN_DEBUG "%s: dropped TX "
1250 "filtered frame queue_len=%d "
1252 wiphy_name(local->hw.wiphy),
1255 !!(sta->flags & WLAN_STA_PS),
1264 rate_control_tx_status(local->mdev, skb, status);
1266 ieee80211_led_tx(local, 0);
1269 * Fragments are passed to low-level drivers as separate skbs, so these
1270 * are actually fragments, not frames. Update frame counters only for
1271 * the first fragment of the frame. */
1273 frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
1274 type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
1276 if (status->flags & IEEE80211_TX_STATUS_ACK) {
1278 local->dot11TransmittedFrameCount++;
1279 if (is_multicast_ether_addr(hdr->addr1))
1280 local->dot11MulticastTransmittedFrameCount++;
1281 if (status->retry_count > 0)
1282 local->dot11RetryCount++;
1283 if (status->retry_count > 1)
1284 local->dot11MultipleRetryCount++;
1287 /* This counter shall be incremented for an acknowledged MPDU
1288 * with an individual address in the address 1 field or an MPDU
1289 * with a multicast address in the address 1 field of type Data
1291 if (!is_multicast_ether_addr(hdr->addr1) ||
1292 type == IEEE80211_FTYPE_DATA ||
1293 type == IEEE80211_FTYPE_MGMT)
1294 local->dot11TransmittedFragmentCount++;
1297 local->dot11FailedCount++;
1300 /* this was a transmitted frame, but now we want to reuse it */
1304 * This is a bit racy but we can avoid a lot of work
1307 if (!local->monitors && !local->cooked_mntrs) {
1312 /* send frame to monitor interfaces now */
1314 if (skb_headroom(skb) < sizeof(*rthdr)) {
1315 printk(KERN_ERR "ieee80211_tx_status: headroom too small\n");
1320 rthdr = (struct ieee80211_tx_status_rtap_hdr*)
1321 skb_push(skb, sizeof(*rthdr));
1323 memset(rthdr, 0, sizeof(*rthdr));
1324 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
1325 rthdr->hdr.it_present =
1326 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
1327 (1 << IEEE80211_RADIOTAP_DATA_RETRIES));
1329 if (!(status->flags & IEEE80211_TX_STATUS_ACK) &&
1330 !is_multicast_ether_addr(hdr->addr1))
1331 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL);
1333 if ((status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS) &&
1334 (status->control.flags & IEEE80211_TXCTL_USE_CTS_PROTECT))
1335 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS);
1336 else if (status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS)
1337 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS);
1339 rthdr->data_retries = status->retry_count;
1341 /* XXX: is this sufficient for BPF? */
1342 skb_set_mac_header(skb, 0);
1343 skb->ip_summed = CHECKSUM_UNNECESSARY;
1344 skb->pkt_type = PACKET_OTHERHOST;
1345 skb->protocol = htons(ETH_P_802_2);
1346 memset(skb->cb, 0, sizeof(skb->cb));
1349 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1350 if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR) {
1351 if (!netif_running(sdata->dev))
1355 skb2 = skb_clone(skb, GFP_ATOMIC);
1357 skb2->dev = prev_dev;
1362 prev_dev = sdata->dev;
1366 skb->dev = prev_dev;
1373 EXPORT_SYMBOL(ieee80211_tx_status);
1375 struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
1376 const struct ieee80211_ops *ops)
1378 struct ieee80211_local *local;
1380 struct wiphy *wiphy;
1382 /* Ensure 32-byte alignment of our private data and hw private data.
1383 * We use the wiphy priv data for both our ieee80211_local and for
1384 * the driver's private data
1386 * In memory it'll be like this:
1388 * +-------------------------+
1390 * +-------------------------+
1391 * | struct ieee80211_local |
1392 * +-------------------------+
1393 * | driver's private data |
1394 * +-------------------------+
1397 priv_size = ((sizeof(struct ieee80211_local) +
1398 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) +
1401 wiphy = wiphy_new(&mac80211_config_ops, priv_size);
1406 wiphy->privid = mac80211_wiphy_privid;
1408 local = wiphy_priv(wiphy);
1409 local->hw.wiphy = wiphy;
1411 local->hw.priv = (char *)local +
1412 ((sizeof(struct ieee80211_local) +
1413 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
1416 BUG_ON(!ops->start);
1418 BUG_ON(!ops->config);
1419 BUG_ON(!ops->add_interface);
1420 BUG_ON(!ops->remove_interface);
1421 BUG_ON(!ops->configure_filter);
1424 local->hw.queues = 1; /* default */
1426 local->bridge_packets = 1;
1428 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
1429 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
1430 local->short_retry_limit = 7;
1431 local->long_retry_limit = 4;
1432 local->hw.conf.radio_enabled = 1;
1434 INIT_LIST_HEAD(&local->interfaces);
1436 INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work);
1438 sta_info_init(local);
1440 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
1441 (unsigned long)local);
1442 tasklet_disable(&local->tx_pending_tasklet);
1444 tasklet_init(&local->tasklet,
1445 ieee80211_tasklet_handler,
1446 (unsigned long) local);
1447 tasklet_disable(&local->tasklet);
1449 skb_queue_head_init(&local->skb_queue);
1450 skb_queue_head_init(&local->skb_queue_unreliable);
1452 return local_to_hw(local);
1454 EXPORT_SYMBOL(ieee80211_alloc_hw);
1456 int ieee80211_register_hw(struct ieee80211_hw *hw)
1458 struct ieee80211_local *local = hw_to_local(hw);
1461 enum ieee80211_band band;
1462 struct net_device *mdev;
1463 struct ieee80211_sub_if_data *sdata;
1466 * generic code guarantees at least one band,
1467 * set this very early because much code assumes
1468 * that hw.conf.channel is assigned
1470 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1471 struct ieee80211_supported_band *sband;
1473 sband = local->hw.wiphy->bands[band];
1475 /* init channel we're on */
1476 local->hw.conf.channel =
1477 local->oper_channel =
1478 local->scan_channel = &sband->channels[0];
1483 result = wiphy_register(local->hw.wiphy);
1487 /* for now, mdev needs sub_if_data :/ */
1488 mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
1489 "wmaster%d", ether_setup);
1491 goto fail_mdev_alloc;
1493 sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
1494 mdev->ieee80211_ptr = &sdata->wdev;
1495 sdata->wdev.wiphy = local->hw.wiphy;
1499 ieee80211_rx_bss_list_init(mdev);
1501 mdev->hard_start_xmit = ieee80211_master_start_xmit;
1502 mdev->open = ieee80211_master_open;
1503 mdev->stop = ieee80211_master_stop;
1504 mdev->type = ARPHRD_IEEE80211;
1505 mdev->header_ops = &ieee80211_header_ops;
1506 mdev->set_multicast_list = ieee80211_master_set_multicast_list;
1508 sdata->vif.type = IEEE80211_IF_TYPE_AP;
1510 sdata->local = local;
1511 sdata->u.ap.force_unicast_rateidx = -1;
1512 sdata->u.ap.max_ratectrl_rateidx = -1;
1513 ieee80211_if_sdata_init(sdata);
1515 /* no RCU needed since we're still during init phase */
1516 list_add_tail(&sdata->list, &local->interfaces);
1518 name = wiphy_dev(local->hw.wiphy)->driver->name;
1519 local->hw.workqueue = create_singlethread_workqueue(name);
1520 if (!local->hw.workqueue) {
1522 goto fail_workqueue;
1526 * The hardware needs headroom for sending the frame,
1527 * and we need some headroom for passing the frame to monitor
1528 * interfaces, but never both at the same time.
1530 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
1531 sizeof(struct ieee80211_tx_status_rtap_hdr));
1533 debugfs_hw_add(local);
1535 local->hw.conf.beacon_int = 1000;
1537 local->wstats_flags |= local->hw.max_rssi ?
1538 IW_QUAL_LEVEL_UPDATED : IW_QUAL_LEVEL_INVALID;
1539 local->wstats_flags |= local->hw.max_signal ?
1540 IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
1541 local->wstats_flags |= local->hw.max_noise ?
1542 IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
1543 if (local->hw.max_rssi < 0 || local->hw.max_noise < 0)
1544 local->wstats_flags |= IW_QUAL_DBM;
1546 result = sta_info_start(local);
1551 result = dev_alloc_name(local->mdev, local->mdev->name);
1555 memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
1556 SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy));
1558 result = register_netdevice(local->mdev);
1562 ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
1563 ieee80211_if_set_type(local->mdev, IEEE80211_IF_TYPE_AP);
1565 result = ieee80211_init_rate_ctrl_alg(local,
1566 hw->rate_control_algorithm);
1568 printk(KERN_DEBUG "%s: Failed to initialize rate control "
1569 "algorithm\n", wiphy_name(local->hw.wiphy));
1573 result = ieee80211_wep_init(local);
1576 printk(KERN_DEBUG "%s: Failed to initialize wep\n",
1577 wiphy_name(local->hw.wiphy));
1581 ieee80211_install_qdisc(local->mdev);
1583 /* add one default STA interface */
1584 result = ieee80211_if_add(local->mdev, "wlan%d", NULL,
1585 IEEE80211_IF_TYPE_STA);
1587 printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
1588 wiphy_name(local->hw.wiphy));
1590 local->reg_state = IEEE80211_DEV_REGISTERED;
1593 ieee80211_led_init(local);
1598 rate_control_deinitialize(local);
1600 ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
1601 unregister_netdevice(local->mdev);
1604 sta_info_stop(local);
1606 debugfs_hw_del(local);
1607 destroy_workqueue(local->hw.workqueue);
1609 ieee80211_if_free(local->mdev);
1612 wiphy_unregister(local->hw.wiphy);
1615 EXPORT_SYMBOL(ieee80211_register_hw);
1617 void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1619 struct ieee80211_local *local = hw_to_local(hw);
1620 struct ieee80211_sub_if_data *sdata, *tmp;
1622 tasklet_kill(&local->tx_pending_tasklet);
1623 tasklet_kill(&local->tasklet);
1627 BUG_ON(local->reg_state != IEEE80211_DEV_REGISTERED);
1629 local->reg_state = IEEE80211_DEV_UNREGISTERED;
1632 * At this point, interface list manipulations are fine
1633 * because the driver cannot be handing us frames any
1634 * more and the tasklet is killed.
1638 * First, we remove all non-master interfaces. Do this because they
1639 * may have bss pointer dependency on the master, and when we free
1640 * the master these would be freed as well, breaking our list
1641 * iteration completely.
1643 list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
1644 if (sdata->dev == local->mdev)
1646 list_del(&sdata->list);
1647 __ieee80211_if_del(local, sdata);
1650 /* then, finally, remove the master interface */
1651 __ieee80211_if_del(local, IEEE80211_DEV_TO_SUB_IF(local->mdev));
1655 ieee80211_rx_bss_list_deinit(local->mdev);
1656 ieee80211_clear_tx_pending(local);
1657 sta_info_stop(local);
1658 rate_control_deinitialize(local);
1659 debugfs_hw_del(local);
1661 if (skb_queue_len(&local->skb_queue)
1662 || skb_queue_len(&local->skb_queue_unreliable))
1663 printk(KERN_WARNING "%s: skb_queue not empty\n",
1664 wiphy_name(local->hw.wiphy));
1665 skb_queue_purge(&local->skb_queue);
1666 skb_queue_purge(&local->skb_queue_unreliable);
1668 destroy_workqueue(local->hw.workqueue);
1669 wiphy_unregister(local->hw.wiphy);
1670 ieee80211_wep_free(local);
1671 ieee80211_led_exit(local);
1672 ieee80211_if_free(local->mdev);
1675 EXPORT_SYMBOL(ieee80211_unregister_hw);
1677 void ieee80211_free_hw(struct ieee80211_hw *hw)
1679 struct ieee80211_local *local = hw_to_local(hw);
1681 wiphy_free(local->hw.wiphy);
1683 EXPORT_SYMBOL(ieee80211_free_hw);
1685 static int __init ieee80211_init(void)
1687 struct sk_buff *skb;
1690 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb));
1692 ret = rc80211_simple_init();
1696 ret = rc80211_pid_init();
1698 goto out_cleanup_simple;
1700 ret = ieee80211_wme_register();
1702 printk(KERN_DEBUG "ieee80211_init: failed to "
1703 "initialize WME (err=%d)\n", ret);
1704 goto out_cleanup_pid;
1707 ieee80211_debugfs_netdev_init();
1714 rc80211_simple_exit();
1719 static void __exit ieee80211_exit(void)
1721 rc80211_simple_exit();
1724 ieee80211_wme_unregister();
1725 ieee80211_debugfs_netdev_exit();
1729 subsys_initcall(ieee80211_init);
1730 module_exit(ieee80211_exit);
1732 MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1733 MODULE_LICENSE("GPL");