blob: c936017f6d4888201698fe39abd03841f4c0779f [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 Berge8975582008-10-09 12:18:51 +0200200int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
Johannes Bergb2c258f2007-07-27 15:43:23 +0200201{
Johannes Bergb2c258f2007-07-27 15:43:23 +0200202 struct ieee80211_channel *chan;
203 int ret = 0;
Johannes Berge8975582008-10-09 12:18:51 +0200204 int power;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200205
Johannes Bergc2b13452008-09-11 00:01:55 +0200206 if (local->sw_scanning)
Johannes Bergb2c258f2007-07-27 15:43:23 +0200207 chan = local->scan_channel;
Johannes Berg8318d782008-01-24 19:38:38 +0100208 else
Johannes Bergb2c258f2007-07-27 15:43:23 +0200209 chan = local->oper_channel;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200210
Johannes Berge8975582008-10-09 12:18:51 +0200211 if (chan != local->hw.conf.channel) {
212 local->hw.conf.channel = chan;
213 changed |= IEEE80211_CONF_CHANGE_CHANNEL;
214 }
215
Johannes Berg8318d782008-01-24 19:38:38 +0100216
217 if (!local->hw.conf.power_level)
Johannes Berge8975582008-10-09 12:18:51 +0200218 power = chan->max_power;
Johannes Berg8318d782008-01-24 19:38:38 +0100219 else
Johannes Berge8975582008-10-09 12:18:51 +0200220 power = min(chan->max_power, local->hw.conf.power_level);
221 if (local->hw.conf.power_level != power) {
222 changed |= IEEE80211_CONF_CHANGE_POWER;
223 local->hw.conf.power_level = power;
224 }
Johannes Berg8318d782008-01-24 19:38:38 +0100225
Johannes Berge8975582008-10-09 12:18:51 +0200226 if (changed && local->open_count) {
227 ret = local->ops->config(local_to_hw(local), changed);
Johannes Bergd73782f2008-10-07 12:04:34 +0200228 /*
229 * HW reconfiguration should never fail, the driver has told
230 * us what it can support so it should live up to that promise.
231 */
232 WARN_ON(ret);
233 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200234
235 return ret;
236}
237
Johannes Berg471b3ef2007-12-28 14:32:58 +0100238void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
239 u32 changed)
Daniel Draked9430a32007-07-27 15:43:24 +0200240{
Johannes Berg471b3ef2007-12-28 14:32:58 +0100241 struct ieee80211_local *local = sdata->local;
242
Johannes Berg7a725f72008-09-11 00:02:00 +0200243 if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
244 return;
245
Johannes Berg471b3ef2007-12-28 14:32:58 +0100246 if (!changed)
247 return;
248
249 if (local->ops->bss_info_changed)
250 local->ops->bss_info_changed(local_to_hw(local),
251 &sdata->vif,
252 &sdata->bss_conf,
253 changed);
Daniel Draked9430a32007-07-27 15:43:24 +0200254}
255
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200256u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata)
Daniel Draked9430a32007-07-27 15:43:24 +0200257{
Johannes Berg7a5158e2008-10-08 10:59:33 +0200258 sdata->bss_conf.use_cts_prot = false;
259 sdata->bss_conf.use_short_preamble = false;
260 sdata->bss_conf.use_short_slot = false;
261 return BSS_CHANGED_ERP_CTS_PROT |
262 BSS_CHANGED_ERP_PREAMBLE |
263 BSS_CHANGED_ERP_SLOT;
Daniel Draked9430a32007-07-27 15:43:24 +0200264}
265
Jiri Bencf0706e82007-05-05 11:45:53 -0700266void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
Johannes Berge039fa42008-05-15 12:55:29 +0200267 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -0700268{
269 struct ieee80211_local *local = hw_to_local(hw);
Johannes Berge039fa42008-05-15 12:55:29 +0200270 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Jiri Bencf0706e82007-05-05 11:45:53 -0700271 int tmp;
272
273 skb->dev = local->mdev;
Jiri Bencf0706e82007-05-05 11:45:53 -0700274 skb->pkt_type = IEEE80211_TX_STATUS_MSG;
Johannes Berge039fa42008-05-15 12:55:29 +0200275 skb_queue_tail(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS ?
Jiri Bencf0706e82007-05-05 11:45:53 -0700276 &local->skb_queue : &local->skb_queue_unreliable, skb);
277 tmp = skb_queue_len(&local->skb_queue) +
278 skb_queue_len(&local->skb_queue_unreliable);
279 while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
280 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700281 dev_kfree_skb_irq(skb);
282 tmp--;
283 I802_DEBUG_INC(local->tx_status_drop);
284 }
285 tasklet_schedule(&local->tasklet);
286}
287EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
288
289static void ieee80211_tasklet_handler(unsigned long data)
290{
291 struct ieee80211_local *local = (struct ieee80211_local *) data;
292 struct sk_buff *skb;
293 struct ieee80211_rx_status rx_status;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200294 struct ieee80211_ra_tid *ra_tid;
Jiri Bencf0706e82007-05-05 11:45:53 -0700295
296 while ((skb = skb_dequeue(&local->skb_queue)) ||
297 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
298 switch (skb->pkt_type) {
299 case IEEE80211_RX_MSG:
300 /* status is in skb->cb */
301 memcpy(&rx_status, skb->cb, sizeof(rx_status));
Johannes Berg51fb61e2007-12-19 01:31:27 +0100302 /* Clear skb->pkt_type in order to not confuse kernel
Jiri Bencf0706e82007-05-05 11:45:53 -0700303 * netstack. */
304 skb->pkt_type = 0;
305 __ieee80211_rx(local_to_hw(local), skb, &rx_status);
306 break;
307 case IEEE80211_TX_STATUS_MSG:
Jiri Bencf0706e82007-05-05 11:45:53 -0700308 skb->pkt_type = 0;
Johannes Berge039fa42008-05-15 12:55:29 +0200309 ieee80211_tx_status(local_to_hw(local), skb);
Jiri Bencf0706e82007-05-05 11:45:53 -0700310 break;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200311 case IEEE80211_DELBA_MSG:
312 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
313 ieee80211_stop_tx_ba_cb(local_to_hw(local),
314 ra_tid->ra, ra_tid->tid);
315 dev_kfree_skb(skb);
316 break;
317 case IEEE80211_ADDBA_MSG:
318 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
319 ieee80211_start_tx_ba_cb(local_to_hw(local),
320 ra_tid->ra, ra_tid->tid);
321 dev_kfree_skb(skb);
322 break ;
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200323 default:
324 WARN_ON(1);
Jiri Bencf0706e82007-05-05 11:45:53 -0700325 dev_kfree_skb(skb);
326 break;
327 }
328 }
329}
330
Jiri Bencf0706e82007-05-05 11:45:53 -0700331/* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
332 * make a prepared TX frame (one that has been given to hw) to look like brand
333 * new IEEE 802.11 frame that is ready to go through TX processing again.
Johannes Bergd0f09802008-07-29 11:32:07 +0200334 */
Jiri Bencf0706e82007-05-05 11:45:53 -0700335static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
336 struct ieee80211_key *key,
Johannes Berge039fa42008-05-15 12:55:29 +0200337 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -0700338{
Harvey Harrison62bf1d72008-07-15 18:44:05 -0700339 unsigned int hdrlen, iv_len, mic_len;
340 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Jiri Bencf0706e82007-05-05 11:45:53 -0700341
Harvey Harrison62bf1d72008-07-15 18:44:05 -0700342 hdrlen = ieee80211_hdrlen(hdr->frame_control);
Jiri Bencf0706e82007-05-05 11:45:53 -0700343
344 if (!key)
345 goto no_key;
346
Johannes Berg8f20fc22007-08-28 17:01:54 -0400347 switch (key->conf.alg) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700348 case ALG_WEP:
349 iv_len = WEP_IV_LEN;
350 mic_len = WEP_ICV_LEN;
351 break;
352 case ALG_TKIP:
353 iv_len = TKIP_IV_LEN;
354 mic_len = TKIP_ICV_LEN;
355 break;
356 case ALG_CCMP:
357 iv_len = CCMP_HDR_LEN;
358 mic_len = CCMP_MIC_LEN;
359 break;
360 default:
361 goto no_key;
362 }
363
Harvey Harrison62bf1d72008-07-15 18:44:05 -0700364 if (skb->len >= hdrlen + mic_len &&
Johannes Berg11a843b2007-08-28 17:01:55 -0400365 !(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
Jiri Bencf0706e82007-05-05 11:45:53 -0700366 skb_trim(skb, skb->len - mic_len);
Harvey Harrison62bf1d72008-07-15 18:44:05 -0700367 if (skb->len >= hdrlen + iv_len) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700368 memmove(skb->data + iv_len, skb->data, hdrlen);
Harvey Harrison62bf1d72008-07-15 18:44:05 -0700369 hdr = (struct ieee80211_hdr *)skb_pull(skb, iv_len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700370 }
371
372no_key:
Harvey Harrison62bf1d72008-07-15 18:44:05 -0700373 if (ieee80211_is_data_qos(hdr->frame_control)) {
374 hdr->frame_control &= ~cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
375 memmove(skb->data + IEEE80211_QOS_CTL_LEN, skb->data,
376 hdrlen - IEEE80211_QOS_CTL_LEN);
377 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Jiri Bencf0706e82007-05-05 11:45:53 -0700378 }
379}
380
Johannes Bergd46e1442008-02-20 23:59:33 +0100381static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
382 struct sta_info *sta,
Johannes Berge039fa42008-05-15 12:55:29 +0200383 struct sk_buff *skb)
Johannes Bergd46e1442008-02-20 23:59:33 +0100384{
Johannes Berge039fa42008-05-15 12:55:29 +0200385 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
386
Johannes Bergd46e1442008-02-20 23:59:33 +0100387 sta->tx_filtered_count++;
388
389 /*
390 * Clear the TX filter mask for this STA when sending the next
391 * packet. If the STA went to power save mode, this will happen
Yi Zhuf6d97102008-05-27 17:50:50 +0300392 * when it wakes up for the next time.
Johannes Bergd46e1442008-02-20 23:59:33 +0100393 */
Johannes Berg07346f812008-05-03 01:02:02 +0200394 set_sta_flags(sta, WLAN_STA_CLEAR_PS_FILT);
Johannes Bergd46e1442008-02-20 23:59:33 +0100395
396 /*
397 * This code races in the following way:
398 *
399 * (1) STA sends frame indicating it will go to sleep and does so
400 * (2) hardware/firmware adds STA to filter list, passes frame up
401 * (3) hardware/firmware processes TX fifo and suppresses a frame
402 * (4) we get TX status before having processed the frame and
403 * knowing that the STA has gone to sleep.
404 *
405 * This is actually quite unlikely even when both those events are
406 * processed from interrupts coming in quickly after one another or
407 * even at the same time because we queue both TX status events and
408 * RX frames to be processed by a tasklet and process them in the
409 * same order that they were received or TX status last. Hence, there
410 * is no race as long as the frame RX is processed before the next TX
411 * status, which drivers can ensure, see below.
412 *
413 * Note that this can only happen if the hardware or firmware can
414 * actually add STAs to the filter list, if this is done by the
415 * driver in response to set_tim() (which will only reduce the race
416 * this whole filtering tries to solve, not completely solve it)
417 * this situation cannot happen.
418 *
419 * To completely solve this race drivers need to make sure that they
420 * (a) don't mix the irq-safe/not irq-safe TX status/RX processing
421 * functions and
422 * (b) always process RX events before TX status events if ordering
423 * can be unknown, for example with different interrupt status
424 * bits.
425 */
Johannes Berg07346f812008-05-03 01:02:02 +0200426 if (test_sta_flags(sta, WLAN_STA_PS) &&
Johannes Bergd46e1442008-02-20 23:59:33 +0100427 skb_queue_len(&sta->tx_filtered) < STA_MAX_TX_BUFFER) {
Johannes Berge039fa42008-05-15 12:55:29 +0200428 ieee80211_remove_tx_extra(local, sta->key, skb);
Johannes Bergd46e1442008-02-20 23:59:33 +0100429 skb_queue_tail(&sta->tx_filtered, skb);
430 return;
431 }
432
Johannes Berg07346f812008-05-03 01:02:02 +0200433 if (!test_sta_flags(sta, WLAN_STA_PS) &&
Johannes Berge039fa42008-05-15 12:55:29 +0200434 !(info->flags & IEEE80211_TX_CTL_REQUEUE)) {
Johannes Bergd46e1442008-02-20 23:59:33 +0100435 /* Software retry the packet once */
Johannes Berge039fa42008-05-15 12:55:29 +0200436 info->flags |= IEEE80211_TX_CTL_REQUEUE;
437 ieee80211_remove_tx_extra(local, sta->key, skb);
Johannes Bergd46e1442008-02-20 23:59:33 +0100438 dev_queue_xmit(skb);
439 return;
440 }
441
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200442#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Bergd46e1442008-02-20 23:59:33 +0100443 if (net_ratelimit())
444 printk(KERN_DEBUG "%s: dropped TX filtered frame, "
445 "queue_len=%d PS=%d @%lu\n",
446 wiphy_name(local->hw.wiphy),
447 skb_queue_len(&sta->tx_filtered),
Johannes Berg07346f812008-05-03 01:02:02 +0200448 !!test_sta_flags(sta, WLAN_STA_PS), jiffies);
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200449#endif
Johannes Bergd46e1442008-02-20 23:59:33 +0100450 dev_kfree_skb(skb);
451}
452
Johannes Berge039fa42008-05-15 12:55:29 +0200453void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -0700454{
455 struct sk_buff *skb2;
456 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
457 struct ieee80211_local *local = hw_to_local(hw);
Johannes Berge039fa42008-05-15 12:55:29 +0200458 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Jiri Bencf0706e82007-05-05 11:45:53 -0700459 u16 frag, type;
Ron Rindjunsky429a3802008-07-01 14:16:03 +0300460 __le16 fc;
Johannes Berg4b7679a2008-09-18 18:14:18 +0200461 struct ieee80211_supported_band *sband;
Johannes Bergb306f452007-07-10 19:32:08 +0200462 struct ieee80211_tx_status_rtap_hdr *rthdr;
463 struct ieee80211_sub_if_data *sdata;
Michael Wu3d30d942008-01-31 19:48:27 +0100464 struct net_device *prev_dev = NULL;
Ron Rindjunsky429a3802008-07-01 14:16:03 +0300465 struct sta_info *sta;
Jiri Bencf0706e82007-05-05 11:45:53 -0700466
Johannes Bergd0709a62008-02-25 16:27:46 +0100467 rcu_read_lock();
468
Johannes Berg95dac0402008-09-11 02:03:28 +0200469 sta = sta_info_get(local, hdr->addr1);
470
471 if (sta) {
472 if (info->status.excessive_retries &&
473 test_sta_flags(sta, WLAN_STA_PS)) {
474 /*
475 * The STA is in power save mode, so assume
476 * that this TX packet failed because of that.
477 */
478 ieee80211_handle_filtered_frame(local, sta, skb);
479 rcu_read_unlock();
480 return;
Jiri Bencf0706e82007-05-05 11:45:53 -0700481 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700482
Johannes Berg95dac0402008-09-11 02:03:28 +0200483 fc = hdr->frame_control;
Ron Rindjunsky429a3802008-07-01 14:16:03 +0300484
Johannes Berg95dac0402008-09-11 02:03:28 +0200485 if ((info->flags & IEEE80211_TX_STAT_AMPDU_NO_BACK) &&
486 (ieee80211_is_data_qos(fc))) {
487 u16 tid, ssn;
488 u8 *qc;
489
Ron Rindjunsky429a3802008-07-01 14:16:03 +0300490 qc = ieee80211_get_qos_ctl(hdr);
491 tid = qc[0] & 0xf;
492 ssn = ((le16_to_cpu(hdr->seq_ctrl) + 0x10)
493 & IEEE80211_SCTL_SEQ);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200494 ieee80211_send_bar(sta->sdata, hdr->addr1,
Ron Rindjunsky429a3802008-07-01 14:16:03 +0300495 tid, ssn);
496 }
Ron Rindjunsky429a3802008-07-01 14:16:03 +0300497
Johannes Berg95dac0402008-09-11 02:03:28 +0200498 if (info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
Johannes Berge039fa42008-05-15 12:55:29 +0200499 ieee80211_handle_filtered_frame(local, sta, skb);
Johannes Bergd0709a62008-02-25 16:27:46 +0100500 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -0700501 return;
Johannes Berg95dac0402008-09-11 02:03:28 +0200502 } else {
503 if (info->status.excessive_retries)
504 sta->tx_retry_failed++;
505 sta->tx_retry_count += info->status.retry_count;
Jiri Bencf0706e82007-05-05 11:45:53 -0700506 }
Johannes Berg95dac0402008-09-11 02:03:28 +0200507
Johannes Berg4b7679a2008-09-18 18:14:18 +0200508 sband = local->hw.wiphy->bands[info->band];
509 rate_control_tx_status(local, sband, sta, skb);
Johannes Berg95dac0402008-09-11 02:03:28 +0200510 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700511
Johannes Bergd0709a62008-02-25 16:27:46 +0100512 rcu_read_unlock();
513
Jiri Bencf0706e82007-05-05 11:45:53 -0700514 ieee80211_led_tx(local, 0);
515
516 /* SNMP counters
517 * Fragments are passed to low-level drivers as separate skbs, so these
518 * are actually fragments, not frames. Update frame counters only for
519 * the first fragment of the frame. */
520
521 frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
522 type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
523
Johannes Berge039fa42008-05-15 12:55:29 +0200524 if (info->flags & IEEE80211_TX_STAT_ACK) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700525 if (frag == 0) {
526 local->dot11TransmittedFrameCount++;
527 if (is_multicast_ether_addr(hdr->addr1))
528 local->dot11MulticastTransmittedFrameCount++;
Johannes Berge039fa42008-05-15 12:55:29 +0200529 if (info->status.retry_count > 0)
Jiri Bencf0706e82007-05-05 11:45:53 -0700530 local->dot11RetryCount++;
Johannes Berge039fa42008-05-15 12:55:29 +0200531 if (info->status.retry_count > 1)
Jiri Bencf0706e82007-05-05 11:45:53 -0700532 local->dot11MultipleRetryCount++;
533 }
534
535 /* This counter shall be incremented for an acknowledged MPDU
536 * with an individual address in the address 1 field or an MPDU
537 * with a multicast address in the address 1 field of type Data
538 * or Management. */
539 if (!is_multicast_ether_addr(hdr->addr1) ||
540 type == IEEE80211_FTYPE_DATA ||
541 type == IEEE80211_FTYPE_MGMT)
542 local->dot11TransmittedFragmentCount++;
543 } else {
544 if (frag == 0)
545 local->dot11FailedCount++;
546 }
547
Johannes Bergb306f452007-07-10 19:32:08 +0200548 /* this was a transmitted frame, but now we want to reuse it */
549 skb_orphan(skb);
550
Michael Wu3d30d942008-01-31 19:48:27 +0100551 /*
552 * This is a bit racy but we can avoid a lot of work
553 * with this test...
554 */
555 if (!local->monitors && !local->cooked_mntrs) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700556 dev_kfree_skb(skb);
557 return;
558 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700559
Johannes Bergb306f452007-07-10 19:32:08 +0200560 /* send frame to monitor interfaces now */
561
562 if (skb_headroom(skb) < sizeof(*rthdr)) {
563 printk(KERN_ERR "ieee80211_tx_status: headroom too small\n");
564 dev_kfree_skb(skb);
565 return;
566 }
567
Johannes Berg988c0f72008-04-17 19:21:22 +0200568 rthdr = (struct ieee80211_tx_status_rtap_hdr *)
Johannes Bergb306f452007-07-10 19:32:08 +0200569 skb_push(skb, sizeof(*rthdr));
570
571 memset(rthdr, 0, sizeof(*rthdr));
572 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
573 rthdr->hdr.it_present =
574 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
575 (1 << IEEE80211_RADIOTAP_DATA_RETRIES));
576
Johannes Berge039fa42008-05-15 12:55:29 +0200577 if (!(info->flags & IEEE80211_TX_STAT_ACK) &&
Johannes Bergb306f452007-07-10 19:32:08 +0200578 !is_multicast_ether_addr(hdr->addr1))
579 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL);
580
Johannes Berge039fa42008-05-15 12:55:29 +0200581 if ((info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) &&
582 (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT))
Johannes Bergb306f452007-07-10 19:32:08 +0200583 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS);
Johannes Berge039fa42008-05-15 12:55:29 +0200584 else if (info->flags & IEEE80211_TX_CTL_USE_RTS_CTS)
Johannes Bergb306f452007-07-10 19:32:08 +0200585 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS);
586
Johannes Berge039fa42008-05-15 12:55:29 +0200587 rthdr->data_retries = info->status.retry_count;
Johannes Bergb306f452007-07-10 19:32:08 +0200588
Michael Wu3d30d942008-01-31 19:48:27 +0100589 /* XXX: is this sufficient for BPF? */
590 skb_set_mac_header(skb, 0);
591 skb->ip_summed = CHECKSUM_UNNECESSARY;
592 skb->pkt_type = PACKET_OTHERHOST;
593 skb->protocol = htons(ETH_P_802_2);
594 memset(skb->cb, 0, sizeof(skb->cb));
Johannes Bergb306f452007-07-10 19:32:08 +0200595
Michael Wu3d30d942008-01-31 19:48:27 +0100596 rcu_read_lock();
597 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200598 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
Johannes Bergb306f452007-07-10 19:32:08 +0200599 if (!netif_running(sdata->dev))
600 continue;
Michael Wu3d30d942008-01-31 19:48:27 +0100601
602 if (prev_dev) {
Johannes Berg79010422007-09-18 17:29:21 -0400603 skb2 = skb_clone(skb, GFP_ATOMIC);
Michael Wu3d30d942008-01-31 19:48:27 +0100604 if (skb2) {
605 skb2->dev = prev_dev;
606 netif_rx(skb2);
607 }
608 }
609
610 prev_dev = sdata->dev;
Johannes Bergb306f452007-07-10 19:32:08 +0200611 }
612 }
Michael Wu3d30d942008-01-31 19:48:27 +0100613 if (prev_dev) {
614 skb->dev = prev_dev;
615 netif_rx(skb);
616 skb = NULL;
617 }
Johannes Berg79010422007-09-18 17:29:21 -0400618 rcu_read_unlock();
Michael Wu3d30d942008-01-31 19:48:27 +0100619 dev_kfree_skb(skb);
Jiri Bencf0706e82007-05-05 11:45:53 -0700620}
621EXPORT_SYMBOL(ieee80211_tx_status);
622
Jiri Bencf0706e82007-05-05 11:45:53 -0700623struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
624 const struct ieee80211_ops *ops)
625{
Jiri Bencf0706e82007-05-05 11:45:53 -0700626 struct ieee80211_local *local;
Jiri Bencf0706e82007-05-05 11:45:53 -0700627 int priv_size;
628 struct wiphy *wiphy;
629
630 /* Ensure 32-byte alignment of our private data and hw private data.
631 * We use the wiphy priv data for both our ieee80211_local and for
632 * the driver's private data
633 *
634 * In memory it'll be like this:
635 *
636 * +-------------------------+
637 * | struct wiphy |
638 * +-------------------------+
639 * | struct ieee80211_local |
640 * +-------------------------+
641 * | driver's private data |
642 * +-------------------------+
643 *
644 */
645 priv_size = ((sizeof(struct ieee80211_local) +
646 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) +
647 priv_data_len;
648
649 wiphy = wiphy_new(&mac80211_config_ops, priv_size);
650
651 if (!wiphy)
652 return NULL;
653
654 wiphy->privid = mac80211_wiphy_privid;
655
656 local = wiphy_priv(wiphy);
657 local->hw.wiphy = wiphy;
658
659 local->hw.priv = (char *)local +
660 ((sizeof(struct ieee80211_local) +
661 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
662
Johannes Berg4480f15c2007-07-10 19:32:10 +0200663 BUG_ON(!ops->tx);
Johannes Berg4150c572007-09-17 01:29:23 -0400664 BUG_ON(!ops->start);
665 BUG_ON(!ops->stop);
Johannes Berg4480f15c2007-07-10 19:32:10 +0200666 BUG_ON(!ops->config);
667 BUG_ON(!ops->add_interface);
Johannes Berg4150c572007-09-17 01:29:23 -0400668 BUG_ON(!ops->remove_interface);
669 BUG_ON(!ops->configure_filter);
Jiri Bencf0706e82007-05-05 11:45:53 -0700670 local->ops = ops;
671
Jiri Bencf0706e82007-05-05 11:45:53 -0700672 local->hw.queues = 1; /* default */
673
Jiri Bencf0706e82007-05-05 11:45:53 -0700674 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
675 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
676 local->short_retry_limit = 7;
677 local->long_retry_limit = 4;
Johannes Berge8975582008-10-09 12:18:51 +0200678 local->hw.conf.radio_enabled = true;
Jiri Bencf0706e82007-05-05 11:45:53 -0700679
Johannes Berg79010422007-09-18 17:29:21 -0400680 INIT_LIST_HEAD(&local->interfaces);
Jiri Bencf0706e82007-05-05 11:45:53 -0700681
Johannes Bergb16bd152008-04-11 21:40:35 +0200682 spin_lock_init(&local->key_lock);
683
Johannes Bergc2b13452008-09-11 00:01:55 +0200684 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
Jiri Bencf0706e82007-05-05 11:45:53 -0700685
686 sta_info_init(local);
687
Jiri Bencf0706e82007-05-05 11:45:53 -0700688 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
689 (unsigned long)local);
690 tasklet_disable(&local->tx_pending_tasklet);
691
692 tasklet_init(&local->tasklet,
693 ieee80211_tasklet_handler,
694 (unsigned long) local);
695 tasklet_disable(&local->tasklet);
696
697 skb_queue_head_init(&local->skb_queue);
698 skb_queue_head_init(&local->skb_queue_unreliable);
699
700 return local_to_hw(local);
701}
702EXPORT_SYMBOL(ieee80211_alloc_hw);
703
704int ieee80211_register_hw(struct ieee80211_hw *hw)
705{
706 struct ieee80211_local *local = hw_to_local(hw);
707 const char *name;
708 int result;
Johannes Berg8318d782008-01-24 19:38:38 +0100709 enum ieee80211_band band;
Johannes Berg96d51052008-02-08 09:48:13 +0100710 struct net_device *mdev;
Johannes Berg133b8222008-09-16 14:18:59 +0200711 struct ieee80211_master_priv *mpriv;
Johannes Berg8318d782008-01-24 19:38:38 +0100712
713 /*
714 * generic code guarantees at least one band,
715 * set this very early because much code assumes
716 * that hw.conf.channel is assigned
717 */
718 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
719 struct ieee80211_supported_band *sband;
720
721 sband = local->hw.wiphy->bands[band];
722 if (sband) {
723 /* init channel we're on */
724 local->hw.conf.channel =
725 local->oper_channel =
726 local->scan_channel = &sband->channels[0];
727 break;
728 }
729 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700730
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700731 /* if low-level driver supports AP, we also support VLAN */
732 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_AP))
733 local->hw.wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
734
735 /* mac80211 always supports monitor */
736 local->hw.wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
737
Jiri Bencf0706e82007-05-05 11:45:53 -0700738 result = wiphy_register(local->hw.wiphy);
739 if (result < 0)
740 return result;
741
Johannes Berge2530082008-05-17 00:57:14 +0200742 /*
743 * We use the number of queues for feature tests (QoS, HT) internally
744 * so restrict them appropriately.
745 */
Johannes Berge2530082008-05-17 00:57:14 +0200746 if (hw->queues > IEEE80211_MAX_QUEUES)
747 hw->queues = IEEE80211_MAX_QUEUES;
748 if (hw->ampdu_queues > IEEE80211_MAX_AMPDU_QUEUES)
749 hw->ampdu_queues = IEEE80211_MAX_AMPDU_QUEUES;
750 if (hw->queues < 4)
751 hw->ampdu_queues = 0;
Johannes Berge2530082008-05-17 00:57:14 +0200752
Johannes Berg133b8222008-09-16 14:18:59 +0200753 mdev = alloc_netdev_mq(sizeof(struct ieee80211_master_priv),
Johannes Berge2530082008-05-17 00:57:14 +0200754 "wmaster%d", ether_setup,
755 ieee80211_num_queues(hw));
Johannes Berg96d51052008-02-08 09:48:13 +0100756 if (!mdev)
757 goto fail_mdev_alloc;
758
Johannes Berg133b8222008-09-16 14:18:59 +0200759 mpriv = netdev_priv(mdev);
760 mpriv->local = local;
Johannes Berg96d51052008-02-08 09:48:13 +0100761 local->mdev = mdev;
762
Johannes Berg3e122be2008-07-09 14:40:34 +0200763 ieee80211_rx_bss_list_init(local);
Johannes Berg96d51052008-02-08 09:48:13 +0100764
765 mdev->hard_start_xmit = ieee80211_master_start_xmit;
766 mdev->open = ieee80211_master_open;
767 mdev->stop = ieee80211_master_stop;
768 mdev->type = ARPHRD_IEEE80211;
769 mdev->header_ops = &ieee80211_header_ops;
770 mdev->set_multicast_list = ieee80211_master_set_multicast_list;
771
Jiri Bencf0706e82007-05-05 11:45:53 -0700772 name = wiphy_dev(local->hw.wiphy)->driver->name;
Johannes Berg59959a62008-06-26 19:59:56 +0200773 local->hw.workqueue = create_freezeable_workqueue(name);
Jiri Bencf0706e82007-05-05 11:45:53 -0700774 if (!local->hw.workqueue) {
775 result = -ENOMEM;
776 goto fail_workqueue;
777 }
778
Johannes Bergb306f452007-07-10 19:32:08 +0200779 /*
780 * The hardware needs headroom for sending the frame,
781 * and we need some headroom for passing the frame to monitor
782 * interfaces, but never both at the same time.
783 */
Jiri Benc33ccad32007-07-18 17:10:44 +0200784 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
785 sizeof(struct ieee80211_tx_status_rtap_hdr));
Johannes Bergb306f452007-07-10 19:32:08 +0200786
Jiri Bence9f207f2007-05-05 11:46:38 -0700787 debugfs_hw_add(local);
788
Tomas Winklerdc0ae302008-06-12 22:38:37 +0300789 if (local->hw.conf.beacon_int < 10)
790 local->hw.conf.beacon_int = 100;
Jiri Bencf0706e82007-05-05 11:45:53 -0700791
Tomas Winklerea95bba2008-07-18 13:53:00 +0800792 if (local->hw.max_listen_interval == 0)
793 local->hw.max_listen_interval = 1;
794
795 local->hw.conf.listen_interval = local->hw.max_listen_interval;
796
Bruno Randolf566bfe52008-05-08 19:15:40 +0200797 local->wstats_flags |= local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
798 IEEE80211_HW_SIGNAL_DB |
799 IEEE80211_HW_SIGNAL_DBM) ?
Jiri Bencf0706e82007-05-05 11:45:53 -0700800 IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
Bruno Randolf566bfe52008-05-08 19:15:40 +0200801 local->wstats_flags |= local->hw.flags & IEEE80211_HW_NOISE_DBM ?
Jiri Bencf0706e82007-05-05 11:45:53 -0700802 IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
Bruno Randolf566bfe52008-05-08 19:15:40 +0200803 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
Jiri Bencf0706e82007-05-05 11:45:53 -0700804 local->wstats_flags |= IW_QUAL_DBM;
805
806 result = sta_info_start(local);
807 if (result < 0)
808 goto fail_sta_info;
809
810 rtnl_lock();
811 result = dev_alloc_name(local->mdev, local->mdev->name);
812 if (result < 0)
813 goto fail_dev;
814
815 memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
816 SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy));
817
818 result = register_netdevice(local->mdev);
819 if (result < 0)
820 goto fail_dev;
821
Johannes Berg830f9032007-10-28 14:51:05 +0100822 result = ieee80211_init_rate_ctrl_alg(local,
823 hw->rate_control_algorithm);
Jiri Bencf0706e82007-05-05 11:45:53 -0700824 if (result < 0) {
825 printk(KERN_DEBUG "%s: Failed to initialize rate control "
Johannes Bergdd1cd4c2007-09-18 17:29:20 -0400826 "algorithm\n", wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -0700827 goto fail_rate;
828 }
829
830 result = ieee80211_wep_init(local);
831
832 if (result < 0) {
Jeremy Fitzhardinge023a04b2008-07-14 12:52:08 -0700833 printk(KERN_DEBUG "%s: Failed to initialize wep: %d\n",
834 wiphy_name(local->hw.wiphy), result);
Jiri Bencf0706e82007-05-05 11:45:53 -0700835 goto fail_wep;
836 }
837
David S. Miller51cb6db2008-07-15 03:34:57 -0700838 local->mdev->select_queue = ieee80211_select_queue;
Jiri Bencf0706e82007-05-05 11:45:53 -0700839
840 /* add one default STA interface */
Johannes Berg3e122be2008-07-09 14:40:34 +0200841 result = ieee80211_if_add(local, "wlan%d", NULL,
Johannes Berg05c914f2008-09-11 00:01:58 +0200842 NL80211_IFTYPE_STATION, NULL);
Jiri Bencf0706e82007-05-05 11:45:53 -0700843 if (result)
844 printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -0400845 wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -0700846
Jiri Bencf0706e82007-05-05 11:45:53 -0700847 rtnl_unlock();
848
849 ieee80211_led_init(local);
850
851 return 0;
852
853fail_wep:
854 rate_control_deinitialize(local);
855fail_rate:
856 unregister_netdevice(local->mdev);
Pavel Emelyanov339a7c42008-05-04 17:59:30 -0700857 local->mdev = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700858fail_dev:
859 rtnl_unlock();
860 sta_info_stop(local);
861fail_sta_info:
Jiri Bence9f207f2007-05-05 11:46:38 -0700862 debugfs_hw_del(local);
Jiri Bencf0706e82007-05-05 11:45:53 -0700863 destroy_workqueue(local->hw.workqueue);
864fail_workqueue:
Johannes Berg3e122be2008-07-09 14:40:34 +0200865 if (local->mdev)
866 free_netdev(local->mdev);
Johannes Berg96d51052008-02-08 09:48:13 +0100867fail_mdev_alloc:
Jiri Bencf0706e82007-05-05 11:45:53 -0700868 wiphy_unregister(local->hw.wiphy);
869 return result;
870}
871EXPORT_SYMBOL(ieee80211_register_hw);
872
Jiri Bencf0706e82007-05-05 11:45:53 -0700873void ieee80211_unregister_hw(struct ieee80211_hw *hw)
874{
875 struct ieee80211_local *local = hw_to_local(hw);
Jiri Bencf0706e82007-05-05 11:45:53 -0700876
877 tasklet_kill(&local->tx_pending_tasklet);
878 tasklet_kill(&local->tasklet);
879
880 rtnl_lock();
881
Johannes Berg79010422007-09-18 17:29:21 -0400882 /*
883 * At this point, interface list manipulations are fine
884 * because the driver cannot be handing us frames any
885 * more and the tasklet is killed.
886 */
Johannes Berg5b2812e2007-09-26 14:27:23 +0200887
Johannes Berg75636522008-07-09 14:40:35 +0200888 /* First, we remove all virtual interfaces. */
889 ieee80211_remove_interfaces(local);
Johannes Berg5b2812e2007-09-26 14:27:23 +0200890
891 /* then, finally, remove the master interface */
Johannes Berg3e122be2008-07-09 14:40:34 +0200892 unregister_netdevice(local->mdev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700893
894 rtnl_unlock();
895
Johannes Berg3e122be2008-07-09 14:40:34 +0200896 ieee80211_rx_bss_list_deinit(local);
Jiri Bencf0706e82007-05-05 11:45:53 -0700897 ieee80211_clear_tx_pending(local);
898 sta_info_stop(local);
899 rate_control_deinitialize(local);
Jiri Bence9f207f2007-05-05 11:46:38 -0700900 debugfs_hw_del(local);
Jiri Bencf0706e82007-05-05 11:45:53 -0700901
Jiri Bencf0706e82007-05-05 11:45:53 -0700902 if (skb_queue_len(&local->skb_queue)
903 || skb_queue_len(&local->skb_queue_unreliable))
904 printk(KERN_WARNING "%s: skb_queue not empty\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -0400905 wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -0700906 skb_queue_purge(&local->skb_queue);
907 skb_queue_purge(&local->skb_queue_unreliable);
908
909 destroy_workqueue(local->hw.workqueue);
910 wiphy_unregister(local->hw.wiphy);
911 ieee80211_wep_free(local);
912 ieee80211_led_exit(local);
Johannes Berg3e122be2008-07-09 14:40:34 +0200913 free_netdev(local->mdev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700914}
915EXPORT_SYMBOL(ieee80211_unregister_hw);
916
917void ieee80211_free_hw(struct ieee80211_hw *hw)
918{
919 struct ieee80211_local *local = hw_to_local(hw);
920
Jiri Bencf0706e82007-05-05 11:45:53 -0700921 wiphy_free(local->hw.wiphy);
922}
923EXPORT_SYMBOL(ieee80211_free_hw);
924
Jiri Bencf0706e82007-05-05 11:45:53 -0700925static int __init ieee80211_init(void)
926{
927 struct sk_buff *skb;
928 int ret;
929
Johannes Berge039fa42008-05-15 12:55:29 +0200930 BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb));
931 BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) +
Johannes Bergc6a1fa12008-10-07 12:04:32 +0200932 IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb));
Jiri Bencf0706e82007-05-05 11:45:53 -0700933
Felix Fietkaucccf1292008-10-05 18:07:45 +0200934 ret = rc80211_minstrel_init();
935 if (ret)
936 return ret;
937
Johannes Berg4b475892008-01-02 15:17:03 +0100938 ret = rc80211_pid_init();
Mattias Nisslerad018372007-12-19 01:25:57 +0100939 if (ret)
David S. Miller51cb6db2008-07-15 03:34:57 -0700940 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -0700941
Jiri Bence9f207f2007-05-05 11:46:38 -0700942 ieee80211_debugfs_netdev_init();
943
Jiri Bencf0706e82007-05-05 11:45:53 -0700944 return 0;
945}
946
Jiri Bencf0706e82007-05-05 11:45:53 -0700947static void __exit ieee80211_exit(void)
948{
Johannes Berg4b475892008-01-02 15:17:03 +0100949 rc80211_pid_exit();
Felix Fietkaucccf1292008-10-05 18:07:45 +0200950 rc80211_minstrel_exit();
Johannes Bergac71c692007-10-28 14:17:44 +0100951
Johannes Berg3b967662008-04-08 17:56:52 +0200952 /*
953 * For key todo, it'll be empty by now but the work
954 * might still be scheduled.
955 */
956 flush_scheduled_work();
957
Luis Carlos Cobof7a92142008-02-23 15:17:18 +0100958 if (mesh_allocated)
959 ieee80211s_stop();
Johannes Berg902acc72008-02-23 15:17:19 +0100960
Jiri Bence9f207f2007-05-05 11:46:38 -0700961 ieee80211_debugfs_netdev_exit();
Jiri Bencf0706e82007-05-05 11:45:53 -0700962}
963
964
Johannes Bergca9938f2007-09-11 12:50:32 +0200965subsys_initcall(ieee80211_init);
Jiri Bencf0706e82007-05-05 11:45:53 -0700966module_exit(ieee80211_exit);
967
968MODULE_DESCRIPTION("IEEE 802.11 subsystem");
969MODULE_LICENSE("GPL");