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/cfg80211.h>
26 #include "ieee80211_common.h"
27 #include "ieee80211_i.h"
28 #include "ieee80211_rate.h"
32 #include "ieee80211_led.h"
33 #include "ieee80211_cfg.h"
35 #include "debugfs_netdev.h"
38 * For seeing transmitted packets on monitor interfaces
39 * we have a radiotap header too.
41 struct ieee80211_tx_status_rtap_hdr {
42 struct ieee80211_radiotap_header hdr;
45 } __attribute__ ((packed));
47 /* common interface routines */
49 static struct net_device_stats *ieee80211_get_stats(struct net_device *dev)
51 struct ieee80211_sub_if_data *sdata;
52 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
53 return &(sdata->stats);
56 static int header_parse_80211(struct sk_buff *skb, unsigned char *haddr)
58 memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
62 /* master interface */
64 static int ieee80211_master_open(struct net_device *dev)
66 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
67 struct ieee80211_sub_if_data *sdata;
68 int res = -EOPNOTSUPP;
70 read_lock(&local->sub_if_lock);
71 list_for_each_entry(sdata, &local->sub_if_list, list) {
72 if (sdata->dev != dev && netif_running(sdata->dev)) {
77 read_unlock(&local->sub_if_lock);
81 static int ieee80211_master_stop(struct net_device *dev)
83 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
84 struct ieee80211_sub_if_data *sdata;
86 read_lock(&local->sub_if_lock);
87 list_for_each_entry(sdata, &local->sub_if_list, list)
88 if (sdata->dev != dev && netif_running(sdata->dev))
89 dev_close(sdata->dev);
90 read_unlock(&local->sub_if_lock);
95 /* management interface */
98 ieee80211_fill_frame_info(struct ieee80211_local *local,
99 struct ieee80211_frame_info *fi,
100 struct ieee80211_rx_status *status)
104 struct ieee80211_rate *rate;
106 jiffies_to_timespec(jiffies, &ts);
107 fi->hosttime = cpu_to_be64((u64) ts.tv_sec * 1000000 +
109 fi->mactime = cpu_to_be64(status->mactime);
110 switch (status->phymode) {
111 case MODE_IEEE80211A:
112 fi->phytype = htonl(ieee80211_phytype_ofdm_dot11_a);
114 case MODE_IEEE80211B:
115 fi->phytype = htonl(ieee80211_phytype_dsss_dot11_b);
117 case MODE_IEEE80211G:
118 fi->phytype = htonl(ieee80211_phytype_pbcc_dot11_g);
120 case MODE_ATHEROS_TURBO:
122 htonl(ieee80211_phytype_dsss_dot11_turbo);
125 fi->phytype = htonl(0xAAAAAAAA);
128 fi->channel = htonl(status->channel);
129 rate = ieee80211_get_rate(local, status->phymode,
132 fi->datarate = htonl(rate->rate);
133 if (rate->flags & IEEE80211_RATE_PREAMBLE2) {
134 if (status->rate == rate->val)
135 fi->preamble = htonl(2); /* long */
136 else if (status->rate == rate->val2)
137 fi->preamble = htonl(1); /* short */
139 fi->preamble = htonl(0);
141 fi->datarate = htonl(0);
142 fi->preamble = htonl(0);
145 fi->antenna = htonl(status->antenna);
146 fi->priority = htonl(0xffffffff); /* no clue */
147 fi->ssi_type = htonl(ieee80211_ssi_raw);
148 fi->ssi_signal = htonl(status->ssi);
149 fi->ssi_noise = 0x00000000;
152 /* clear everything because we really don't know.
153 * the msg_type field isn't present on monitor frames
154 * so we don't know whether it will be present or not,
155 * but it's ok to not clear it since it'll be assigned
157 memset(fi, 0, sizeof(*fi) - sizeof(fi->msg_type));
159 fi->ssi_type = htonl(ieee80211_ssi_none);
161 fi->version = htonl(IEEE80211_FI_VERSION);
162 fi->length = cpu_to_be32(sizeof(*fi) - sizeof(fi->msg_type));
165 /* this routine is actually not just for this, but also
166 * for pushing fake 'management' frames into userspace.
167 * it shall be replaced by a netlink-based system. */
169 ieee80211_rx_mgmt(struct ieee80211_local *local, struct sk_buff *skb,
170 struct ieee80211_rx_status *status, u32 msg_type)
172 struct ieee80211_frame_info *fi;
173 const size_t hlen = sizeof(struct ieee80211_frame_info);
174 struct ieee80211_sub_if_data *sdata;
176 skb->dev = local->apdev;
178 sdata = IEEE80211_DEV_TO_SUB_IF(local->apdev);
180 if (skb_headroom(skb) < hlen) {
181 I802_DEBUG_INC(local->rx_expand_skb_head);
182 if (pskb_expand_head(skb, hlen, 0, GFP_ATOMIC)) {
188 fi = (struct ieee80211_frame_info *) skb_push(skb, hlen);
190 ieee80211_fill_frame_info(local, fi, status);
191 fi->msg_type = htonl(msg_type);
193 sdata->stats.rx_packets++;
194 sdata->stats.rx_bytes += skb->len;
196 skb_set_mac_header(skb, 0);
197 skb->ip_summed = CHECKSUM_UNNECESSARY;
198 skb->pkt_type = PACKET_OTHERHOST;
199 skb->protocol = htons(ETH_P_802_2);
200 memset(skb->cb, 0, sizeof(skb->cb));
204 void ieee80211_key_threshold_notify(struct net_device *dev,
205 struct ieee80211_key *key,
206 struct sta_info *sta)
208 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
210 struct ieee80211_msg_key_notification *msg;
212 /* if no one will get it anyway, don't even allocate it.
213 * unlikely because this is only relevant for APs
214 * where the device must be open... */
215 if (unlikely(!local->apdev))
218 skb = dev_alloc_skb(sizeof(struct ieee80211_frame_info) +
219 sizeof(struct ieee80211_msg_key_notification));
223 skb_reserve(skb, sizeof(struct ieee80211_frame_info));
224 msg = (struct ieee80211_msg_key_notification *)
225 skb_put(skb, sizeof(struct ieee80211_msg_key_notification));
226 msg->tx_rx_count = key->tx_rx_count;
227 memcpy(msg->ifname, dev->name, IFNAMSIZ);
229 memcpy(msg->addr, sta->addr, ETH_ALEN);
231 memset(msg->addr, 0xff, ETH_ALEN);
233 key->tx_rx_count = 0;
235 ieee80211_rx_mgmt(local, skb, NULL,
236 ieee80211_msg_key_threshold_notification);
239 static int ieee80211_mgmt_open(struct net_device *dev)
241 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
243 if (!netif_running(local->mdev))
248 static int ieee80211_mgmt_stop(struct net_device *dev)
253 static int ieee80211_change_mtu_apdev(struct net_device *dev, int new_mtu)
255 /* FIX: what would be proper limits for MTU?
256 * This interface uses 802.11 frames. */
257 if (new_mtu < 256 || new_mtu > IEEE80211_MAX_DATA_LEN) {
258 printk(KERN_WARNING "%s: invalid MTU %d\n",
263 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
264 printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu);
265 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
270 void ieee80211_if_mgmt_setup(struct net_device *dev)
273 dev->hard_start_xmit = ieee80211_mgmt_start_xmit;
274 dev->change_mtu = ieee80211_change_mtu_apdev;
275 dev->get_stats = ieee80211_get_stats;
276 dev->open = ieee80211_mgmt_open;
277 dev->stop = ieee80211_mgmt_stop;
278 dev->type = ARPHRD_IEEE80211_PRISM;
279 dev->hard_header_parse = header_parse_80211;
280 dev->uninit = ieee80211_if_reinit;
281 dev->destructor = ieee80211_if_free;
284 /* regular interfaces */
286 static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
288 /* FIX: what would be proper limits for MTU?
289 * This interface uses 802.3 frames. */
290 if (new_mtu < 256 || new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6) {
291 printk(KERN_WARNING "%s: invalid MTU %d\n",
296 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
297 printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu);
298 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
303 static inline int identical_mac_addr_allowed(int type1, int type2)
305 return (type1 == IEEE80211_IF_TYPE_MNTR ||
306 type2 == IEEE80211_IF_TYPE_MNTR ||
307 (type1 == IEEE80211_IF_TYPE_AP &&
308 type2 == IEEE80211_IF_TYPE_WDS) ||
309 (type1 == IEEE80211_IF_TYPE_WDS &&
310 (type2 == IEEE80211_IF_TYPE_WDS ||
311 type2 == IEEE80211_IF_TYPE_AP)) ||
312 (type1 == IEEE80211_IF_TYPE_AP &&
313 type2 == IEEE80211_IF_TYPE_VLAN) ||
314 (type1 == IEEE80211_IF_TYPE_VLAN &&
315 (type2 == IEEE80211_IF_TYPE_AP ||
316 type2 == IEEE80211_IF_TYPE_VLAN)));
319 /* Check if running monitor interfaces should go to a "soft monitor" mode
320 * and switch them if necessary. */
321 static inline void ieee80211_start_soft_monitor(struct ieee80211_local *local)
323 struct ieee80211_if_init_conf conf;
325 if (local->open_count && local->open_count == local->monitors &&
326 !(local->hw.flags & IEEE80211_HW_MONITOR_DURING_OPER) &&
327 local->ops->remove_interface) {
329 conf.type = IEEE80211_IF_TYPE_MNTR;
330 conf.mac_addr = NULL;
331 local->ops->remove_interface(local_to_hw(local), &conf);
335 /* Check if running monitor interfaces should go to a "hard monitor" mode
336 * and switch them if necessary. */
337 static void ieee80211_start_hard_monitor(struct ieee80211_local *local)
339 struct ieee80211_if_init_conf conf;
341 if (local->open_count && local->open_count == local->monitors &&
342 !(local->hw.flags & IEEE80211_HW_MONITOR_DURING_OPER)) {
344 conf.type = IEEE80211_IF_TYPE_MNTR;
345 conf.mac_addr = NULL;
346 local->ops->add_interface(local_to_hw(local), &conf);
350 static void ieee80211_if_open(struct net_device *dev)
352 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
354 switch (sdata->type) {
355 case IEEE80211_IF_TYPE_STA:
356 case IEEE80211_IF_TYPE_IBSS:
357 sdata->u.sta.prev_bssid_set = 0;
362 static int ieee80211_open(struct net_device *dev)
364 struct ieee80211_sub_if_data *sdata, *nsdata;
365 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
366 struct ieee80211_if_init_conf conf;
369 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
370 read_lock(&local->sub_if_lock);
371 list_for_each_entry(nsdata, &local->sub_if_list, list) {
372 struct net_device *ndev = nsdata->dev;
374 if (ndev != dev && ndev != local->mdev && netif_running(ndev) &&
375 compare_ether_addr(dev->dev_addr, ndev->dev_addr) == 0 &&
376 !identical_mac_addr_allowed(sdata->type, nsdata->type)) {
377 read_unlock(&local->sub_if_lock);
381 read_unlock(&local->sub_if_lock);
383 if (sdata->type == IEEE80211_IF_TYPE_WDS &&
384 is_zero_ether_addr(sdata->u.wds.remote_addr))
387 if (sdata->type == IEEE80211_IF_TYPE_MNTR && local->open_count &&
388 !(local->hw.flags & IEEE80211_HW_MONITOR_DURING_OPER)) {
389 /* run the interface in a "soft monitor" mode */
392 local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
395 ieee80211_if_open(dev);
396 ieee80211_start_soft_monitor(local);
398 conf.if_id = dev->ifindex;
399 conf.type = sdata->type;
400 if (sdata->type == IEEE80211_IF_TYPE_MNTR)
401 conf.mac_addr = NULL;
403 conf.mac_addr = dev->dev_addr;
404 res = local->ops->add_interface(local_to_hw(local), &conf);
406 if (sdata->type == IEEE80211_IF_TYPE_MNTR)
407 ieee80211_start_hard_monitor(local);
411 if (local->open_count == 0) {
413 tasklet_enable(&local->tx_pending_tasklet);
414 tasklet_enable(&local->tasklet);
415 if (local->ops->open)
416 res = local->ops->open(local_to_hw(local));
418 res = dev_open(local->mdev);
420 if (local->ops->stop)
421 local->ops->stop(local_to_hw(local));
423 res = ieee80211_hw_config(local);
424 if (res && local->ops->stop)
425 local->ops->stop(local_to_hw(local));
426 else if (!res && local->apdev)
427 dev_open(local->apdev);
431 if (local->ops->remove_interface)
432 local->ops->remove_interface(local_to_hw(local),
439 if (sdata->type == IEEE80211_IF_TYPE_MNTR) {
441 local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
443 ieee80211_if_config(dev);
444 ieee80211_reset_erp_info(dev);
447 if (sdata->type == IEEE80211_IF_TYPE_STA &&
448 !local->user_space_mlme)
449 netif_carrier_off(dev);
451 netif_carrier_on(dev);
453 netif_start_queue(dev);
457 static void ieee80211_if_shutdown(struct net_device *dev)
459 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
460 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
463 switch (sdata->type) {
464 case IEEE80211_IF_TYPE_STA:
465 case IEEE80211_IF_TYPE_IBSS:
466 sdata->u.sta.state = IEEE80211_DISABLED;
467 del_timer_sync(&sdata->u.sta.timer);
469 * Holding the sub_if_lock for writing here blocks
470 * out the receive path and makes sure it's not
471 * currently processing a packet that may get
472 * added to the queue.
474 write_lock_bh(&local->sub_if_lock);
475 skb_queue_purge(&sdata->u.sta.skb_queue);
476 write_unlock_bh(&local->sub_if_lock);
478 if (!local->ops->hw_scan &&
479 local->scan_dev == sdata->dev) {
480 local->sta_scanning = 0;
481 cancel_delayed_work(&local->scan_work);
483 flush_workqueue(local->hw.workqueue);
488 static int ieee80211_stop(struct net_device *dev)
490 struct ieee80211_sub_if_data *sdata;
491 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
493 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
495 if (sdata->type == IEEE80211_IF_TYPE_MNTR &&
496 local->open_count > 1 &&
497 !(local->hw.flags & IEEE80211_HW_MONITOR_DURING_OPER)) {
498 /* remove "soft monitor" interface */
501 if (!local->monitors)
502 local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
506 netif_stop_queue(dev);
507 ieee80211_if_shutdown(dev);
509 if (sdata->type == IEEE80211_IF_TYPE_MNTR) {
511 if (!local->monitors)
512 local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
516 if (local->open_count == 0) {
517 if (netif_running(local->mdev))
518 dev_close(local->mdev);
520 dev_close(local->apdev);
521 if (local->ops->stop)
522 local->ops->stop(local_to_hw(local));
523 tasklet_disable(&local->tx_pending_tasklet);
524 tasklet_disable(&local->tasklet);
526 if (local->ops->remove_interface) {
527 struct ieee80211_if_init_conf conf;
529 conf.if_id = dev->ifindex;
530 conf.type = sdata->type;
531 conf.mac_addr = dev->dev_addr;
532 local->ops->remove_interface(local_to_hw(local), &conf);
535 ieee80211_start_hard_monitor(local);
540 enum netif_tx_lock_class {
545 static inline void netif_tx_lock_nested(struct net_device *dev, int subclass)
547 spin_lock_nested(&dev->_xmit_lock, subclass);
548 dev->xmit_lock_owner = smp_processor_id();
551 static void ieee80211_set_multicast_list(struct net_device *dev)
553 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
554 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
555 unsigned short flags;
557 netif_tx_lock_nested(local->mdev, TX_LOCK_MASTER);
558 if (((dev->flags & IFF_ALLMULTI) != 0) ^ (sdata->allmulti != 0)) {
559 if (sdata->allmulti) {
561 local->iff_allmultis--;
564 local->iff_allmultis++;
567 if (((dev->flags & IFF_PROMISC) != 0) ^ (sdata->promisc != 0)) {
568 if (sdata->promisc) {
570 local->iff_promiscs--;
573 local->iff_promiscs++;
576 if (dev->mc_count != sdata->mc_count) {
577 local->mc_count = local->mc_count - sdata->mc_count +
579 sdata->mc_count = dev->mc_count;
581 if (local->ops->set_multicast_list) {
582 flags = local->mdev->flags;
583 if (local->iff_allmultis)
584 flags |= IFF_ALLMULTI;
585 if (local->iff_promiscs)
586 flags |= IFF_PROMISC;
587 read_lock(&local->sub_if_lock);
588 local->ops->set_multicast_list(local_to_hw(local), flags,
590 read_unlock(&local->sub_if_lock);
592 netif_tx_unlock(local->mdev);
595 /* Must not be called for mdev and apdev */
596 void ieee80211_if_setup(struct net_device *dev)
599 dev->hard_start_xmit = ieee80211_subif_start_xmit;
600 dev->wireless_handlers = &ieee80211_iw_handler_def;
601 dev->set_multicast_list = ieee80211_set_multicast_list;
602 dev->change_mtu = ieee80211_change_mtu;
603 dev->get_stats = ieee80211_get_stats;
604 dev->open = ieee80211_open;
605 dev->stop = ieee80211_stop;
606 dev->uninit = ieee80211_if_reinit;
607 dev->destructor = ieee80211_if_free;
610 /* WDS specialties */
612 int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr)
614 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
615 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
616 struct sta_info *sta;
618 if (compare_ether_addr(remote_addr, sdata->u.wds.remote_addr) == 0)
621 /* Create STA entry for the new peer */
622 sta = sta_info_add(local, dev, remote_addr, GFP_KERNEL);
627 /* Remove STA entry for the old peer */
628 sta = sta_info_get(local, sdata->u.wds.remote_addr);
633 printk(KERN_DEBUG "%s: could not find STA entry for WDS link "
634 "peer " MAC_FMT "\n",
635 dev->name, MAC_ARG(sdata->u.wds.remote_addr));
638 /* Update WDS link data */
639 memcpy(&sdata->u.wds.remote_addr, remote_addr, ETH_ALEN);
644 /* everything else */
646 static int __ieee80211_if_config(struct net_device *dev,
647 struct sk_buff *beacon,
648 struct ieee80211_tx_control *control)
650 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
651 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
652 struct ieee80211_if_conf conf;
653 static u8 scan_bssid[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
655 if (!local->ops->config_interface || !netif_running(dev))
658 memset(&conf, 0, sizeof(conf));
659 conf.type = sdata->type;
660 if (sdata->type == IEEE80211_IF_TYPE_STA ||
661 sdata->type == IEEE80211_IF_TYPE_IBSS) {
662 if (local->sta_scanning &&
663 local->scan_dev == dev)
664 conf.bssid = scan_bssid;
666 conf.bssid = sdata->u.sta.bssid;
667 conf.ssid = sdata->u.sta.ssid;
668 conf.ssid_len = sdata->u.sta.ssid_len;
669 conf.generic_elem = sdata->u.sta.extra_ie;
670 conf.generic_elem_len = sdata->u.sta.extra_ie_len;
671 } else if (sdata->type == IEEE80211_IF_TYPE_AP) {
672 conf.ssid = sdata->u.ap.ssid;
673 conf.ssid_len = sdata->u.ap.ssid_len;
674 conf.generic_elem = sdata->u.ap.generic_elem;
675 conf.generic_elem_len = sdata->u.ap.generic_elem_len;
676 conf.beacon = beacon;
677 conf.beacon_control = control;
679 return local->ops->config_interface(local_to_hw(local),
680 dev->ifindex, &conf);
683 int ieee80211_if_config(struct net_device *dev)
685 return __ieee80211_if_config(dev, NULL, NULL);
688 int ieee80211_if_config_beacon(struct net_device *dev)
690 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
691 struct ieee80211_tx_control control;
694 if (!(local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE))
696 skb = ieee80211_beacon_get(local_to_hw(local), dev->ifindex, &control);
699 return __ieee80211_if_config(dev, skb, &control);
702 int ieee80211_hw_config(struct ieee80211_local *local)
704 struct ieee80211_hw_mode *mode;
705 struct ieee80211_channel *chan;
708 if (local->sta_scanning) {
709 chan = local->scan_channel;
710 mode = local->scan_hw_mode;
712 chan = local->oper_channel;
713 mode = local->oper_hw_mode;
716 local->hw.conf.channel = chan->chan;
717 local->hw.conf.channel_val = chan->val;
718 local->hw.conf.power_level = chan->power_level;
719 local->hw.conf.freq = chan->freq;
720 local->hw.conf.phymode = mode->mode;
721 local->hw.conf.antenna_max = chan->antenna_max;
722 local->hw.conf.chan = chan;
723 local->hw.conf.mode = mode;
725 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
726 printk(KERN_DEBUG "HW CONFIG: channel=%d freq=%d "
727 "phymode=%d\n", local->hw.conf.channel, local->hw.conf.freq,
728 local->hw.conf.phymode);
729 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
731 if (local->ops->config)
732 ret = local->ops->config(local_to_hw(local), &local->hw.conf);
737 void ieee80211_erp_info_change_notify(struct net_device *dev, u8 changes)
739 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
740 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
741 if (local->ops->erp_ie_changed)
742 local->ops->erp_ie_changed(local_to_hw(local), changes,
743 sdata->use_protection,
744 !sdata->short_preamble);
747 void ieee80211_reset_erp_info(struct net_device *dev)
749 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
751 sdata->short_preamble = 0;
752 sdata->use_protection = 0;
753 ieee80211_erp_info_change_notify(dev,
754 IEEE80211_ERP_CHANGE_PROTECTION |
755 IEEE80211_ERP_CHANGE_PREAMBLE);
758 struct dev_mc_list *ieee80211_get_mc_list_item(struct ieee80211_hw *hw,
759 struct dev_mc_list *prev,
762 struct ieee80211_local *local = hw_to_local(hw);
763 struct ieee80211_sub_if_data *sdata = *ptr;
764 struct dev_mc_list *mc;
770 if (!prev || !prev->next) {
772 sdata = list_entry(sdata->list.next,
773 struct ieee80211_sub_if_data, list);
775 sdata = list_entry(local->sub_if_list.next,
776 struct ieee80211_sub_if_data, list);
777 if (&sdata->list != &local->sub_if_list)
778 mc = sdata->dev->mc_list;
787 EXPORT_SYMBOL(ieee80211_get_mc_list_item);
789 static void ieee80211_stat_refresh(unsigned long data)
791 struct ieee80211_local *local = (struct ieee80211_local *) data;
792 struct sta_info *sta;
793 struct ieee80211_sub_if_data *sdata;
795 if (!local->stat_time)
798 /* go through all stations */
799 read_lock_bh(&local->sta_lock);
800 list_for_each_entry(sta, &local->sta_list, list) {
801 sta->channel_use = (sta->channel_use_raw / local->stat_time) /
803 sta->channel_use_raw = 0;
805 read_unlock_bh(&local->sta_lock);
807 /* go through all subinterfaces */
808 read_lock(&local->sub_if_lock);
809 list_for_each_entry(sdata, &local->sub_if_list, list) {
810 sdata->channel_use = (sdata->channel_use_raw /
811 local->stat_time) / CHAN_UTIL_PER_10MS;
812 sdata->channel_use_raw = 0;
814 read_unlock(&local->sub_if_lock);
816 /* hardware interface */
817 local->channel_use = (local->channel_use_raw /
818 local->stat_time) / CHAN_UTIL_PER_10MS;
819 local->channel_use_raw = 0;
821 local->stat_timer.expires = jiffies + HZ * local->stat_time / 100;
822 add_timer(&local->stat_timer);
825 void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
827 struct ieee80211_tx_status *status)
829 struct ieee80211_local *local = hw_to_local(hw);
830 struct ieee80211_tx_status *saved;
833 skb->dev = local->mdev;
834 saved = kmalloc(sizeof(struct ieee80211_tx_status), GFP_ATOMIC);
835 if (unlikely(!saved)) {
837 printk(KERN_WARNING "%s: Not enough memory, "
838 "dropping tx status", skb->dev->name);
839 /* should be dev_kfree_skb_irq, but due to this function being
840 * named _irqsafe instead of just _irq we can't be sure that
841 * people won't call it from non-irq contexts */
842 dev_kfree_skb_any(skb);
845 memcpy(saved, status, sizeof(struct ieee80211_tx_status));
846 /* copy pointer to saved status into skb->cb for use by tasklet */
847 memcpy(skb->cb, &saved, sizeof(saved));
849 skb->pkt_type = IEEE80211_TX_STATUS_MSG;
850 skb_queue_tail(status->control.flags & IEEE80211_TXCTL_REQ_TX_STATUS ?
851 &local->skb_queue : &local->skb_queue_unreliable, skb);
852 tmp = skb_queue_len(&local->skb_queue) +
853 skb_queue_len(&local->skb_queue_unreliable);
854 while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
855 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
856 memcpy(&saved, skb->cb, sizeof(saved));
858 dev_kfree_skb_irq(skb);
860 I802_DEBUG_INC(local->tx_status_drop);
862 tasklet_schedule(&local->tasklet);
864 EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
866 static void ieee80211_tasklet_handler(unsigned long data)
868 struct ieee80211_local *local = (struct ieee80211_local *) data;
870 struct ieee80211_rx_status rx_status;
871 struct ieee80211_tx_status *tx_status;
873 while ((skb = skb_dequeue(&local->skb_queue)) ||
874 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
875 switch (skb->pkt_type) {
876 case IEEE80211_RX_MSG:
877 /* status is in skb->cb */
878 memcpy(&rx_status, skb->cb, sizeof(rx_status));
879 /* Clear skb->type in order to not confuse kernel
882 __ieee80211_rx(local_to_hw(local), skb, &rx_status);
884 case IEEE80211_TX_STATUS_MSG:
885 /* get pointer to saved status out of skb->cb */
886 memcpy(&tx_status, skb->cb, sizeof(tx_status));
888 ieee80211_tx_status(local_to_hw(local),
892 default: /* should never get here! */
893 printk(KERN_ERR "%s: Unknown message type (%d)\n",
894 local->mdev->name, skb->pkt_type);
901 /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
902 * make a prepared TX frame (one that has been given to hw) to look like brand
903 * new IEEE 802.11 frame that is ready to go through TX processing again.
904 * Also, tx_packet_data in cb is restored from tx_control. */
905 static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
906 struct ieee80211_key *key,
908 struct ieee80211_tx_control *control)
910 int hdrlen, iv_len, mic_len;
911 struct ieee80211_tx_packet_data *pkt_data;
913 pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
914 pkt_data->ifindex = control->ifindex;
915 pkt_data->mgmt_iface = (control->type == IEEE80211_IF_TYPE_MGMT);
916 pkt_data->req_tx_status = !!(control->flags & IEEE80211_TXCTL_REQ_TX_STATUS);
917 pkt_data->do_not_encrypt = !!(control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT);
918 pkt_data->requeue = !!(control->flags & IEEE80211_TXCTL_REQUEUE);
919 pkt_data->queue = control->queue;
921 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
929 mic_len = WEP_ICV_LEN;
932 iv_len = TKIP_IV_LEN;
933 mic_len = TKIP_ICV_LEN;
936 iv_len = CCMP_HDR_LEN;
937 mic_len = CCMP_MIC_LEN;
943 if (skb->len >= mic_len && key->force_sw_encrypt)
944 skb_trim(skb, skb->len - mic_len);
945 if (skb->len >= iv_len && skb->len > hdrlen) {
946 memmove(skb->data + iv_len, skb->data, hdrlen);
947 skb_pull(skb, iv_len);
952 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
953 u16 fc = le16_to_cpu(hdr->frame_control);
954 if ((fc & 0x8C) == 0x88) /* QoS Control Field */ {
955 fc &= ~IEEE80211_STYPE_QOS_DATA;
956 hdr->frame_control = cpu_to_le16(fc);
957 memmove(skb->data + 2, skb->data, hdrlen - 2);
963 void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
964 struct ieee80211_tx_status *status)
966 struct sk_buff *skb2;
967 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
968 struct ieee80211_local *local = hw_to_local(hw);
971 struct ieee80211_tx_status_rtap_hdr *rthdr;
972 struct ieee80211_sub_if_data *sdata;
977 "%s: ieee80211_tx_status called with NULL status\n",
983 if (status->excessive_retries) {
984 struct sta_info *sta;
985 sta = sta_info_get(local, hdr->addr1);
987 if (sta->flags & WLAN_STA_PS) {
988 /* The STA is in power save mode, so assume
989 * that this TX packet failed because of that.
991 status->excessive_retries = 0;
992 status->flags |= IEEE80211_TX_STATUS_TX_FILTERED;
998 if (status->flags & IEEE80211_TX_STATUS_TX_FILTERED) {
999 struct sta_info *sta;
1000 sta = sta_info_get(local, hdr->addr1);
1002 sta->tx_filtered_count++;
1004 /* Clear the TX filter mask for this STA when sending
1005 * the next packet. If the STA went to power save mode,
1006 * this will happen when it is waking up for the next
1008 sta->clear_dst_mask = 1;
1010 /* TODO: Is the WLAN_STA_PS flag always set here or is
1011 * the race between RX and TX status causing some
1012 * packets to be filtered out before 80211.o gets an
1013 * update for PS status? This seems to be the case, so
1014 * no changes are likely to be needed. */
1015 if (sta->flags & WLAN_STA_PS &&
1016 skb_queue_len(&sta->tx_filtered) <
1017 STA_MAX_TX_BUFFER) {
1018 ieee80211_remove_tx_extra(local, sta->key,
1021 skb_queue_tail(&sta->tx_filtered, skb);
1022 } else if (!(sta->flags & WLAN_STA_PS) &&
1023 !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) {
1024 /* Software retry the packet once */
1025 status->control.flags |= IEEE80211_TXCTL_REQUEUE;
1026 ieee80211_remove_tx_extra(local, sta->key,
1029 dev_queue_xmit(skb);
1031 if (net_ratelimit()) {
1032 printk(KERN_DEBUG "%s: dropped TX "
1033 "filtered frame queue_len=%d "
1038 !!(sta->flags & WLAN_STA_PS),
1047 /* FIXME: STUPID to call this with both local and local->mdev */
1048 rate_control_tx_status(local, local->mdev, skb, status);
1051 ieee80211_led_tx(local, 0);
1054 * Fragments are passed to low-level drivers as separate skbs, so these
1055 * are actually fragments, not frames. Update frame counters only for
1056 * the first fragment of the frame. */
1058 frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
1059 type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
1061 if (status->flags & IEEE80211_TX_STATUS_ACK) {
1063 local->dot11TransmittedFrameCount++;
1064 if (is_multicast_ether_addr(hdr->addr1))
1065 local->dot11MulticastTransmittedFrameCount++;
1066 if (status->retry_count > 0)
1067 local->dot11RetryCount++;
1068 if (status->retry_count > 1)
1069 local->dot11MultipleRetryCount++;
1072 /* This counter shall be incremented for an acknowledged MPDU
1073 * with an individual address in the address 1 field or an MPDU
1074 * with a multicast address in the address 1 field of type Data
1076 if (!is_multicast_ether_addr(hdr->addr1) ||
1077 type == IEEE80211_FTYPE_DATA ||
1078 type == IEEE80211_FTYPE_MGMT)
1079 local->dot11TransmittedFragmentCount++;
1082 local->dot11FailedCount++;
1085 msg_type = (status->flags & IEEE80211_TX_STATUS_ACK) ?
1086 ieee80211_msg_tx_callback_ack : ieee80211_msg_tx_callback_fail;
1088 /* this was a transmitted frame, but now we want to reuse it */
1091 if ((status->control.flags & IEEE80211_TXCTL_REQ_TX_STATUS) &&
1093 if (local->monitors) {
1094 skb2 = skb_clone(skb, GFP_ATOMIC);
1101 /* Send frame to hostapd */
1102 ieee80211_rx_mgmt(local, skb2, NULL, msg_type);
1108 if (!local->monitors) {
1113 /* send frame to monitor interfaces now */
1115 if (skb_headroom(skb) < sizeof(*rthdr)) {
1116 printk(KERN_ERR "ieee80211_tx_status: headroom too small\n");
1121 rthdr = (struct ieee80211_tx_status_rtap_hdr*)
1122 skb_push(skb, sizeof(*rthdr));
1124 memset(rthdr, 0, sizeof(*rthdr));
1125 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
1126 rthdr->hdr.it_present =
1127 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
1128 (1 << IEEE80211_RADIOTAP_DATA_RETRIES));
1130 if (!(status->flags & IEEE80211_TX_STATUS_ACK) &&
1131 !is_multicast_ether_addr(hdr->addr1))
1132 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL);
1134 if ((status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS) &&
1135 (status->control.flags & IEEE80211_TXCTL_USE_CTS_PROTECT))
1136 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS);
1137 else if (status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS)
1138 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS);
1140 rthdr->data_retries = status->retry_count;
1142 read_lock(&local->sub_if_lock);
1143 monitors = local->monitors;
1144 list_for_each_entry(sdata, &local->sub_if_list, list) {
1146 * Using the monitors counter is possibly racy, but
1147 * if the value is wrong we simply either clone the skb
1148 * once too much or forget sending it to one monitor iface
1149 * The latter case isn't nice but fixing the race is much
1152 if (!monitors || !skb)
1155 if (sdata->type == IEEE80211_IF_TYPE_MNTR) {
1156 if (!netif_running(sdata->dev))
1160 skb2 = skb_clone(skb, GFP_KERNEL);
1163 skb->dev = sdata->dev;
1164 /* XXX: is this sufficient for BPF? */
1165 skb_set_mac_header(skb, 0);
1166 skb->ip_summed = CHECKSUM_UNNECESSARY;
1167 skb->pkt_type = PACKET_OTHERHOST;
1168 skb->protocol = htons(ETH_P_802_2);
1169 memset(skb->cb, 0, sizeof(skb->cb));
1175 read_unlock(&local->sub_if_lock);
1179 EXPORT_SYMBOL(ieee80211_tx_status);
1181 struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
1182 const struct ieee80211_ops *ops)
1184 struct net_device *mdev;
1185 struct ieee80211_local *local;
1186 struct ieee80211_sub_if_data *sdata;
1188 struct wiphy *wiphy;
1190 /* Ensure 32-byte alignment of our private data and hw private data.
1191 * We use the wiphy priv data for both our ieee80211_local and for
1192 * the driver's private data
1194 * In memory it'll be like this:
1196 * +-------------------------+
1198 * +-------------------------+
1199 * | struct ieee80211_local |
1200 * +-------------------------+
1201 * | driver's private data |
1202 * +-------------------------+
1205 priv_size = ((sizeof(struct ieee80211_local) +
1206 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) +
1209 wiphy = wiphy_new(&mac80211_config_ops, priv_size);
1214 wiphy->privid = mac80211_wiphy_privid;
1216 local = wiphy_priv(wiphy);
1217 local->hw.wiphy = wiphy;
1219 local->hw.priv = (char *)local +
1220 ((sizeof(struct ieee80211_local) +
1221 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
1224 BUG_ON(!ops->config);
1225 BUG_ON(!ops->add_interface);
1228 /* for now, mdev needs sub_if_data :/ */
1229 mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
1230 "wmaster%d", ether_setup);
1236 sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
1237 mdev->ieee80211_ptr = &sdata->wdev;
1238 sdata->wdev.wiphy = wiphy;
1240 local->hw.queues = 1; /* default */
1243 local->rx_pre_handlers = ieee80211_rx_pre_handlers;
1244 local->rx_handlers = ieee80211_rx_handlers;
1245 local->tx_handlers = ieee80211_tx_handlers;
1247 local->bridge_packets = 1;
1249 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
1250 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
1251 local->short_retry_limit = 7;
1252 local->long_retry_limit = 4;
1253 local->hw.conf.radio_enabled = 1;
1255 local->enabled_modes = (unsigned int) -1;
1257 INIT_LIST_HEAD(&local->modes_list);
1259 rwlock_init(&local->sub_if_lock);
1260 INIT_LIST_HEAD(&local->sub_if_list);
1262 INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work);
1263 init_timer(&local->stat_timer);
1264 local->stat_timer.function = ieee80211_stat_refresh;
1265 local->stat_timer.data = (unsigned long) local;
1266 ieee80211_rx_bss_list_init(mdev);
1268 sta_info_init(local);
1270 mdev->hard_start_xmit = ieee80211_master_start_xmit;
1271 mdev->open = ieee80211_master_open;
1272 mdev->stop = ieee80211_master_stop;
1273 mdev->type = ARPHRD_IEEE80211;
1274 mdev->hard_header_parse = header_parse_80211;
1276 sdata->type = IEEE80211_IF_TYPE_AP;
1278 sdata->local = local;
1279 sdata->u.ap.force_unicast_rateidx = -1;
1280 sdata->u.ap.max_ratectrl_rateidx = -1;
1281 ieee80211_if_sdata_init(sdata);
1282 list_add_tail(&sdata->list, &local->sub_if_list);
1284 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
1285 (unsigned long)local);
1286 tasklet_disable(&local->tx_pending_tasklet);
1288 tasklet_init(&local->tasklet,
1289 ieee80211_tasklet_handler,
1290 (unsigned long) local);
1291 tasklet_disable(&local->tasklet);
1293 skb_queue_head_init(&local->skb_queue);
1294 skb_queue_head_init(&local->skb_queue_unreliable);
1296 return local_to_hw(local);
1298 EXPORT_SYMBOL(ieee80211_alloc_hw);
1300 int ieee80211_register_hw(struct ieee80211_hw *hw)
1302 struct ieee80211_local *local = hw_to_local(hw);
1306 result = wiphy_register(local->hw.wiphy);
1310 name = wiphy_dev(local->hw.wiphy)->driver->name;
1311 local->hw.workqueue = create_singlethread_workqueue(name);
1312 if (!local->hw.workqueue) {
1314 goto fail_workqueue;
1318 * The hardware needs headroom for sending the frame,
1319 * and we need some headroom for passing the frame to monitor
1320 * interfaces, but never both at the same time.
1322 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
1323 sizeof(struct ieee80211_tx_status_rtap_hdr));
1325 debugfs_hw_add(local);
1327 local->hw.conf.beacon_int = 1000;
1329 local->wstats_flags |= local->hw.max_rssi ?
1330 IW_QUAL_LEVEL_UPDATED : IW_QUAL_LEVEL_INVALID;
1331 local->wstats_flags |= local->hw.max_signal ?
1332 IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
1333 local->wstats_flags |= local->hw.max_noise ?
1334 IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
1335 if (local->hw.max_rssi < 0 || local->hw.max_noise < 0)
1336 local->wstats_flags |= IW_QUAL_DBM;
1338 result = sta_info_start(local);
1343 result = dev_alloc_name(local->mdev, local->mdev->name);
1347 memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
1348 SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy));
1350 result = register_netdevice(local->mdev);
1354 ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
1356 result = ieee80211_init_rate_ctrl_alg(local, NULL);
1358 printk(KERN_DEBUG "%s: Failed to initialize rate control "
1359 "algorithm\n", local->mdev->name);
1363 result = ieee80211_wep_init(local);
1366 printk(KERN_DEBUG "%s: Failed to initialize wep\n",
1371 ieee80211_install_qdisc(local->mdev);
1373 /* add one default STA interface */
1374 result = ieee80211_if_add(local->mdev, "wlan%d", NULL,
1375 IEEE80211_IF_TYPE_STA);
1377 printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
1380 local->reg_state = IEEE80211_DEV_REGISTERED;
1383 ieee80211_led_init(local);
1388 rate_control_deinitialize(local);
1390 ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
1391 unregister_netdevice(local->mdev);
1394 sta_info_stop(local);
1396 debugfs_hw_del(local);
1397 destroy_workqueue(local->hw.workqueue);
1399 wiphy_unregister(local->hw.wiphy);
1402 EXPORT_SYMBOL(ieee80211_register_hw);
1404 int ieee80211_register_hwmode(struct ieee80211_hw *hw,
1405 struct ieee80211_hw_mode *mode)
1407 struct ieee80211_local *local = hw_to_local(hw);
1408 struct ieee80211_rate *rate;
1411 INIT_LIST_HEAD(&mode->list);
1412 list_add_tail(&mode->list, &local->modes_list);
1414 local->hw_modes |= (1 << mode->mode);
1415 for (i = 0; i < mode->num_rates; i++) {
1416 rate = &(mode->rates[i]);
1417 rate->rate_inv = CHAN_UTIL_RATE_LCM / rate->rate;
1419 ieee80211_prepare_rates(local, mode);
1421 if (!local->oper_hw_mode) {
1422 /* Default to this mode */
1423 local->hw.conf.phymode = mode->mode;
1424 local->oper_hw_mode = local->scan_hw_mode = mode;
1425 local->oper_channel = local->scan_channel = &mode->channels[0];
1426 local->hw.conf.mode = local->oper_hw_mode;
1427 local->hw.conf.chan = local->oper_channel;
1430 if (!(hw->flags & IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED))
1431 ieee80211_set_default_regdomain(mode);
1435 EXPORT_SYMBOL(ieee80211_register_hwmode);
1437 void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1439 struct ieee80211_local *local = hw_to_local(hw);
1440 struct ieee80211_sub_if_data *sdata, *tmp;
1441 struct list_head tmp_list;
1444 tasklet_kill(&local->tx_pending_tasklet);
1445 tasklet_kill(&local->tasklet);
1449 BUG_ON(local->reg_state != IEEE80211_DEV_REGISTERED);
1451 local->reg_state = IEEE80211_DEV_UNREGISTERED;
1453 ieee80211_if_del_mgmt(local);
1455 write_lock_bh(&local->sub_if_lock);
1456 list_replace_init(&local->sub_if_list, &tmp_list);
1457 write_unlock_bh(&local->sub_if_lock);
1459 list_for_each_entry_safe(sdata, tmp, &tmp_list, list)
1460 __ieee80211_if_del(local, sdata);
1464 if (local->stat_time)
1465 del_timer_sync(&local->stat_timer);
1467 ieee80211_rx_bss_list_deinit(local->mdev);
1468 ieee80211_clear_tx_pending(local);
1469 sta_info_stop(local);
1470 rate_control_deinitialize(local);
1471 debugfs_hw_del(local);
1473 for (i = 0; i < NUM_IEEE80211_MODES; i++) {
1474 kfree(local->supp_rates[i]);
1475 kfree(local->basic_rates[i]);
1478 if (skb_queue_len(&local->skb_queue)
1479 || skb_queue_len(&local->skb_queue_unreliable))
1480 printk(KERN_WARNING "%s: skb_queue not empty\n",
1482 skb_queue_purge(&local->skb_queue);
1483 skb_queue_purge(&local->skb_queue_unreliable);
1485 destroy_workqueue(local->hw.workqueue);
1486 wiphy_unregister(local->hw.wiphy);
1487 ieee80211_wep_free(local);
1488 ieee80211_led_exit(local);
1490 EXPORT_SYMBOL(ieee80211_unregister_hw);
1492 void ieee80211_free_hw(struct ieee80211_hw *hw)
1494 struct ieee80211_local *local = hw_to_local(hw);
1496 ieee80211_if_free(local->mdev);
1497 wiphy_free(local->hw.wiphy);
1499 EXPORT_SYMBOL(ieee80211_free_hw);
1501 struct net_device_stats *ieee80211_dev_stats(struct net_device *dev)
1503 struct ieee80211_sub_if_data *sdata;
1504 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1505 return &sdata->stats;
1508 static int __init ieee80211_init(void)
1510 struct sk_buff *skb;
1513 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb));
1515 ret = ieee80211_wme_register();
1517 printk(KERN_DEBUG "ieee80211_init: failed to "
1518 "initialize WME (err=%d)\n", ret);
1522 ieee80211_debugfs_netdev_init();
1523 ieee80211_regdomain_init();
1528 static void __exit ieee80211_exit(void)
1530 ieee80211_wme_unregister();
1531 ieee80211_debugfs_netdev_exit();
1535 subsys_initcall(ieee80211_init);
1536 module_exit(ieee80211_exit);
1538 MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1539 MODULE_LICENSE("GPL");