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_i.h"
27 #include "ieee80211_rate.h"
31 #include "ieee80211_led.h"
34 #include "debugfs_netdev.h"
37 * For seeing transmitted packets on monitor interfaces
38 * we have a radiotap header too.
40 struct ieee80211_tx_status_rtap_hdr {
41 struct ieee80211_radiotap_header hdr;
44 } __attribute__ ((packed));
46 /* common interface routines */
48 static int header_parse_80211(struct sk_buff *skb, unsigned char *haddr)
50 memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
54 /* must be called under mdev tx lock */
55 static void ieee80211_configure_filter(struct ieee80211_local *local)
57 unsigned int changed_flags;
58 unsigned int new_flags = 0;
60 if (atomic_read(&local->iff_promiscs))
61 new_flags |= FIF_PROMISC_IN_BSS;
63 if (atomic_read(&local->iff_allmultis))
64 new_flags |= FIF_ALLMULTI;
67 new_flags |= FIF_CONTROL |
69 FIF_BCN_PRBRESP_PROMISC;
71 changed_flags = local->filter_flags ^ new_flags;
76 local->ops->configure_filter(local_to_hw(local),
77 changed_flags, &new_flags,
78 local->mdev->mc_count,
79 local->mdev->mc_list);
81 WARN_ON(new_flags & (1<<31));
83 local->filter_flags = new_flags & ~(1<<31);
86 /* master interface */
88 static int ieee80211_master_open(struct net_device *dev)
90 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
91 struct ieee80211_sub_if_data *sdata;
92 int res = -EOPNOTSUPP;
94 /* we hold the RTNL here so can safely walk the list */
95 list_for_each_entry(sdata, &local->interfaces, list) {
96 if (sdata->dev != dev && netif_running(sdata->dev)) {
104 static int ieee80211_master_stop(struct net_device *dev)
106 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
107 struct ieee80211_sub_if_data *sdata;
109 /* we hold the RTNL here so can safely walk the list */
110 list_for_each_entry(sdata, &local->interfaces, list)
111 if (sdata->dev != dev && netif_running(sdata->dev))
112 dev_close(sdata->dev);
117 static void ieee80211_master_set_multicast_list(struct net_device *dev)
119 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
121 ieee80211_configure_filter(local);
124 /* regular interfaces */
126 static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
128 /* FIX: what would be proper limits for MTU?
129 * This interface uses 802.3 frames. */
130 if (new_mtu < 256 || new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6) {
131 printk(KERN_WARNING "%s: invalid MTU %d\n",
136 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
137 printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu);
138 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
143 static inline int identical_mac_addr_allowed(int type1, int type2)
145 return (type1 == IEEE80211_IF_TYPE_MNTR ||
146 type2 == IEEE80211_IF_TYPE_MNTR ||
147 (type1 == IEEE80211_IF_TYPE_AP &&
148 type2 == IEEE80211_IF_TYPE_WDS) ||
149 (type1 == IEEE80211_IF_TYPE_WDS &&
150 (type2 == IEEE80211_IF_TYPE_WDS ||
151 type2 == IEEE80211_IF_TYPE_AP)) ||
152 (type1 == IEEE80211_IF_TYPE_AP &&
153 type2 == IEEE80211_IF_TYPE_VLAN) ||
154 (type1 == IEEE80211_IF_TYPE_VLAN &&
155 (type2 == IEEE80211_IF_TYPE_AP ||
156 type2 == IEEE80211_IF_TYPE_VLAN)));
159 static int ieee80211_open(struct net_device *dev)
161 struct ieee80211_sub_if_data *sdata, *nsdata;
162 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
163 struct ieee80211_if_init_conf conf;
166 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
168 /* we hold the RTNL here so can safely walk the list */
169 list_for_each_entry(nsdata, &local->interfaces, list) {
170 struct net_device *ndev = nsdata->dev;
172 if (ndev != dev && ndev != local->mdev && netif_running(ndev) &&
173 compare_ether_addr(dev->dev_addr, ndev->dev_addr) == 0) {
175 * check whether it may have the same address
177 if (!identical_mac_addr_allowed(sdata->type,
182 * can only add VLANs to enabled APs
184 if (sdata->type == IEEE80211_IF_TYPE_VLAN &&
185 nsdata->type == IEEE80211_IF_TYPE_AP &&
186 netif_running(nsdata->dev))
187 sdata->u.vlan.ap = nsdata;
191 switch (sdata->type) {
192 case IEEE80211_IF_TYPE_WDS:
193 if (is_zero_ether_addr(sdata->u.wds.remote_addr))
196 case IEEE80211_IF_TYPE_VLAN:
197 if (!sdata->u.vlan.ap)
200 case IEEE80211_IF_TYPE_AP:
201 case IEEE80211_IF_TYPE_STA:
202 case IEEE80211_IF_TYPE_MNTR:
203 case IEEE80211_IF_TYPE_IBSS:
204 /* no special treatment */
206 case IEEE80211_IF_TYPE_INVALID:
212 if (local->open_count == 0) {
214 if (local->ops->start)
215 res = local->ops->start(local_to_hw(local));
220 switch (sdata->type) {
221 case IEEE80211_IF_TYPE_VLAN:
222 list_add(&sdata->u.vlan.list, &sdata->u.vlan.ap->u.ap.vlans);
223 /* no need to tell driver */
225 case IEEE80211_IF_TYPE_MNTR:
226 /* must be before the call to ieee80211_configure_filter */
228 if (local->monitors == 1) {
229 netif_tx_lock_bh(local->mdev);
230 ieee80211_configure_filter(local);
231 netif_tx_unlock_bh(local->mdev);
233 local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
234 ieee80211_hw_config(local);
237 case IEEE80211_IF_TYPE_STA:
238 case IEEE80211_IF_TYPE_IBSS:
239 sdata->u.sta.flags &= ~IEEE80211_STA_PREV_BSSID_SET;
242 conf.if_id = dev->ifindex;
243 conf.type = sdata->type;
244 conf.mac_addr = dev->dev_addr;
245 res = local->ops->add_interface(local_to_hw(local), &conf);
246 if (res && !local->open_count && local->ops->stop)
247 local->ops->stop(local_to_hw(local));
251 ieee80211_if_config(dev);
252 ieee80211_reset_erp_info(dev);
253 ieee80211_enable_keys(sdata);
255 if (sdata->type == IEEE80211_IF_TYPE_STA &&
256 !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME))
257 netif_carrier_off(dev);
259 netif_carrier_on(dev);
262 if (local->open_count == 0) {
263 res = dev_open(local->mdev);
265 tasklet_enable(&local->tx_pending_tasklet);
266 tasklet_enable(&local->tasklet);
271 netif_start_queue(dev);
276 static int ieee80211_stop(struct net_device *dev)
278 struct ieee80211_sub_if_data *sdata;
279 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
280 struct ieee80211_if_init_conf conf;
282 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
284 netif_stop_queue(dev);
286 dev_mc_unsync(local->mdev, dev);
288 /* down all dependent devices, that is VLANs */
289 if (sdata->type == IEEE80211_IF_TYPE_AP) {
290 struct ieee80211_sub_if_data *vlan, *tmp;
292 list_for_each_entry_safe(vlan, tmp, &sdata->u.ap.vlans,
294 dev_close(vlan->dev);
295 WARN_ON(!list_empty(&sdata->u.ap.vlans));
300 switch (sdata->type) {
301 case IEEE80211_IF_TYPE_VLAN:
302 list_del(&sdata->u.vlan.list);
303 sdata->u.vlan.ap = NULL;
304 /* no need to tell driver */
306 case IEEE80211_IF_TYPE_MNTR:
308 if (local->monitors == 0) {
309 netif_tx_lock_bh(local->mdev);
310 ieee80211_configure_filter(local);
311 netif_tx_unlock_bh(local->mdev);
313 local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
314 ieee80211_hw_config(local);
317 case IEEE80211_IF_TYPE_STA:
318 case IEEE80211_IF_TYPE_IBSS:
319 sdata->u.sta.state = IEEE80211_DISABLED;
320 del_timer_sync(&sdata->u.sta.timer);
322 * When we get here, the interface is marked down.
323 * Call synchronize_rcu() to wait for the RX path
324 * should it be using the interface and enqueuing
325 * frames at this very time on another CPU.
328 skb_queue_purge(&sdata->u.sta.skb_queue);
330 if (!local->ops->hw_scan &&
331 local->scan_dev == sdata->dev) {
332 local->sta_scanning = 0;
333 cancel_delayed_work(&local->scan_work);
335 flush_workqueue(local->hw.workqueue);
338 conf.if_id = dev->ifindex;
339 conf.type = sdata->type;
340 conf.mac_addr = dev->dev_addr;
341 /* disable all keys for as long as this netdev is down */
342 ieee80211_disable_keys(sdata);
343 local->ops->remove_interface(local_to_hw(local), &conf);
346 if (local->open_count == 0) {
347 if (netif_running(local->mdev))
348 dev_close(local->mdev);
350 if (local->ops->stop)
351 local->ops->stop(local_to_hw(local));
353 tasklet_disable(&local->tx_pending_tasklet);
354 tasklet_disable(&local->tasklet);
360 static void ieee80211_set_multicast_list(struct net_device *dev)
362 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
363 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
364 int allmulti, promisc, sdata_allmulti, sdata_promisc;
366 allmulti = !!(dev->flags & IFF_ALLMULTI);
367 promisc = !!(dev->flags & IFF_PROMISC);
368 sdata_allmulti = sdata->flags & IEEE80211_SDATA_ALLMULTI;
369 sdata_promisc = sdata->flags & IEEE80211_SDATA_PROMISC;
371 if (allmulti != sdata_allmulti) {
372 if (dev->flags & IFF_ALLMULTI)
373 atomic_inc(&local->iff_allmultis);
375 atomic_dec(&local->iff_allmultis);
376 sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
379 if (promisc != sdata_promisc) {
380 if (dev->flags & IFF_PROMISC)
381 atomic_inc(&local->iff_promiscs);
383 atomic_dec(&local->iff_promiscs);
384 sdata->flags ^= IEEE80211_SDATA_PROMISC;
387 dev_mc_sync(local->mdev, dev);
390 /* Must not be called for mdev */
391 void ieee80211_if_setup(struct net_device *dev)
394 dev->hard_start_xmit = ieee80211_subif_start_xmit;
395 dev->wireless_handlers = &ieee80211_iw_handler_def;
396 dev->set_multicast_list = ieee80211_set_multicast_list;
397 dev->change_mtu = ieee80211_change_mtu;
398 dev->open = ieee80211_open;
399 dev->stop = ieee80211_stop;
400 dev->destructor = ieee80211_if_free;
403 /* WDS specialties */
405 int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr)
407 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
408 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
409 struct sta_info *sta;
411 if (compare_ether_addr(remote_addr, sdata->u.wds.remote_addr) == 0)
414 /* Create STA entry for the new peer */
415 sta = sta_info_add(local, dev, remote_addr, GFP_KERNEL);
420 /* Remove STA entry for the old peer */
421 sta = sta_info_get(local, sdata->u.wds.remote_addr);
426 printk(KERN_DEBUG "%s: could not find STA entry for WDS link "
427 "peer " MAC_FMT "\n",
428 dev->name, MAC_ARG(sdata->u.wds.remote_addr));
431 /* Update WDS link data */
432 memcpy(&sdata->u.wds.remote_addr, remote_addr, ETH_ALEN);
437 /* everything else */
439 static int __ieee80211_if_config(struct net_device *dev,
440 struct sk_buff *beacon,
441 struct ieee80211_tx_control *control)
443 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
444 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
445 struct ieee80211_if_conf conf;
447 if (!local->ops->config_interface || !netif_running(dev))
450 memset(&conf, 0, sizeof(conf));
451 conf.type = sdata->type;
452 if (sdata->type == IEEE80211_IF_TYPE_STA ||
453 sdata->type == IEEE80211_IF_TYPE_IBSS) {
454 conf.bssid = sdata->u.sta.bssid;
455 conf.ssid = sdata->u.sta.ssid;
456 conf.ssid_len = sdata->u.sta.ssid_len;
457 } else if (sdata->type == IEEE80211_IF_TYPE_AP) {
458 conf.ssid = sdata->u.ap.ssid;
459 conf.ssid_len = sdata->u.ap.ssid_len;
460 conf.beacon = beacon;
461 conf.beacon_control = control;
463 return local->ops->config_interface(local_to_hw(local),
464 dev->ifindex, &conf);
467 int ieee80211_if_config(struct net_device *dev)
469 return __ieee80211_if_config(dev, NULL, NULL);
472 int ieee80211_if_config_beacon(struct net_device *dev)
474 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
475 struct ieee80211_tx_control control;
478 if (!(local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE))
480 skb = ieee80211_beacon_get(local_to_hw(local), dev->ifindex, &control);
483 return __ieee80211_if_config(dev, skb, &control);
486 int ieee80211_hw_config(struct ieee80211_local *local)
488 struct ieee80211_hw_mode *mode;
489 struct ieee80211_channel *chan;
492 if (local->sta_scanning) {
493 chan = local->scan_channel;
494 mode = local->scan_hw_mode;
496 chan = local->oper_channel;
497 mode = local->oper_hw_mode;
500 local->hw.conf.channel = chan->chan;
501 local->hw.conf.channel_val = chan->val;
502 if (!local->hw.conf.power_level) {
503 local->hw.conf.power_level = chan->power_level;
505 local->hw.conf.power_level = min(chan->power_level,
506 local->hw.conf.power_level);
508 local->hw.conf.freq = chan->freq;
509 local->hw.conf.phymode = mode->mode;
510 local->hw.conf.antenna_max = chan->antenna_max;
511 local->hw.conf.chan = chan;
512 local->hw.conf.mode = mode;
514 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
515 printk(KERN_DEBUG "HW CONFIG: channel=%d freq=%d "
516 "phymode=%d\n", local->hw.conf.channel, local->hw.conf.freq,
517 local->hw.conf.phymode);
518 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
520 if (local->open_count)
521 ret = local->ops->config(local_to_hw(local), &local->hw.conf);
526 void ieee80211_erp_info_change_notify(struct net_device *dev, u8 changes)
528 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
529 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
530 if (local->ops->erp_ie_changed)
531 local->ops->erp_ie_changed(local_to_hw(local), changes,
532 !!(sdata->flags & IEEE80211_SDATA_USE_PROTECTION),
533 !(sdata->flags & IEEE80211_SDATA_SHORT_PREAMBLE));
536 void ieee80211_reset_erp_info(struct net_device *dev)
538 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
540 sdata->flags &= ~(IEEE80211_SDATA_USE_PROTECTION |
541 IEEE80211_SDATA_SHORT_PREAMBLE);
542 ieee80211_erp_info_change_notify(dev,
543 IEEE80211_ERP_CHANGE_PROTECTION |
544 IEEE80211_ERP_CHANGE_PREAMBLE);
547 void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
549 struct ieee80211_tx_status *status)
551 struct ieee80211_local *local = hw_to_local(hw);
552 struct ieee80211_tx_status *saved;
555 skb->dev = local->mdev;
556 saved = kmalloc(sizeof(struct ieee80211_tx_status), GFP_ATOMIC);
557 if (unlikely(!saved)) {
559 printk(KERN_WARNING "%s: Not enough memory, "
560 "dropping tx status", skb->dev->name);
561 /* should be dev_kfree_skb_irq, but due to this function being
562 * named _irqsafe instead of just _irq we can't be sure that
563 * people won't call it from non-irq contexts */
564 dev_kfree_skb_any(skb);
567 memcpy(saved, status, sizeof(struct ieee80211_tx_status));
568 /* copy pointer to saved status into skb->cb for use by tasklet */
569 memcpy(skb->cb, &saved, sizeof(saved));
571 skb->pkt_type = IEEE80211_TX_STATUS_MSG;
572 skb_queue_tail(status->control.flags & IEEE80211_TXCTL_REQ_TX_STATUS ?
573 &local->skb_queue : &local->skb_queue_unreliable, skb);
574 tmp = skb_queue_len(&local->skb_queue) +
575 skb_queue_len(&local->skb_queue_unreliable);
576 while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
577 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
578 memcpy(&saved, skb->cb, sizeof(saved));
580 dev_kfree_skb_irq(skb);
582 I802_DEBUG_INC(local->tx_status_drop);
584 tasklet_schedule(&local->tasklet);
586 EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
588 static void ieee80211_tasklet_handler(unsigned long data)
590 struct ieee80211_local *local = (struct ieee80211_local *) data;
592 struct ieee80211_rx_status rx_status;
593 struct ieee80211_tx_status *tx_status;
595 while ((skb = skb_dequeue(&local->skb_queue)) ||
596 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
597 switch (skb->pkt_type) {
598 case IEEE80211_RX_MSG:
599 /* status is in skb->cb */
600 memcpy(&rx_status, skb->cb, sizeof(rx_status));
601 /* Clear skb->type in order to not confuse kernel
604 __ieee80211_rx(local_to_hw(local), skb, &rx_status);
606 case IEEE80211_TX_STATUS_MSG:
607 /* get pointer to saved status out of skb->cb */
608 memcpy(&tx_status, skb->cb, sizeof(tx_status));
610 ieee80211_tx_status(local_to_hw(local),
614 default: /* should never get here! */
615 printk(KERN_ERR "%s: Unknown message type (%d)\n",
616 wiphy_name(local->hw.wiphy), skb->pkt_type);
623 /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
624 * make a prepared TX frame (one that has been given to hw) to look like brand
625 * new IEEE 802.11 frame that is ready to go through TX processing again.
626 * Also, tx_packet_data in cb is restored from tx_control. */
627 static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
628 struct ieee80211_key *key,
630 struct ieee80211_tx_control *control)
632 int hdrlen, iv_len, mic_len;
633 struct ieee80211_tx_packet_data *pkt_data;
635 pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
636 pkt_data->ifindex = control->ifindex;
638 if (control->flags & IEEE80211_TXCTL_REQ_TX_STATUS)
639 pkt_data->flags |= IEEE80211_TXPD_REQ_TX_STATUS;
640 if (control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)
641 pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT;
642 if (control->flags & IEEE80211_TXCTL_REQUEUE)
643 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
644 pkt_data->queue = control->queue;
646 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
651 switch (key->conf.alg) {
654 mic_len = WEP_ICV_LEN;
657 iv_len = TKIP_IV_LEN;
658 mic_len = TKIP_ICV_LEN;
661 iv_len = CCMP_HDR_LEN;
662 mic_len = CCMP_MIC_LEN;
668 if (skb->len >= mic_len &&
669 !(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
670 skb_trim(skb, skb->len - mic_len);
671 if (skb->len >= iv_len && skb->len > hdrlen) {
672 memmove(skb->data + iv_len, skb->data, hdrlen);
673 skb_pull(skb, iv_len);
678 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
679 u16 fc = le16_to_cpu(hdr->frame_control);
680 if ((fc & 0x8C) == 0x88) /* QoS Control Field */ {
681 fc &= ~IEEE80211_STYPE_QOS_DATA;
682 hdr->frame_control = cpu_to_le16(fc);
683 memmove(skb->data + 2, skb->data, hdrlen - 2);
689 void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
690 struct ieee80211_tx_status *status)
692 struct sk_buff *skb2;
693 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
694 struct ieee80211_local *local = hw_to_local(hw);
696 struct ieee80211_tx_status_rtap_hdr *rthdr;
697 struct ieee80211_sub_if_data *sdata;
702 "%s: ieee80211_tx_status called with NULL status\n",
703 wiphy_name(local->hw.wiphy));
708 if (status->excessive_retries) {
709 struct sta_info *sta;
710 sta = sta_info_get(local, hdr->addr1);
712 if (sta->flags & WLAN_STA_PS) {
713 /* The STA is in power save mode, so assume
714 * that this TX packet failed because of that.
716 status->excessive_retries = 0;
717 status->flags |= IEEE80211_TX_STATUS_TX_FILTERED;
723 if (status->flags & IEEE80211_TX_STATUS_TX_FILTERED) {
724 struct sta_info *sta;
725 sta = sta_info_get(local, hdr->addr1);
727 sta->tx_filtered_count++;
729 /* Clear the TX filter mask for this STA when sending
730 * the next packet. If the STA went to power save mode,
731 * this will happen when it is waking up for the next
733 sta->clear_dst_mask = 1;
735 /* TODO: Is the WLAN_STA_PS flag always set here or is
736 * the race between RX and TX status causing some
737 * packets to be filtered out before 80211.o gets an
738 * update for PS status? This seems to be the case, so
739 * no changes are likely to be needed. */
740 if (sta->flags & WLAN_STA_PS &&
741 skb_queue_len(&sta->tx_filtered) <
743 ieee80211_remove_tx_extra(local, sta->key,
746 skb_queue_tail(&sta->tx_filtered, skb);
747 } else if (!(sta->flags & WLAN_STA_PS) &&
748 !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) {
749 /* Software retry the packet once */
750 status->control.flags |= IEEE80211_TXCTL_REQUEUE;
751 ieee80211_remove_tx_extra(local, sta->key,
756 if (net_ratelimit()) {
757 printk(KERN_DEBUG "%s: dropped TX "
758 "filtered frame queue_len=%d "
760 wiphy_name(local->hw.wiphy),
763 !!(sta->flags & WLAN_STA_PS),
772 /* FIXME: STUPID to call this with both local and local->mdev */
773 rate_control_tx_status(local, local->mdev, skb, status);
776 ieee80211_led_tx(local, 0);
779 * Fragments are passed to low-level drivers as separate skbs, so these
780 * are actually fragments, not frames. Update frame counters only for
781 * the first fragment of the frame. */
783 frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
784 type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
786 if (status->flags & IEEE80211_TX_STATUS_ACK) {
788 local->dot11TransmittedFrameCount++;
789 if (is_multicast_ether_addr(hdr->addr1))
790 local->dot11MulticastTransmittedFrameCount++;
791 if (status->retry_count > 0)
792 local->dot11RetryCount++;
793 if (status->retry_count > 1)
794 local->dot11MultipleRetryCount++;
797 /* This counter shall be incremented for an acknowledged MPDU
798 * with an individual address in the address 1 field or an MPDU
799 * with a multicast address in the address 1 field of type Data
801 if (!is_multicast_ether_addr(hdr->addr1) ||
802 type == IEEE80211_FTYPE_DATA ||
803 type == IEEE80211_FTYPE_MGMT)
804 local->dot11TransmittedFragmentCount++;
807 local->dot11FailedCount++;
810 /* this was a transmitted frame, but now we want to reuse it */
813 if (!local->monitors) {
818 /* send frame to monitor interfaces now */
820 if (skb_headroom(skb) < sizeof(*rthdr)) {
821 printk(KERN_ERR "ieee80211_tx_status: headroom too small\n");
826 rthdr = (struct ieee80211_tx_status_rtap_hdr*)
827 skb_push(skb, sizeof(*rthdr));
829 memset(rthdr, 0, sizeof(*rthdr));
830 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
831 rthdr->hdr.it_present =
832 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
833 (1 << IEEE80211_RADIOTAP_DATA_RETRIES));
835 if (!(status->flags & IEEE80211_TX_STATUS_ACK) &&
836 !is_multicast_ether_addr(hdr->addr1))
837 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL);
839 if ((status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS) &&
840 (status->control.flags & IEEE80211_TXCTL_USE_CTS_PROTECT))
841 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS);
842 else if (status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS)
843 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS);
845 rthdr->data_retries = status->retry_count;
848 monitors = local->monitors;
849 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
851 * Using the monitors counter is possibly racy, but
852 * if the value is wrong we simply either clone the skb
853 * once too much or forget sending it to one monitor iface
854 * The latter case isn't nice but fixing the race is much
857 if (!monitors || !skb)
860 if (sdata->type == IEEE80211_IF_TYPE_MNTR) {
861 if (!netif_running(sdata->dev))
865 skb2 = skb_clone(skb, GFP_ATOMIC);
868 skb->dev = sdata->dev;
869 /* XXX: is this sufficient for BPF? */
870 skb_set_mac_header(skb, 0);
871 skb->ip_summed = CHECKSUM_UNNECESSARY;
872 skb->pkt_type = PACKET_OTHERHOST;
873 skb->protocol = htons(ETH_P_802_2);
874 memset(skb->cb, 0, sizeof(skb->cb));
884 EXPORT_SYMBOL(ieee80211_tx_status);
886 struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
887 const struct ieee80211_ops *ops)
889 struct net_device *mdev;
890 struct ieee80211_local *local;
891 struct ieee80211_sub_if_data *sdata;
895 /* Ensure 32-byte alignment of our private data and hw private data.
896 * We use the wiphy priv data for both our ieee80211_local and for
897 * the driver's private data
899 * In memory it'll be like this:
901 * +-------------------------+
903 * +-------------------------+
904 * | struct ieee80211_local |
905 * +-------------------------+
906 * | driver's private data |
907 * +-------------------------+
910 priv_size = ((sizeof(struct ieee80211_local) +
911 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) +
914 wiphy = wiphy_new(&mac80211_config_ops, priv_size);
919 wiphy->privid = mac80211_wiphy_privid;
921 local = wiphy_priv(wiphy);
922 local->hw.wiphy = wiphy;
924 local->hw.priv = (char *)local +
925 ((sizeof(struct ieee80211_local) +
926 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
931 BUG_ON(!ops->config);
932 BUG_ON(!ops->add_interface);
933 BUG_ON(!ops->remove_interface);
934 BUG_ON(!ops->configure_filter);
937 /* for now, mdev needs sub_if_data :/ */
938 mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
939 "wmaster%d", ether_setup);
945 sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
946 mdev->ieee80211_ptr = &sdata->wdev;
947 sdata->wdev.wiphy = wiphy;
949 local->hw.queues = 1; /* default */
952 local->rx_pre_handlers = ieee80211_rx_pre_handlers;
953 local->rx_handlers = ieee80211_rx_handlers;
954 local->tx_handlers = ieee80211_tx_handlers;
956 local->bridge_packets = 1;
958 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
959 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
960 local->short_retry_limit = 7;
961 local->long_retry_limit = 4;
962 local->hw.conf.radio_enabled = 1;
964 local->enabled_modes = ~0;
966 INIT_LIST_HEAD(&local->modes_list);
968 INIT_LIST_HEAD(&local->interfaces);
970 INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work);
971 ieee80211_rx_bss_list_init(mdev);
973 sta_info_init(local);
975 mdev->hard_start_xmit = ieee80211_master_start_xmit;
976 mdev->open = ieee80211_master_open;
977 mdev->stop = ieee80211_master_stop;
978 mdev->type = ARPHRD_IEEE80211;
979 mdev->hard_header_parse = header_parse_80211;
980 mdev->set_multicast_list = ieee80211_master_set_multicast_list;
982 sdata->type = IEEE80211_IF_TYPE_AP;
984 sdata->local = local;
985 sdata->u.ap.force_unicast_rateidx = -1;
986 sdata->u.ap.max_ratectrl_rateidx = -1;
987 ieee80211_if_sdata_init(sdata);
988 /* no RCU needed since we're still during init phase */
989 list_add_tail(&sdata->list, &local->interfaces);
991 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
992 (unsigned long)local);
993 tasklet_disable(&local->tx_pending_tasklet);
995 tasklet_init(&local->tasklet,
996 ieee80211_tasklet_handler,
997 (unsigned long) local);
998 tasklet_disable(&local->tasklet);
1000 skb_queue_head_init(&local->skb_queue);
1001 skb_queue_head_init(&local->skb_queue_unreliable);
1003 return local_to_hw(local);
1005 EXPORT_SYMBOL(ieee80211_alloc_hw);
1007 int ieee80211_register_hw(struct ieee80211_hw *hw)
1009 struct ieee80211_local *local = hw_to_local(hw);
1013 result = wiphy_register(local->hw.wiphy);
1017 name = wiphy_dev(local->hw.wiphy)->driver->name;
1018 local->hw.workqueue = create_singlethread_workqueue(name);
1019 if (!local->hw.workqueue) {
1021 goto fail_workqueue;
1025 * The hardware needs headroom for sending the frame,
1026 * and we need some headroom for passing the frame to monitor
1027 * interfaces, but never both at the same time.
1029 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
1030 sizeof(struct ieee80211_tx_status_rtap_hdr));
1032 debugfs_hw_add(local);
1034 local->hw.conf.beacon_int = 1000;
1036 local->wstats_flags |= local->hw.max_rssi ?
1037 IW_QUAL_LEVEL_UPDATED : IW_QUAL_LEVEL_INVALID;
1038 local->wstats_flags |= local->hw.max_signal ?
1039 IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
1040 local->wstats_flags |= local->hw.max_noise ?
1041 IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
1042 if (local->hw.max_rssi < 0 || local->hw.max_noise < 0)
1043 local->wstats_flags |= IW_QUAL_DBM;
1045 result = sta_info_start(local);
1050 result = dev_alloc_name(local->mdev, local->mdev->name);
1054 memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
1055 SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy));
1057 result = register_netdevice(local->mdev);
1061 ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
1062 ieee80211_if_set_type(local->mdev, IEEE80211_IF_TYPE_AP);
1064 result = ieee80211_init_rate_ctrl_alg(local, NULL);
1066 printk(KERN_DEBUG "%s: Failed to initialize rate control "
1067 "algorithm\n", wiphy_name(local->hw.wiphy));
1071 result = ieee80211_wep_init(local);
1074 printk(KERN_DEBUG "%s: Failed to initialize wep\n",
1075 wiphy_name(local->hw.wiphy));
1079 ieee80211_install_qdisc(local->mdev);
1081 /* add one default STA interface */
1082 result = ieee80211_if_add(local->mdev, "wlan%d", NULL,
1083 IEEE80211_IF_TYPE_STA);
1085 printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
1086 wiphy_name(local->hw.wiphy));
1088 local->reg_state = IEEE80211_DEV_REGISTERED;
1091 ieee80211_led_init(local);
1096 rate_control_deinitialize(local);
1098 ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
1099 unregister_netdevice(local->mdev);
1102 sta_info_stop(local);
1104 debugfs_hw_del(local);
1105 destroy_workqueue(local->hw.workqueue);
1107 wiphy_unregister(local->hw.wiphy);
1110 EXPORT_SYMBOL(ieee80211_register_hw);
1112 int ieee80211_register_hwmode(struct ieee80211_hw *hw,
1113 struct ieee80211_hw_mode *mode)
1115 struct ieee80211_local *local = hw_to_local(hw);
1116 struct ieee80211_rate *rate;
1119 INIT_LIST_HEAD(&mode->list);
1120 list_add_tail(&mode->list, &local->modes_list);
1122 local->hw_modes |= (1 << mode->mode);
1123 for (i = 0; i < mode->num_rates; i++) {
1124 rate = &(mode->rates[i]);
1125 rate->rate_inv = CHAN_UTIL_RATE_LCM / rate->rate;
1127 ieee80211_prepare_rates(local, mode);
1129 if (!local->oper_hw_mode) {
1130 /* Default to this mode */
1131 local->hw.conf.phymode = mode->mode;
1132 local->oper_hw_mode = local->scan_hw_mode = mode;
1133 local->oper_channel = local->scan_channel = &mode->channels[0];
1134 local->hw.conf.mode = local->oper_hw_mode;
1135 local->hw.conf.chan = local->oper_channel;
1138 if (!(hw->flags & IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED))
1139 ieee80211_set_default_regdomain(mode);
1143 EXPORT_SYMBOL(ieee80211_register_hwmode);
1145 void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1147 struct ieee80211_local *local = hw_to_local(hw);
1148 struct ieee80211_sub_if_data *sdata, *tmp;
1151 tasklet_kill(&local->tx_pending_tasklet);
1152 tasklet_kill(&local->tasklet);
1156 BUG_ON(local->reg_state != IEEE80211_DEV_REGISTERED);
1158 local->reg_state = IEEE80211_DEV_UNREGISTERED;
1161 * At this point, interface list manipulations are fine
1162 * because the driver cannot be handing us frames any
1163 * more and the tasklet is killed.
1167 * First, we remove all non-master interfaces. Do this because they
1168 * may have bss pointer dependency on the master, and when we free
1169 * the master these would be freed as well, breaking our list
1170 * iteration completely.
1172 list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
1173 if (sdata->dev == local->mdev)
1175 list_del(&sdata->list);
1176 __ieee80211_if_del(local, sdata);
1179 /* then, finally, remove the master interface */
1180 __ieee80211_if_del(local, IEEE80211_DEV_TO_SUB_IF(local->mdev));
1184 ieee80211_rx_bss_list_deinit(local->mdev);
1185 ieee80211_clear_tx_pending(local);
1186 sta_info_stop(local);
1187 rate_control_deinitialize(local);
1188 debugfs_hw_del(local);
1190 for (i = 0; i < NUM_IEEE80211_MODES; i++) {
1191 kfree(local->supp_rates[i]);
1192 kfree(local->basic_rates[i]);
1195 if (skb_queue_len(&local->skb_queue)
1196 || skb_queue_len(&local->skb_queue_unreliable))
1197 printk(KERN_WARNING "%s: skb_queue not empty\n",
1198 wiphy_name(local->hw.wiphy));
1199 skb_queue_purge(&local->skb_queue);
1200 skb_queue_purge(&local->skb_queue_unreliable);
1202 destroy_workqueue(local->hw.workqueue);
1203 wiphy_unregister(local->hw.wiphy);
1204 ieee80211_wep_free(local);
1205 ieee80211_led_exit(local);
1207 EXPORT_SYMBOL(ieee80211_unregister_hw);
1209 void ieee80211_free_hw(struct ieee80211_hw *hw)
1211 struct ieee80211_local *local = hw_to_local(hw);
1213 ieee80211_if_free(local->mdev);
1214 wiphy_free(local->hw.wiphy);
1216 EXPORT_SYMBOL(ieee80211_free_hw);
1218 static int __init ieee80211_init(void)
1220 struct sk_buff *skb;
1223 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb));
1225 ret = ieee80211_wme_register();
1227 printk(KERN_DEBUG "ieee80211_init: failed to "
1228 "initialize WME (err=%d)\n", ret);
1232 ieee80211_debugfs_netdev_init();
1233 ieee80211_regdomain_init();
1238 static void __exit ieee80211_exit(void)
1240 ieee80211_wme_unregister();
1241 ieee80211_debugfs_netdev_exit();
1245 subsys_initcall(ieee80211_init);
1246 module_exit(ieee80211_exit);
1248 MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1249 MODULE_LICENSE("GPL");