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;
46 } __attribute__ ((packed));
49 /* must be called under mdev tx lock */
50 void ieee80211_configure_filter(struct ieee80211_local *local)
52 unsigned int changed_flags;
53 unsigned int new_flags = 0;
55 if (atomic_read(&local->iff_promiscs))
56 new_flags |= FIF_PROMISC_IN_BSS;
58 if (atomic_read(&local->iff_allmultis))
59 new_flags |= FIF_ALLMULTI;
62 new_flags |= FIF_BCN_PRBRESP_PROMISC;
64 if (local->fif_fcsfail)
65 new_flags |= FIF_FCSFAIL;
67 if (local->fif_plcpfail)
68 new_flags |= FIF_PLCPFAIL;
70 if (local->fif_control)
71 new_flags |= FIF_CONTROL;
73 if (local->fif_other_bss)
74 new_flags |= FIF_OTHER_BSS;
76 changed_flags = local->filter_flags ^ new_flags;
81 local->ops->configure_filter(local_to_hw(local),
82 changed_flags, &new_flags,
83 local->mdev->mc_count,
84 local->mdev->mc_list);
86 WARN_ON(new_flags & (1<<31));
88 local->filter_flags = new_flags & ~(1<<31);
91 /* master interface */
93 static int header_parse_80211(const struct sk_buff *skb, unsigned char *haddr)
95 memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
99 static const struct header_ops ieee80211_header_ops = {
100 .create = eth_header,
101 .parse = header_parse_80211,
102 .rebuild = eth_rebuild_header,
103 .cache = eth_header_cache,
104 .cache_update = eth_header_cache_update,
107 static int ieee80211_master_open(struct net_device *dev)
109 struct ieee80211_master_priv *mpriv = netdev_priv(dev);
110 struct ieee80211_local *local = mpriv->local;
111 struct ieee80211_sub_if_data *sdata;
112 int res = -EOPNOTSUPP;
114 /* we hold the RTNL here so can safely walk the list */
115 list_for_each_entry(sdata, &local->interfaces, list) {
116 if (netif_running(sdata->dev)) {
125 netif_tx_start_all_queues(local->mdev);
130 static int ieee80211_master_stop(struct net_device *dev)
132 struct ieee80211_master_priv *mpriv = netdev_priv(dev);
133 struct ieee80211_local *local = mpriv->local;
134 struct ieee80211_sub_if_data *sdata;
136 /* we hold the RTNL here so can safely walk the list */
137 list_for_each_entry(sdata, &local->interfaces, list)
138 if (netif_running(sdata->dev))
139 dev_close(sdata->dev);
144 static void ieee80211_master_set_multicast_list(struct net_device *dev)
146 struct ieee80211_master_priv *mpriv = netdev_priv(dev);
147 struct ieee80211_local *local = mpriv->local;
149 ieee80211_configure_filter(local);
152 /* everything else */
154 int ieee80211_if_config(struct ieee80211_sub_if_data *sdata, u32 changed)
156 struct ieee80211_local *local = sdata->local;
157 struct ieee80211_if_conf conf;
159 if (WARN_ON(!netif_running(sdata->dev)))
162 if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
165 if (!local->ops->config_interface)
168 memset(&conf, 0, sizeof(conf));
169 conf.changed = changed;
171 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
172 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
173 conf.bssid = sdata->u.sta.bssid;
174 conf.ssid = sdata->u.sta.ssid;
175 conf.ssid_len = sdata->u.sta.ssid_len;
176 } else if (sdata->vif.type == NL80211_IFTYPE_AP) {
177 conf.bssid = sdata->dev->dev_addr;
178 conf.ssid = sdata->u.ap.ssid;
179 conf.ssid_len = sdata->u.ap.ssid_len;
180 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
181 u8 zero[ETH_ALEN] = { 0 };
190 if (WARN_ON(!conf.bssid && (changed & IEEE80211_IFCC_BSSID)))
193 if (WARN_ON(!conf.ssid && (changed & IEEE80211_IFCC_SSID)))
196 return local->ops->config_interface(local_to_hw(local),
200 int ieee80211_hw_config(struct ieee80211_local *local)
202 struct ieee80211_channel *chan;
205 if (local->sw_scanning)
206 chan = local->scan_channel;
208 chan = local->oper_channel;
210 local->hw.conf.channel = chan;
212 if (!local->hw.conf.power_level)
213 local->hw.conf.power_level = chan->max_power;
215 local->hw.conf.power_level = min(chan->max_power,
216 local->hw.conf.power_level);
218 local->hw.conf.max_antenna_gain = chan->max_antenna_gain;
220 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
221 printk(KERN_DEBUG "%s: HW CONFIG: freq=%d\n",
222 wiphy_name(local->hw.wiphy), chan->center_freq);
225 if (local->open_count) {
226 ret = local->ops->config(local_to_hw(local), &local->hw.conf);
228 * HW reconfiguration should never fail, the driver has told
229 * us what it can support so it should live up to that promise.
238 * ieee80211_handle_ht should be used only after legacy configuration
239 * has been determined namely band, as ht configuration depends upon
240 * the hardware's HT abilities for a _specific_ band.
242 u32 ieee80211_handle_ht(struct ieee80211_local *local, int enable_ht,
243 struct ieee80211_ht_info *req_ht_cap,
244 struct ieee80211_ht_bss_info *req_bss_cap)
246 struct ieee80211_conf *conf = &local->hw.conf;
247 struct ieee80211_supported_band *sband;
248 struct ieee80211_ht_info ht_conf;
249 struct ieee80211_ht_bss_info ht_bss_conf;
252 u8 max_tx_streams = IEEE80211_HT_CAP_MAX_STREAMS;
255 sband = local->hw.wiphy->bands[conf->channel->band];
257 memset(&ht_conf, 0, sizeof(struct ieee80211_ht_info));
258 memset(&ht_bss_conf, 0, sizeof(struct ieee80211_ht_bss_info));
260 /* HT is not supported */
261 if (!sband->ht_info.ht_supported) {
262 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
268 if (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)
269 changed |= BSS_CHANGED_HT;
270 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
271 conf->ht_conf.ht_supported = 0;
276 if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE))
277 changed |= BSS_CHANGED_HT;
279 conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE;
280 ht_conf.ht_supported = 1;
282 ht_conf.cap = req_ht_cap->cap & sband->ht_info.cap;
283 ht_conf.cap &= ~(IEEE80211_HT_CAP_SM_PS);
284 ht_conf.cap |= sband->ht_info.cap & IEEE80211_HT_CAP_SM_PS;
285 ht_bss_conf.primary_channel = req_bss_cap->primary_channel;
286 ht_bss_conf.bss_cap = req_bss_cap->bss_cap;
287 ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode;
289 ht_conf.ampdu_factor = req_ht_cap->ampdu_factor;
290 ht_conf.ampdu_density = req_ht_cap->ampdu_density;
293 tx_mcs_set_cap = sband->ht_info.supp_mcs_set[12];
295 /* configure suppoerted Tx MCS according to requested MCS
296 * (based in most cases on Rx capabilities of peer) and self
297 * Tx MCS capabilities (as defined by low level driver HW
298 * Tx capabilities) */
299 if (!(tx_mcs_set_cap & IEEE80211_HT_CAP_MCS_TX_DEFINED))
302 /* Counting from 0 therfore + 1 */
303 if (tx_mcs_set_cap & IEEE80211_HT_CAP_MCS_TX_RX_DIFF)
304 max_tx_streams = ((tx_mcs_set_cap &
305 IEEE80211_HT_CAP_MCS_TX_STREAMS) >> 2) + 1;
307 for (i = 0; i < max_tx_streams; i++)
308 ht_conf.supp_mcs_set[i] =
309 sband->ht_info.supp_mcs_set[i] &
310 req_ht_cap->supp_mcs_set[i];
312 if (tx_mcs_set_cap & IEEE80211_HT_CAP_MCS_TX_UEQM)
313 for (i = IEEE80211_SUPP_MCS_SET_UEQM;
314 i < IEEE80211_SUPP_MCS_SET_LEN; i++)
315 ht_conf.supp_mcs_set[i] =
316 sband->ht_info.supp_mcs_set[i] &
317 req_ht_cap->supp_mcs_set[i];
320 /* if bss configuration changed store the new one */
321 if (memcmp(&conf->ht_conf, &ht_conf, sizeof(ht_conf)) ||
322 memcmp(&conf->ht_bss_conf, &ht_bss_conf, sizeof(ht_bss_conf))) {
323 changed |= BSS_CHANGED_HT;
324 memcpy(&conf->ht_conf, &ht_conf, sizeof(ht_conf));
325 memcpy(&conf->ht_bss_conf, &ht_bss_conf, sizeof(ht_bss_conf));
331 void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
334 struct ieee80211_local *local = sdata->local;
336 if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
342 if (local->ops->bss_info_changed)
343 local->ops->bss_info_changed(local_to_hw(local),
349 u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata)
351 sdata->bss_conf.use_cts_prot = 0;
352 sdata->bss_conf.use_short_preamble = 0;
353 return BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_ERP_PREAMBLE;
356 void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
359 struct ieee80211_local *local = hw_to_local(hw);
360 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
363 skb->dev = local->mdev;
364 skb->pkt_type = IEEE80211_TX_STATUS_MSG;
365 skb_queue_tail(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS ?
366 &local->skb_queue : &local->skb_queue_unreliable, skb);
367 tmp = skb_queue_len(&local->skb_queue) +
368 skb_queue_len(&local->skb_queue_unreliable);
369 while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
370 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
371 dev_kfree_skb_irq(skb);
373 I802_DEBUG_INC(local->tx_status_drop);
375 tasklet_schedule(&local->tasklet);
377 EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
379 static void ieee80211_tasklet_handler(unsigned long data)
381 struct ieee80211_local *local = (struct ieee80211_local *) data;
383 struct ieee80211_rx_status rx_status;
384 struct ieee80211_ra_tid *ra_tid;
386 while ((skb = skb_dequeue(&local->skb_queue)) ||
387 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
388 switch (skb->pkt_type) {
389 case IEEE80211_RX_MSG:
390 /* status is in skb->cb */
391 memcpy(&rx_status, skb->cb, sizeof(rx_status));
392 /* Clear skb->pkt_type in order to not confuse kernel
395 __ieee80211_rx(local_to_hw(local), skb, &rx_status);
397 case IEEE80211_TX_STATUS_MSG:
399 ieee80211_tx_status(local_to_hw(local), skb);
401 case IEEE80211_DELBA_MSG:
402 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
403 ieee80211_stop_tx_ba_cb(local_to_hw(local),
404 ra_tid->ra, ra_tid->tid);
407 case IEEE80211_ADDBA_MSG:
408 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
409 ieee80211_start_tx_ba_cb(local_to_hw(local),
410 ra_tid->ra, ra_tid->tid);
421 /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
422 * make a prepared TX frame (one that has been given to hw) to look like brand
423 * new IEEE 802.11 frame that is ready to go through TX processing again.
425 static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
426 struct ieee80211_key *key,
429 unsigned int hdrlen, iv_len, mic_len;
430 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
432 hdrlen = ieee80211_hdrlen(hdr->frame_control);
437 switch (key->conf.alg) {
440 mic_len = WEP_ICV_LEN;
443 iv_len = TKIP_IV_LEN;
444 mic_len = TKIP_ICV_LEN;
447 iv_len = CCMP_HDR_LEN;
448 mic_len = CCMP_MIC_LEN;
454 if (skb->len >= hdrlen + mic_len &&
455 !(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
456 skb_trim(skb, skb->len - mic_len);
457 if (skb->len >= hdrlen + iv_len) {
458 memmove(skb->data + iv_len, skb->data, hdrlen);
459 hdr = (struct ieee80211_hdr *)skb_pull(skb, iv_len);
463 if (ieee80211_is_data_qos(hdr->frame_control)) {
464 hdr->frame_control &= ~cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
465 memmove(skb->data + IEEE80211_QOS_CTL_LEN, skb->data,
466 hdrlen - IEEE80211_QOS_CTL_LEN);
467 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
471 static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
472 struct sta_info *sta,
475 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
477 sta->tx_filtered_count++;
480 * Clear the TX filter mask for this STA when sending the next
481 * packet. If the STA went to power save mode, this will happen
482 * when it wakes up for the next time.
484 set_sta_flags(sta, WLAN_STA_CLEAR_PS_FILT);
487 * This code races in the following way:
489 * (1) STA sends frame indicating it will go to sleep and does so
490 * (2) hardware/firmware adds STA to filter list, passes frame up
491 * (3) hardware/firmware processes TX fifo and suppresses a frame
492 * (4) we get TX status before having processed the frame and
493 * knowing that the STA has gone to sleep.
495 * This is actually quite unlikely even when both those events are
496 * processed from interrupts coming in quickly after one another or
497 * even at the same time because we queue both TX status events and
498 * RX frames to be processed by a tasklet and process them in the
499 * same order that they were received or TX status last. Hence, there
500 * is no race as long as the frame RX is processed before the next TX
501 * status, which drivers can ensure, see below.
503 * Note that this can only happen if the hardware or firmware can
504 * actually add STAs to the filter list, if this is done by the
505 * driver in response to set_tim() (which will only reduce the race
506 * this whole filtering tries to solve, not completely solve it)
507 * this situation cannot happen.
509 * To completely solve this race drivers need to make sure that they
510 * (a) don't mix the irq-safe/not irq-safe TX status/RX processing
512 * (b) always process RX events before TX status events if ordering
513 * can be unknown, for example with different interrupt status
516 if (test_sta_flags(sta, WLAN_STA_PS) &&
517 skb_queue_len(&sta->tx_filtered) < STA_MAX_TX_BUFFER) {
518 ieee80211_remove_tx_extra(local, sta->key, skb);
519 skb_queue_tail(&sta->tx_filtered, skb);
523 if (!test_sta_flags(sta, WLAN_STA_PS) &&
524 !(info->flags & IEEE80211_TX_CTL_REQUEUE)) {
525 /* Software retry the packet once */
526 info->flags |= IEEE80211_TX_CTL_REQUEUE;
527 ieee80211_remove_tx_extra(local, sta->key, skb);
532 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
534 printk(KERN_DEBUG "%s: dropped TX filtered frame, "
535 "queue_len=%d PS=%d @%lu\n",
536 wiphy_name(local->hw.wiphy),
537 skb_queue_len(&sta->tx_filtered),
538 !!test_sta_flags(sta, WLAN_STA_PS), jiffies);
543 void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
545 struct sk_buff *skb2;
546 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
547 struct ieee80211_local *local = hw_to_local(hw);
548 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
551 struct ieee80211_supported_band *sband;
552 struct ieee80211_tx_status_rtap_hdr *rthdr;
553 struct ieee80211_sub_if_data *sdata;
554 struct net_device *prev_dev = NULL;
555 struct sta_info *sta;
559 sta = sta_info_get(local, hdr->addr1);
562 if (info->status.excessive_retries &&
563 test_sta_flags(sta, WLAN_STA_PS)) {
565 * The STA is in power save mode, so assume
566 * that this TX packet failed because of that.
568 ieee80211_handle_filtered_frame(local, sta, skb);
573 fc = hdr->frame_control;
575 if ((info->flags & IEEE80211_TX_STAT_AMPDU_NO_BACK) &&
576 (ieee80211_is_data_qos(fc))) {
580 qc = ieee80211_get_qos_ctl(hdr);
582 ssn = ((le16_to_cpu(hdr->seq_ctrl) + 0x10)
583 & IEEE80211_SCTL_SEQ);
584 ieee80211_send_bar(sta->sdata, hdr->addr1,
588 if (info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
589 ieee80211_handle_filtered_frame(local, sta, skb);
593 if (info->status.excessive_retries)
594 sta->tx_retry_failed++;
595 sta->tx_retry_count += info->status.retry_count;
598 sband = local->hw.wiphy->bands[info->band];
599 rate_control_tx_status(local, sband, sta, skb);
604 ieee80211_led_tx(local, 0);
607 * Fragments are passed to low-level drivers as separate skbs, so these
608 * are actually fragments, not frames. Update frame counters only for
609 * the first fragment of the frame. */
611 frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
612 type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
614 if (info->flags & IEEE80211_TX_STAT_ACK) {
616 local->dot11TransmittedFrameCount++;
617 if (is_multicast_ether_addr(hdr->addr1))
618 local->dot11MulticastTransmittedFrameCount++;
619 if (info->status.retry_count > 0)
620 local->dot11RetryCount++;
621 if (info->status.retry_count > 1)
622 local->dot11MultipleRetryCount++;
625 /* This counter shall be incremented for an acknowledged MPDU
626 * with an individual address in the address 1 field or an MPDU
627 * with a multicast address in the address 1 field of type Data
629 if (!is_multicast_ether_addr(hdr->addr1) ||
630 type == IEEE80211_FTYPE_DATA ||
631 type == IEEE80211_FTYPE_MGMT)
632 local->dot11TransmittedFragmentCount++;
635 local->dot11FailedCount++;
638 /* this was a transmitted frame, but now we want to reuse it */
642 * This is a bit racy but we can avoid a lot of work
645 if (!local->monitors && !local->cooked_mntrs) {
650 /* send frame to monitor interfaces now */
652 if (skb_headroom(skb) < sizeof(*rthdr)) {
653 printk(KERN_ERR "ieee80211_tx_status: headroom too small\n");
658 rthdr = (struct ieee80211_tx_status_rtap_hdr *)
659 skb_push(skb, sizeof(*rthdr));
661 memset(rthdr, 0, sizeof(*rthdr));
662 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
663 rthdr->hdr.it_present =
664 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
665 (1 << IEEE80211_RADIOTAP_DATA_RETRIES));
667 if (!(info->flags & IEEE80211_TX_STAT_ACK) &&
668 !is_multicast_ether_addr(hdr->addr1))
669 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL);
671 if ((info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) &&
672 (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT))
673 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS);
674 else if (info->flags & IEEE80211_TX_CTL_USE_RTS_CTS)
675 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS);
677 rthdr->data_retries = info->status.retry_count;
679 /* XXX: is this sufficient for BPF? */
680 skb_set_mac_header(skb, 0);
681 skb->ip_summed = CHECKSUM_UNNECESSARY;
682 skb->pkt_type = PACKET_OTHERHOST;
683 skb->protocol = htons(ETH_P_802_2);
684 memset(skb->cb, 0, sizeof(skb->cb));
687 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
688 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
689 if (!netif_running(sdata->dev))
693 skb2 = skb_clone(skb, GFP_ATOMIC);
695 skb2->dev = prev_dev;
700 prev_dev = sdata->dev;
711 EXPORT_SYMBOL(ieee80211_tx_status);
713 struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
714 const struct ieee80211_ops *ops)
716 struct ieee80211_local *local;
720 /* Ensure 32-byte alignment of our private data and hw private data.
721 * We use the wiphy priv data for both our ieee80211_local and for
722 * the driver's private data
724 * In memory it'll be like this:
726 * +-------------------------+
728 * +-------------------------+
729 * | struct ieee80211_local |
730 * +-------------------------+
731 * | driver's private data |
732 * +-------------------------+
735 priv_size = ((sizeof(struct ieee80211_local) +
736 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) +
739 wiphy = wiphy_new(&mac80211_config_ops, priv_size);
744 wiphy->privid = mac80211_wiphy_privid;
746 local = wiphy_priv(wiphy);
747 local->hw.wiphy = wiphy;
749 local->hw.priv = (char *)local +
750 ((sizeof(struct ieee80211_local) +
751 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
756 BUG_ON(!ops->config);
757 BUG_ON(!ops->add_interface);
758 BUG_ON(!ops->remove_interface);
759 BUG_ON(!ops->configure_filter);
762 local->hw.queues = 1; /* default */
764 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
765 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
766 local->short_retry_limit = 7;
767 local->long_retry_limit = 4;
768 local->hw.conf.radio_enabled = 1;
770 INIT_LIST_HEAD(&local->interfaces);
772 spin_lock_init(&local->key_lock);
774 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
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);
799 enum ieee80211_band band;
800 struct net_device *mdev;
801 struct ieee80211_master_priv *mpriv;
804 * generic code guarantees at least one band,
805 * set this very early because much code assumes
806 * that hw.conf.channel is assigned
808 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
809 struct ieee80211_supported_band *sband;
811 sband = local->hw.wiphy->bands[band];
813 /* init channel we're on */
814 local->hw.conf.channel =
815 local->oper_channel =
816 local->scan_channel = &sband->channels[0];
821 /* if low-level driver supports AP, we also support VLAN */
822 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_AP))
823 local->hw.wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
825 /* mac80211 always supports monitor */
826 local->hw.wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
828 result = wiphy_register(local->hw.wiphy);
833 * We use the number of queues for feature tests (QoS, HT) internally
834 * so restrict them appropriately.
836 if (hw->queues > IEEE80211_MAX_QUEUES)
837 hw->queues = IEEE80211_MAX_QUEUES;
838 if (hw->ampdu_queues > IEEE80211_MAX_AMPDU_QUEUES)
839 hw->ampdu_queues = IEEE80211_MAX_AMPDU_QUEUES;
841 hw->ampdu_queues = 0;
843 mdev = alloc_netdev_mq(sizeof(struct ieee80211_master_priv),
844 "wmaster%d", ether_setup,
845 ieee80211_num_queues(hw));
847 goto fail_mdev_alloc;
849 mpriv = netdev_priv(mdev);
850 mpriv->local = local;
853 ieee80211_rx_bss_list_init(local);
855 mdev->hard_start_xmit = ieee80211_master_start_xmit;
856 mdev->open = ieee80211_master_open;
857 mdev->stop = ieee80211_master_stop;
858 mdev->type = ARPHRD_IEEE80211;
859 mdev->header_ops = &ieee80211_header_ops;
860 mdev->set_multicast_list = ieee80211_master_set_multicast_list;
862 name = wiphy_dev(local->hw.wiphy)->driver->name;
863 local->hw.workqueue = create_freezeable_workqueue(name);
864 if (!local->hw.workqueue) {
870 * The hardware needs headroom for sending the frame,
871 * and we need some headroom for passing the frame to monitor
872 * interfaces, but never both at the same time.
874 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
875 sizeof(struct ieee80211_tx_status_rtap_hdr));
877 debugfs_hw_add(local);
879 if (local->hw.conf.beacon_int < 10)
880 local->hw.conf.beacon_int = 100;
882 if (local->hw.max_listen_interval == 0)
883 local->hw.max_listen_interval = 1;
885 local->hw.conf.listen_interval = local->hw.max_listen_interval;
887 local->wstats_flags |= local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
888 IEEE80211_HW_SIGNAL_DB |
889 IEEE80211_HW_SIGNAL_DBM) ?
890 IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
891 local->wstats_flags |= local->hw.flags & IEEE80211_HW_NOISE_DBM ?
892 IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
893 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
894 local->wstats_flags |= IW_QUAL_DBM;
896 result = sta_info_start(local);
901 result = dev_alloc_name(local->mdev, local->mdev->name);
905 memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
906 SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy));
908 result = register_netdevice(local->mdev);
912 result = ieee80211_init_rate_ctrl_alg(local,
913 hw->rate_control_algorithm);
915 printk(KERN_DEBUG "%s: Failed to initialize rate control "
916 "algorithm\n", wiphy_name(local->hw.wiphy));
920 result = ieee80211_wep_init(local);
923 printk(KERN_DEBUG "%s: Failed to initialize wep: %d\n",
924 wiphy_name(local->hw.wiphy), result);
928 local->mdev->select_queue = ieee80211_select_queue;
930 /* add one default STA interface */
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));
939 ieee80211_led_init(local);
944 rate_control_deinitialize(local);
946 unregister_netdevice(local->mdev);
950 sta_info_stop(local);
952 debugfs_hw_del(local);
953 destroy_workqueue(local->hw.workqueue);
956 free_netdev(local->mdev);
958 wiphy_unregister(local->hw.wiphy);
961 EXPORT_SYMBOL(ieee80211_register_hw);
963 void ieee80211_unregister_hw(struct ieee80211_hw *hw)
965 struct ieee80211_local *local = hw_to_local(hw);
967 tasklet_kill(&local->tx_pending_tasklet);
968 tasklet_kill(&local->tasklet);
973 * At this point, interface list manipulations are fine
974 * because the driver cannot be handing us frames any
975 * more and the tasklet is killed.
978 /* First, we remove all virtual interfaces. */
979 ieee80211_remove_interfaces(local);
981 /* then, finally, remove the master interface */
982 unregister_netdevice(local->mdev);
986 ieee80211_rx_bss_list_deinit(local);
987 ieee80211_clear_tx_pending(local);
988 sta_info_stop(local);
989 rate_control_deinitialize(local);
990 debugfs_hw_del(local);
992 if (skb_queue_len(&local->skb_queue)
993 || skb_queue_len(&local->skb_queue_unreliable))
994 printk(KERN_WARNING "%s: skb_queue not empty\n",
995 wiphy_name(local->hw.wiphy));
996 skb_queue_purge(&local->skb_queue);
997 skb_queue_purge(&local->skb_queue_unreliable);
999 destroy_workqueue(local->hw.workqueue);
1000 wiphy_unregister(local->hw.wiphy);
1001 ieee80211_wep_free(local);
1002 ieee80211_led_exit(local);
1003 free_netdev(local->mdev);
1005 EXPORT_SYMBOL(ieee80211_unregister_hw);
1007 void ieee80211_free_hw(struct ieee80211_hw *hw)
1009 struct ieee80211_local *local = hw_to_local(hw);
1011 wiphy_free(local->hw.wiphy);
1013 EXPORT_SYMBOL(ieee80211_free_hw);
1015 static int __init ieee80211_init(void)
1017 struct sk_buff *skb;
1020 BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb));
1021 BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) +
1022 IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb));
1024 ret = rc80211_minstrel_init();
1028 ret = rc80211_pid_init();
1032 ieee80211_debugfs_netdev_init();
1037 static void __exit ieee80211_exit(void)
1040 rc80211_minstrel_exit();
1043 * For key todo, it'll be empty by now but the work
1044 * might still be scheduled.
1046 flush_scheduled_work();
1051 ieee80211_debugfs_netdev_exit();
1055 subsys_initcall(ieee80211_init);
1056 module_exit(ieee80211_exit);
1058 MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1059 MODULE_LICENSE("GPL");