blob: 2ff26d03cd503338302e40cc88ecafb1ccb3c0a9 [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
5 *
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.
9 */
10
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>
Jiri Bencf0706e82007-05-05 11:45:53 -070023#include <linux/bitmap.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070024#include <net/net_namespace.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070025#include <net/cfg80211.h>
26
Jiri Bencf0706e82007-05-05 11:45:53 -070027#include "ieee80211_i.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040028#include "rate.h"
Luis Carlos Cobof7a92142008-02-23 15:17:18 +010029#include "mesh.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070030#include "wep.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070031#include "wme.h"
32#include "aes_ccm.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040033#include "led.h"
Michael Wue0eb6852007-09-18 17:29:21 -040034#include "cfg.h"
Jiri Bence9f207f2007-05-05 11:46:38 -070035#include "debugfs.h"
36#include "debugfs_netdev.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070037
Johannes Bergb306f452007-07-10 19:32:08 +020038/*
39 * For seeing transmitted packets on monitor interfaces
40 * we have a radiotap header too.
41 */
42struct ieee80211_tx_status_rtap_hdr {
43 struct ieee80211_radiotap_header hdr;
44 __le16 tx_flags;
45 u8 data_retries;
46} __attribute__ ((packed));
47
Jiri Bencf0706e82007-05-05 11:45:53 -070048
Johannes Berg4150c572007-09-17 01:29:23 -040049/* must be called under mdev tx lock */
Johannes Berg0d143fe2008-09-11 00:01:59 +020050void ieee80211_configure_filter(struct ieee80211_local *local)
Johannes Berg4150c572007-09-17 01:29:23 -040051{
52 unsigned int changed_flags;
53 unsigned int new_flags = 0;
54
Johannes Berg53918992007-09-26 15:19:47 +020055 if (atomic_read(&local->iff_promiscs))
Johannes Berg4150c572007-09-17 01:29:23 -040056 new_flags |= FIF_PROMISC_IN_BSS;
57
Johannes Berg53918992007-09-26 15:19:47 +020058 if (atomic_read(&local->iff_allmultis))
Johannes Berg4150c572007-09-17 01:29:23 -040059 new_flags |= FIF_ALLMULTI;
60
61 if (local->monitors)
Michael Wu8cc9a732008-01-31 19:48:23 +010062 new_flags |= FIF_BCN_PRBRESP_PROMISC;
63
64 if (local->fif_fcsfail)
65 new_flags |= FIF_FCSFAIL;
66
67 if (local->fif_plcpfail)
68 new_flags |= FIF_PLCPFAIL;
69
70 if (local->fif_control)
71 new_flags |= FIF_CONTROL;
72
73 if (local->fif_other_bss)
74 new_flags |= FIF_OTHER_BSS;
Johannes Berg4150c572007-09-17 01:29:23 -040075
76 changed_flags = local->filter_flags ^ new_flags;
77
78 /* be a bit nasty */
79 new_flags |= (1<<31);
80
81 local->ops->configure_filter(local_to_hw(local),
82 changed_flags, &new_flags,
83 local->mdev->mc_count,
84 local->mdev->mc_list);
85
86 WARN_ON(new_flags & (1<<31));
87
88 local->filter_flags = new_flags & ~(1<<31);
89}
90
Johannes Bergb2c258f2007-07-27 15:43:23 +020091/* master interface */
Jiri Bencf0706e82007-05-05 11:45:53 -070092
Johannes Berg0d143fe2008-09-11 00:01:59 +020093static int header_parse_80211(const struct sk_buff *skb, unsigned char *haddr)
94{
95 memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
96 return ETH_ALEN;
97}
98
99static 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,
105};
106
Jiri Bencf0706e82007-05-05 11:45:53 -0700107static int ieee80211_master_open(struct net_device *dev)
108{
Johannes Berg133b8222008-09-16 14:18:59 +0200109 struct ieee80211_master_priv *mpriv = netdev_priv(dev);
110 struct ieee80211_local *local = mpriv->local;
Jiri Bencf0706e82007-05-05 11:45:53 -0700111 struct ieee80211_sub_if_data *sdata;
112 int res = -EOPNOTSUPP;
113
Johannes Berg79010422007-09-18 17:29:21 -0400114 /* we hold the RTNL here so can safely walk the list */
115 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg3e122be2008-07-09 14:40:34 +0200116 if (netif_running(sdata->dev)) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700117 res = 0;
118 break;
119 }
120 }
Johannes Berg36d68252008-05-15 12:55:26 +0200121
122 if (res)
123 return res;
124
David S. Miller51cb6db2008-07-15 03:34:57 -0700125 netif_tx_start_all_queues(local->mdev);
Johannes Berg36d68252008-05-15 12:55:26 +0200126
127 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700128}
129
130static int ieee80211_master_stop(struct net_device *dev)
131{
Johannes Berg133b8222008-09-16 14:18:59 +0200132 struct ieee80211_master_priv *mpriv = netdev_priv(dev);
133 struct ieee80211_local *local = mpriv->local;
Jiri Bencf0706e82007-05-05 11:45:53 -0700134 struct ieee80211_sub_if_data *sdata;
135
Johannes Berg79010422007-09-18 17:29:21 -0400136 /* we hold the RTNL here so can safely walk the list */
137 list_for_each_entry(sdata, &local->interfaces, list)
Johannes Berg3e122be2008-07-09 14:40:34 +0200138 if (netif_running(sdata->dev))
Jiri Bencf0706e82007-05-05 11:45:53 -0700139 dev_close(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700140
141 return 0;
142}
143
Johannes Berg4150c572007-09-17 01:29:23 -0400144static void ieee80211_master_set_multicast_list(struct net_device *dev)
145{
Johannes Berg133b8222008-09-16 14:18:59 +0200146 struct ieee80211_master_priv *mpriv = netdev_priv(dev);
147 struct ieee80211_local *local = mpriv->local;
Johannes Berg4150c572007-09-17 01:29:23 -0400148
149 ieee80211_configure_filter(local);
150}
151
Johannes Bergb2c258f2007-07-27 15:43:23 +0200152/* everything else */
153
Johannes Berg9d139c82008-07-09 14:40:37 +0200154int ieee80211_if_config(struct ieee80211_sub_if_data *sdata, u32 changed)
Johannes Bergb2c258f2007-07-27 15:43:23 +0200155{
Johannes Berg9d139c82008-07-09 14:40:37 +0200156 struct ieee80211_local *local = sdata->local;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200157 struct ieee80211_if_conf conf;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200158
Johannes Berg9d139c82008-07-09 14:40:37 +0200159 if (WARN_ON(!netif_running(sdata->dev)))
160 return 0;
161
Johannes Berg7a725f72008-09-11 00:02:00 +0200162 if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
163 return -EINVAL;
164
Johannes Berg9d139c82008-07-09 14:40:37 +0200165 if (!local->ops->config_interface)
Johannes Bergb2c258f2007-07-27 15:43:23 +0200166 return 0;
167
168 memset(&conf, 0, sizeof(conf));
Johannes Berg9d139c82008-07-09 14:40:37 +0200169 conf.changed = changed;
170
Johannes Berg05c914f2008-09-11 00:01:58 +0200171 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
172 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Johannes Berg4150c572007-09-17 01:29:23 -0400173 conf.bssid = sdata->u.sta.bssid;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200174 conf.ssid = sdata->u.sta.ssid;
175 conf.ssid_len = sdata->u.sta.ssid_len;
Johannes Berg05c914f2008-09-11 00:01:58 +0200176 } else if (sdata->vif.type == NL80211_IFTYPE_AP) {
Johannes Berg9d139c82008-07-09 14:40:37 +0200177 conf.bssid = sdata->dev->dev_addr;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200178 conf.ssid = sdata->u.ap.ssid;
179 conf.ssid_len = sdata->u.ap.ssid_len;
Johannes Berg9d139c82008-07-09 14:40:37 +0200180 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
181 u8 zero[ETH_ALEN] = { 0 };
182 conf.bssid = zero;
183 conf.ssid = zero;
184 conf.ssid_len = 0;
185 } else {
186 WARN_ON(1);
187 return -EINVAL;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200188 }
Johannes Berg9d139c82008-07-09 14:40:37 +0200189
190 if (WARN_ON(!conf.bssid && (changed & IEEE80211_IFCC_BSSID)))
191 return -EINVAL;
192
193 if (WARN_ON(!conf.ssid && (changed & IEEE80211_IFCC_SSID)))
194 return -EINVAL;
195
Johannes Bergb2c258f2007-07-27 15:43:23 +0200196 return local->ops->config_interface(local_to_hw(local),
Johannes Berg32bfd352007-12-19 01:31:26 +0100197 &sdata->vif, &conf);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200198}
199
Johannes Bergb2c258f2007-07-27 15:43:23 +0200200int ieee80211_hw_config(struct ieee80211_local *local)
201{
Johannes Bergb2c258f2007-07-27 15:43:23 +0200202 struct ieee80211_channel *chan;
203 int ret = 0;
204
Johannes Bergc2b13452008-09-11 00:01:55 +0200205 if (local->sw_scanning)
Johannes Bergb2c258f2007-07-27 15:43:23 +0200206 chan = local->scan_channel;
Johannes Berg8318d782008-01-24 19:38:38 +0100207 else
Johannes Bergb2c258f2007-07-27 15:43:23 +0200208 chan = local->oper_channel;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200209
Johannes Berg8318d782008-01-24 19:38:38 +0100210 local->hw.conf.channel = chan;
211
212 if (!local->hw.conf.power_level)
213 local->hw.conf.power_level = chan->max_power;
214 else
215 local->hw.conf.power_level = min(chan->max_power,
216 local->hw.conf.power_level);
217
218 local->hw.conf.max_antenna_gain = chan->max_antenna_gain;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200219
220#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Berg8318d782008-01-24 19:38:38 +0100221 printk(KERN_DEBUG "%s: HW CONFIG: freq=%d\n",
222 wiphy_name(local->hw.wiphy), chan->center_freq);
223#endif
Johannes Bergb2c258f2007-07-27 15:43:23 +0200224
Johannes Bergd73782f2008-10-07 12:04:34 +0200225 if (local->open_count) {
Johannes Bergb2c258f2007-07-27 15:43:23 +0200226 ret = local->ops->config(local_to_hw(local), &local->hw.conf);
Johannes Bergd73782f2008-10-07 12:04:34 +0200227 /*
228 * HW reconfiguration should never fail, the driver has told
229 * us what it can support so it should live up to that promise.
230 */
231 WARN_ON(ret);
232 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200233
234 return ret;
235}
236
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +0200237/**
Tomas Winkler38668c02008-03-28 16:33:32 -0700238 * 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.
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +0200241 */
Tomas Winkler38668c02008-03-28 16:33:32 -0700242u32 ieee80211_handle_ht(struct ieee80211_local *local, int enable_ht,
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +0200243 struct ieee80211_ht_info *req_ht_cap,
244 struct ieee80211_ht_bss_info *req_bss_cap)
245{
246 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg8318d782008-01-24 19:38:38 +0100247 struct ieee80211_supported_band *sband;
Tomas Winkler38668c02008-03-28 16:33:32 -0700248 struct ieee80211_ht_info ht_conf;
249 struct ieee80211_ht_bss_info ht_bss_conf;
Tomas Winkler38668c02008-03-28 16:33:32 -0700250 u32 changed = 0;
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +0800251 int i;
252 u8 max_tx_streams = IEEE80211_HT_CAP_MAX_STREAMS;
253 u8 tx_mcs_set_cap;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +0200254
Johannes Berg8318d782008-01-24 19:38:38 +0100255 sband = local->hw.wiphy->bands[conf->channel->band];
256
Tomas Winkler38668c02008-03-28 16:33:32 -0700257 memset(&ht_conf, 0, sizeof(struct ieee80211_ht_info));
258 memset(&ht_bss_conf, 0, sizeof(struct ieee80211_ht_bss_info));
259
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +0800260 /* HT is not supported */
261 if (!sband->ht_info.ht_supported) {
262 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
263 goto out;
264 }
Tomas Winkler38668c02008-03-28 16:33:32 -0700265
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +0800266 /* disable HT */
267 if (!enable_ht) {
Tomas Winkler38668c02008-03-28 16:33:32 -0700268 if (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)
269 changed |= BSS_CHANGED_HT;
270 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +0800271 conf->ht_conf.ht_supported = 0;
272 goto out;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +0200273 }
274
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +0800275
276 if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE))
277 changed |= BSS_CHANGED_HT;
278
279 conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE;
280 ht_conf.ht_supported = 1;
281
282 ht_conf.cap = req_ht_cap->cap & sband->ht_info.cap;
Tomas Winkler00c5ae22008-09-03 11:26:42 +0800283 ht_conf.cap &= ~(IEEE80211_HT_CAP_SM_PS);
284 ht_conf.cap |= sband->ht_info.cap & IEEE80211_HT_CAP_SM_PS;
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +0800285 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;
288
289 ht_conf.ampdu_factor = req_ht_cap->ampdu_factor;
290 ht_conf.ampdu_density = req_ht_cap->ampdu_density;
291
292 /* Bits 96-100 */
293 tx_mcs_set_cap = sband->ht_info.supp_mcs_set[12];
294
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))
300 goto check_changed;
301
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;
306
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];
311
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];
318
319check_changed:
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));
326 }
327out:
Tomas Winkler38668c02008-03-28 16:33:32 -0700328 return changed;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +0200329}
330
Johannes Berg471b3ef2007-12-28 14:32:58 +0100331void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
332 u32 changed)
Daniel Draked9430a32007-07-27 15:43:24 +0200333{
Johannes Berg471b3ef2007-12-28 14:32:58 +0100334 struct ieee80211_local *local = sdata->local;
335
Johannes Berg7a725f72008-09-11 00:02:00 +0200336 if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
337 return;
338
Johannes Berg471b3ef2007-12-28 14:32:58 +0100339 if (!changed)
340 return;
341
342 if (local->ops->bss_info_changed)
343 local->ops->bss_info_changed(local_to_hw(local),
344 &sdata->vif,
345 &sdata->bss_conf,
346 changed);
Daniel Draked9430a32007-07-27 15:43:24 +0200347}
348
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200349u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata)
Daniel Draked9430a32007-07-27 15:43:24 +0200350{
Johannes Berg471b3ef2007-12-28 14:32:58 +0100351 sdata->bss_conf.use_cts_prot = 0;
352 sdata->bss_conf.use_short_preamble = 0;
Tomas Winklerfc32f922008-07-03 01:27:13 +0300353 return BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_ERP_PREAMBLE;
Daniel Draked9430a32007-07-27 15:43:24 +0200354}
355
Jiri Bencf0706e82007-05-05 11:45:53 -0700356void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
Johannes Berge039fa42008-05-15 12:55:29 +0200357 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -0700358{
359 struct ieee80211_local *local = hw_to_local(hw);
Johannes Berge039fa42008-05-15 12:55:29 +0200360 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Jiri Bencf0706e82007-05-05 11:45:53 -0700361 int tmp;
362
363 skb->dev = local->mdev;
Jiri Bencf0706e82007-05-05 11:45:53 -0700364 skb->pkt_type = IEEE80211_TX_STATUS_MSG;
Johannes Berge039fa42008-05-15 12:55:29 +0200365 skb_queue_tail(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS ?
Jiri Bencf0706e82007-05-05 11:45:53 -0700366 &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))) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700371 dev_kfree_skb_irq(skb);
372 tmp--;
373 I802_DEBUG_INC(local->tx_status_drop);
374 }
375 tasklet_schedule(&local->tasklet);
376}
377EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
378
379static void ieee80211_tasklet_handler(unsigned long data)
380{
381 struct ieee80211_local *local = (struct ieee80211_local *) data;
382 struct sk_buff *skb;
383 struct ieee80211_rx_status rx_status;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200384 struct ieee80211_ra_tid *ra_tid;
Jiri Bencf0706e82007-05-05 11:45:53 -0700385
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));
Johannes Berg51fb61e2007-12-19 01:31:27 +0100392 /* Clear skb->pkt_type in order to not confuse kernel
Jiri Bencf0706e82007-05-05 11:45:53 -0700393 * netstack. */
394 skb->pkt_type = 0;
395 __ieee80211_rx(local_to_hw(local), skb, &rx_status);
396 break;
397 case IEEE80211_TX_STATUS_MSG:
Jiri Bencf0706e82007-05-05 11:45:53 -0700398 skb->pkt_type = 0;
Johannes Berge039fa42008-05-15 12:55:29 +0200399 ieee80211_tx_status(local_to_hw(local), skb);
Jiri Bencf0706e82007-05-05 11:45:53 -0700400 break;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200401 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);
405 dev_kfree_skb(skb);
406 break;
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);
411 dev_kfree_skb(skb);
412 break ;
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200413 default:
414 WARN_ON(1);
Jiri Bencf0706e82007-05-05 11:45:53 -0700415 dev_kfree_skb(skb);
416 break;
417 }
418 }
419}
420
Jiri Bencf0706e82007-05-05 11:45:53 -0700421/* 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.
Johannes Bergd0f09802008-07-29 11:32:07 +0200424 */
Jiri Bencf0706e82007-05-05 11:45:53 -0700425static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
426 struct ieee80211_key *key,
Johannes Berge039fa42008-05-15 12:55:29 +0200427 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -0700428{
Harvey Harrison62bf1d72008-07-15 18:44:05 -0700429 unsigned int hdrlen, iv_len, mic_len;
430 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Jiri Bencf0706e82007-05-05 11:45:53 -0700431
Harvey Harrison62bf1d72008-07-15 18:44:05 -0700432 hdrlen = ieee80211_hdrlen(hdr->frame_control);
Jiri Bencf0706e82007-05-05 11:45:53 -0700433
434 if (!key)
435 goto no_key;
436
Johannes Berg8f20fc22007-08-28 17:01:54 -0400437 switch (key->conf.alg) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700438 case ALG_WEP:
439 iv_len = WEP_IV_LEN;
440 mic_len = WEP_ICV_LEN;
441 break;
442 case ALG_TKIP:
443 iv_len = TKIP_IV_LEN;
444 mic_len = TKIP_ICV_LEN;
445 break;
446 case ALG_CCMP:
447 iv_len = CCMP_HDR_LEN;
448 mic_len = CCMP_MIC_LEN;
449 break;
450 default:
451 goto no_key;
452 }
453
Harvey Harrison62bf1d72008-07-15 18:44:05 -0700454 if (skb->len >= hdrlen + mic_len &&
Johannes Berg11a843b2007-08-28 17:01:55 -0400455 !(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
Jiri Bencf0706e82007-05-05 11:45:53 -0700456 skb_trim(skb, skb->len - mic_len);
Harvey Harrison62bf1d72008-07-15 18:44:05 -0700457 if (skb->len >= hdrlen + iv_len) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700458 memmove(skb->data + iv_len, skb->data, hdrlen);
Harvey Harrison62bf1d72008-07-15 18:44:05 -0700459 hdr = (struct ieee80211_hdr *)skb_pull(skb, iv_len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700460 }
461
462no_key:
Harvey Harrison62bf1d72008-07-15 18:44:05 -0700463 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);
Jiri Bencf0706e82007-05-05 11:45:53 -0700468 }
469}
470
Johannes Bergd46e1442008-02-20 23:59:33 +0100471static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
472 struct sta_info *sta,
Johannes Berge039fa42008-05-15 12:55:29 +0200473 struct sk_buff *skb)
Johannes Bergd46e1442008-02-20 23:59:33 +0100474{
Johannes Berge039fa42008-05-15 12:55:29 +0200475 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
476
Johannes Bergd46e1442008-02-20 23:59:33 +0100477 sta->tx_filtered_count++;
478
479 /*
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
Yi Zhuf6d97102008-05-27 17:50:50 +0300482 * when it wakes up for the next time.
Johannes Bergd46e1442008-02-20 23:59:33 +0100483 */
Johannes Berg07346f812008-05-03 01:02:02 +0200484 set_sta_flags(sta, WLAN_STA_CLEAR_PS_FILT);
Johannes Bergd46e1442008-02-20 23:59:33 +0100485
486 /*
487 * This code races in the following way:
488 *
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.
494 *
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.
502 *
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.
508 *
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
511 * functions and
512 * (b) always process RX events before TX status events if ordering
513 * can be unknown, for example with different interrupt status
514 * bits.
515 */
Johannes Berg07346f812008-05-03 01:02:02 +0200516 if (test_sta_flags(sta, WLAN_STA_PS) &&
Johannes Bergd46e1442008-02-20 23:59:33 +0100517 skb_queue_len(&sta->tx_filtered) < STA_MAX_TX_BUFFER) {
Johannes Berge039fa42008-05-15 12:55:29 +0200518 ieee80211_remove_tx_extra(local, sta->key, skb);
Johannes Bergd46e1442008-02-20 23:59:33 +0100519 skb_queue_tail(&sta->tx_filtered, skb);
520 return;
521 }
522
Johannes Berg07346f812008-05-03 01:02:02 +0200523 if (!test_sta_flags(sta, WLAN_STA_PS) &&
Johannes Berge039fa42008-05-15 12:55:29 +0200524 !(info->flags & IEEE80211_TX_CTL_REQUEUE)) {
Johannes Bergd46e1442008-02-20 23:59:33 +0100525 /* Software retry the packet once */
Johannes Berge039fa42008-05-15 12:55:29 +0200526 info->flags |= IEEE80211_TX_CTL_REQUEUE;
527 ieee80211_remove_tx_extra(local, sta->key, skb);
Johannes Bergd46e1442008-02-20 23:59:33 +0100528 dev_queue_xmit(skb);
529 return;
530 }
531
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200532#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Bergd46e1442008-02-20 23:59:33 +0100533 if (net_ratelimit())
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),
Johannes Berg07346f812008-05-03 01:02:02 +0200538 !!test_sta_flags(sta, WLAN_STA_PS), jiffies);
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200539#endif
Johannes Bergd46e1442008-02-20 23:59:33 +0100540 dev_kfree_skb(skb);
541}
542
Johannes Berge039fa42008-05-15 12:55:29 +0200543void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -0700544{
545 struct sk_buff *skb2;
546 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
547 struct ieee80211_local *local = hw_to_local(hw);
Johannes Berge039fa42008-05-15 12:55:29 +0200548 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Jiri Bencf0706e82007-05-05 11:45:53 -0700549 u16 frag, type;
Ron Rindjunsky429a3802008-07-01 14:16:03 +0300550 __le16 fc;
Johannes Berg4b7679a2008-09-18 18:14:18 +0200551 struct ieee80211_supported_band *sband;
Johannes Bergb306f452007-07-10 19:32:08 +0200552 struct ieee80211_tx_status_rtap_hdr *rthdr;
553 struct ieee80211_sub_if_data *sdata;
Michael Wu3d30d942008-01-31 19:48:27 +0100554 struct net_device *prev_dev = NULL;
Ron Rindjunsky429a3802008-07-01 14:16:03 +0300555 struct sta_info *sta;
Jiri Bencf0706e82007-05-05 11:45:53 -0700556
Johannes Bergd0709a62008-02-25 16:27:46 +0100557 rcu_read_lock();
558
Johannes Berg95dac0402008-09-11 02:03:28 +0200559 sta = sta_info_get(local, hdr->addr1);
560
561 if (sta) {
562 if (info->status.excessive_retries &&
563 test_sta_flags(sta, WLAN_STA_PS)) {
564 /*
565 * The STA is in power save mode, so assume
566 * that this TX packet failed because of that.
567 */
568 ieee80211_handle_filtered_frame(local, sta, skb);
569 rcu_read_unlock();
570 return;
Jiri Bencf0706e82007-05-05 11:45:53 -0700571 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700572
Johannes Berg95dac0402008-09-11 02:03:28 +0200573 fc = hdr->frame_control;
Ron Rindjunsky429a3802008-07-01 14:16:03 +0300574
Johannes Berg95dac0402008-09-11 02:03:28 +0200575 if ((info->flags & IEEE80211_TX_STAT_AMPDU_NO_BACK) &&
576 (ieee80211_is_data_qos(fc))) {
577 u16 tid, ssn;
578 u8 *qc;
579
Ron Rindjunsky429a3802008-07-01 14:16:03 +0300580 qc = ieee80211_get_qos_ctl(hdr);
581 tid = qc[0] & 0xf;
582 ssn = ((le16_to_cpu(hdr->seq_ctrl) + 0x10)
583 & IEEE80211_SCTL_SEQ);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200584 ieee80211_send_bar(sta->sdata, hdr->addr1,
Ron Rindjunsky429a3802008-07-01 14:16:03 +0300585 tid, ssn);
586 }
Ron Rindjunsky429a3802008-07-01 14:16:03 +0300587
Johannes Berg95dac0402008-09-11 02:03:28 +0200588 if (info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
Johannes Berge039fa42008-05-15 12:55:29 +0200589 ieee80211_handle_filtered_frame(local, sta, skb);
Johannes Bergd0709a62008-02-25 16:27:46 +0100590 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -0700591 return;
Johannes Berg95dac0402008-09-11 02:03:28 +0200592 } else {
593 if (info->status.excessive_retries)
594 sta->tx_retry_failed++;
595 sta->tx_retry_count += info->status.retry_count;
Jiri Bencf0706e82007-05-05 11:45:53 -0700596 }
Johannes Berg95dac0402008-09-11 02:03:28 +0200597
Johannes Berg4b7679a2008-09-18 18:14:18 +0200598 sband = local->hw.wiphy->bands[info->band];
599 rate_control_tx_status(local, sband, sta, skb);
Johannes Berg95dac0402008-09-11 02:03:28 +0200600 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700601
Johannes Bergd0709a62008-02-25 16:27:46 +0100602 rcu_read_unlock();
603
Jiri Bencf0706e82007-05-05 11:45:53 -0700604 ieee80211_led_tx(local, 0);
605
606 /* SNMP counters
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. */
610
611 frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
612 type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
613
Johannes Berge039fa42008-05-15 12:55:29 +0200614 if (info->flags & IEEE80211_TX_STAT_ACK) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700615 if (frag == 0) {
616 local->dot11TransmittedFrameCount++;
617 if (is_multicast_ether_addr(hdr->addr1))
618 local->dot11MulticastTransmittedFrameCount++;
Johannes Berge039fa42008-05-15 12:55:29 +0200619 if (info->status.retry_count > 0)
Jiri Bencf0706e82007-05-05 11:45:53 -0700620 local->dot11RetryCount++;
Johannes Berge039fa42008-05-15 12:55:29 +0200621 if (info->status.retry_count > 1)
Jiri Bencf0706e82007-05-05 11:45:53 -0700622 local->dot11MultipleRetryCount++;
623 }
624
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
628 * or Management. */
629 if (!is_multicast_ether_addr(hdr->addr1) ||
630 type == IEEE80211_FTYPE_DATA ||
631 type == IEEE80211_FTYPE_MGMT)
632 local->dot11TransmittedFragmentCount++;
633 } else {
634 if (frag == 0)
635 local->dot11FailedCount++;
636 }
637
Johannes Bergb306f452007-07-10 19:32:08 +0200638 /* this was a transmitted frame, but now we want to reuse it */
639 skb_orphan(skb);
640
Michael Wu3d30d942008-01-31 19:48:27 +0100641 /*
642 * This is a bit racy but we can avoid a lot of work
643 * with this test...
644 */
645 if (!local->monitors && !local->cooked_mntrs) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700646 dev_kfree_skb(skb);
647 return;
648 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700649
Johannes Bergb306f452007-07-10 19:32:08 +0200650 /* send frame to monitor interfaces now */
651
652 if (skb_headroom(skb) < sizeof(*rthdr)) {
653 printk(KERN_ERR "ieee80211_tx_status: headroom too small\n");
654 dev_kfree_skb(skb);
655 return;
656 }
657
Johannes Berg988c0f72008-04-17 19:21:22 +0200658 rthdr = (struct ieee80211_tx_status_rtap_hdr *)
Johannes Bergb306f452007-07-10 19:32:08 +0200659 skb_push(skb, sizeof(*rthdr));
660
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));
666
Johannes Berge039fa42008-05-15 12:55:29 +0200667 if (!(info->flags & IEEE80211_TX_STAT_ACK) &&
Johannes Bergb306f452007-07-10 19:32:08 +0200668 !is_multicast_ether_addr(hdr->addr1))
669 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL);
670
Johannes Berge039fa42008-05-15 12:55:29 +0200671 if ((info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) &&
672 (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT))
Johannes Bergb306f452007-07-10 19:32:08 +0200673 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS);
Johannes Berge039fa42008-05-15 12:55:29 +0200674 else if (info->flags & IEEE80211_TX_CTL_USE_RTS_CTS)
Johannes Bergb306f452007-07-10 19:32:08 +0200675 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS);
676
Johannes Berge039fa42008-05-15 12:55:29 +0200677 rthdr->data_retries = info->status.retry_count;
Johannes Bergb306f452007-07-10 19:32:08 +0200678
Michael Wu3d30d942008-01-31 19:48:27 +0100679 /* 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));
Johannes Bergb306f452007-07-10 19:32:08 +0200685
Michael Wu3d30d942008-01-31 19:48:27 +0100686 rcu_read_lock();
687 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200688 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
Johannes Bergb306f452007-07-10 19:32:08 +0200689 if (!netif_running(sdata->dev))
690 continue;
Michael Wu3d30d942008-01-31 19:48:27 +0100691
692 if (prev_dev) {
Johannes Berg79010422007-09-18 17:29:21 -0400693 skb2 = skb_clone(skb, GFP_ATOMIC);
Michael Wu3d30d942008-01-31 19:48:27 +0100694 if (skb2) {
695 skb2->dev = prev_dev;
696 netif_rx(skb2);
697 }
698 }
699
700 prev_dev = sdata->dev;
Johannes Bergb306f452007-07-10 19:32:08 +0200701 }
702 }
Michael Wu3d30d942008-01-31 19:48:27 +0100703 if (prev_dev) {
704 skb->dev = prev_dev;
705 netif_rx(skb);
706 skb = NULL;
707 }
Johannes Berg79010422007-09-18 17:29:21 -0400708 rcu_read_unlock();
Michael Wu3d30d942008-01-31 19:48:27 +0100709 dev_kfree_skb(skb);
Jiri Bencf0706e82007-05-05 11:45:53 -0700710}
711EXPORT_SYMBOL(ieee80211_tx_status);
712
Jiri Bencf0706e82007-05-05 11:45:53 -0700713struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
714 const struct ieee80211_ops *ops)
715{
Jiri Bencf0706e82007-05-05 11:45:53 -0700716 struct ieee80211_local *local;
Jiri Bencf0706e82007-05-05 11:45:53 -0700717 int priv_size;
718 struct wiphy *wiphy;
719
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
723 *
724 * In memory it'll be like this:
725 *
726 * +-------------------------+
727 * | struct wiphy |
728 * +-------------------------+
729 * | struct ieee80211_local |
730 * +-------------------------+
731 * | driver's private data |
732 * +-------------------------+
733 *
734 */
735 priv_size = ((sizeof(struct ieee80211_local) +
736 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) +
737 priv_data_len;
738
739 wiphy = wiphy_new(&mac80211_config_ops, priv_size);
740
741 if (!wiphy)
742 return NULL;
743
744 wiphy->privid = mac80211_wiphy_privid;
745
746 local = wiphy_priv(wiphy);
747 local->hw.wiphy = wiphy;
748
749 local->hw.priv = (char *)local +
750 ((sizeof(struct ieee80211_local) +
751 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
752
Johannes Berg4480f15c2007-07-10 19:32:10 +0200753 BUG_ON(!ops->tx);
Johannes Berg4150c572007-09-17 01:29:23 -0400754 BUG_ON(!ops->start);
755 BUG_ON(!ops->stop);
Johannes Berg4480f15c2007-07-10 19:32:10 +0200756 BUG_ON(!ops->config);
757 BUG_ON(!ops->add_interface);
Johannes Berg4150c572007-09-17 01:29:23 -0400758 BUG_ON(!ops->remove_interface);
759 BUG_ON(!ops->configure_filter);
Jiri Bencf0706e82007-05-05 11:45:53 -0700760 local->ops = ops;
761
Jiri Bencf0706e82007-05-05 11:45:53 -0700762 local->hw.queues = 1; /* default */
763
Jiri Bencf0706e82007-05-05 11:45:53 -0700764 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;
Jiri Bencf0706e82007-05-05 11:45:53 -0700769
Johannes Berg79010422007-09-18 17:29:21 -0400770 INIT_LIST_HEAD(&local->interfaces);
Jiri Bencf0706e82007-05-05 11:45:53 -0700771
Johannes Bergb16bd152008-04-11 21:40:35 +0200772 spin_lock_init(&local->key_lock);
773
Johannes Bergc2b13452008-09-11 00:01:55 +0200774 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
Jiri Bencf0706e82007-05-05 11:45:53 -0700775
776 sta_info_init(local);
777
Jiri Bencf0706e82007-05-05 11:45:53 -0700778 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
779 (unsigned long)local);
780 tasklet_disable(&local->tx_pending_tasklet);
781
782 tasklet_init(&local->tasklet,
783 ieee80211_tasklet_handler,
784 (unsigned long) local);
785 tasklet_disable(&local->tasklet);
786
787 skb_queue_head_init(&local->skb_queue);
788 skb_queue_head_init(&local->skb_queue_unreliable);
789
790 return local_to_hw(local);
791}
792EXPORT_SYMBOL(ieee80211_alloc_hw);
793
794int ieee80211_register_hw(struct ieee80211_hw *hw)
795{
796 struct ieee80211_local *local = hw_to_local(hw);
797 const char *name;
798 int result;
Johannes Berg8318d782008-01-24 19:38:38 +0100799 enum ieee80211_band band;
Johannes Berg96d51052008-02-08 09:48:13 +0100800 struct net_device *mdev;
Johannes Berg133b8222008-09-16 14:18:59 +0200801 struct ieee80211_master_priv *mpriv;
Johannes Berg8318d782008-01-24 19:38:38 +0100802
803 /*
804 * generic code guarantees at least one band,
805 * set this very early because much code assumes
806 * that hw.conf.channel is assigned
807 */
808 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
809 struct ieee80211_supported_band *sband;
810
811 sband = local->hw.wiphy->bands[band];
812 if (sband) {
813 /* init channel we're on */
814 local->hw.conf.channel =
815 local->oper_channel =
816 local->scan_channel = &sband->channels[0];
817 break;
818 }
819 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700820
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700821 /* 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);
824
825 /* mac80211 always supports monitor */
826 local->hw.wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
827
Jiri Bencf0706e82007-05-05 11:45:53 -0700828 result = wiphy_register(local->hw.wiphy);
829 if (result < 0)
830 return result;
831
Johannes Berge2530082008-05-17 00:57:14 +0200832 /*
833 * We use the number of queues for feature tests (QoS, HT) internally
834 * so restrict them appropriately.
835 */
Johannes Berge2530082008-05-17 00:57:14 +0200836 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;
840 if (hw->queues < 4)
841 hw->ampdu_queues = 0;
Johannes Berge2530082008-05-17 00:57:14 +0200842
Johannes Berg133b8222008-09-16 14:18:59 +0200843 mdev = alloc_netdev_mq(sizeof(struct ieee80211_master_priv),
Johannes Berge2530082008-05-17 00:57:14 +0200844 "wmaster%d", ether_setup,
845 ieee80211_num_queues(hw));
Johannes Berg96d51052008-02-08 09:48:13 +0100846 if (!mdev)
847 goto fail_mdev_alloc;
848
Johannes Berg133b8222008-09-16 14:18:59 +0200849 mpriv = netdev_priv(mdev);
850 mpriv->local = local;
Johannes Berg96d51052008-02-08 09:48:13 +0100851 local->mdev = mdev;
852
Johannes Berg3e122be2008-07-09 14:40:34 +0200853 ieee80211_rx_bss_list_init(local);
Johannes Berg96d51052008-02-08 09:48:13 +0100854
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;
861
Jiri Bencf0706e82007-05-05 11:45:53 -0700862 name = wiphy_dev(local->hw.wiphy)->driver->name;
Johannes Berg59959a62008-06-26 19:59:56 +0200863 local->hw.workqueue = create_freezeable_workqueue(name);
Jiri Bencf0706e82007-05-05 11:45:53 -0700864 if (!local->hw.workqueue) {
865 result = -ENOMEM;
866 goto fail_workqueue;
867 }
868
Johannes Bergb306f452007-07-10 19:32:08 +0200869 /*
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.
873 */
Jiri Benc33ccad32007-07-18 17:10:44 +0200874 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
875 sizeof(struct ieee80211_tx_status_rtap_hdr));
Johannes Bergb306f452007-07-10 19:32:08 +0200876
Jiri Bence9f207f2007-05-05 11:46:38 -0700877 debugfs_hw_add(local);
878
Tomas Winklerdc0ae302008-06-12 22:38:37 +0300879 if (local->hw.conf.beacon_int < 10)
880 local->hw.conf.beacon_int = 100;
Jiri Bencf0706e82007-05-05 11:45:53 -0700881
Tomas Winklerea95bba2008-07-18 13:53:00 +0800882 if (local->hw.max_listen_interval == 0)
883 local->hw.max_listen_interval = 1;
884
885 local->hw.conf.listen_interval = local->hw.max_listen_interval;
886
Bruno Randolf566bfe52008-05-08 19:15:40 +0200887 local->wstats_flags |= local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
888 IEEE80211_HW_SIGNAL_DB |
889 IEEE80211_HW_SIGNAL_DBM) ?
Jiri Bencf0706e82007-05-05 11:45:53 -0700890 IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
Bruno Randolf566bfe52008-05-08 19:15:40 +0200891 local->wstats_flags |= local->hw.flags & IEEE80211_HW_NOISE_DBM ?
Jiri Bencf0706e82007-05-05 11:45:53 -0700892 IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
Bruno Randolf566bfe52008-05-08 19:15:40 +0200893 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
Jiri Bencf0706e82007-05-05 11:45:53 -0700894 local->wstats_flags |= IW_QUAL_DBM;
895
896 result = sta_info_start(local);
897 if (result < 0)
898 goto fail_sta_info;
899
900 rtnl_lock();
901 result = dev_alloc_name(local->mdev, local->mdev->name);
902 if (result < 0)
903 goto fail_dev;
904
905 memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
906 SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy));
907
908 result = register_netdevice(local->mdev);
909 if (result < 0)
910 goto fail_dev;
911
Johannes Berg830f9032007-10-28 14:51:05 +0100912 result = ieee80211_init_rate_ctrl_alg(local,
913 hw->rate_control_algorithm);
Jiri Bencf0706e82007-05-05 11:45:53 -0700914 if (result < 0) {
915 printk(KERN_DEBUG "%s: Failed to initialize rate control "
Johannes Bergdd1cd4c2007-09-18 17:29:20 -0400916 "algorithm\n", wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -0700917 goto fail_rate;
918 }
919
920 result = ieee80211_wep_init(local);
921
922 if (result < 0) {
Jeremy Fitzhardinge023a04b2008-07-14 12:52:08 -0700923 printk(KERN_DEBUG "%s: Failed to initialize wep: %d\n",
924 wiphy_name(local->hw.wiphy), result);
Jiri Bencf0706e82007-05-05 11:45:53 -0700925 goto fail_wep;
926 }
927
David S. Miller51cb6db2008-07-15 03:34:57 -0700928 local->mdev->select_queue = ieee80211_select_queue;
Jiri Bencf0706e82007-05-05 11:45:53 -0700929
930 /* add one default STA interface */
Johannes Berg3e122be2008-07-09 14:40:34 +0200931 result = ieee80211_if_add(local, "wlan%d", NULL,
Johannes Berg05c914f2008-09-11 00:01:58 +0200932 NL80211_IFTYPE_STATION, NULL);
Jiri Bencf0706e82007-05-05 11:45:53 -0700933 if (result)
934 printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -0400935 wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -0700936
Jiri Bencf0706e82007-05-05 11:45:53 -0700937 rtnl_unlock();
938
939 ieee80211_led_init(local);
940
941 return 0;
942
943fail_wep:
944 rate_control_deinitialize(local);
945fail_rate:
946 unregister_netdevice(local->mdev);
Pavel Emelyanov339a7c42008-05-04 17:59:30 -0700947 local->mdev = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700948fail_dev:
949 rtnl_unlock();
950 sta_info_stop(local);
951fail_sta_info:
Jiri Bence9f207f2007-05-05 11:46:38 -0700952 debugfs_hw_del(local);
Jiri Bencf0706e82007-05-05 11:45:53 -0700953 destroy_workqueue(local->hw.workqueue);
954fail_workqueue:
Johannes Berg3e122be2008-07-09 14:40:34 +0200955 if (local->mdev)
956 free_netdev(local->mdev);
Johannes Berg96d51052008-02-08 09:48:13 +0100957fail_mdev_alloc:
Jiri Bencf0706e82007-05-05 11:45:53 -0700958 wiphy_unregister(local->hw.wiphy);
959 return result;
960}
961EXPORT_SYMBOL(ieee80211_register_hw);
962
Jiri Bencf0706e82007-05-05 11:45:53 -0700963void ieee80211_unregister_hw(struct ieee80211_hw *hw)
964{
965 struct ieee80211_local *local = hw_to_local(hw);
Jiri Bencf0706e82007-05-05 11:45:53 -0700966
967 tasklet_kill(&local->tx_pending_tasklet);
968 tasklet_kill(&local->tasklet);
969
970 rtnl_lock();
971
Johannes Berg79010422007-09-18 17:29:21 -0400972 /*
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.
976 */
Johannes Berg5b2812e2007-09-26 14:27:23 +0200977
Johannes Berg75636522008-07-09 14:40:35 +0200978 /* First, we remove all virtual interfaces. */
979 ieee80211_remove_interfaces(local);
Johannes Berg5b2812e2007-09-26 14:27:23 +0200980
981 /* then, finally, remove the master interface */
Johannes Berg3e122be2008-07-09 14:40:34 +0200982 unregister_netdevice(local->mdev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700983
984 rtnl_unlock();
985
Johannes Berg3e122be2008-07-09 14:40:34 +0200986 ieee80211_rx_bss_list_deinit(local);
Jiri Bencf0706e82007-05-05 11:45:53 -0700987 ieee80211_clear_tx_pending(local);
988 sta_info_stop(local);
989 rate_control_deinitialize(local);
Jiri Bence9f207f2007-05-05 11:46:38 -0700990 debugfs_hw_del(local);
Jiri Bencf0706e82007-05-05 11:45:53 -0700991
Jiri Bencf0706e82007-05-05 11:45:53 -0700992 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",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -0400995 wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -0700996 skb_queue_purge(&local->skb_queue);
997 skb_queue_purge(&local->skb_queue_unreliable);
998
999 destroy_workqueue(local->hw.workqueue);
1000 wiphy_unregister(local->hw.wiphy);
1001 ieee80211_wep_free(local);
1002 ieee80211_led_exit(local);
Johannes Berg3e122be2008-07-09 14:40:34 +02001003 free_netdev(local->mdev);
Jiri Bencf0706e82007-05-05 11:45:53 -07001004}
1005EXPORT_SYMBOL(ieee80211_unregister_hw);
1006
1007void ieee80211_free_hw(struct ieee80211_hw *hw)
1008{
1009 struct ieee80211_local *local = hw_to_local(hw);
1010
Jiri Bencf0706e82007-05-05 11:45:53 -07001011 wiphy_free(local->hw.wiphy);
1012}
1013EXPORT_SYMBOL(ieee80211_free_hw);
1014
Jiri Bencf0706e82007-05-05 11:45:53 -07001015static int __init ieee80211_init(void)
1016{
1017 struct sk_buff *skb;
1018 int ret;
1019
Johannes Berge039fa42008-05-15 12:55:29 +02001020 BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb));
1021 BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) +
Johannes Bergc6a1fa12008-10-07 12:04:32 +02001022 IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb));
Jiri Bencf0706e82007-05-05 11:45:53 -07001023
Felix Fietkaucccf1292008-10-05 18:07:45 +02001024 ret = rc80211_minstrel_init();
1025 if (ret)
1026 return ret;
1027
Johannes Berg4b475892008-01-02 15:17:03 +01001028 ret = rc80211_pid_init();
Mattias Nisslerad018372007-12-19 01:25:57 +01001029 if (ret)
David S. Miller51cb6db2008-07-15 03:34:57 -07001030 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07001031
Jiri Bence9f207f2007-05-05 11:46:38 -07001032 ieee80211_debugfs_netdev_init();
1033
Jiri Bencf0706e82007-05-05 11:45:53 -07001034 return 0;
1035}
1036
Jiri Bencf0706e82007-05-05 11:45:53 -07001037static void __exit ieee80211_exit(void)
1038{
Johannes Berg4b475892008-01-02 15:17:03 +01001039 rc80211_pid_exit();
Felix Fietkaucccf1292008-10-05 18:07:45 +02001040 rc80211_minstrel_exit();
Johannes Bergac71c692007-10-28 14:17:44 +01001041
Johannes Berg3b967662008-04-08 17:56:52 +02001042 /*
1043 * For key todo, it'll be empty by now but the work
1044 * might still be scheduled.
1045 */
1046 flush_scheduled_work();
1047
Luis Carlos Cobof7a92142008-02-23 15:17:18 +01001048 if (mesh_allocated)
1049 ieee80211s_stop();
Johannes Berg902acc72008-02-23 15:17:19 +01001050
Jiri Bence9f207f2007-05-05 11:46:38 -07001051 ieee80211_debugfs_netdev_exit();
Jiri Bencf0706e82007-05-05 11:45:53 -07001052}
1053
1054
Johannes Bergca9938f2007-09-11 12:50:32 +02001055subsys_initcall(ieee80211_init);
Jiri Bencf0706e82007-05-05 11:45:53 -07001056module_exit(ieee80211_exit);
1057
1058MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1059MODULE_LICENSE("GPL");