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"
36 #include "debugfs_netdev.h"
39 * For seeing transmitted packets on monitor interfaces
40 * we have a radiotap header too.
42 struct ieee80211_tx_status_rtap_hdr {
43 struct ieee80211_radiotap_header hdr;
48 } __attribute__ ((packed));
51 /* must be called under mdev tx lock */
52 void ieee80211_configure_filter(struct ieee80211_local *local)
54 unsigned int changed_flags;
55 unsigned int new_flags = 0;
57 if (atomic_read(&local->iff_promiscs))
58 new_flags |= FIF_PROMISC_IN_BSS;
60 if (atomic_read(&local->iff_allmultis))
61 new_flags |= FIF_ALLMULTI;
64 new_flags |= FIF_BCN_PRBRESP_PROMISC;
66 if (local->fif_fcsfail)
67 new_flags |= FIF_FCSFAIL;
69 if (local->fif_plcpfail)
70 new_flags |= FIF_PLCPFAIL;
72 if (local->fif_control)
73 new_flags |= FIF_CONTROL;
75 if (local->fif_other_bss)
76 new_flags |= FIF_OTHER_BSS;
78 changed_flags = local->filter_flags ^ new_flags;
83 local->ops->configure_filter(local_to_hw(local),
84 changed_flags, &new_flags,
85 local->mdev->mc_count,
86 local->mdev->mc_list);
88 WARN_ON(new_flags & (1<<31));
90 local->filter_flags = new_flags & ~(1<<31);
93 /* master interface */
95 static int header_parse_80211(const struct sk_buff *skb, unsigned char *haddr)
97 memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
101 static const struct header_ops ieee80211_header_ops = {
102 .create = eth_header,
103 .parse = header_parse_80211,
104 .rebuild = eth_rebuild_header,
105 .cache = eth_header_cache,
106 .cache_update = eth_header_cache_update,
109 static int ieee80211_master_open(struct net_device *dev)
111 struct ieee80211_master_priv *mpriv = netdev_priv(dev);
112 struct ieee80211_local *local = mpriv->local;
113 struct ieee80211_sub_if_data *sdata;
114 int res = -EOPNOTSUPP;
116 /* we hold the RTNL here so can safely walk the list */
117 list_for_each_entry(sdata, &local->interfaces, list) {
118 if (netif_running(sdata->dev)) {
127 netif_tx_start_all_queues(local->mdev);
132 static int ieee80211_master_stop(struct net_device *dev)
134 struct ieee80211_master_priv *mpriv = netdev_priv(dev);
135 struct ieee80211_local *local = mpriv->local;
136 struct ieee80211_sub_if_data *sdata;
138 /* we hold the RTNL here so can safely walk the list */
139 list_for_each_entry(sdata, &local->interfaces, list)
140 if (netif_running(sdata->dev))
141 dev_close(sdata->dev);
146 static void ieee80211_master_set_multicast_list(struct net_device *dev)
148 struct ieee80211_master_priv *mpriv = netdev_priv(dev);
149 struct ieee80211_local *local = mpriv->local;
151 ieee80211_configure_filter(local);
154 /* everything else */
156 int ieee80211_if_config(struct ieee80211_sub_if_data *sdata, u32 changed)
158 struct ieee80211_local *local = sdata->local;
159 struct ieee80211_if_conf conf;
161 if (WARN_ON(!netif_running(sdata->dev)))
164 if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
167 if (!local->ops->config_interface)
170 memset(&conf, 0, sizeof(conf));
172 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
173 sdata->vif.type == NL80211_IFTYPE_ADHOC)
174 conf.bssid = sdata->u.sta.bssid;
175 else if (sdata->vif.type == NL80211_IFTYPE_AP)
176 conf.bssid = sdata->dev->dev_addr;
177 else if (ieee80211_vif_is_mesh(&sdata->vif)) {
178 static const u8 zero[ETH_ALEN] = { 0 };
185 switch (sdata->vif.type) {
186 case NL80211_IFTYPE_AP:
187 case NL80211_IFTYPE_ADHOC:
188 case NL80211_IFTYPE_MESH_POINT:
191 /* do not warn to simplify caller in scan.c */
192 changed &= ~IEEE80211_IFCC_BEACON_ENABLED;
193 if (WARN_ON(changed & IEEE80211_IFCC_BEACON))
195 changed &= ~IEEE80211_IFCC_BEACON;
199 if (changed & IEEE80211_IFCC_BEACON_ENABLED) {
200 if (local->sw_scanning) {
201 conf.enable_beacon = false;
204 * Beacon should be enabled, but AP mode must
205 * check whether there is a beacon configured.
207 switch (sdata->vif.type) {
208 case NL80211_IFTYPE_AP:
210 !!rcu_dereference(sdata->u.ap.beacon);
212 case NL80211_IFTYPE_ADHOC:
213 case NL80211_IFTYPE_MESH_POINT:
214 conf.enable_beacon = true;
224 if (WARN_ON(!conf.bssid && (changed & IEEE80211_IFCC_BSSID)))
227 conf.changed = changed;
229 return local->ops->config_interface(local_to_hw(local),
233 int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
235 struct ieee80211_channel *chan;
238 enum nl80211_channel_type channel_type;
242 if (local->sw_scanning) {
243 chan = local->scan_channel;
244 channel_type = NL80211_CHAN_NO_HT;
246 chan = local->oper_channel;
247 channel_type = local->oper_channel_type;
250 if (chan != local->hw.conf.channel ||
251 channel_type != local->hw.conf.channel_type) {
252 local->hw.conf.channel = chan;
253 local->hw.conf.channel_type = channel_type;
254 changed |= IEEE80211_CONF_CHANGE_CHANNEL;
257 if (local->sw_scanning)
258 power = chan->max_power;
260 power = local->power_constr_level ?
261 (chan->max_power - local->power_constr_level) :
264 if (local->user_power_level)
265 power = min(power, local->user_power_level);
267 if (local->hw.conf.power_level != power) {
268 changed |= IEEE80211_CONF_CHANGE_POWER;
269 local->hw.conf.power_level = power;
272 if (changed && local->open_count) {
273 ret = local->ops->config(local_to_hw(local), changed);
276 * HW reconfiguration should never fail, the driver has told
277 * us what it can support so it should live up to that promise.
280 * rfkill is not integrated with mac80211 and a
281 * configuration command can thus fail if hardware rfkill
284 * FIXME: integrate rfkill with mac80211 and then add this
294 void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
297 struct ieee80211_local *local = sdata->local;
299 if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
305 if (local->ops->bss_info_changed)
306 local->ops->bss_info_changed(local_to_hw(local),
308 &sdata->vif.bss_conf,
312 u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata)
314 sdata->vif.bss_conf.use_cts_prot = false;
315 sdata->vif.bss_conf.use_short_preamble = false;
316 sdata->vif.bss_conf.use_short_slot = false;
317 return BSS_CHANGED_ERP_CTS_PROT |
318 BSS_CHANGED_ERP_PREAMBLE |
319 BSS_CHANGED_ERP_SLOT;
322 void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
325 struct ieee80211_local *local = hw_to_local(hw);
326 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
329 skb->dev = local->mdev;
330 skb->pkt_type = IEEE80211_TX_STATUS_MSG;
331 skb_queue_tail(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS ?
332 &local->skb_queue : &local->skb_queue_unreliable, skb);
333 tmp = skb_queue_len(&local->skb_queue) +
334 skb_queue_len(&local->skb_queue_unreliable);
335 while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
336 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
337 dev_kfree_skb_irq(skb);
339 I802_DEBUG_INC(local->tx_status_drop);
341 tasklet_schedule(&local->tasklet);
343 EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
345 static void ieee80211_tasklet_handler(unsigned long data)
347 struct ieee80211_local *local = (struct ieee80211_local *) data;
349 struct ieee80211_rx_status rx_status;
350 struct ieee80211_ra_tid *ra_tid;
352 while ((skb = skb_dequeue(&local->skb_queue)) ||
353 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
354 switch (skb->pkt_type) {
355 case IEEE80211_RX_MSG:
356 /* status is in skb->cb */
357 memcpy(&rx_status, skb->cb, sizeof(rx_status));
358 /* Clear skb->pkt_type in order to not confuse kernel
361 __ieee80211_rx(local_to_hw(local), skb, &rx_status);
363 case IEEE80211_TX_STATUS_MSG:
365 ieee80211_tx_status(local_to_hw(local), skb);
367 case IEEE80211_DELBA_MSG:
368 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
369 ieee80211_stop_tx_ba_cb(local_to_hw(local),
370 ra_tid->ra, ra_tid->tid);
373 case IEEE80211_ADDBA_MSG:
374 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
375 ieee80211_start_tx_ba_cb(local_to_hw(local),
376 ra_tid->ra, ra_tid->tid);
380 WARN(1, "mac80211: Packet is of unknown type %d\n",
388 /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
389 * make a prepared TX frame (one that has been given to hw) to look like brand
390 * new IEEE 802.11 frame that is ready to go through TX processing again.
392 static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
393 struct ieee80211_key *key,
396 unsigned int hdrlen, iv_len, mic_len;
397 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
399 hdrlen = ieee80211_hdrlen(hdr->frame_control);
404 switch (key->conf.alg) {
407 mic_len = WEP_ICV_LEN;
410 iv_len = TKIP_IV_LEN;
411 mic_len = TKIP_ICV_LEN;
414 iv_len = CCMP_HDR_LEN;
415 mic_len = CCMP_MIC_LEN;
421 if (skb->len >= hdrlen + mic_len &&
422 !(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
423 skb_trim(skb, skb->len - mic_len);
424 if (skb->len >= hdrlen + iv_len) {
425 memmove(skb->data + iv_len, skb->data, hdrlen);
426 hdr = (struct ieee80211_hdr *)skb_pull(skb, iv_len);
430 if (ieee80211_is_data_qos(hdr->frame_control)) {
431 hdr->frame_control &= ~cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
432 memmove(skb->data + IEEE80211_QOS_CTL_LEN, skb->data,
433 hdrlen - IEEE80211_QOS_CTL_LEN);
434 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
438 static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
439 struct sta_info *sta,
442 sta->tx_filtered_count++;
445 * Clear the TX filter mask for this STA when sending the next
446 * packet. If the STA went to power save mode, this will happen
447 * when it wakes up for the next time.
449 set_sta_flags(sta, WLAN_STA_CLEAR_PS_FILT);
452 * This code races in the following way:
454 * (1) STA sends frame indicating it will go to sleep and does so
455 * (2) hardware/firmware adds STA to filter list, passes frame up
456 * (3) hardware/firmware processes TX fifo and suppresses a frame
457 * (4) we get TX status before having processed the frame and
458 * knowing that the STA has gone to sleep.
460 * This is actually quite unlikely even when both those events are
461 * processed from interrupts coming in quickly after one another or
462 * even at the same time because we queue both TX status events and
463 * RX frames to be processed by a tasklet and process them in the
464 * same order that they were received or TX status last. Hence, there
465 * is no race as long as the frame RX is processed before the next TX
466 * status, which drivers can ensure, see below.
468 * Note that this can only happen if the hardware or firmware can
469 * actually add STAs to the filter list, if this is done by the
470 * driver in response to set_tim() (which will only reduce the race
471 * this whole filtering tries to solve, not completely solve it)
472 * this situation cannot happen.
474 * To completely solve this race drivers need to make sure that they
475 * (a) don't mix the irq-safe/not irq-safe TX status/RX processing
477 * (b) always process RX events before TX status events if ordering
478 * can be unknown, for example with different interrupt status
481 if (test_sta_flags(sta, WLAN_STA_PS) &&
482 skb_queue_len(&sta->tx_filtered) < STA_MAX_TX_BUFFER) {
483 ieee80211_remove_tx_extra(local, sta->key, skb);
484 skb_queue_tail(&sta->tx_filtered, skb);
488 if (!test_sta_flags(sta, WLAN_STA_PS) && !skb->requeue) {
489 /* Software retry the packet once */
491 ieee80211_remove_tx_extra(local, sta->key, skb);
496 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
498 printk(KERN_DEBUG "%s: dropped TX filtered frame, "
499 "queue_len=%d PS=%d @%lu\n",
500 wiphy_name(local->hw.wiphy),
501 skb_queue_len(&sta->tx_filtered),
502 !!test_sta_flags(sta, WLAN_STA_PS), jiffies);
507 void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
509 struct sk_buff *skb2;
510 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
511 struct ieee80211_local *local = hw_to_local(hw);
512 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
515 struct ieee80211_supported_band *sband;
516 struct ieee80211_tx_status_rtap_hdr *rthdr;
517 struct ieee80211_sub_if_data *sdata;
518 struct net_device *prev_dev = NULL;
519 struct sta_info *sta;
520 int retry_count = -1, i;
522 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
523 /* the HW cannot have attempted that rate */
524 if (i >= hw->max_rates) {
525 info->status.rates[i].idx = -1;
526 info->status.rates[i].count = 0;
529 retry_count += info->status.rates[i].count;
536 sband = local->hw.wiphy->bands[info->band];
538 sta = sta_info_get(local, hdr->addr1);
541 if (!(info->flags & IEEE80211_TX_STAT_ACK) &&
542 test_sta_flags(sta, WLAN_STA_PS)) {
544 * The STA is in power save mode, so assume
545 * that this TX packet failed because of that.
547 ieee80211_handle_filtered_frame(local, sta, skb);
552 fc = hdr->frame_control;
554 if ((info->flags & IEEE80211_TX_STAT_AMPDU_NO_BACK) &&
555 (ieee80211_is_data_qos(fc))) {
559 qc = ieee80211_get_qos_ctl(hdr);
561 ssn = ((le16_to_cpu(hdr->seq_ctrl) + 0x10)
562 & IEEE80211_SCTL_SEQ);
563 ieee80211_send_bar(sta->sdata, hdr->addr1,
567 if (info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
568 ieee80211_handle_filtered_frame(local, sta, skb);
572 if (!(info->flags & IEEE80211_TX_STAT_ACK))
573 sta->tx_retry_failed++;
574 sta->tx_retry_count += retry_count;
577 rate_control_tx_status(local, sband, sta, skb);
582 ieee80211_led_tx(local, 0);
585 * Fragments are passed to low-level drivers as separate skbs, so these
586 * are actually fragments, not frames. Update frame counters only for
587 * the first fragment of the frame. */
589 frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
590 type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
592 if (info->flags & IEEE80211_TX_STAT_ACK) {
594 local->dot11TransmittedFrameCount++;
595 if (is_multicast_ether_addr(hdr->addr1))
596 local->dot11MulticastTransmittedFrameCount++;
598 local->dot11RetryCount++;
600 local->dot11MultipleRetryCount++;
603 /* This counter shall be incremented for an acknowledged MPDU
604 * with an individual address in the address 1 field or an MPDU
605 * with a multicast address in the address 1 field of type Data
607 if (!is_multicast_ether_addr(hdr->addr1) ||
608 type == IEEE80211_FTYPE_DATA ||
609 type == IEEE80211_FTYPE_MGMT)
610 local->dot11TransmittedFragmentCount++;
613 local->dot11FailedCount++;
616 /* this was a transmitted frame, but now we want to reuse it */
620 * This is a bit racy but we can avoid a lot of work
623 if (!local->monitors && !local->cooked_mntrs) {
628 /* send frame to monitor interfaces now */
630 if (skb_headroom(skb) < sizeof(*rthdr)) {
631 printk(KERN_ERR "ieee80211_tx_status: headroom too small\n");
636 rthdr = (struct ieee80211_tx_status_rtap_hdr *)
637 skb_push(skb, sizeof(*rthdr));
639 memset(rthdr, 0, sizeof(*rthdr));
640 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
641 rthdr->hdr.it_present =
642 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
643 (1 << IEEE80211_RADIOTAP_DATA_RETRIES) |
644 (1 << IEEE80211_RADIOTAP_RATE));
646 if (!(info->flags & IEEE80211_TX_STAT_ACK) &&
647 !is_multicast_ether_addr(hdr->addr1))
648 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL);
651 * XXX: Once radiotap gets the bitmap reset thing the vendor
652 * extensions proposal contains, we can actually report
653 * the whole set of tries we did.
655 if ((info->status.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
656 (info->status.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT))
657 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS);
658 else if (info->status.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
659 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS);
660 if (info->status.rates[0].idx >= 0 &&
661 !(info->status.rates[0].flags & IEEE80211_TX_RC_MCS))
662 rthdr->rate = sband->bitrates[
663 info->status.rates[0].idx].bitrate / 5;
665 /* for now report the total retry_count */
666 rthdr->data_retries = retry_count;
668 /* XXX: is this sufficient for BPF? */
669 skb_set_mac_header(skb, 0);
670 skb->ip_summed = CHECKSUM_UNNECESSARY;
671 skb->pkt_type = PACKET_OTHERHOST;
672 skb->protocol = htons(ETH_P_802_2);
673 memset(skb->cb, 0, sizeof(skb->cb));
676 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
677 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
678 if (!netif_running(sdata->dev))
682 skb2 = skb_clone(skb, GFP_ATOMIC);
684 skb2->dev = prev_dev;
689 prev_dev = sdata->dev;
700 EXPORT_SYMBOL(ieee80211_tx_status);
702 struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
703 const struct ieee80211_ops *ops)
705 struct ieee80211_local *local;
709 /* Ensure 32-byte alignment of our private data and hw private data.
710 * We use the wiphy priv data for both our ieee80211_local and for
711 * the driver's private data
713 * In memory it'll be like this:
715 * +-------------------------+
717 * +-------------------------+
718 * | struct ieee80211_local |
719 * +-------------------------+
720 * | driver's private data |
721 * +-------------------------+
724 priv_size = ((sizeof(struct ieee80211_local) +
725 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) +
728 wiphy = wiphy_new(&mac80211_config_ops, priv_size);
733 wiphy->privid = mac80211_wiphy_privid;
735 local = wiphy_priv(wiphy);
736 local->hw.wiphy = wiphy;
738 local->hw.priv = (char *)local +
739 ((sizeof(struct ieee80211_local) +
740 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
745 BUG_ON(!ops->config);
746 BUG_ON(!ops->add_interface);
747 BUG_ON(!ops->remove_interface);
748 BUG_ON(!ops->configure_filter);
751 /* set up some defaults */
752 local->hw.queues = 1;
753 local->hw.max_rates = 1;
754 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
755 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
756 local->hw.conf.long_frame_max_tx_count = 4;
757 local->hw.conf.short_frame_max_tx_count = 7;
758 local->hw.conf.radio_enabled = true;
760 INIT_LIST_HEAD(&local->interfaces);
761 mutex_init(&local->iflist_mtx);
763 spin_lock_init(&local->key_lock);
765 spin_lock_init(&local->queue_stop_reason_lock);
767 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
769 INIT_WORK(&local->dynamic_ps_enable_work,
770 ieee80211_dynamic_ps_enable_work);
771 INIT_WORK(&local->dynamic_ps_disable_work,
772 ieee80211_dynamic_ps_disable_work);
773 setup_timer(&local->dynamic_ps_timer,
774 ieee80211_dynamic_ps_timer, (unsigned long) local);
776 sta_info_init(local);
778 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
779 (unsigned long)local);
780 tasklet_disable(&local->tx_pending_tasklet);
782 tasklet_init(&local->tasklet,
783 ieee80211_tasklet_handler,
784 (unsigned long) local);
785 tasklet_disable(&local->tasklet);
787 skb_queue_head_init(&local->skb_queue);
788 skb_queue_head_init(&local->skb_queue_unreliable);
790 return local_to_hw(local);
792 EXPORT_SYMBOL(ieee80211_alloc_hw);
794 int ieee80211_register_hw(struct ieee80211_hw *hw)
796 struct ieee80211_local *local = hw_to_local(hw);
798 enum ieee80211_band band;
799 struct net_device *mdev;
800 struct ieee80211_master_priv *mpriv;
803 * generic code guarantees at least one band,
804 * set this very early because much code assumes
805 * that hw.conf.channel is assigned
807 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
808 struct ieee80211_supported_band *sband;
810 sband = local->hw.wiphy->bands[band];
812 /* init channel we're on */
813 local->hw.conf.channel =
814 local->oper_channel =
815 local->scan_channel = &sband->channels[0];
820 /* if low-level driver supports AP, we also support VLAN */
821 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_AP))
822 local->hw.wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
824 /* mac80211 always supports monitor */
825 local->hw.wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
827 result = wiphy_register(local->hw.wiphy);
832 * We use the number of queues for feature tests (QoS, HT) internally
833 * so restrict them appropriately.
835 if (hw->queues > IEEE80211_MAX_QUEUES)
836 hw->queues = IEEE80211_MAX_QUEUES;
837 if (hw->ampdu_queues > IEEE80211_MAX_AMPDU_QUEUES)
838 hw->ampdu_queues = IEEE80211_MAX_AMPDU_QUEUES;
840 hw->ampdu_queues = 0;
842 mdev = alloc_netdev_mq(sizeof(struct ieee80211_master_priv),
843 "wmaster%d", ether_setup,
844 ieee80211_num_queues(hw));
846 goto fail_mdev_alloc;
848 mpriv = netdev_priv(mdev);
849 mpriv->local = local;
852 ieee80211_rx_bss_list_init(local);
854 mdev->hard_start_xmit = ieee80211_master_start_xmit;
855 mdev->open = ieee80211_master_open;
856 mdev->stop = ieee80211_master_stop;
857 mdev->type = ARPHRD_IEEE80211;
858 mdev->header_ops = &ieee80211_header_ops;
859 mdev->set_multicast_list = ieee80211_master_set_multicast_list;
861 local->hw.workqueue =
862 create_singlethread_workqueue(wiphy_name(local->hw.wiphy));
863 if (!local->hw.workqueue) {
869 * The hardware needs headroom for sending the frame,
870 * and we need some headroom for passing the frame to monitor
871 * interfaces, but never both at the same time.
873 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
874 sizeof(struct ieee80211_tx_status_rtap_hdr));
876 debugfs_hw_add(local);
878 if (local->hw.conf.beacon_int < 10)
879 local->hw.conf.beacon_int = 100;
881 if (local->hw.max_listen_interval == 0)
882 local->hw.max_listen_interval = 1;
884 local->hw.conf.listen_interval = local->hw.max_listen_interval;
886 local->wstats_flags |= local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
887 IEEE80211_HW_SIGNAL_DB |
888 IEEE80211_HW_SIGNAL_DBM) ?
889 IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
890 local->wstats_flags |= local->hw.flags & IEEE80211_HW_NOISE_DBM ?
891 IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
892 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
893 local->wstats_flags |= IW_QUAL_DBM;
895 result = sta_info_start(local);
900 result = dev_alloc_name(local->mdev, local->mdev->name);
904 memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
905 SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy));
907 result = register_netdevice(local->mdev);
911 result = ieee80211_init_rate_ctrl_alg(local,
912 hw->rate_control_algorithm);
914 printk(KERN_DEBUG "%s: Failed to initialize rate control "
915 "algorithm\n", wiphy_name(local->hw.wiphy));
919 result = ieee80211_wep_init(local);
922 printk(KERN_DEBUG "%s: Failed to initialize wep: %d\n",
923 wiphy_name(local->hw.wiphy), result);
927 local->mdev->select_queue = ieee80211_select_queue;
929 /* add one default STA interface if supported */
930 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION)) {
931 result = ieee80211_if_add(local, "wlan%d", NULL,
932 NL80211_IFTYPE_STATION, NULL);
934 printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
935 wiphy_name(local->hw.wiphy));
940 ieee80211_led_init(local);
945 rate_control_deinitialize(local);
947 unregister_netdevice(local->mdev);
951 sta_info_stop(local);
953 debugfs_hw_del(local);
954 destroy_workqueue(local->hw.workqueue);
957 free_netdev(local->mdev);
959 wiphy_unregister(local->hw.wiphy);
962 EXPORT_SYMBOL(ieee80211_register_hw);
964 void ieee80211_unregister_hw(struct ieee80211_hw *hw)
966 struct ieee80211_local *local = hw_to_local(hw);
968 tasklet_kill(&local->tx_pending_tasklet);
969 tasklet_kill(&local->tasklet);
974 * At this point, interface list manipulations are fine
975 * because the driver cannot be handing us frames any
976 * more and the tasklet is killed.
979 /* First, we remove all virtual interfaces. */
980 ieee80211_remove_interfaces(local);
982 /* then, finally, remove the master interface */
983 unregister_netdevice(local->mdev);
987 ieee80211_rx_bss_list_deinit(local);
988 ieee80211_clear_tx_pending(local);
989 sta_info_stop(local);
990 rate_control_deinitialize(local);
991 debugfs_hw_del(local);
993 if (skb_queue_len(&local->skb_queue)
994 || skb_queue_len(&local->skb_queue_unreliable))
995 printk(KERN_WARNING "%s: skb_queue not empty\n",
996 wiphy_name(local->hw.wiphy));
997 skb_queue_purge(&local->skb_queue);
998 skb_queue_purge(&local->skb_queue_unreliable);
1000 destroy_workqueue(local->hw.workqueue);
1001 wiphy_unregister(local->hw.wiphy);
1002 ieee80211_wep_free(local);
1003 ieee80211_led_exit(local);
1004 free_netdev(local->mdev);
1006 EXPORT_SYMBOL(ieee80211_unregister_hw);
1008 void ieee80211_free_hw(struct ieee80211_hw *hw)
1010 struct ieee80211_local *local = hw_to_local(hw);
1012 mutex_destroy(&local->iflist_mtx);
1014 wiphy_free(local->hw.wiphy);
1016 EXPORT_SYMBOL(ieee80211_free_hw);
1018 static int __init ieee80211_init(void)
1020 struct sk_buff *skb;
1023 BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb));
1024 BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) +
1025 IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb));
1027 ret = rc80211_minstrel_init();
1031 ret = rc80211_pid_init();
1035 ieee80211_debugfs_netdev_init();
1040 static void __exit ieee80211_exit(void)
1043 rc80211_minstrel_exit();
1046 * For key todo, it'll be empty by now but the work
1047 * might still be scheduled.
1049 flush_scheduled_work();
1054 ieee80211_debugfs_netdev_exit();
1058 subsys_initcall(ieee80211_init);
1059 module_exit(ieee80211_exit);
1061 MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1062 MODULE_LICENSE("GPL");