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"
33 #include "ieee80211_led.h"
36 #include "debugfs_netdev.h"
38 #define SUPP_MCS_SET_LEN 16
41 * For seeing transmitted packets on monitor interfaces
42 * we have a radiotap header too.
44 struct ieee80211_tx_status_rtap_hdr {
45 struct ieee80211_radiotap_header hdr;
48 } __attribute__ ((packed));
50 /* common interface routines */
52 static int header_parse_80211(const struct sk_buff *skb, unsigned char *haddr)
54 memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
58 /* must be called under mdev tx lock */
59 static void ieee80211_configure_filter(struct ieee80211_local *local)
61 unsigned int changed_flags;
62 unsigned int new_flags = 0;
64 if (atomic_read(&local->iff_promiscs))
65 new_flags |= FIF_PROMISC_IN_BSS;
67 if (atomic_read(&local->iff_allmultis))
68 new_flags |= FIF_ALLMULTI;
71 new_flags |= FIF_BCN_PRBRESP_PROMISC;
73 if (local->fif_fcsfail)
74 new_flags |= FIF_FCSFAIL;
76 if (local->fif_plcpfail)
77 new_flags |= FIF_PLCPFAIL;
79 if (local->fif_control)
80 new_flags |= FIF_CONTROL;
82 if (local->fif_other_bss)
83 new_flags |= FIF_OTHER_BSS;
85 changed_flags = local->filter_flags ^ new_flags;
90 local->ops->configure_filter(local_to_hw(local),
91 changed_flags, &new_flags,
92 local->mdev->mc_count,
93 local->mdev->mc_list);
95 WARN_ON(new_flags & (1<<31));
97 local->filter_flags = new_flags & ~(1<<31);
100 /* master interface */
102 static int ieee80211_master_open(struct net_device *dev)
104 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
105 struct ieee80211_sub_if_data *sdata;
106 int res = -EOPNOTSUPP;
108 /* we hold the RTNL here so can safely walk the list */
109 list_for_each_entry(sdata, &local->interfaces, list) {
110 if (sdata->dev != dev && netif_running(sdata->dev)) {
118 static int ieee80211_master_stop(struct net_device *dev)
120 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
121 struct ieee80211_sub_if_data *sdata;
123 /* we hold the RTNL here so can safely walk the list */
124 list_for_each_entry(sdata, &local->interfaces, list)
125 if (sdata->dev != dev && netif_running(sdata->dev))
126 dev_close(sdata->dev);
131 static void ieee80211_master_set_multicast_list(struct net_device *dev)
133 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
135 ieee80211_configure_filter(local);
138 /* regular interfaces */
140 static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
143 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
145 meshhdrlen = (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT) ? 5 : 0;
147 /* FIX: what would be proper limits for MTU?
148 * This interface uses 802.3 frames. */
150 new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6 - meshhdrlen) {
151 printk(KERN_WARNING "%s: invalid MTU %d\n",
156 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
157 printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu);
158 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
163 static inline int identical_mac_addr_allowed(int type1, int type2)
165 return (type1 == IEEE80211_IF_TYPE_MNTR ||
166 type2 == IEEE80211_IF_TYPE_MNTR ||
167 (type1 == IEEE80211_IF_TYPE_AP &&
168 type2 == IEEE80211_IF_TYPE_WDS) ||
169 (type1 == IEEE80211_IF_TYPE_WDS &&
170 (type2 == IEEE80211_IF_TYPE_WDS ||
171 type2 == IEEE80211_IF_TYPE_AP)) ||
172 (type1 == IEEE80211_IF_TYPE_AP &&
173 type2 == IEEE80211_IF_TYPE_VLAN) ||
174 (type1 == IEEE80211_IF_TYPE_VLAN &&
175 (type2 == IEEE80211_IF_TYPE_AP ||
176 type2 == IEEE80211_IF_TYPE_VLAN)));
179 static int ieee80211_open(struct net_device *dev)
181 struct ieee80211_sub_if_data *sdata, *nsdata;
182 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
183 struct ieee80211_if_init_conf conf;
185 bool need_hw_reconfig = 0;
187 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
189 /* we hold the RTNL here so can safely walk the list */
190 list_for_each_entry(nsdata, &local->interfaces, list) {
191 struct net_device *ndev = nsdata->dev;
193 if (ndev != dev && ndev != local->mdev && netif_running(ndev)) {
195 * Allow only a single IBSS interface to be up at any
196 * time. This is restricted because beacon distribution
197 * cannot work properly if both are in the same IBSS.
199 * To remove this restriction we'd have to disallow them
200 * from setting the same SSID on different IBSS interfaces
201 * belonging to the same hardware. Then, however, we're
202 * faced with having to adopt two different TSF timers...
204 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
205 nsdata->vif.type == IEEE80211_IF_TYPE_IBSS)
209 * Disallow multiple IBSS/STA mode interfaces.
211 * This is a technical restriction, it is possible although
212 * most likely not IEEE 802.11 compliant to have multiple
213 * STAs with just a single hardware (the TSF timer will not
214 * be adjusted properly.)
216 * However, because mac80211 uses the master device's BSS
217 * information for each STA/IBSS interface, doing this will
218 * currently corrupt that BSS information completely, unless,
219 * a not very useful case, both STAs are associated to the
222 * To remove this restriction, the BSS information needs to
223 * be embedded in the STA/IBSS mode sdata instead of using
224 * the master device's BSS structure.
226 if ((sdata->vif.type == IEEE80211_IF_TYPE_STA ||
227 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) &&
228 (nsdata->vif.type == IEEE80211_IF_TYPE_STA ||
229 nsdata->vif.type == IEEE80211_IF_TYPE_IBSS))
233 * The remaining checks are only performed for interfaces
234 * with the same MAC address.
236 if (compare_ether_addr(dev->dev_addr, ndev->dev_addr))
240 * check whether it may have the same address
242 if (!identical_mac_addr_allowed(sdata->vif.type,
247 * can only add VLANs to enabled APs
249 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN &&
250 nsdata->vif.type == IEEE80211_IF_TYPE_AP)
251 sdata->u.vlan.ap = nsdata;
255 switch (sdata->vif.type) {
256 case IEEE80211_IF_TYPE_WDS:
257 if (is_zero_ether_addr(sdata->u.wds.remote_addr))
260 case IEEE80211_IF_TYPE_VLAN:
261 if (!sdata->u.vlan.ap)
264 case IEEE80211_IF_TYPE_AP:
265 case IEEE80211_IF_TYPE_STA:
266 case IEEE80211_IF_TYPE_MNTR:
267 case IEEE80211_IF_TYPE_IBSS:
268 case IEEE80211_IF_TYPE_MESH_POINT:
269 /* no special treatment */
271 case IEEE80211_IF_TYPE_INVALID:
277 if (local->open_count == 0) {
279 if (local->ops->start)
280 res = local->ops->start(local_to_hw(local));
283 need_hw_reconfig = 1;
284 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
287 switch (sdata->vif.type) {
288 case IEEE80211_IF_TYPE_VLAN:
289 list_add(&sdata->u.vlan.list, &sdata->u.vlan.ap->u.ap.vlans);
290 /* no need to tell driver */
292 case IEEE80211_IF_TYPE_MNTR:
293 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
294 local->cooked_mntrs++;
298 /* must be before the call to ieee80211_configure_filter */
300 if (local->monitors == 1)
301 local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
303 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
304 local->fif_fcsfail++;
305 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
306 local->fif_plcpfail++;
307 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
308 local->fif_control++;
309 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
310 local->fif_other_bss++;
312 netif_tx_lock_bh(local->mdev);
313 ieee80211_configure_filter(local);
314 netif_tx_unlock_bh(local->mdev);
316 case IEEE80211_IF_TYPE_STA:
317 case IEEE80211_IF_TYPE_IBSS:
318 sdata->u.sta.flags &= ~IEEE80211_STA_PREV_BSSID_SET;
321 conf.vif = &sdata->vif;
322 conf.type = sdata->vif.type;
323 conf.mac_addr = dev->dev_addr;
324 res = local->ops->add_interface(local_to_hw(local), &conf);
325 if (res && !local->open_count && local->ops->stop)
326 local->ops->stop(local_to_hw(local));
330 ieee80211_if_config(dev);
331 ieee80211_reset_erp_info(dev);
332 ieee80211_enable_keys(sdata);
334 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
335 !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME))
336 netif_carrier_off(dev);
338 netif_carrier_on(dev);
341 if (local->open_count == 0) {
342 res = dev_open(local->mdev);
344 tasklet_enable(&local->tx_pending_tasklet);
345 tasklet_enable(&local->tasklet);
349 * set_multicast_list will be invoked by the networking core
350 * which will check whether any increments here were done in
351 * error and sync them down to the hardware as filter flags.
353 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
354 atomic_inc(&local->iff_allmultis);
356 if (sdata->flags & IEEE80211_SDATA_PROMISC)
357 atomic_inc(&local->iff_promiscs);
360 if (need_hw_reconfig)
361 ieee80211_hw_config(local);
363 netif_start_queue(dev);
368 static int ieee80211_stop(struct net_device *dev)
370 struct ieee80211_sub_if_data *sdata;
371 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
372 struct ieee80211_if_init_conf conf;
373 struct sta_info *sta;
376 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
380 list_for_each_entry_rcu(sta, &local->sta_list, list) {
381 if (sta->sdata == sdata)
382 for (i = 0; i < STA_TID_NUM; i++)
383 ieee80211_sta_stop_rx_ba_session(sdata->dev,
386 WLAN_REASON_QSTA_LEAVE_QBSS);
391 netif_stop_queue(dev);
394 * Don't count this interface for promisc/allmulti while it
395 * is down. dev_mc_unsync() will invoke set_multicast_list
396 * on the master interface which will sync these down to the
397 * hardware as filter flags.
399 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
400 atomic_dec(&local->iff_allmultis);
402 if (sdata->flags & IEEE80211_SDATA_PROMISC)
403 atomic_dec(&local->iff_promiscs);
405 dev_mc_unsync(local->mdev, dev);
407 /* APs need special treatment */
408 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
409 struct ieee80211_sub_if_data *vlan, *tmp;
410 struct beacon_data *old_beacon = sdata->u.ap.beacon;
413 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
417 /* down all dependent devices, that is VLANs */
418 list_for_each_entry_safe(vlan, tmp, &sdata->u.ap.vlans,
420 dev_close(vlan->dev);
421 WARN_ON(!list_empty(&sdata->u.ap.vlans));
426 switch (sdata->vif.type) {
427 case IEEE80211_IF_TYPE_VLAN:
428 list_del(&sdata->u.vlan.list);
429 sdata->u.vlan.ap = NULL;
430 /* no need to tell driver */
432 case IEEE80211_IF_TYPE_MNTR:
433 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
434 local->cooked_mntrs--;
439 if (local->monitors == 0)
440 local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
442 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
443 local->fif_fcsfail--;
444 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
445 local->fif_plcpfail--;
446 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
447 local->fif_control--;
448 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
449 local->fif_other_bss--;
451 netif_tx_lock_bh(local->mdev);
452 ieee80211_configure_filter(local);
453 netif_tx_unlock_bh(local->mdev);
455 case IEEE80211_IF_TYPE_MESH_POINT:
456 sta_info_flush(local, sdata);
458 case IEEE80211_IF_TYPE_STA:
459 case IEEE80211_IF_TYPE_IBSS:
460 sdata->u.sta.state = IEEE80211_DISABLED;
461 del_timer_sync(&sdata->u.sta.timer);
463 * When we get here, the interface is marked down.
464 * Call synchronize_rcu() to wait for the RX path
465 * should it be using the interface and enqueuing
466 * frames at this very time on another CPU.
469 skb_queue_purge(&sdata->u.sta.skb_queue);
471 if (local->scan_dev == sdata->dev) {
472 if (!local->ops->hw_scan) {
473 local->sta_sw_scanning = 0;
474 cancel_delayed_work(&local->scan_work);
476 local->sta_hw_scanning = 0;
479 flush_workqueue(local->hw.workqueue);
481 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
482 kfree(sdata->u.sta.extra_ie);
483 sdata->u.sta.extra_ie = NULL;
484 sdata->u.sta.extra_ie_len = 0;
487 conf.vif = &sdata->vif;
488 conf.type = sdata->vif.type;
489 conf.mac_addr = dev->dev_addr;
490 /* disable all keys for as long as this netdev is down */
491 ieee80211_disable_keys(sdata);
492 local->ops->remove_interface(local_to_hw(local), &conf);
495 if (local->open_count == 0) {
496 if (netif_running(local->mdev))
497 dev_close(local->mdev);
499 if (local->ops->stop)
500 local->ops->stop(local_to_hw(local));
502 ieee80211_led_radio(local, 0);
504 tasklet_disable(&local->tx_pending_tasklet);
505 tasklet_disable(&local->tasklet);
511 int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
513 struct ieee80211_local *local = hw_to_local(hw);
514 struct sta_info *sta;
515 struct ieee80211_sub_if_data *sdata;
516 u16 start_seq_num = 0;
519 DECLARE_MAC_BUF(mac);
521 if (tid >= STA_TID_NUM)
524 #ifdef CONFIG_MAC80211_HT_DEBUG
525 printk(KERN_DEBUG "Open BA session requested for %s tid %u\n",
526 print_mac(mac, ra), tid);
527 #endif /* CONFIG_MAC80211_HT_DEBUG */
531 sta = sta_info_get(local, ra);
533 printk(KERN_DEBUG "Could not find the station\n");
538 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
540 /* we have tried too many times, receiver does not want A-MPDU */
541 if (sta->ampdu_mlme.tid_tx[tid].addba_req_num > HT_AGG_MAX_RETRIES) {
546 state = &sta->ampdu_mlme.tid_tx[tid].state;
547 /* check if the TID is not in aggregation flow already */
548 if (*state != HT_AGG_STATE_IDLE) {
549 #ifdef CONFIG_MAC80211_HT_DEBUG
550 printk(KERN_DEBUG "BA request denied - session is not "
551 "idle on tid %u\n", tid);
552 #endif /* CONFIG_MAC80211_HT_DEBUG */
557 /* ensure that TX flow won't interrupt us
558 * until the end of the call to requeue function */
559 spin_lock_bh(&local->mdev->queue_lock);
561 /* create a new queue for this aggregation */
562 ret = ieee80211_ht_agg_queue_add(local, sta, tid);
564 /* case no queue is available to aggregation
565 * don't switch to aggregation */
567 #ifdef CONFIG_MAC80211_HT_DEBUG
568 printk(KERN_DEBUG "BA request denied - no queue available for"
570 #endif /* CONFIG_MAC80211_HT_DEBUG */
571 spin_unlock_bh(&local->mdev->queue_lock);
576 /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
577 * call back right away, it must see that the flow has begun */
578 *state |= HT_ADDBA_REQUESTED_MSK;
580 if (local->ops->ampdu_action)
581 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START,
582 ra, tid, &start_seq_num);
585 /* No need to requeue the packets in the agg queue, since we
586 * held the tx lock: no packet could be enqueued to the newly
588 ieee80211_ht_agg_queue_remove(local, sta, tid, 0);
589 #ifdef CONFIG_MAC80211_HT_DEBUG
590 printk(KERN_DEBUG "BA request denied - HW or queue unavailable"
591 " for tid %d\n", tid);
592 #endif /* CONFIG_MAC80211_HT_DEBUG */
593 spin_unlock_bh(&local->mdev->queue_lock);
594 *state = HT_AGG_STATE_IDLE;
598 /* Will put all the packets in the new SW queue */
599 ieee80211_requeue(local, ieee802_1d_to_ac[tid]);
600 spin_unlock_bh(&local->mdev->queue_lock);
602 /* We have most probably almost emptied the legacy queue */
603 /* ieee80211_wake_queue(local_to_hw(local), ieee802_1d_to_ac[tid]); */
605 /* send an addBA request */
606 sta->ampdu_mlme.dialog_token_allocator++;
607 sta->ampdu_mlme.tid_tx[tid].dialog_token =
608 sta->ampdu_mlme.dialog_token_allocator;
609 sta->ampdu_mlme.tid_tx[tid].ssn = start_seq_num;
611 ieee80211_send_addba_request(sta->sdata->dev, ra, tid,
612 sta->ampdu_mlme.tid_tx[tid].dialog_token,
613 sta->ampdu_mlme.tid_tx[tid].ssn,
616 /* activate the timer for the recipient's addBA response */
617 sta->ampdu_mlme.tid_tx[tid].addba_resp_timer.expires =
618 jiffies + ADDBA_RESP_INTERVAL;
619 add_timer(&sta->ampdu_mlme.tid_tx[tid].addba_resp_timer);
620 printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
623 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
627 EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
629 int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
631 enum ieee80211_back_parties initiator)
633 struct ieee80211_local *local = hw_to_local(hw);
634 struct sta_info *sta;
637 DECLARE_MAC_BUF(mac);
639 if (tid >= STA_TID_NUM)
642 #ifdef CONFIG_MAC80211_HT_DEBUG
643 printk(KERN_DEBUG "Stop a BA session requested for %s tid %u\n",
644 print_mac(mac, ra), tid);
645 #endif /* CONFIG_MAC80211_HT_DEBUG */
648 sta = sta_info_get(local, ra);
654 /* check if the TID is in aggregation */
655 state = &sta->ampdu_mlme.tid_tx[tid].state;
656 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
658 if (*state != HT_AGG_STATE_OPERATIONAL) {
659 #ifdef CONFIG_MAC80211_HT_DEBUG
660 printk(KERN_DEBUG "Try to stop Tx aggregation on"
661 " non active TID\n");
662 #endif /* CONFIG_MAC80211_HT_DEBUG */
667 ieee80211_stop_queue(hw, sta->tid_to_tx_q[tid]);
669 *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
670 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
672 if (local->ops->ampdu_action)
673 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_STOP,
676 /* case HW denied going back to legacy */
678 WARN_ON(ret != -EBUSY);
679 *state = HT_AGG_STATE_OPERATIONAL;
680 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
685 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
689 EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
691 void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
693 struct ieee80211_local *local = hw_to_local(hw);
694 struct sta_info *sta;
696 DECLARE_MAC_BUF(mac);
698 if (tid >= STA_TID_NUM) {
699 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
705 sta = sta_info_get(local, ra);
708 printk(KERN_DEBUG "Could not find station: %s\n",
713 state = &sta->ampdu_mlme.tid_tx[tid].state;
714 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
716 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
717 printk(KERN_DEBUG "addBA was not requested yet, state is %d\n",
719 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
724 WARN_ON_ONCE(*state & HT_ADDBA_DRV_READY_MSK);
726 *state |= HT_ADDBA_DRV_READY_MSK;
728 if (*state == HT_AGG_STATE_OPERATIONAL) {
729 printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid);
730 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
732 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
735 EXPORT_SYMBOL(ieee80211_start_tx_ba_cb);
737 void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
739 struct ieee80211_local *local = hw_to_local(hw);
740 struct sta_info *sta;
743 DECLARE_MAC_BUF(mac);
745 if (tid >= STA_TID_NUM) {
746 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
751 printk(KERN_DEBUG "Stop a BA session requested on DA %s tid %d\n",
752 print_mac(mac, ra), tid);
755 sta = sta_info_get(local, ra);
757 printk(KERN_DEBUG "Could not find station: %s\n",
762 state = &sta->ampdu_mlme.tid_tx[tid].state;
764 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
765 if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) {
766 printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
767 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
772 if (*state & HT_AGG_STATE_INITIATOR_MSK)
773 ieee80211_send_delba(sta->sdata->dev, ra, tid,
774 WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
776 agg_queue = sta->tid_to_tx_q[tid];
778 /* avoid ordering issues: we are the only one that can modify
779 * the content of the qdiscs */
780 spin_lock_bh(&local->mdev->queue_lock);
781 /* remove the queue for this aggregation */
782 ieee80211_ht_agg_queue_remove(local, sta, tid, 1);
783 spin_unlock_bh(&local->mdev->queue_lock);
785 /* we just requeued the all the frames that were in the removed
786 * queue, and since we might miss a softirq we do netif_schedule.
787 * ieee80211_wake_queue is not used here as this queue is not
788 * necessarily stopped */
789 netif_schedule(local->mdev);
790 *state = HT_AGG_STATE_IDLE;
791 sta->ampdu_mlme.tid_tx[tid].addba_req_num = 0;
792 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
796 EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb);
798 void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
799 const u8 *ra, u16 tid)
801 struct ieee80211_local *local = hw_to_local(hw);
802 struct ieee80211_ra_tid *ra_tid;
803 struct sk_buff *skb = dev_alloc_skb(0);
805 if (unlikely(!skb)) {
807 printk(KERN_WARNING "%s: Not enough memory, "
808 "dropping start BA session", skb->dev->name);
811 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
812 memcpy(&ra_tid->ra, ra, ETH_ALEN);
815 skb->pkt_type = IEEE80211_ADDBA_MSG;
816 skb_queue_tail(&local->skb_queue, skb);
817 tasklet_schedule(&local->tasklet);
819 EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
821 void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
822 const u8 *ra, u16 tid)
824 struct ieee80211_local *local = hw_to_local(hw);
825 struct ieee80211_ra_tid *ra_tid;
826 struct sk_buff *skb = dev_alloc_skb(0);
828 if (unlikely(!skb)) {
830 printk(KERN_WARNING "%s: Not enough memory, "
831 "dropping stop BA session", skb->dev->name);
834 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
835 memcpy(&ra_tid->ra, ra, ETH_ALEN);
838 skb->pkt_type = IEEE80211_DELBA_MSG;
839 skb_queue_tail(&local->skb_queue, skb);
840 tasklet_schedule(&local->tasklet);
842 EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
844 static void ieee80211_set_multicast_list(struct net_device *dev)
846 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
847 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
848 int allmulti, promisc, sdata_allmulti, sdata_promisc;
850 allmulti = !!(dev->flags & IFF_ALLMULTI);
851 promisc = !!(dev->flags & IFF_PROMISC);
852 sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
853 sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC);
855 if (allmulti != sdata_allmulti) {
856 if (dev->flags & IFF_ALLMULTI)
857 atomic_inc(&local->iff_allmultis);
859 atomic_dec(&local->iff_allmultis);
860 sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
863 if (promisc != sdata_promisc) {
864 if (dev->flags & IFF_PROMISC)
865 atomic_inc(&local->iff_promiscs);
867 atomic_dec(&local->iff_promiscs);
868 sdata->flags ^= IEEE80211_SDATA_PROMISC;
871 dev_mc_sync(local->mdev, dev);
874 static const struct header_ops ieee80211_header_ops = {
875 .create = eth_header,
876 .parse = header_parse_80211,
877 .rebuild = eth_rebuild_header,
878 .cache = eth_header_cache,
879 .cache_update = eth_header_cache_update,
882 /* Must not be called for mdev */
883 void ieee80211_if_setup(struct net_device *dev)
886 dev->hard_start_xmit = ieee80211_subif_start_xmit;
887 dev->wireless_handlers = &ieee80211_iw_handler_def;
888 dev->set_multicast_list = ieee80211_set_multicast_list;
889 dev->change_mtu = ieee80211_change_mtu;
890 dev->open = ieee80211_open;
891 dev->stop = ieee80211_stop;
892 dev->destructor = ieee80211_if_free;
895 /* WDS specialties */
897 int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr)
899 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
900 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
901 struct sta_info *sta;
903 DECLARE_MAC_BUF(mac);
907 if (compare_ether_addr(remote_addr, sdata->u.wds.remote_addr) == 0)
910 /* Create STA entry for the new peer */
911 sta = sta_info_alloc(sdata, remote_addr, GFP_KERNEL);
915 sta->flags |= WLAN_STA_AUTHORIZED;
916 err = sta_info_insert(sta);
918 sta_info_destroy(sta);
924 /* Remove STA entry for the old peer */
925 sta = sta_info_get(local, sdata->u.wds.remote_addr);
927 sta_info_unlink(&sta);
929 printk(KERN_DEBUG "%s: could not find STA entry for WDS link "
931 dev->name, print_mac(mac, sdata->u.wds.remote_addr));
933 /* Update WDS link data */
934 memcpy(&sdata->u.wds.remote_addr, remote_addr, ETH_ALEN);
940 sta_info_destroy(sta);
946 /* everything else */
948 static int __ieee80211_if_config(struct net_device *dev,
949 struct sk_buff *beacon,
950 struct ieee80211_tx_control *control)
952 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
953 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
954 struct ieee80211_if_conf conf;
956 if (!local->ops->config_interface || !netif_running(dev))
959 memset(&conf, 0, sizeof(conf));
960 conf.type = sdata->vif.type;
961 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
962 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
963 conf.bssid = sdata->u.sta.bssid;
964 conf.ssid = sdata->u.sta.ssid;
965 conf.ssid_len = sdata->u.sta.ssid_len;
966 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
967 conf.beacon = beacon;
968 ieee80211_start_mesh(dev);
969 } else if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
970 conf.ssid = sdata->u.ap.ssid;
971 conf.ssid_len = sdata->u.ap.ssid_len;
972 conf.beacon = beacon;
973 conf.beacon_control = control;
975 return local->ops->config_interface(local_to_hw(local),
979 int ieee80211_if_config(struct net_device *dev)
981 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
982 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
983 if (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT &&
984 (local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE))
985 return ieee80211_if_config_beacon(dev);
986 return __ieee80211_if_config(dev, NULL, NULL);
989 int ieee80211_if_config_beacon(struct net_device *dev)
991 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
992 struct ieee80211_tx_control control;
993 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
996 if (!(local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE))
998 skb = ieee80211_beacon_get(local_to_hw(local), &sdata->vif,
1002 return __ieee80211_if_config(dev, skb, &control);
1005 int ieee80211_hw_config(struct ieee80211_local *local)
1007 struct ieee80211_channel *chan;
1010 if (local->sta_sw_scanning)
1011 chan = local->scan_channel;
1013 chan = local->oper_channel;
1015 local->hw.conf.channel = chan;
1017 if (!local->hw.conf.power_level)
1018 local->hw.conf.power_level = chan->max_power;
1020 local->hw.conf.power_level = min(chan->max_power,
1021 local->hw.conf.power_level);
1023 local->hw.conf.max_antenna_gain = chan->max_antenna_gain;
1025 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1026 printk(KERN_DEBUG "%s: HW CONFIG: freq=%d\n",
1027 wiphy_name(local->hw.wiphy), chan->center_freq);
1030 if (local->open_count)
1031 ret = local->ops->config(local_to_hw(local), &local->hw.conf);
1037 * ieee80211_hw_config_ht should be used only after legacy configuration
1038 * has been determined, as ht configuration depends upon the hardware's
1039 * HT abilities for a _specific_ band.
1041 int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht,
1042 struct ieee80211_ht_info *req_ht_cap,
1043 struct ieee80211_ht_bss_info *req_bss_cap)
1045 struct ieee80211_conf *conf = &local->hw.conf;
1046 struct ieee80211_supported_band *sband;
1049 sband = local->hw.wiphy->bands[conf->channel->band];
1051 /* HT is not supported */
1052 if (!sband->ht_info.ht_supported) {
1053 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
1059 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
1061 conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE;
1062 conf->ht_conf.cap = req_ht_cap->cap & sband->ht_info.cap;
1063 conf->ht_conf.cap &= ~(IEEE80211_HT_CAP_MIMO_PS);
1064 conf->ht_conf.cap |=
1065 sband->ht_info.cap & IEEE80211_HT_CAP_MIMO_PS;
1066 conf->ht_bss_conf.primary_channel =
1067 req_bss_cap->primary_channel;
1068 conf->ht_bss_conf.bss_cap = req_bss_cap->bss_cap;
1069 conf->ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode;
1070 for (i = 0; i < SUPP_MCS_SET_LEN; i++)
1071 conf->ht_conf.supp_mcs_set[i] =
1072 sband->ht_info.supp_mcs_set[i] &
1073 req_ht_cap->supp_mcs_set[i];
1075 /* In STA mode, this gives us indication
1076 * to the AP's mode of operation */
1077 conf->ht_conf.ht_supported = 1;
1078 conf->ht_conf.ampdu_factor = req_ht_cap->ampdu_factor;
1079 conf->ht_conf.ampdu_density = req_ht_cap->ampdu_density;
1082 local->ops->conf_ht(local_to_hw(local), &local->hw.conf);
1087 void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
1090 struct ieee80211_local *local = sdata->local;
1095 if (local->ops->bss_info_changed)
1096 local->ops->bss_info_changed(local_to_hw(local),
1102 void ieee80211_reset_erp_info(struct net_device *dev)
1104 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1106 sdata->bss_conf.use_cts_prot = 0;
1107 sdata->bss_conf.use_short_preamble = 0;
1108 ieee80211_bss_info_change_notify(sdata,
1109 BSS_CHANGED_ERP_CTS_PROT |
1110 BSS_CHANGED_ERP_PREAMBLE);
1113 void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
1114 struct sk_buff *skb,
1115 struct ieee80211_tx_status *status)
1117 struct ieee80211_local *local = hw_to_local(hw);
1118 struct ieee80211_tx_status *saved;
1121 skb->dev = local->mdev;
1122 saved = kmalloc(sizeof(struct ieee80211_tx_status), GFP_ATOMIC);
1123 if (unlikely(!saved)) {
1124 if (net_ratelimit())
1125 printk(KERN_WARNING "%s: Not enough memory, "
1126 "dropping tx status", skb->dev->name);
1127 /* should be dev_kfree_skb_irq, but due to this function being
1128 * named _irqsafe instead of just _irq we can't be sure that
1129 * people won't call it from non-irq contexts */
1130 dev_kfree_skb_any(skb);
1133 memcpy(saved, status, sizeof(struct ieee80211_tx_status));
1134 /* copy pointer to saved status into skb->cb for use by tasklet */
1135 memcpy(skb->cb, &saved, sizeof(saved));
1137 skb->pkt_type = IEEE80211_TX_STATUS_MSG;
1138 skb_queue_tail(status->control.flags & IEEE80211_TXCTL_REQ_TX_STATUS ?
1139 &local->skb_queue : &local->skb_queue_unreliable, skb);
1140 tmp = skb_queue_len(&local->skb_queue) +
1141 skb_queue_len(&local->skb_queue_unreliable);
1142 while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
1143 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
1144 memcpy(&saved, skb->cb, sizeof(saved));
1146 dev_kfree_skb_irq(skb);
1148 I802_DEBUG_INC(local->tx_status_drop);
1150 tasklet_schedule(&local->tasklet);
1152 EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
1154 static void ieee80211_tasklet_handler(unsigned long data)
1156 struct ieee80211_local *local = (struct ieee80211_local *) data;
1157 struct sk_buff *skb;
1158 struct ieee80211_rx_status rx_status;
1159 struct ieee80211_tx_status *tx_status;
1160 struct ieee80211_ra_tid *ra_tid;
1162 while ((skb = skb_dequeue(&local->skb_queue)) ||
1163 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
1164 switch (skb->pkt_type) {
1165 case IEEE80211_RX_MSG:
1166 /* status is in skb->cb */
1167 memcpy(&rx_status, skb->cb, sizeof(rx_status));
1168 /* Clear skb->pkt_type in order to not confuse kernel
1171 __ieee80211_rx(local_to_hw(local), skb, &rx_status);
1173 case IEEE80211_TX_STATUS_MSG:
1174 /* get pointer to saved status out of skb->cb */
1175 memcpy(&tx_status, skb->cb, sizeof(tx_status));
1177 ieee80211_tx_status(local_to_hw(local),
1181 case IEEE80211_DELBA_MSG:
1182 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
1183 ieee80211_stop_tx_ba_cb(local_to_hw(local),
1184 ra_tid->ra, ra_tid->tid);
1187 case IEEE80211_ADDBA_MSG:
1188 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
1189 ieee80211_start_tx_ba_cb(local_to_hw(local),
1190 ra_tid->ra, ra_tid->tid);
1193 default: /* should never get here! */
1194 printk(KERN_ERR "%s: Unknown message type (%d)\n",
1195 wiphy_name(local->hw.wiphy), skb->pkt_type);
1202 /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
1203 * make a prepared TX frame (one that has been given to hw) to look like brand
1204 * new IEEE 802.11 frame that is ready to go through TX processing again.
1205 * Also, tx_packet_data in cb is restored from tx_control. */
1206 static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
1207 struct ieee80211_key *key,
1208 struct sk_buff *skb,
1209 struct ieee80211_tx_control *control)
1211 int hdrlen, iv_len, mic_len;
1212 struct ieee80211_tx_packet_data *pkt_data;
1214 pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
1215 pkt_data->ifindex = vif_to_sdata(control->vif)->dev->ifindex;
1216 pkt_data->flags = 0;
1217 if (control->flags & IEEE80211_TXCTL_REQ_TX_STATUS)
1218 pkt_data->flags |= IEEE80211_TXPD_REQ_TX_STATUS;
1219 if (control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)
1220 pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT;
1221 if (control->flags & IEEE80211_TXCTL_REQUEUE)
1222 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
1223 if (control->flags & IEEE80211_TXCTL_EAPOL_FRAME)
1224 pkt_data->flags |= IEEE80211_TXPD_EAPOL_FRAME;
1225 pkt_data->queue = control->queue;
1227 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1232 switch (key->conf.alg) {
1234 iv_len = WEP_IV_LEN;
1235 mic_len = WEP_ICV_LEN;
1238 iv_len = TKIP_IV_LEN;
1239 mic_len = TKIP_ICV_LEN;
1242 iv_len = CCMP_HDR_LEN;
1243 mic_len = CCMP_MIC_LEN;
1249 if (skb->len >= mic_len &&
1250 !(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
1251 skb_trim(skb, skb->len - mic_len);
1252 if (skb->len >= iv_len && skb->len > hdrlen) {
1253 memmove(skb->data + iv_len, skb->data, hdrlen);
1254 skb_pull(skb, iv_len);
1259 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1260 u16 fc = le16_to_cpu(hdr->frame_control);
1261 if ((fc & 0x8C) == 0x88) /* QoS Control Field */ {
1262 fc &= ~IEEE80211_STYPE_QOS_DATA;
1263 hdr->frame_control = cpu_to_le16(fc);
1264 memmove(skb->data + 2, skb->data, hdrlen - 2);
1270 static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
1271 struct sta_info *sta,
1272 struct sk_buff *skb,
1273 struct ieee80211_tx_status *status)
1275 sta->tx_filtered_count++;
1278 * Clear the TX filter mask for this STA when sending the next
1279 * packet. If the STA went to power save mode, this will happen
1280 * happen when it wakes up for the next time.
1282 sta->flags |= WLAN_STA_CLEAR_PS_FILT;
1285 * This code races in the following way:
1287 * (1) STA sends frame indicating it will go to sleep and does so
1288 * (2) hardware/firmware adds STA to filter list, passes frame up
1289 * (3) hardware/firmware processes TX fifo and suppresses a frame
1290 * (4) we get TX status before having processed the frame and
1291 * knowing that the STA has gone to sleep.
1293 * This is actually quite unlikely even when both those events are
1294 * processed from interrupts coming in quickly after one another or
1295 * even at the same time because we queue both TX status events and
1296 * RX frames to be processed by a tasklet and process them in the
1297 * same order that they were received or TX status last. Hence, there
1298 * is no race as long as the frame RX is processed before the next TX
1299 * status, which drivers can ensure, see below.
1301 * Note that this can only happen if the hardware or firmware can
1302 * actually add STAs to the filter list, if this is done by the
1303 * driver in response to set_tim() (which will only reduce the race
1304 * this whole filtering tries to solve, not completely solve it)
1305 * this situation cannot happen.
1307 * To completely solve this race drivers need to make sure that they
1308 * (a) don't mix the irq-safe/not irq-safe TX status/RX processing
1310 * (b) always process RX events before TX status events if ordering
1311 * can be unknown, for example with different interrupt status
1314 if (sta->flags & WLAN_STA_PS &&
1315 skb_queue_len(&sta->tx_filtered) < STA_MAX_TX_BUFFER) {
1316 ieee80211_remove_tx_extra(local, sta->key, skb,
1318 skb_queue_tail(&sta->tx_filtered, skb);
1322 if (!(sta->flags & WLAN_STA_PS) &&
1323 !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) {
1324 /* Software retry the packet once */
1325 status->control.flags |= IEEE80211_TXCTL_REQUEUE;
1326 ieee80211_remove_tx_extra(local, sta->key, skb,
1328 dev_queue_xmit(skb);
1332 if (net_ratelimit())
1333 printk(KERN_DEBUG "%s: dropped TX filtered frame, "
1334 "queue_len=%d PS=%d @%lu\n",
1335 wiphy_name(local->hw.wiphy),
1336 skb_queue_len(&sta->tx_filtered),
1337 !!(sta->flags & WLAN_STA_PS), jiffies);
1341 void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
1342 struct ieee80211_tx_status *status)
1344 struct sk_buff *skb2;
1345 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1346 struct ieee80211_local *local = hw_to_local(hw);
1348 struct ieee80211_tx_status_rtap_hdr *rthdr;
1349 struct ieee80211_sub_if_data *sdata;
1350 struct net_device *prev_dev = NULL;
1354 "%s: ieee80211_tx_status called with NULL status\n",
1355 wiphy_name(local->hw.wiphy));
1362 if (status->excessive_retries) {
1363 struct sta_info *sta;
1364 sta = sta_info_get(local, hdr->addr1);
1366 if (sta->flags & WLAN_STA_PS) {
1368 * The STA is in power save mode, so assume
1369 * that this TX packet failed because of that.
1371 status->excessive_retries = 0;
1372 status->flags |= IEEE80211_TX_STATUS_TX_FILTERED;
1373 ieee80211_handle_filtered_frame(local, sta,
1381 if (status->flags & IEEE80211_TX_STATUS_TX_FILTERED) {
1382 struct sta_info *sta;
1383 sta = sta_info_get(local, hdr->addr1);
1385 ieee80211_handle_filtered_frame(local, sta, skb,
1391 rate_control_tx_status(local->mdev, skb, status);
1395 ieee80211_led_tx(local, 0);
1398 * Fragments are passed to low-level drivers as separate skbs, so these
1399 * are actually fragments, not frames. Update frame counters only for
1400 * the first fragment of the frame. */
1402 frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
1403 type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
1405 if (status->flags & IEEE80211_TX_STATUS_ACK) {
1407 local->dot11TransmittedFrameCount++;
1408 if (is_multicast_ether_addr(hdr->addr1))
1409 local->dot11MulticastTransmittedFrameCount++;
1410 if (status->retry_count > 0)
1411 local->dot11RetryCount++;
1412 if (status->retry_count > 1)
1413 local->dot11MultipleRetryCount++;
1416 /* This counter shall be incremented for an acknowledged MPDU
1417 * with an individual address in the address 1 field or an MPDU
1418 * with a multicast address in the address 1 field of type Data
1420 if (!is_multicast_ether_addr(hdr->addr1) ||
1421 type == IEEE80211_FTYPE_DATA ||
1422 type == IEEE80211_FTYPE_MGMT)
1423 local->dot11TransmittedFragmentCount++;
1426 local->dot11FailedCount++;
1429 /* this was a transmitted frame, but now we want to reuse it */
1433 * This is a bit racy but we can avoid a lot of work
1436 if (!local->monitors && !local->cooked_mntrs) {
1441 /* send frame to monitor interfaces now */
1443 if (skb_headroom(skb) < sizeof(*rthdr)) {
1444 printk(KERN_ERR "ieee80211_tx_status: headroom too small\n");
1449 rthdr = (struct ieee80211_tx_status_rtap_hdr*)
1450 skb_push(skb, sizeof(*rthdr));
1452 memset(rthdr, 0, sizeof(*rthdr));
1453 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
1454 rthdr->hdr.it_present =
1455 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
1456 (1 << IEEE80211_RADIOTAP_DATA_RETRIES));
1458 if (!(status->flags & IEEE80211_TX_STATUS_ACK) &&
1459 !is_multicast_ether_addr(hdr->addr1))
1460 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL);
1462 if ((status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS) &&
1463 (status->control.flags & IEEE80211_TXCTL_USE_CTS_PROTECT))
1464 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS);
1465 else if (status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS)
1466 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS);
1468 rthdr->data_retries = status->retry_count;
1470 /* XXX: is this sufficient for BPF? */
1471 skb_set_mac_header(skb, 0);
1472 skb->ip_summed = CHECKSUM_UNNECESSARY;
1473 skb->pkt_type = PACKET_OTHERHOST;
1474 skb->protocol = htons(ETH_P_802_2);
1475 memset(skb->cb, 0, sizeof(skb->cb));
1478 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1479 if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR) {
1480 if (!netif_running(sdata->dev))
1484 skb2 = skb_clone(skb, GFP_ATOMIC);
1486 skb2->dev = prev_dev;
1491 prev_dev = sdata->dev;
1495 skb->dev = prev_dev;
1502 EXPORT_SYMBOL(ieee80211_tx_status);
1504 struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
1505 const struct ieee80211_ops *ops)
1507 struct ieee80211_local *local;
1509 struct wiphy *wiphy;
1511 /* Ensure 32-byte alignment of our private data and hw private data.
1512 * We use the wiphy priv data for both our ieee80211_local and for
1513 * the driver's private data
1515 * In memory it'll be like this:
1517 * +-------------------------+
1519 * +-------------------------+
1520 * | struct ieee80211_local |
1521 * +-------------------------+
1522 * | driver's private data |
1523 * +-------------------------+
1526 priv_size = ((sizeof(struct ieee80211_local) +
1527 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) +
1530 wiphy = wiphy_new(&mac80211_config_ops, priv_size);
1535 wiphy->privid = mac80211_wiphy_privid;
1537 local = wiphy_priv(wiphy);
1538 local->hw.wiphy = wiphy;
1540 local->hw.priv = (char *)local +
1541 ((sizeof(struct ieee80211_local) +
1542 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
1545 BUG_ON(!ops->start);
1547 BUG_ON(!ops->config);
1548 BUG_ON(!ops->add_interface);
1549 BUG_ON(!ops->remove_interface);
1550 BUG_ON(!ops->configure_filter);
1553 local->hw.queues = 1; /* default */
1555 local->bridge_packets = 1;
1557 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
1558 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
1559 local->short_retry_limit = 7;
1560 local->long_retry_limit = 4;
1561 local->hw.conf.radio_enabled = 1;
1563 INIT_LIST_HEAD(&local->interfaces);
1565 INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work);
1567 sta_info_init(local);
1569 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
1570 (unsigned long)local);
1571 tasklet_disable(&local->tx_pending_tasklet);
1573 tasklet_init(&local->tasklet,
1574 ieee80211_tasklet_handler,
1575 (unsigned long) local);
1576 tasklet_disable(&local->tasklet);
1578 skb_queue_head_init(&local->skb_queue);
1579 skb_queue_head_init(&local->skb_queue_unreliable);
1581 return local_to_hw(local);
1583 EXPORT_SYMBOL(ieee80211_alloc_hw);
1585 int ieee80211_register_hw(struct ieee80211_hw *hw)
1587 struct ieee80211_local *local = hw_to_local(hw);
1590 enum ieee80211_band band;
1591 struct net_device *mdev;
1592 struct ieee80211_sub_if_data *sdata;
1595 * generic code guarantees at least one band,
1596 * set this very early because much code assumes
1597 * that hw.conf.channel is assigned
1599 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1600 struct ieee80211_supported_band *sband;
1602 sband = local->hw.wiphy->bands[band];
1604 /* init channel we're on */
1605 local->hw.conf.channel =
1606 local->oper_channel =
1607 local->scan_channel = &sband->channels[0];
1612 result = wiphy_register(local->hw.wiphy);
1616 /* for now, mdev needs sub_if_data :/ */
1617 mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
1618 "wmaster%d", ether_setup);
1620 goto fail_mdev_alloc;
1622 sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
1623 mdev->ieee80211_ptr = &sdata->wdev;
1624 sdata->wdev.wiphy = local->hw.wiphy;
1628 ieee80211_rx_bss_list_init(mdev);
1630 mdev->hard_start_xmit = ieee80211_master_start_xmit;
1631 mdev->open = ieee80211_master_open;
1632 mdev->stop = ieee80211_master_stop;
1633 mdev->type = ARPHRD_IEEE80211;
1634 mdev->header_ops = &ieee80211_header_ops;
1635 mdev->set_multicast_list = ieee80211_master_set_multicast_list;
1637 sdata->vif.type = IEEE80211_IF_TYPE_AP;
1639 sdata->local = local;
1640 sdata->u.ap.force_unicast_rateidx = -1;
1641 sdata->u.ap.max_ratectrl_rateidx = -1;
1642 ieee80211_if_sdata_init(sdata);
1644 /* no RCU needed since we're still during init phase */
1645 list_add_tail(&sdata->list, &local->interfaces);
1647 name = wiphy_dev(local->hw.wiphy)->driver->name;
1648 local->hw.workqueue = create_singlethread_workqueue(name);
1649 if (!local->hw.workqueue) {
1651 goto fail_workqueue;
1655 * The hardware needs headroom for sending the frame,
1656 * and we need some headroom for passing the frame to monitor
1657 * interfaces, but never both at the same time.
1659 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
1660 sizeof(struct ieee80211_tx_status_rtap_hdr));
1662 debugfs_hw_add(local);
1664 local->hw.conf.beacon_int = 1000;
1666 local->wstats_flags |= local->hw.max_rssi ?
1667 IW_QUAL_LEVEL_UPDATED : IW_QUAL_LEVEL_INVALID;
1668 local->wstats_flags |= local->hw.max_signal ?
1669 IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
1670 local->wstats_flags |= local->hw.max_noise ?
1671 IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
1672 if (local->hw.max_rssi < 0 || local->hw.max_noise < 0)
1673 local->wstats_flags |= IW_QUAL_DBM;
1675 result = sta_info_start(local);
1680 result = dev_alloc_name(local->mdev, local->mdev->name);
1684 memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
1685 SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy));
1687 result = register_netdevice(local->mdev);
1691 ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
1692 ieee80211_if_set_type(local->mdev, IEEE80211_IF_TYPE_AP);
1694 result = ieee80211_init_rate_ctrl_alg(local,
1695 hw->rate_control_algorithm);
1697 printk(KERN_DEBUG "%s: Failed to initialize rate control "
1698 "algorithm\n", wiphy_name(local->hw.wiphy));
1702 result = ieee80211_wep_init(local);
1705 printk(KERN_DEBUG "%s: Failed to initialize wep\n",
1706 wiphy_name(local->hw.wiphy));
1710 ieee80211_install_qdisc(local->mdev);
1712 /* add one default STA interface */
1713 result = ieee80211_if_add(local->mdev, "wlan%d", NULL,
1714 IEEE80211_IF_TYPE_STA, NULL);
1716 printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
1717 wiphy_name(local->hw.wiphy));
1719 local->reg_state = IEEE80211_DEV_REGISTERED;
1722 ieee80211_led_init(local);
1727 rate_control_deinitialize(local);
1729 ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
1730 unregister_netdevice(local->mdev);
1733 sta_info_stop(local);
1735 debugfs_hw_del(local);
1736 destroy_workqueue(local->hw.workqueue);
1738 ieee80211_if_free(local->mdev);
1741 wiphy_unregister(local->hw.wiphy);
1744 EXPORT_SYMBOL(ieee80211_register_hw);
1746 void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1748 struct ieee80211_local *local = hw_to_local(hw);
1749 struct ieee80211_sub_if_data *sdata, *tmp;
1751 tasklet_kill(&local->tx_pending_tasklet);
1752 tasklet_kill(&local->tasklet);
1756 BUG_ON(local->reg_state != IEEE80211_DEV_REGISTERED);
1758 local->reg_state = IEEE80211_DEV_UNREGISTERED;
1761 * At this point, interface list manipulations are fine
1762 * because the driver cannot be handing us frames any
1763 * more and the tasklet is killed.
1767 * First, we remove all non-master interfaces. Do this because they
1768 * may have bss pointer dependency on the master, and when we free
1769 * the master these would be freed as well, breaking our list
1770 * iteration completely.
1772 list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
1773 if (sdata->dev == local->mdev)
1775 list_del(&sdata->list);
1776 __ieee80211_if_del(local, sdata);
1779 /* then, finally, remove the master interface */
1780 __ieee80211_if_del(local, IEEE80211_DEV_TO_SUB_IF(local->mdev));
1784 ieee80211_rx_bss_list_deinit(local->mdev);
1785 ieee80211_clear_tx_pending(local);
1786 sta_info_stop(local);
1787 rate_control_deinitialize(local);
1788 debugfs_hw_del(local);
1790 if (skb_queue_len(&local->skb_queue)
1791 || skb_queue_len(&local->skb_queue_unreliable))
1792 printk(KERN_WARNING "%s: skb_queue not empty\n",
1793 wiphy_name(local->hw.wiphy));
1794 skb_queue_purge(&local->skb_queue);
1795 skb_queue_purge(&local->skb_queue_unreliable);
1797 destroy_workqueue(local->hw.workqueue);
1798 wiphy_unregister(local->hw.wiphy);
1799 ieee80211_wep_free(local);
1800 ieee80211_led_exit(local);
1801 ieee80211_if_free(local->mdev);
1804 EXPORT_SYMBOL(ieee80211_unregister_hw);
1806 void ieee80211_free_hw(struct ieee80211_hw *hw)
1808 struct ieee80211_local *local = hw_to_local(hw);
1810 wiphy_free(local->hw.wiphy);
1812 EXPORT_SYMBOL(ieee80211_free_hw);
1814 static int __init ieee80211_init(void)
1816 struct sk_buff *skb;
1819 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb));
1821 ret = rc80211_simple_init();
1825 ret = rc80211_pid_init();
1827 goto out_cleanup_simple;
1829 ret = ieee80211_wme_register();
1831 printk(KERN_DEBUG "ieee80211_init: failed to "
1832 "initialize WME (err=%d)\n", ret);
1833 goto out_cleanup_pid;
1836 ieee80211_debugfs_netdev_init();
1843 rc80211_simple_exit();
1848 static void __exit ieee80211_exit(void)
1850 rc80211_simple_exit();
1856 ieee80211_wme_unregister();
1857 ieee80211_debugfs_netdev_exit();
1861 subsys_initcall(ieee80211_init);
1862 module_exit(ieee80211_exit);
1864 MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1865 MODULE_LICENSE("GPL");