blob: 8c0f782d21e361a20fe1b828b327d4fc481125c3 [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"
28#include "ieee80211_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"
33#include "ieee80211_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
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +020038#define SUPP_MCS_SET_LEN 16
39
Johannes Bergb306f452007-07-10 19:32:08 +020040/*
41 * For seeing transmitted packets on monitor interfaces
42 * we have a radiotap header too.
43 */
44struct ieee80211_tx_status_rtap_hdr {
45 struct ieee80211_radiotap_header hdr;
46 __le16 tx_flags;
47 u8 data_retries;
48} __attribute__ ((packed));
49
Johannes Bergb2c258f2007-07-27 15:43:23 +020050/* common interface routines */
Jiri Bencf0706e82007-05-05 11:45:53 -070051
Stephen Hemmingerb95cce32007-09-26 22:13:38 -070052static int header_parse_80211(const struct sk_buff *skb, unsigned char *haddr)
Jiri Bencf0706e82007-05-05 11:45:53 -070053{
Johannes Bergb2c258f2007-07-27 15:43:23 +020054 memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
55 return ETH_ALEN;
Jiri Bencf0706e82007-05-05 11:45:53 -070056}
57
Johannes Berg4150c572007-09-17 01:29:23 -040058/* must be called under mdev tx lock */
59static void ieee80211_configure_filter(struct ieee80211_local *local)
60{
61 unsigned int changed_flags;
62 unsigned int new_flags = 0;
63
Johannes Berg53918992007-09-26 15:19:47 +020064 if (atomic_read(&local->iff_promiscs))
Johannes Berg4150c572007-09-17 01:29:23 -040065 new_flags |= FIF_PROMISC_IN_BSS;
66
Johannes Berg53918992007-09-26 15:19:47 +020067 if (atomic_read(&local->iff_allmultis))
Johannes Berg4150c572007-09-17 01:29:23 -040068 new_flags |= FIF_ALLMULTI;
69
70 if (local->monitors)
Michael Wu8cc9a732008-01-31 19:48:23 +010071 new_flags |= FIF_BCN_PRBRESP_PROMISC;
72
73 if (local->fif_fcsfail)
74 new_flags |= FIF_FCSFAIL;
75
76 if (local->fif_plcpfail)
77 new_flags |= FIF_PLCPFAIL;
78
79 if (local->fif_control)
80 new_flags |= FIF_CONTROL;
81
82 if (local->fif_other_bss)
83 new_flags |= FIF_OTHER_BSS;
Johannes Berg4150c572007-09-17 01:29:23 -040084
85 changed_flags = local->filter_flags ^ new_flags;
86
87 /* be a bit nasty */
88 new_flags |= (1<<31);
89
90 local->ops->configure_filter(local_to_hw(local),
91 changed_flags, &new_flags,
92 local->mdev->mc_count,
93 local->mdev->mc_list);
94
95 WARN_ON(new_flags & (1<<31));
96
97 local->filter_flags = new_flags & ~(1<<31);
98}
99
Johannes Bergb2c258f2007-07-27 15:43:23 +0200100/* master interface */
Jiri Bencf0706e82007-05-05 11:45:53 -0700101
102static int ieee80211_master_open(struct net_device *dev)
103{
104 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
105 struct ieee80211_sub_if_data *sdata;
106 int res = -EOPNOTSUPP;
107
Johannes Berg79010422007-09-18 17:29:21 -0400108 /* we hold the RTNL here so can safely walk the list */
109 list_for_each_entry(sdata, &local->interfaces, list) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700110 if (sdata->dev != dev && netif_running(sdata->dev)) {
111 res = 0;
112 break;
113 }
114 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700115 return res;
116}
117
118static int ieee80211_master_stop(struct net_device *dev)
119{
120 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
121 struct ieee80211_sub_if_data *sdata;
122
Johannes Berg79010422007-09-18 17:29:21 -0400123 /* we hold the RTNL here so can safely walk the list */
124 list_for_each_entry(sdata, &local->interfaces, list)
Jiri Bencf0706e82007-05-05 11:45:53 -0700125 if (sdata->dev != dev && netif_running(sdata->dev))
126 dev_close(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700127
128 return 0;
129}
130
Johannes Berg4150c572007-09-17 01:29:23 -0400131static void ieee80211_master_set_multicast_list(struct net_device *dev)
132{
133 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
134
135 ieee80211_configure_filter(local);
136}
137
Johannes Bergb2c258f2007-07-27 15:43:23 +0200138/* regular interfaces */
139
140static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
141{
Luis Carlos Cobof7a92142008-02-23 15:17:18 +0100142 int meshhdrlen;
143 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
144
145 meshhdrlen = (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT) ? 5 : 0;
146
Johannes Bergb2c258f2007-07-27 15:43:23 +0200147 /* FIX: what would be proper limits for MTU?
148 * This interface uses 802.3 frames. */
Luis Carlos Cobof7a92142008-02-23 15:17:18 +0100149 if (new_mtu < 256 ||
150 new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6 - meshhdrlen) {
Johannes Bergb2c258f2007-07-27 15:43:23 +0200151 printk(KERN_WARNING "%s: invalid MTU %d\n",
152 dev->name, new_mtu);
153 return -EINVAL;
154 }
155
156#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
157 printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu);
158#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
159 dev->mtu = new_mtu;
160 return 0;
161}
162
163static inline int identical_mac_addr_allowed(int type1, int type2)
164{
165 return (type1 == IEEE80211_IF_TYPE_MNTR ||
166 type2 == IEEE80211_IF_TYPE_MNTR ||
167 (type1 == IEEE80211_IF_TYPE_AP &&
168 type2 == IEEE80211_IF_TYPE_WDS) ||
169 (type1 == IEEE80211_IF_TYPE_WDS &&
170 (type2 == IEEE80211_IF_TYPE_WDS ||
171 type2 == IEEE80211_IF_TYPE_AP)) ||
172 (type1 == IEEE80211_IF_TYPE_AP &&
173 type2 == IEEE80211_IF_TYPE_VLAN) ||
174 (type1 == IEEE80211_IF_TYPE_VLAN &&
175 (type2 == IEEE80211_IF_TYPE_AP ||
176 type2 == IEEE80211_IF_TYPE_VLAN)));
177}
178
Johannes Bergb2c258f2007-07-27 15:43:23 +0200179static int ieee80211_open(struct net_device *dev)
180{
181 struct ieee80211_sub_if_data *sdata, *nsdata;
182 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
183 struct ieee80211_if_init_conf conf;
184 int res;
Michael Bueschceffefd2008-02-10 14:16:52 +0100185 bool need_hw_reconfig = 0;
Johannes Berg44213b52008-02-25 16:27:49 +0100186 struct sta_info *sta;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200187
188 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400189
Johannes Berg79010422007-09-18 17:29:21 -0400190 /* we hold the RTNL here so can safely walk the list */
191 list_for_each_entry(nsdata, &local->interfaces, list) {
Johannes Bergb2c258f2007-07-27 15:43:23 +0200192 struct net_device *ndev = nsdata->dev;
193
Johannes Berg665e8aa2008-02-21 01:10:07 +0100194 if (ndev != dev && ndev != local->mdev && netif_running(ndev)) {
195 /*
196 * Allow only a single IBSS interface to be up at any
197 * time. This is restricted because beacon distribution
198 * cannot work properly if both are in the same IBSS.
199 *
200 * To remove this restriction we'd have to disallow them
201 * from setting the same SSID on different IBSS interfaces
202 * belonging to the same hardware. Then, however, we're
203 * faced with having to adopt two different TSF timers...
204 */
205 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
206 nsdata->vif.type == IEEE80211_IF_TYPE_IBSS)
207 return -EBUSY;
208
209 /*
210 * Disallow multiple IBSS/STA mode interfaces.
211 *
212 * This is a technical restriction, it is possible although
213 * most likely not IEEE 802.11 compliant to have multiple
214 * STAs with just a single hardware (the TSF timer will not
215 * be adjusted properly.)
216 *
217 * However, because mac80211 uses the master device's BSS
218 * information for each STA/IBSS interface, doing this will
219 * currently corrupt that BSS information completely, unless,
220 * a not very useful case, both STAs are associated to the
221 * same BSS.
222 *
223 * To remove this restriction, the BSS information needs to
224 * be embedded in the STA/IBSS mode sdata instead of using
225 * the master device's BSS structure.
226 */
227 if ((sdata->vif.type == IEEE80211_IF_TYPE_STA ||
228 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) &&
229 (nsdata->vif.type == IEEE80211_IF_TYPE_STA ||
230 nsdata->vif.type == IEEE80211_IF_TYPE_IBSS))
231 return -EBUSY;
232
233 /*
234 * The remaining checks are only performed for interfaces
235 * with the same MAC address.
236 */
237 if (compare_ether_addr(dev->dev_addr, ndev->dev_addr))
238 continue;
239
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400240 /*
241 * check whether it may have the same address
242 */
Johannes Berg51fb61e2007-12-19 01:31:27 +0100243 if (!identical_mac_addr_allowed(sdata->vif.type,
244 nsdata->vif.type))
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400245 return -ENOTUNIQ;
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400246
247 /*
248 * can only add VLANs to enabled APs
249 */
Johannes Berg51fb61e2007-12-19 01:31:27 +0100250 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN &&
Johannes Berg665e8aa2008-02-21 01:10:07 +0100251 nsdata->vif.type == IEEE80211_IF_TYPE_AP)
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400252 sdata->u.vlan.ap = nsdata;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200253 }
254 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200255
Johannes Berg51fb61e2007-12-19 01:31:27 +0100256 switch (sdata->vif.type) {
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400257 case IEEE80211_IF_TYPE_WDS:
258 if (is_zero_ether_addr(sdata->u.wds.remote_addr))
259 return -ENOLINK;
Johannes Berg44213b52008-02-25 16:27:49 +0100260
261 /* Create STA entry for the WDS peer */
262 sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
263 GFP_KERNEL);
264 if (!sta)
265 return -ENOMEM;
266
267 sta->flags |= WLAN_STA_AUTHORIZED;
268
269 res = sta_info_insert(sta);
270 if (res) {
271 sta_info_destroy(sta);
272 return res;
273 }
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400274 break;
275 case IEEE80211_IF_TYPE_VLAN:
276 if (!sdata->u.vlan.ap)
277 return -ENOLINK;
278 break;
Johannes Bergfb1c1cd2007-09-26 15:19:43 +0200279 case IEEE80211_IF_TYPE_AP:
Johannes Bergfb1c1cd2007-09-26 15:19:43 +0200280 case IEEE80211_IF_TYPE_STA:
281 case IEEE80211_IF_TYPE_MNTR:
282 case IEEE80211_IF_TYPE_IBSS:
Johannes Berg6032f932008-02-23 15:17:07 +0100283 case IEEE80211_IF_TYPE_MESH_POINT:
Johannes Bergfb1c1cd2007-09-26 15:19:43 +0200284 /* no special treatment */
285 break;
Johannes Berga2897552007-09-28 14:01:25 +0200286 case IEEE80211_IF_TYPE_INVALID:
287 /* cannot happen */
288 WARN_ON(1);
289 break;
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400290 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200291
Johannes Bergb2c258f2007-07-27 15:43:23 +0200292 if (local->open_count == 0) {
293 res = 0;
Johannes Berg4150c572007-09-17 01:29:23 -0400294 if (local->ops->start)
295 res = local->ops->start(local_to_hw(local));
296 if (res)
Johannes Bergb2c258f2007-07-27 15:43:23 +0200297 return res;
Michael Bueschceffefd2008-02-10 14:16:52 +0100298 need_hw_reconfig = 1;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100299 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200300 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200301
Johannes Berg51fb61e2007-12-19 01:31:27 +0100302 switch (sdata->vif.type) {
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400303 case IEEE80211_IF_TYPE_VLAN:
304 list_add(&sdata->u.vlan.list, &sdata->u.vlan.ap->u.ap.vlans);
305 /* no need to tell driver */
306 break;
Johannes Berg4150c572007-09-17 01:29:23 -0400307 case IEEE80211_IF_TYPE_MNTR:
Michael Wu3d30d942008-01-31 19:48:27 +0100308 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
309 local->cooked_mntrs++;
310 break;
311 }
312
Johannes Berg4150c572007-09-17 01:29:23 -0400313 /* must be before the call to ieee80211_configure_filter */
Johannes Bergb2c258f2007-07-27 15:43:23 +0200314 local->monitors++;
Michael Wu8cc9a732008-01-31 19:48:23 +0100315 if (local->monitors == 1)
Johannes Berg4150c572007-09-17 01:29:23 -0400316 local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
Michael Wu8cc9a732008-01-31 19:48:23 +0100317
318 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
319 local->fif_fcsfail++;
320 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
321 local->fif_plcpfail++;
322 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
323 local->fif_control++;
324 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
325 local->fif_other_bss++;
326
327 netif_tx_lock_bh(local->mdev);
328 ieee80211_configure_filter(local);
329 netif_tx_unlock_bh(local->mdev);
Johannes Berg4150c572007-09-17 01:29:23 -0400330 break;
331 case IEEE80211_IF_TYPE_STA:
332 case IEEE80211_IF_TYPE_IBSS:
333 sdata->u.sta.flags &= ~IEEE80211_STA_PREV_BSSID_SET;
334 /* fall through */
335 default:
Johannes Berg32bfd352007-12-19 01:31:26 +0100336 conf.vif = &sdata->vif;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100337 conf.type = sdata->vif.type;
Johannes Berg4150c572007-09-17 01:29:23 -0400338 conf.mac_addr = dev->dev_addr;
339 res = local->ops->add_interface(local_to_hw(local), &conf);
340 if (res && !local->open_count && local->ops->stop)
341 local->ops->stop(local_to_hw(local));
342 if (res)
343 return res;
344
Johannes Bergb2c258f2007-07-27 15:43:23 +0200345 ieee80211_if_config(dev);
Daniel Draked9430a32007-07-27 15:43:24 +0200346 ieee80211_reset_erp_info(dev);
Johannes Berg11a843b2007-08-28 17:01:55 -0400347 ieee80211_enable_keys(sdata);
Johannes Berg4150c572007-09-17 01:29:23 -0400348
Johannes Berg51fb61e2007-12-19 01:31:27 +0100349 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200350 !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME))
Johannes Berg4150c572007-09-17 01:29:23 -0400351 netif_carrier_off(dev);
352 else
353 netif_carrier_on(dev);
Daniel Draked9430a32007-07-27 15:43:24 +0200354 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200355
Johannes Berg4150c572007-09-17 01:29:23 -0400356 if (local->open_count == 0) {
357 res = dev_open(local->mdev);
358 WARN_ON(res);
Johannes Berg4150c572007-09-17 01:29:23 -0400359 tasklet_enable(&local->tx_pending_tasklet);
360 tasklet_enable(&local->tasklet);
361 }
362
Johannes Bergc1428b32007-11-16 02:54:53 +0100363 /*
364 * set_multicast_list will be invoked by the networking core
365 * which will check whether any increments here were done in
366 * error and sync them down to the hardware as filter flags.
367 */
368 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
369 atomic_inc(&local->iff_allmultis);
370
371 if (sdata->flags & IEEE80211_SDATA_PROMISC)
372 atomic_inc(&local->iff_promiscs);
373
Johannes Berg4150c572007-09-17 01:29:23 -0400374 local->open_count++;
Michael Bueschceffefd2008-02-10 14:16:52 +0100375 if (need_hw_reconfig)
376 ieee80211_hw_config(local);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200377
378 netif_start_queue(dev);
Johannes Berg4150c572007-09-17 01:29:23 -0400379
Johannes Bergb2c258f2007-07-27 15:43:23 +0200380 return 0;
381}
382
Johannes Berg4150c572007-09-17 01:29:23 -0400383static int ieee80211_stop(struct net_device *dev)
Johannes Bergb2c258f2007-07-27 15:43:23 +0200384{
Johannes Berg44213b52008-02-25 16:27:49 +0100385 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
386 struct ieee80211_local *local = sdata->local;
Johannes Berg4150c572007-09-17 01:29:23 -0400387 struct ieee80211_if_init_conf conf;
Ron Rindjunsky07db2182007-12-25 17:00:33 +0200388 struct sta_info *sta;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200389
Johannes Berg44213b52008-02-25 16:27:49 +0100390 /*
391 * Stop TX on this interface first.
392 */
393 netif_stop_queue(dev);
Johannes Berg4150c572007-09-17 01:29:23 -0400394
Johannes Berg44213b52008-02-25 16:27:49 +0100395 /*
396 * Now delete all active aggregation sessions.
397 */
Johannes Bergd0709a62008-02-25 16:27:46 +0100398 rcu_read_lock();
399
400 list_for_each_entry_rcu(sta, &local->sta_list, list) {
401 if (sta->sdata == sdata)
Ron Rindjunsky85249e52008-03-18 15:00:32 -0700402 ieee80211_sta_tear_down_BA_sessions(dev, sta->addr);
Ron Rindjunsky07db2182007-12-25 17:00:33 +0200403 }
404
Johannes Bergd0709a62008-02-25 16:27:46 +0100405 rcu_read_unlock();
406
Johannes Berg44213b52008-02-25 16:27:49 +0100407 /*
408 * Remove all stations associated with this interface.
409 *
410 * This must be done before calling ops->remove_interface()
411 * because otherwise we can later invoke ops->sta_notify()
412 * whenever the STAs are removed, and that invalidates driver
413 * assumptions about always getting a vif pointer that is valid
414 * (because if we remove a STA after ops->remove_interface()
415 * the driver will have removed the vif info already!)
416 *
417 * We could relax this and only unlink the stations from the
418 * hash table and list but keep them on a per-sdata list that
419 * will be inserted back again when the interface is brought
420 * up again, but I don't currently see a use case for that,
421 * except with WDS which gets a STA entry created when it is
422 * brought up.
423 */
424 sta_info_flush(local, sdata);
Johannes Berg4150c572007-09-17 01:29:23 -0400425
Johannes Bergc1428b32007-11-16 02:54:53 +0100426 /*
427 * Don't count this interface for promisc/allmulti while it
428 * is down. dev_mc_unsync() will invoke set_multicast_list
429 * on the master interface which will sync these down to the
430 * hardware as filter flags.
431 */
432 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
433 atomic_dec(&local->iff_allmultis);
434
435 if (sdata->flags & IEEE80211_SDATA_PROMISC)
436 atomic_dec(&local->iff_promiscs);
437
Johannes Berg4150c572007-09-17 01:29:23 -0400438 dev_mc_unsync(local->mdev, dev);
439
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100440 /* APs need special treatment */
Johannes Berg51fb61e2007-12-19 01:31:27 +0100441 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400442 struct ieee80211_sub_if_data *vlan, *tmp;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100443 struct beacon_data *old_beacon = sdata->u.ap.beacon;
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400444
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100445 /* remove beacon */
446 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
447 synchronize_rcu();
448 kfree(old_beacon);
449
450 /* down all dependent devices, that is VLANs */
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400451 list_for_each_entry_safe(vlan, tmp, &sdata->u.ap.vlans,
452 u.vlan.list)
453 dev_close(vlan->dev);
454 WARN_ON(!list_empty(&sdata->u.ap.vlans));
455 }
456
Johannes Berg4150c572007-09-17 01:29:23 -0400457 local->open_count--;
458
Johannes Berg51fb61e2007-12-19 01:31:27 +0100459 switch (sdata->vif.type) {
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400460 case IEEE80211_IF_TYPE_VLAN:
461 list_del(&sdata->u.vlan.list);
462 sdata->u.vlan.ap = NULL;
463 /* no need to tell driver */
464 break;
Johannes Berg4150c572007-09-17 01:29:23 -0400465 case IEEE80211_IF_TYPE_MNTR:
Michael Wu3d30d942008-01-31 19:48:27 +0100466 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
467 local->cooked_mntrs--;
468 break;
469 }
470
Johannes Berg4150c572007-09-17 01:29:23 -0400471 local->monitors--;
Michael Wu8cc9a732008-01-31 19:48:23 +0100472 if (local->monitors == 0)
Michael Wu8b393f12007-11-28 01:57:08 -0500473 local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
Michael Wu8cc9a732008-01-31 19:48:23 +0100474
475 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
476 local->fif_fcsfail--;
477 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
478 local->fif_plcpfail--;
479 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
480 local->fif_control--;
481 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
482 local->fif_other_bss--;
483
484 netif_tx_lock_bh(local->mdev);
485 ieee80211_configure_filter(local);
486 netif_tx_unlock_bh(local->mdev);
Johannes Berg4150c572007-09-17 01:29:23 -0400487 break;
Luis Carlos Cobof7a92142008-02-23 15:17:18 +0100488 case IEEE80211_IF_TYPE_MESH_POINT:
Johannes Bergb2c258f2007-07-27 15:43:23 +0200489 case IEEE80211_IF_TYPE_STA:
490 case IEEE80211_IF_TYPE_IBSS:
491 sdata->u.sta.state = IEEE80211_DISABLED;
492 del_timer_sync(&sdata->u.sta.timer);
Johannes Berg2a8a9a82007-08-28 17:01:52 -0400493 /*
Johannes Berg79010422007-09-18 17:29:21 -0400494 * When we get here, the interface is marked down.
495 * Call synchronize_rcu() to wait for the RX path
496 * should it be using the interface and enqueuing
497 * frames at this very time on another CPU.
Johannes Berg2a8a9a82007-08-28 17:01:52 -0400498 */
Johannes Berg79010422007-09-18 17:29:21 -0400499 synchronize_rcu();
Johannes Bergb2c258f2007-07-27 15:43:23 +0200500 skb_queue_purge(&sdata->u.sta.skb_queue);
Johannes Berg2a8a9a82007-08-28 17:01:52 -0400501
Zhu Yiece8edd2007-11-22 10:53:21 +0800502 if (local->scan_dev == sdata->dev) {
503 if (!local->ops->hw_scan) {
504 local->sta_sw_scanning = 0;
505 cancel_delayed_work(&local->scan_work);
506 } else
507 local->sta_hw_scanning = 0;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200508 }
Zhu Yiece8edd2007-11-22 10:53:21 +0800509
Johannes Bergb2c258f2007-07-27 15:43:23 +0200510 flush_workqueue(local->hw.workqueue);
Zhu Yia10605e2007-11-22 11:10:22 +0800511
512 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
513 kfree(sdata->u.sta.extra_ie);
514 sdata->u.sta.extra_ie = NULL;
515 sdata->u.sta.extra_ie_len = 0;
Johannes Berg4150c572007-09-17 01:29:23 -0400516 /* fall through */
517 default:
Johannes Berg32bfd352007-12-19 01:31:26 +0100518 conf.vif = &sdata->vif;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100519 conf.type = sdata->vif.type;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200520 conf.mac_addr = dev->dev_addr;
Johannes Berg4150c572007-09-17 01:29:23 -0400521 /* disable all keys for as long as this netdev is down */
522 ieee80211_disable_keys(sdata);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200523 local->ops->remove_interface(local_to_hw(local), &conf);
524 }
525
Johannes Berg4150c572007-09-17 01:29:23 -0400526 if (local->open_count == 0) {
527 if (netif_running(local->mdev))
528 dev_close(local->mdev);
529
Johannes Berg4150c572007-09-17 01:29:23 -0400530 if (local->ops->stop)
531 local->ops->stop(local_to_hw(local));
532
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100533 ieee80211_led_radio(local, 0);
534
Johannes Berg4150c572007-09-17 01:29:23 -0400535 tasklet_disable(&local->tx_pending_tasklet);
536 tasklet_disable(&local->tasklet);
537 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200538
539 return 0;
540}
541
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200542int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
543{
544 struct ieee80211_local *local = hw_to_local(hw);
545 struct sta_info *sta;
546 struct ieee80211_sub_if_data *sdata;
547 u16 start_seq_num = 0;
548 u8 *state;
549 int ret;
550 DECLARE_MAC_BUF(mac);
551
552 if (tid >= STA_TID_NUM)
553 return -EINVAL;
554
555#ifdef CONFIG_MAC80211_HT_DEBUG
556 printk(KERN_DEBUG "Open BA session requested for %s tid %u\n",
557 print_mac(mac, ra), tid);
558#endif /* CONFIG_MAC80211_HT_DEBUG */
559
Johannes Bergd0709a62008-02-25 16:27:46 +0100560 rcu_read_lock();
561
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200562 sta = sta_info_get(local, ra);
563 if (!sta) {
564 printk(KERN_DEBUG "Could not find the station\n");
Johannes Bergd0709a62008-02-25 16:27:46 +0100565 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200566 return -ENOENT;
567 }
568
569 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
570
571 /* we have tried too many times, receiver does not want A-MPDU */
Ron Rindjunskycee24a32008-03-26 20:36:03 +0200572 if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) {
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200573 ret = -EBUSY;
574 goto start_ba_exit;
575 }
576
Ron Rindjunskycee24a32008-03-26 20:36:03 +0200577 state = &sta->ampdu_mlme.tid_state_tx[tid];
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200578 /* check if the TID is not in aggregation flow already */
579 if (*state != HT_AGG_STATE_IDLE) {
580#ifdef CONFIG_MAC80211_HT_DEBUG
581 printk(KERN_DEBUG "BA request denied - session is not "
582 "idle on tid %u\n", tid);
583#endif /* CONFIG_MAC80211_HT_DEBUG */
584 ret = -EAGAIN;
585 goto start_ba_exit;
586 }
587
Ron Rindjunskycee24a32008-03-26 20:36:03 +0200588 /* prepare A-MPDU MLME for Tx aggregation */
589 sta->ampdu_mlme.tid_tx[tid] =
590 kmalloc(sizeof(struct tid_ampdu_tx), GFP_ATOMIC);
591 if (!sta->ampdu_mlme.tid_tx[tid]) {
592 if (net_ratelimit())
593 printk(KERN_ERR "allocate tx mlme to tid %d failed\n",
594 tid);
595 ret = -ENOMEM;
596 goto start_ba_exit;
597 }
598 /* Tx timer */
599 sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.function =
600 sta_addba_resp_timer_expired;
601 sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.data =
602 (unsigned long)&sta->timer_to_tid[tid];
603 init_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
604
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200605 /* ensure that TX flow won't interrupt us
606 * until the end of the call to requeue function */
607 spin_lock_bh(&local->mdev->queue_lock);
608
609 /* create a new queue for this aggregation */
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200610 ret = ieee80211_ht_agg_queue_add(local, sta, tid);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200611
612 /* case no queue is available to aggregation
613 * don't switch to aggregation */
614 if (ret) {
615#ifdef CONFIG_MAC80211_HT_DEBUG
Ron Rindjunskycee24a32008-03-26 20:36:03 +0200616 printk(KERN_DEBUG "BA request denied - queue unavailable for"
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200617 " tid %d\n", tid);
618#endif /* CONFIG_MAC80211_HT_DEBUG */
Ron Rindjunskycee24a32008-03-26 20:36:03 +0200619 goto start_ba_err;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200620 }
Johannes Bergd0709a62008-02-25 16:27:46 +0100621 sdata = sta->sdata;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200622
623 /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
624 * call back right away, it must see that the flow has begun */
625 *state |= HT_ADDBA_REQUESTED_MSK;
626
627 if (local->ops->ampdu_action)
628 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START,
629 ra, tid, &start_seq_num);
630
631 if (ret) {
632 /* No need to requeue the packets in the agg queue, since we
633 * held the tx lock: no packet could be enqueued to the newly
634 * allocated queue */
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200635 ieee80211_ht_agg_queue_remove(local, sta, tid, 0);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200636#ifdef CONFIG_MAC80211_HT_DEBUG
Ron Rindjunskycee24a32008-03-26 20:36:03 +0200637 printk(KERN_DEBUG "BA request denied - HW unavailable for"
638 " tid %d\n", tid);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200639#endif /* CONFIG_MAC80211_HT_DEBUG */
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200640 *state = HT_AGG_STATE_IDLE;
Ron Rindjunskycee24a32008-03-26 20:36:03 +0200641 goto start_ba_err;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200642 }
643
644 /* Will put all the packets in the new SW queue */
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200645 ieee80211_requeue(local, ieee802_1d_to_ac[tid]);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200646 spin_unlock_bh(&local->mdev->queue_lock);
647
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200648 /* send an addBA request */
649 sta->ampdu_mlme.dialog_token_allocator++;
Ron Rindjunskycee24a32008-03-26 20:36:03 +0200650 sta->ampdu_mlme.tid_tx[tid]->dialog_token =
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200651 sta->ampdu_mlme.dialog_token_allocator;
Ron Rindjunskycee24a32008-03-26 20:36:03 +0200652 sta->ampdu_mlme.tid_tx[tid]->ssn = start_seq_num;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200653
Johannes Bergd0709a62008-02-25 16:27:46 +0100654 ieee80211_send_addba_request(sta->sdata->dev, ra, tid,
Ron Rindjunskycee24a32008-03-26 20:36:03 +0200655 sta->ampdu_mlme.tid_tx[tid]->dialog_token,
656 sta->ampdu_mlme.tid_tx[tid]->ssn,
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200657 0x40, 5000);
658
659 /* activate the timer for the recipient's addBA response */
Ron Rindjunskycee24a32008-03-26 20:36:03 +0200660 sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.expires =
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200661 jiffies + ADDBA_RESP_INTERVAL;
Ron Rindjunskycee24a32008-03-26 20:36:03 +0200662 add_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200663 printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
Ron Rindjunskycee24a32008-03-26 20:36:03 +0200664 goto start_ba_exit;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200665
Ron Rindjunskycee24a32008-03-26 20:36:03 +0200666start_ba_err:
667 kfree(sta->ampdu_mlme.tid_tx[tid]);
668 sta->ampdu_mlme.tid_tx[tid] = NULL;
669 spin_unlock_bh(&local->mdev->queue_lock);
670 ret = -EBUSY;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200671start_ba_exit:
672 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100673 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200674 return ret;
675}
676EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
677
678int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
679 u8 *ra, u16 tid,
680 enum ieee80211_back_parties initiator)
681{
682 struct ieee80211_local *local = hw_to_local(hw);
683 struct sta_info *sta;
684 u8 *state;
685 int ret = 0;
686 DECLARE_MAC_BUF(mac);
687
688 if (tid >= STA_TID_NUM)
689 return -EINVAL;
690
691#ifdef CONFIG_MAC80211_HT_DEBUG
692 printk(KERN_DEBUG "Stop a BA session requested for %s tid %u\n",
693 print_mac(mac, ra), tid);
694#endif /* CONFIG_MAC80211_HT_DEBUG */
695
Johannes Bergd0709a62008-02-25 16:27:46 +0100696 rcu_read_lock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200697 sta = sta_info_get(local, ra);
Johannes Bergd0709a62008-02-25 16:27:46 +0100698 if (!sta) {
699 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200700 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +0100701 }
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200702
703 /* check if the TID is in aggregation */
Ron Rindjunskycee24a32008-03-26 20:36:03 +0200704 state = &sta->ampdu_mlme.tid_state_tx[tid];
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200705 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
706
707 if (*state != HT_AGG_STATE_OPERATIONAL) {
708#ifdef CONFIG_MAC80211_HT_DEBUG
709 printk(KERN_DEBUG "Try to stop Tx aggregation on"
710 " non active TID\n");
711#endif /* CONFIG_MAC80211_HT_DEBUG */
712 ret = -ENOENT;
713 goto stop_BA_exit;
714 }
715
716 ieee80211_stop_queue(hw, sta->tid_to_tx_q[tid]);
717
718 *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
719 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
720
721 if (local->ops->ampdu_action)
722 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_STOP,
723 ra, tid, NULL);
724
725 /* case HW denied going back to legacy */
726 if (ret) {
727 WARN_ON(ret != -EBUSY);
728 *state = HT_AGG_STATE_OPERATIONAL;
729 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
730 goto stop_BA_exit;
731 }
732
733stop_BA_exit:
734 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100735 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200736 return ret;
737}
738EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
739
740void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
741{
742 struct ieee80211_local *local = hw_to_local(hw);
743 struct sta_info *sta;
744 u8 *state;
745 DECLARE_MAC_BUF(mac);
746
747 if (tid >= STA_TID_NUM) {
748 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
749 tid, STA_TID_NUM);
750 return;
751 }
752
Johannes Bergd0709a62008-02-25 16:27:46 +0100753 rcu_read_lock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200754 sta = sta_info_get(local, ra);
755 if (!sta) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100756 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200757 printk(KERN_DEBUG "Could not find station: %s\n",
758 print_mac(mac, ra));
759 return;
760 }
761
Ron Rindjunskycee24a32008-03-26 20:36:03 +0200762 state = &sta->ampdu_mlme.tid_state_tx[tid];
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200763 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
764
765 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
766 printk(KERN_DEBUG "addBA was not requested yet, state is %d\n",
767 *state);
768 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100769 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200770 return;
771 }
772
773 WARN_ON_ONCE(*state & HT_ADDBA_DRV_READY_MSK);
774
775 *state |= HT_ADDBA_DRV_READY_MSK;
776
777 if (*state == HT_AGG_STATE_OPERATIONAL) {
778 printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid);
779 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
780 }
781 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100782 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200783}
784EXPORT_SYMBOL(ieee80211_start_tx_ba_cb);
785
786void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
787{
788 struct ieee80211_local *local = hw_to_local(hw);
789 struct sta_info *sta;
790 u8 *state;
791 int agg_queue;
792 DECLARE_MAC_BUF(mac);
793
794 if (tid >= STA_TID_NUM) {
795 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
796 tid, STA_TID_NUM);
797 return;
798 }
799
800 printk(KERN_DEBUG "Stop a BA session requested on DA %s tid %d\n",
801 print_mac(mac, ra), tid);
802
Johannes Bergd0709a62008-02-25 16:27:46 +0100803 rcu_read_lock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200804 sta = sta_info_get(local, ra);
805 if (!sta) {
806 printk(KERN_DEBUG "Could not find station: %s\n",
807 print_mac(mac, ra));
Johannes Bergd0709a62008-02-25 16:27:46 +0100808 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200809 return;
810 }
Ron Rindjunskycee24a32008-03-26 20:36:03 +0200811 state = &sta->ampdu_mlme.tid_state_tx[tid];
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200812
813 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
814 if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) {
815 printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200816 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100817 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200818 return;
819 }
820
821 if (*state & HT_AGG_STATE_INITIATOR_MSK)
Johannes Bergd0709a62008-02-25 16:27:46 +0100822 ieee80211_send_delba(sta->sdata->dev, ra, tid,
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200823 WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
824
825 agg_queue = sta->tid_to_tx_q[tid];
826
827 /* avoid ordering issues: we are the only one that can modify
828 * the content of the qdiscs */
829 spin_lock_bh(&local->mdev->queue_lock);
830 /* remove the queue for this aggregation */
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200831 ieee80211_ht_agg_queue_remove(local, sta, tid, 1);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200832 spin_unlock_bh(&local->mdev->queue_lock);
833
834 /* we just requeued the all the frames that were in the removed
835 * queue, and since we might miss a softirq we do netif_schedule.
836 * ieee80211_wake_queue is not used here as this queue is not
837 * necessarily stopped */
838 netif_schedule(local->mdev);
839 *state = HT_AGG_STATE_IDLE;
Ron Rindjunskycee24a32008-03-26 20:36:03 +0200840 sta->ampdu_mlme.addba_req_num[tid] = 0;
841 kfree(sta->ampdu_mlme.tid_tx[tid]);
842 sta->ampdu_mlme.tid_tx[tid] = NULL;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200843 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
844
Johannes Bergd0709a62008-02-25 16:27:46 +0100845 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200846}
847EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb);
848
849void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
850 const u8 *ra, u16 tid)
851{
852 struct ieee80211_local *local = hw_to_local(hw);
853 struct ieee80211_ra_tid *ra_tid;
854 struct sk_buff *skb = dev_alloc_skb(0);
855
856 if (unlikely(!skb)) {
857 if (net_ratelimit())
858 printk(KERN_WARNING "%s: Not enough memory, "
859 "dropping start BA session", skb->dev->name);
860 return;
861 }
862 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
863 memcpy(&ra_tid->ra, ra, ETH_ALEN);
864 ra_tid->tid = tid;
865
866 skb->pkt_type = IEEE80211_ADDBA_MSG;
867 skb_queue_tail(&local->skb_queue, skb);
868 tasklet_schedule(&local->tasklet);
869}
870EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
871
872void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
873 const u8 *ra, u16 tid)
874{
875 struct ieee80211_local *local = hw_to_local(hw);
876 struct ieee80211_ra_tid *ra_tid;
877 struct sk_buff *skb = dev_alloc_skb(0);
878
879 if (unlikely(!skb)) {
880 if (net_ratelimit())
881 printk(KERN_WARNING "%s: Not enough memory, "
882 "dropping stop BA session", skb->dev->name);
883 return;
884 }
885 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
886 memcpy(&ra_tid->ra, ra, ETH_ALEN);
887 ra_tid->tid = tid;
888
889 skb->pkt_type = IEEE80211_DELBA_MSG;
890 skb_queue_tail(&local->skb_queue, skb);
891 tasklet_schedule(&local->tasklet);
892}
893EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
894
Johannes Bergb2c258f2007-07-27 15:43:23 +0200895static void ieee80211_set_multicast_list(struct net_device *dev)
896{
897 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
898 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg4150c572007-09-17 01:29:23 -0400899 int allmulti, promisc, sdata_allmulti, sdata_promisc;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200900
Johannes Berg4150c572007-09-17 01:29:23 -0400901 allmulti = !!(dev->flags & IFF_ALLMULTI);
902 promisc = !!(dev->flags & IFF_PROMISC);
Johannes Bergb52f2192007-11-16 01:49:11 +0100903 sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
904 sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC);
Johannes Berg4150c572007-09-17 01:29:23 -0400905
906 if (allmulti != sdata_allmulti) {
907 if (dev->flags & IFF_ALLMULTI)
Johannes Berg53918992007-09-26 15:19:47 +0200908 atomic_inc(&local->iff_allmultis);
Johannes Berg4150c572007-09-17 01:29:23 -0400909 else
Johannes Berg53918992007-09-26 15:19:47 +0200910 atomic_dec(&local->iff_allmultis);
Jiri Slaby13262ff2007-08-28 17:01:54 -0400911 sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200912 }
Johannes Berg4150c572007-09-17 01:29:23 -0400913
914 if (promisc != sdata_promisc) {
915 if (dev->flags & IFF_PROMISC)
Johannes Berg53918992007-09-26 15:19:47 +0200916 atomic_inc(&local->iff_promiscs);
Johannes Berg4150c572007-09-17 01:29:23 -0400917 else
Johannes Berg53918992007-09-26 15:19:47 +0200918 atomic_dec(&local->iff_promiscs);
Jiri Slaby13262ff2007-08-28 17:01:54 -0400919 sdata->flags ^= IEEE80211_SDATA_PROMISC;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200920 }
Johannes Berg4150c572007-09-17 01:29:23 -0400921
922 dev_mc_sync(local->mdev, dev);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200923}
924
Stephen Hemminger3b04ddd2007-10-09 01:40:57 -0700925static const struct header_ops ieee80211_header_ops = {
926 .create = eth_header,
927 .parse = header_parse_80211,
928 .rebuild = eth_rebuild_header,
929 .cache = eth_header_cache,
930 .cache_update = eth_header_cache_update,
931};
932
Johannes Bergf9d540e2007-09-28 14:02:09 +0200933/* Must not be called for mdev */
Johannes Bergb2c258f2007-07-27 15:43:23 +0200934void ieee80211_if_setup(struct net_device *dev)
935{
936 ether_setup(dev);
937 dev->hard_start_xmit = ieee80211_subif_start_xmit;
938 dev->wireless_handlers = &ieee80211_iw_handler_def;
939 dev->set_multicast_list = ieee80211_set_multicast_list;
940 dev->change_mtu = ieee80211_change_mtu;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200941 dev->open = ieee80211_open;
942 dev->stop = ieee80211_stop;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200943 dev->destructor = ieee80211_if_free;
944}
945
Johannes Bergb2c258f2007-07-27 15:43:23 +0200946/* everything else */
947
Johannes Bergb2c258f2007-07-27 15:43:23 +0200948static int __ieee80211_if_config(struct net_device *dev,
949 struct sk_buff *beacon,
950 struct ieee80211_tx_control *control)
951{
952 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
953 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
954 struct ieee80211_if_conf conf;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200955
956 if (!local->ops->config_interface || !netif_running(dev))
957 return 0;
958
959 memset(&conf, 0, sizeof(conf));
Johannes Berg51fb61e2007-12-19 01:31:27 +0100960 conf.type = sdata->vif.type;
961 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
962 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Johannes Berg4150c572007-09-17 01:29:23 -0400963 conf.bssid = sdata->u.sta.bssid;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200964 conf.ssid = sdata->u.sta.ssid;
965 conf.ssid_len = sdata->u.sta.ssid_len;
Johannes Berg902acc72008-02-23 15:17:19 +0100966 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Cobof7a92142008-02-23 15:17:18 +0100967 conf.beacon = beacon;
968 ieee80211_start_mesh(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100969 } else if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Johannes Bergb2c258f2007-07-27 15:43:23 +0200970 conf.ssid = sdata->u.ap.ssid;
971 conf.ssid_len = sdata->u.ap.ssid_len;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200972 conf.beacon = beacon;
973 conf.beacon_control = control;
974 }
975 return local->ops->config_interface(local_to_hw(local),
Johannes Berg32bfd352007-12-19 01:31:26 +0100976 &sdata->vif, &conf);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200977}
978
979int ieee80211_if_config(struct net_device *dev)
980{
Luis Carlos Cobof7a92142008-02-23 15:17:18 +0100981 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
982 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
983 if (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT &&
984 (local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE))
985 return ieee80211_if_config_beacon(dev);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200986 return __ieee80211_if_config(dev, NULL, NULL);
987}
988
989int ieee80211_if_config_beacon(struct net_device *dev)
990{
991 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
992 struct ieee80211_tx_control control;
Johannes Berg32bfd352007-12-19 01:31:26 +0100993 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200994 struct sk_buff *skb;
995
996 if (!(local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE))
997 return 0;
Johannes Berg32bfd352007-12-19 01:31:26 +0100998 skb = ieee80211_beacon_get(local_to_hw(local), &sdata->vif,
999 &control);
Johannes Bergb2c258f2007-07-27 15:43:23 +02001000 if (!skb)
1001 return -ENOMEM;
1002 return __ieee80211_if_config(dev, skb, &control);
1003}
1004
1005int ieee80211_hw_config(struct ieee80211_local *local)
1006{
Johannes Bergb2c258f2007-07-27 15:43:23 +02001007 struct ieee80211_channel *chan;
1008 int ret = 0;
1009
Johannes Berg8318d782008-01-24 19:38:38 +01001010 if (local->sta_sw_scanning)
Johannes Bergb2c258f2007-07-27 15:43:23 +02001011 chan = local->scan_channel;
Johannes Berg8318d782008-01-24 19:38:38 +01001012 else
Johannes Bergb2c258f2007-07-27 15:43:23 +02001013 chan = local->oper_channel;
Johannes Bergb2c258f2007-07-27 15:43:23 +02001014
Johannes Berg8318d782008-01-24 19:38:38 +01001015 local->hw.conf.channel = chan;
1016
1017 if (!local->hw.conf.power_level)
1018 local->hw.conf.power_level = chan->max_power;
1019 else
1020 local->hw.conf.power_level = min(chan->max_power,
1021 local->hw.conf.power_level);
1022
1023 local->hw.conf.max_antenna_gain = chan->max_antenna_gain;
Johannes Bergb2c258f2007-07-27 15:43:23 +02001024
1025#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Berg8318d782008-01-24 19:38:38 +01001026 printk(KERN_DEBUG "%s: HW CONFIG: freq=%d\n",
1027 wiphy_name(local->hw.wiphy), chan->center_freq);
1028#endif
Johannes Bergb2c258f2007-07-27 15:43:23 +02001029
Michael Bueschf7c4dae2007-09-24 18:41:49 +02001030 if (local->open_count)
Johannes Bergb2c258f2007-07-27 15:43:23 +02001031 ret = local->ops->config(local_to_hw(local), &local->hw.conf);
1032
1033 return ret;
1034}
1035
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001036/**
1037 * ieee80211_hw_config_ht should be used only after legacy configuration
1038 * has been determined, as ht configuration depends upon the hardware's
1039 * HT abilities for a _specific_ band.
1040 */
1041int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht,
1042 struct ieee80211_ht_info *req_ht_cap,
1043 struct ieee80211_ht_bss_info *req_bss_cap)
1044{
1045 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg8318d782008-01-24 19:38:38 +01001046 struct ieee80211_supported_band *sband;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001047 int i;
1048
Johannes Berg8318d782008-01-24 19:38:38 +01001049 sband = local->hw.wiphy->bands[conf->channel->band];
1050
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001051 /* HT is not supported */
Johannes Berg8318d782008-01-24 19:38:38 +01001052 if (!sband->ht_info.ht_supported) {
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001053 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
1054 return -EOPNOTSUPP;
1055 }
1056
1057 /* disable HT */
1058 if (!enable_ht) {
1059 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
1060 } else {
1061 conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE;
Johannes Berg8318d782008-01-24 19:38:38 +01001062 conf->ht_conf.cap = req_ht_cap->cap & sband->ht_info.cap;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001063 conf->ht_conf.cap &= ~(IEEE80211_HT_CAP_MIMO_PS);
1064 conf->ht_conf.cap |=
Johannes Berg8318d782008-01-24 19:38:38 +01001065 sband->ht_info.cap & IEEE80211_HT_CAP_MIMO_PS;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001066 conf->ht_bss_conf.primary_channel =
1067 req_bss_cap->primary_channel;
1068 conf->ht_bss_conf.bss_cap = req_bss_cap->bss_cap;
1069 conf->ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode;
1070 for (i = 0; i < SUPP_MCS_SET_LEN; i++)
1071 conf->ht_conf.supp_mcs_set[i] =
Johannes Berg8318d782008-01-24 19:38:38 +01001072 sband->ht_info.supp_mcs_set[i] &
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001073 req_ht_cap->supp_mcs_set[i];
1074
1075 /* In STA mode, this gives us indication
1076 * to the AP's mode of operation */
1077 conf->ht_conf.ht_supported = 1;
1078 conf->ht_conf.ampdu_factor = req_ht_cap->ampdu_factor;
1079 conf->ht_conf.ampdu_density = req_ht_cap->ampdu_density;
1080 }
1081
1082 local->ops->conf_ht(local_to_hw(local), &local->hw.conf);
1083
1084 return 0;
1085}
1086
Johannes Berg471b3ef2007-12-28 14:32:58 +01001087void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
1088 u32 changed)
Daniel Draked9430a32007-07-27 15:43:24 +02001089{
Johannes Berg471b3ef2007-12-28 14:32:58 +01001090 struct ieee80211_local *local = sdata->local;
1091
1092 if (!changed)
1093 return;
1094
1095 if (local->ops->bss_info_changed)
1096 local->ops->bss_info_changed(local_to_hw(local),
1097 &sdata->vif,
1098 &sdata->bss_conf,
1099 changed);
Daniel Draked9430a32007-07-27 15:43:24 +02001100}
1101
1102void ieee80211_reset_erp_info(struct net_device *dev)
1103{
1104 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1105
Johannes Berg471b3ef2007-12-28 14:32:58 +01001106 sdata->bss_conf.use_cts_prot = 0;
1107 sdata->bss_conf.use_short_preamble = 0;
1108 ieee80211_bss_info_change_notify(sdata,
1109 BSS_CHANGED_ERP_CTS_PROT |
1110 BSS_CHANGED_ERP_PREAMBLE);
Daniel Draked9430a32007-07-27 15:43:24 +02001111}
1112
Jiri Bencf0706e82007-05-05 11:45:53 -07001113void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
1114 struct sk_buff *skb,
1115 struct ieee80211_tx_status *status)
1116{
1117 struct ieee80211_local *local = hw_to_local(hw);
1118 struct ieee80211_tx_status *saved;
1119 int tmp;
1120
1121 skb->dev = local->mdev;
1122 saved = kmalloc(sizeof(struct ieee80211_tx_status), GFP_ATOMIC);
1123 if (unlikely(!saved)) {
1124 if (net_ratelimit())
1125 printk(KERN_WARNING "%s: Not enough memory, "
1126 "dropping tx status", skb->dev->name);
1127 /* should be dev_kfree_skb_irq, but due to this function being
1128 * named _irqsafe instead of just _irq we can't be sure that
1129 * people won't call it from non-irq contexts */
1130 dev_kfree_skb_any(skb);
1131 return;
1132 }
1133 memcpy(saved, status, sizeof(struct ieee80211_tx_status));
1134 /* copy pointer to saved status into skb->cb for use by tasklet */
1135 memcpy(skb->cb, &saved, sizeof(saved));
1136
1137 skb->pkt_type = IEEE80211_TX_STATUS_MSG;
1138 skb_queue_tail(status->control.flags & IEEE80211_TXCTL_REQ_TX_STATUS ?
1139 &local->skb_queue : &local->skb_queue_unreliable, skb);
1140 tmp = skb_queue_len(&local->skb_queue) +
1141 skb_queue_len(&local->skb_queue_unreliable);
1142 while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
1143 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
1144 memcpy(&saved, skb->cb, sizeof(saved));
1145 kfree(saved);
1146 dev_kfree_skb_irq(skb);
1147 tmp--;
1148 I802_DEBUG_INC(local->tx_status_drop);
1149 }
1150 tasklet_schedule(&local->tasklet);
1151}
1152EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
1153
1154static void ieee80211_tasklet_handler(unsigned long data)
1155{
1156 struct ieee80211_local *local = (struct ieee80211_local *) data;
1157 struct sk_buff *skb;
1158 struct ieee80211_rx_status rx_status;
1159 struct ieee80211_tx_status *tx_status;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001160 struct ieee80211_ra_tid *ra_tid;
Jiri Bencf0706e82007-05-05 11:45:53 -07001161
1162 while ((skb = skb_dequeue(&local->skb_queue)) ||
1163 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
1164 switch (skb->pkt_type) {
1165 case IEEE80211_RX_MSG:
1166 /* status is in skb->cb */
1167 memcpy(&rx_status, skb->cb, sizeof(rx_status));
Johannes Berg51fb61e2007-12-19 01:31:27 +01001168 /* Clear skb->pkt_type in order to not confuse kernel
Jiri Bencf0706e82007-05-05 11:45:53 -07001169 * netstack. */
1170 skb->pkt_type = 0;
1171 __ieee80211_rx(local_to_hw(local), skb, &rx_status);
1172 break;
1173 case IEEE80211_TX_STATUS_MSG:
1174 /* get pointer to saved status out of skb->cb */
1175 memcpy(&tx_status, skb->cb, sizeof(tx_status));
1176 skb->pkt_type = 0;
1177 ieee80211_tx_status(local_to_hw(local),
1178 skb, tx_status);
1179 kfree(tx_status);
1180 break;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001181 case IEEE80211_DELBA_MSG:
1182 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
1183 ieee80211_stop_tx_ba_cb(local_to_hw(local),
1184 ra_tid->ra, ra_tid->tid);
1185 dev_kfree_skb(skb);
1186 break;
1187 case IEEE80211_ADDBA_MSG:
1188 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
1189 ieee80211_start_tx_ba_cb(local_to_hw(local),
1190 ra_tid->ra, ra_tid->tid);
1191 dev_kfree_skb(skb);
1192 break ;
Jiri Bencf0706e82007-05-05 11:45:53 -07001193 default: /* should never get here! */
1194 printk(KERN_ERR "%s: Unknown message type (%d)\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001195 wiphy_name(local->hw.wiphy), skb->pkt_type);
Jiri Bencf0706e82007-05-05 11:45:53 -07001196 dev_kfree_skb(skb);
1197 break;
1198 }
1199 }
1200}
1201
Jiri Bencf0706e82007-05-05 11:45:53 -07001202/* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
1203 * make a prepared TX frame (one that has been given to hw) to look like brand
1204 * new IEEE 802.11 frame that is ready to go through TX processing again.
1205 * Also, tx_packet_data in cb is restored from tx_control. */
1206static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
1207 struct ieee80211_key *key,
1208 struct sk_buff *skb,
1209 struct ieee80211_tx_control *control)
1210{
1211 int hdrlen, iv_len, mic_len;
1212 struct ieee80211_tx_packet_data *pkt_data;
1213
1214 pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
Johannes Berg32bfd352007-12-19 01:31:26 +01001215 pkt_data->ifindex = vif_to_sdata(control->vif)->dev->ifindex;
Jiri Slabye8bf9642007-08-28 17:01:54 -04001216 pkt_data->flags = 0;
1217 if (control->flags & IEEE80211_TXCTL_REQ_TX_STATUS)
1218 pkt_data->flags |= IEEE80211_TXPD_REQ_TX_STATUS;
1219 if (control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)
1220 pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT;
1221 if (control->flags & IEEE80211_TXCTL_REQUEUE)
1222 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
Johannes Berg678f5f712007-12-19 01:31:23 +01001223 if (control->flags & IEEE80211_TXCTL_EAPOL_FRAME)
1224 pkt_data->flags |= IEEE80211_TXPD_EAPOL_FRAME;
Jiri Bencf0706e82007-05-05 11:45:53 -07001225 pkt_data->queue = control->queue;
1226
1227 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1228
1229 if (!key)
1230 goto no_key;
1231
Johannes Berg8f20fc22007-08-28 17:01:54 -04001232 switch (key->conf.alg) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001233 case ALG_WEP:
1234 iv_len = WEP_IV_LEN;
1235 mic_len = WEP_ICV_LEN;
1236 break;
1237 case ALG_TKIP:
1238 iv_len = TKIP_IV_LEN;
1239 mic_len = TKIP_ICV_LEN;
1240 break;
1241 case ALG_CCMP:
1242 iv_len = CCMP_HDR_LEN;
1243 mic_len = CCMP_MIC_LEN;
1244 break;
1245 default:
1246 goto no_key;
1247 }
1248
Johannes Berg8f20fc22007-08-28 17:01:54 -04001249 if (skb->len >= mic_len &&
Johannes Berg11a843b2007-08-28 17:01:55 -04001250 !(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
Jiri Bencf0706e82007-05-05 11:45:53 -07001251 skb_trim(skb, skb->len - mic_len);
1252 if (skb->len >= iv_len && skb->len > hdrlen) {
1253 memmove(skb->data + iv_len, skb->data, hdrlen);
1254 skb_pull(skb, iv_len);
1255 }
1256
1257no_key:
1258 {
1259 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1260 u16 fc = le16_to_cpu(hdr->frame_control);
1261 if ((fc & 0x8C) == 0x88) /* QoS Control Field */ {
1262 fc &= ~IEEE80211_STYPE_QOS_DATA;
1263 hdr->frame_control = cpu_to_le16(fc);
1264 memmove(skb->data + 2, skb->data, hdrlen - 2);
1265 skb_pull(skb, 2);
1266 }
1267 }
1268}
1269
Johannes Bergd46e1442008-02-20 23:59:33 +01001270static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
1271 struct sta_info *sta,
1272 struct sk_buff *skb,
1273 struct ieee80211_tx_status *status)
1274{
1275 sta->tx_filtered_count++;
1276
1277 /*
1278 * Clear the TX filter mask for this STA when sending the next
1279 * packet. If the STA went to power save mode, this will happen
1280 * happen when it wakes up for the next time.
1281 */
1282 sta->flags |= WLAN_STA_CLEAR_PS_FILT;
1283
1284 /*
1285 * This code races in the following way:
1286 *
1287 * (1) STA sends frame indicating it will go to sleep and does so
1288 * (2) hardware/firmware adds STA to filter list, passes frame up
1289 * (3) hardware/firmware processes TX fifo and suppresses a frame
1290 * (4) we get TX status before having processed the frame and
1291 * knowing that the STA has gone to sleep.
1292 *
1293 * This is actually quite unlikely even when both those events are
1294 * processed from interrupts coming in quickly after one another or
1295 * even at the same time because we queue both TX status events and
1296 * RX frames to be processed by a tasklet and process them in the
1297 * same order that they were received or TX status last. Hence, there
1298 * is no race as long as the frame RX is processed before the next TX
1299 * status, which drivers can ensure, see below.
1300 *
1301 * Note that this can only happen if the hardware or firmware can
1302 * actually add STAs to the filter list, if this is done by the
1303 * driver in response to set_tim() (which will only reduce the race
1304 * this whole filtering tries to solve, not completely solve it)
1305 * this situation cannot happen.
1306 *
1307 * To completely solve this race drivers need to make sure that they
1308 * (a) don't mix the irq-safe/not irq-safe TX status/RX processing
1309 * functions and
1310 * (b) always process RX events before TX status events if ordering
1311 * can be unknown, for example with different interrupt status
1312 * bits.
1313 */
1314 if (sta->flags & WLAN_STA_PS &&
1315 skb_queue_len(&sta->tx_filtered) < STA_MAX_TX_BUFFER) {
1316 ieee80211_remove_tx_extra(local, sta->key, skb,
1317 &status->control);
1318 skb_queue_tail(&sta->tx_filtered, skb);
1319 return;
1320 }
1321
1322 if (!(sta->flags & WLAN_STA_PS) &&
1323 !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) {
1324 /* Software retry the packet once */
1325 status->control.flags |= IEEE80211_TXCTL_REQUEUE;
1326 ieee80211_remove_tx_extra(local, sta->key, skb,
1327 &status->control);
1328 dev_queue_xmit(skb);
1329 return;
1330 }
1331
1332 if (net_ratelimit())
1333 printk(KERN_DEBUG "%s: dropped TX filtered frame, "
1334 "queue_len=%d PS=%d @%lu\n",
1335 wiphy_name(local->hw.wiphy),
1336 skb_queue_len(&sta->tx_filtered),
1337 !!(sta->flags & WLAN_STA_PS), jiffies);
1338 dev_kfree_skb(skb);
1339}
1340
Jiri Bencf0706e82007-05-05 11:45:53 -07001341void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
1342 struct ieee80211_tx_status *status)
1343{
1344 struct sk_buff *skb2;
1345 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1346 struct ieee80211_local *local = hw_to_local(hw);
1347 u16 frag, type;
Johannes Bergb306f452007-07-10 19:32:08 +02001348 struct ieee80211_tx_status_rtap_hdr *rthdr;
1349 struct ieee80211_sub_if_data *sdata;
Michael Wu3d30d942008-01-31 19:48:27 +01001350 struct net_device *prev_dev = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -07001351
1352 if (!status) {
1353 printk(KERN_ERR
1354 "%s: ieee80211_tx_status called with NULL status\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001355 wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -07001356 dev_kfree_skb(skb);
1357 return;
1358 }
1359
Johannes Bergd0709a62008-02-25 16:27:46 +01001360 rcu_read_lock();
1361
Jiri Bencf0706e82007-05-05 11:45:53 -07001362 if (status->excessive_retries) {
1363 struct sta_info *sta;
1364 sta = sta_info_get(local, hdr->addr1);
1365 if (sta) {
1366 if (sta->flags & WLAN_STA_PS) {
Johannes Bergd46e1442008-02-20 23:59:33 +01001367 /*
1368 * The STA is in power save mode, so assume
Jiri Bencf0706e82007-05-05 11:45:53 -07001369 * that this TX packet failed because of that.
1370 */
1371 status->excessive_retries = 0;
1372 status->flags |= IEEE80211_TX_STATUS_TX_FILTERED;
Johannes Bergd46e1442008-02-20 23:59:33 +01001373 ieee80211_handle_filtered_frame(local, sta,
1374 skb, status);
Johannes Bergd0709a62008-02-25 16:27:46 +01001375 rcu_read_unlock();
Johannes Bergd46e1442008-02-20 23:59:33 +01001376 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001377 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001378 }
1379 }
1380
1381 if (status->flags & IEEE80211_TX_STATUS_TX_FILTERED) {
1382 struct sta_info *sta;
1383 sta = sta_info_get(local, hdr->addr1);
1384 if (sta) {
Johannes Bergd46e1442008-02-20 23:59:33 +01001385 ieee80211_handle_filtered_frame(local, sta, skb,
1386 status);
Johannes Bergd0709a62008-02-25 16:27:46 +01001387 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07001388 return;
1389 }
Mattias Nissler1abbe492007-12-20 13:50:07 +01001390 } else
1391 rate_control_tx_status(local->mdev, skb, status);
Jiri Bencf0706e82007-05-05 11:45:53 -07001392
Johannes Bergd0709a62008-02-25 16:27:46 +01001393 rcu_read_unlock();
1394
Jiri Bencf0706e82007-05-05 11:45:53 -07001395 ieee80211_led_tx(local, 0);
1396
1397 /* SNMP counters
1398 * Fragments are passed to low-level drivers as separate skbs, so these
1399 * are actually fragments, not frames. Update frame counters only for
1400 * the first fragment of the frame. */
1401
1402 frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
1403 type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
1404
1405 if (status->flags & IEEE80211_TX_STATUS_ACK) {
1406 if (frag == 0) {
1407 local->dot11TransmittedFrameCount++;
1408 if (is_multicast_ether_addr(hdr->addr1))
1409 local->dot11MulticastTransmittedFrameCount++;
1410 if (status->retry_count > 0)
1411 local->dot11RetryCount++;
1412 if (status->retry_count > 1)
1413 local->dot11MultipleRetryCount++;
1414 }
1415
1416 /* This counter shall be incremented for an acknowledged MPDU
1417 * with an individual address in the address 1 field or an MPDU
1418 * with a multicast address in the address 1 field of type Data
1419 * or Management. */
1420 if (!is_multicast_ether_addr(hdr->addr1) ||
1421 type == IEEE80211_FTYPE_DATA ||
1422 type == IEEE80211_FTYPE_MGMT)
1423 local->dot11TransmittedFragmentCount++;
1424 } else {
1425 if (frag == 0)
1426 local->dot11FailedCount++;
1427 }
1428
Johannes Bergb306f452007-07-10 19:32:08 +02001429 /* this was a transmitted frame, but now we want to reuse it */
1430 skb_orphan(skb);
1431
Michael Wu3d30d942008-01-31 19:48:27 +01001432 /*
1433 * This is a bit racy but we can avoid a lot of work
1434 * with this test...
1435 */
1436 if (!local->monitors && !local->cooked_mntrs) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001437 dev_kfree_skb(skb);
1438 return;
1439 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001440
Johannes Bergb306f452007-07-10 19:32:08 +02001441 /* send frame to monitor interfaces now */
1442
1443 if (skb_headroom(skb) < sizeof(*rthdr)) {
1444 printk(KERN_ERR "ieee80211_tx_status: headroom too small\n");
1445 dev_kfree_skb(skb);
1446 return;
1447 }
1448
1449 rthdr = (struct ieee80211_tx_status_rtap_hdr*)
1450 skb_push(skb, sizeof(*rthdr));
1451
1452 memset(rthdr, 0, sizeof(*rthdr));
1453 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
1454 rthdr->hdr.it_present =
1455 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
1456 (1 << IEEE80211_RADIOTAP_DATA_RETRIES));
1457
1458 if (!(status->flags & IEEE80211_TX_STATUS_ACK) &&
1459 !is_multicast_ether_addr(hdr->addr1))
1460 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL);
1461
1462 if ((status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS) &&
1463 (status->control.flags & IEEE80211_TXCTL_USE_CTS_PROTECT))
1464 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS);
1465 else if (status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS)
1466 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS);
1467
1468 rthdr->data_retries = status->retry_count;
1469
Michael Wu3d30d942008-01-31 19:48:27 +01001470 /* XXX: is this sufficient for BPF? */
1471 skb_set_mac_header(skb, 0);
1472 skb->ip_summed = CHECKSUM_UNNECESSARY;
1473 skb->pkt_type = PACKET_OTHERHOST;
1474 skb->protocol = htons(ETH_P_802_2);
1475 memset(skb->cb, 0, sizeof(skb->cb));
Johannes Bergb306f452007-07-10 19:32:08 +02001476
Michael Wu3d30d942008-01-31 19:48:27 +01001477 rcu_read_lock();
1478 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Johannes Berg51fb61e2007-12-19 01:31:27 +01001479 if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR) {
Johannes Bergb306f452007-07-10 19:32:08 +02001480 if (!netif_running(sdata->dev))
1481 continue;
Michael Wu3d30d942008-01-31 19:48:27 +01001482
1483 if (prev_dev) {
Johannes Berg79010422007-09-18 17:29:21 -04001484 skb2 = skb_clone(skb, GFP_ATOMIC);
Michael Wu3d30d942008-01-31 19:48:27 +01001485 if (skb2) {
1486 skb2->dev = prev_dev;
1487 netif_rx(skb2);
1488 }
1489 }
1490
1491 prev_dev = sdata->dev;
Johannes Bergb306f452007-07-10 19:32:08 +02001492 }
1493 }
Michael Wu3d30d942008-01-31 19:48:27 +01001494 if (prev_dev) {
1495 skb->dev = prev_dev;
1496 netif_rx(skb);
1497 skb = NULL;
1498 }
Johannes Berg79010422007-09-18 17:29:21 -04001499 rcu_read_unlock();
Michael Wu3d30d942008-01-31 19:48:27 +01001500 dev_kfree_skb(skb);
Jiri Bencf0706e82007-05-05 11:45:53 -07001501}
1502EXPORT_SYMBOL(ieee80211_tx_status);
1503
Jiri Bencf0706e82007-05-05 11:45:53 -07001504struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
1505 const struct ieee80211_ops *ops)
1506{
Jiri Bencf0706e82007-05-05 11:45:53 -07001507 struct ieee80211_local *local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001508 int priv_size;
1509 struct wiphy *wiphy;
1510
1511 /* Ensure 32-byte alignment of our private data and hw private data.
1512 * We use the wiphy priv data for both our ieee80211_local and for
1513 * the driver's private data
1514 *
1515 * In memory it'll be like this:
1516 *
1517 * +-------------------------+
1518 * | struct wiphy |
1519 * +-------------------------+
1520 * | struct ieee80211_local |
1521 * +-------------------------+
1522 * | driver's private data |
1523 * +-------------------------+
1524 *
1525 */
1526 priv_size = ((sizeof(struct ieee80211_local) +
1527 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) +
1528 priv_data_len;
1529
1530 wiphy = wiphy_new(&mac80211_config_ops, priv_size);
1531
1532 if (!wiphy)
1533 return NULL;
1534
1535 wiphy->privid = mac80211_wiphy_privid;
1536
1537 local = wiphy_priv(wiphy);
1538 local->hw.wiphy = wiphy;
1539
1540 local->hw.priv = (char *)local +
1541 ((sizeof(struct ieee80211_local) +
1542 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
1543
Johannes Berg4480f15c2007-07-10 19:32:10 +02001544 BUG_ON(!ops->tx);
Johannes Berg4150c572007-09-17 01:29:23 -04001545 BUG_ON(!ops->start);
1546 BUG_ON(!ops->stop);
Johannes Berg4480f15c2007-07-10 19:32:10 +02001547 BUG_ON(!ops->config);
1548 BUG_ON(!ops->add_interface);
Johannes Berg4150c572007-09-17 01:29:23 -04001549 BUG_ON(!ops->remove_interface);
1550 BUG_ON(!ops->configure_filter);
Jiri Bencf0706e82007-05-05 11:45:53 -07001551 local->ops = ops;
1552
Jiri Bencf0706e82007-05-05 11:45:53 -07001553 local->hw.queues = 1; /* default */
1554
Jiri Bencf0706e82007-05-05 11:45:53 -07001555 local->bridge_packets = 1;
1556
1557 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
1558 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
1559 local->short_retry_limit = 7;
1560 local->long_retry_limit = 4;
1561 local->hw.conf.radio_enabled = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001562
Johannes Berg79010422007-09-18 17:29:21 -04001563 INIT_LIST_HEAD(&local->interfaces);
Jiri Bencf0706e82007-05-05 11:45:53 -07001564
1565 INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work);
Jiri Bencf0706e82007-05-05 11:45:53 -07001566
1567 sta_info_init(local);
1568
Jiri Bencf0706e82007-05-05 11:45:53 -07001569 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
1570 (unsigned long)local);
1571 tasklet_disable(&local->tx_pending_tasklet);
1572
1573 tasklet_init(&local->tasklet,
1574 ieee80211_tasklet_handler,
1575 (unsigned long) local);
1576 tasklet_disable(&local->tasklet);
1577
1578 skb_queue_head_init(&local->skb_queue);
1579 skb_queue_head_init(&local->skb_queue_unreliable);
1580
1581 return local_to_hw(local);
1582}
1583EXPORT_SYMBOL(ieee80211_alloc_hw);
1584
1585int ieee80211_register_hw(struct ieee80211_hw *hw)
1586{
1587 struct ieee80211_local *local = hw_to_local(hw);
1588 const char *name;
1589 int result;
Johannes Berg8318d782008-01-24 19:38:38 +01001590 enum ieee80211_band band;
Johannes Berg96d51052008-02-08 09:48:13 +01001591 struct net_device *mdev;
1592 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +01001593
1594 /*
1595 * generic code guarantees at least one band,
1596 * set this very early because much code assumes
1597 * that hw.conf.channel is assigned
1598 */
1599 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1600 struct ieee80211_supported_band *sband;
1601
1602 sband = local->hw.wiphy->bands[band];
1603 if (sband) {
1604 /* init channel we're on */
1605 local->hw.conf.channel =
1606 local->oper_channel =
1607 local->scan_channel = &sband->channels[0];
1608 break;
1609 }
1610 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001611
1612 result = wiphy_register(local->hw.wiphy);
1613 if (result < 0)
1614 return result;
1615
Johannes Berg96d51052008-02-08 09:48:13 +01001616 /* for now, mdev needs sub_if_data :/ */
1617 mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
1618 "wmaster%d", ether_setup);
1619 if (!mdev)
1620 goto fail_mdev_alloc;
1621
1622 sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
1623 mdev->ieee80211_ptr = &sdata->wdev;
1624 sdata->wdev.wiphy = local->hw.wiphy;
1625
1626 local->mdev = mdev;
1627
1628 ieee80211_rx_bss_list_init(mdev);
1629
1630 mdev->hard_start_xmit = ieee80211_master_start_xmit;
1631 mdev->open = ieee80211_master_open;
1632 mdev->stop = ieee80211_master_stop;
1633 mdev->type = ARPHRD_IEEE80211;
1634 mdev->header_ops = &ieee80211_header_ops;
1635 mdev->set_multicast_list = ieee80211_master_set_multicast_list;
1636
1637 sdata->vif.type = IEEE80211_IF_TYPE_AP;
1638 sdata->dev = mdev;
1639 sdata->local = local;
1640 sdata->u.ap.force_unicast_rateidx = -1;
1641 sdata->u.ap.max_ratectrl_rateidx = -1;
1642 ieee80211_if_sdata_init(sdata);
1643
1644 /* no RCU needed since we're still during init phase */
1645 list_add_tail(&sdata->list, &local->interfaces);
1646
Jiri Bencf0706e82007-05-05 11:45:53 -07001647 name = wiphy_dev(local->hw.wiphy)->driver->name;
1648 local->hw.workqueue = create_singlethread_workqueue(name);
1649 if (!local->hw.workqueue) {
1650 result = -ENOMEM;
1651 goto fail_workqueue;
1652 }
1653
Johannes Bergb306f452007-07-10 19:32:08 +02001654 /*
1655 * The hardware needs headroom for sending the frame,
1656 * and we need some headroom for passing the frame to monitor
1657 * interfaces, but never both at the same time.
1658 */
Jiri Benc33ccad32007-07-18 17:10:44 +02001659 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
1660 sizeof(struct ieee80211_tx_status_rtap_hdr));
Johannes Bergb306f452007-07-10 19:32:08 +02001661
Jiri Bence9f207f2007-05-05 11:46:38 -07001662 debugfs_hw_add(local);
1663
Jiri Bencf0706e82007-05-05 11:45:53 -07001664 local->hw.conf.beacon_int = 1000;
1665
1666 local->wstats_flags |= local->hw.max_rssi ?
1667 IW_QUAL_LEVEL_UPDATED : IW_QUAL_LEVEL_INVALID;
1668 local->wstats_flags |= local->hw.max_signal ?
1669 IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
1670 local->wstats_flags |= local->hw.max_noise ?
1671 IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
1672 if (local->hw.max_rssi < 0 || local->hw.max_noise < 0)
1673 local->wstats_flags |= IW_QUAL_DBM;
1674
1675 result = sta_info_start(local);
1676 if (result < 0)
1677 goto fail_sta_info;
1678
1679 rtnl_lock();
1680 result = dev_alloc_name(local->mdev, local->mdev->name);
1681 if (result < 0)
1682 goto fail_dev;
1683
1684 memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
1685 SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy));
1686
1687 result = register_netdevice(local->mdev);
1688 if (result < 0)
1689 goto fail_dev;
1690
Jiri Bence9f207f2007-05-05 11:46:38 -07001691 ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
Johannes Berg5b2812e2007-09-26 14:27:23 +02001692 ieee80211_if_set_type(local->mdev, IEEE80211_IF_TYPE_AP);
Jiri Bence9f207f2007-05-05 11:46:38 -07001693
Johannes Berg830f9032007-10-28 14:51:05 +01001694 result = ieee80211_init_rate_ctrl_alg(local,
1695 hw->rate_control_algorithm);
Jiri Bencf0706e82007-05-05 11:45:53 -07001696 if (result < 0) {
1697 printk(KERN_DEBUG "%s: Failed to initialize rate control "
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001698 "algorithm\n", wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -07001699 goto fail_rate;
1700 }
1701
1702 result = ieee80211_wep_init(local);
1703
1704 if (result < 0) {
1705 printk(KERN_DEBUG "%s: Failed to initialize wep\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001706 wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -07001707 goto fail_wep;
1708 }
1709
1710 ieee80211_install_qdisc(local->mdev);
1711
1712 /* add one default STA interface */
1713 result = ieee80211_if_add(local->mdev, "wlan%d", NULL,
Luis Carlos Coboee385852008-02-23 15:17:11 +01001714 IEEE80211_IF_TYPE_STA, NULL);
Jiri Bencf0706e82007-05-05 11:45:53 -07001715 if (result)
1716 printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001717 wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -07001718
1719 local->reg_state = IEEE80211_DEV_REGISTERED;
1720 rtnl_unlock();
1721
1722 ieee80211_led_init(local);
1723
1724 return 0;
1725
1726fail_wep:
1727 rate_control_deinitialize(local);
1728fail_rate:
Jiri Bence9f207f2007-05-05 11:46:38 -07001729 ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
Jiri Bencf0706e82007-05-05 11:45:53 -07001730 unregister_netdevice(local->mdev);
1731fail_dev:
1732 rtnl_unlock();
1733 sta_info_stop(local);
1734fail_sta_info:
Jiri Bence9f207f2007-05-05 11:46:38 -07001735 debugfs_hw_del(local);
Jiri Bencf0706e82007-05-05 11:45:53 -07001736 destroy_workqueue(local->hw.workqueue);
1737fail_workqueue:
Johannes Berg96d51052008-02-08 09:48:13 +01001738 ieee80211_if_free(local->mdev);
1739 local->mdev = NULL;
1740fail_mdev_alloc:
Jiri Bencf0706e82007-05-05 11:45:53 -07001741 wiphy_unregister(local->hw.wiphy);
1742 return result;
1743}
1744EXPORT_SYMBOL(ieee80211_register_hw);
1745
Jiri Bencf0706e82007-05-05 11:45:53 -07001746void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1747{
1748 struct ieee80211_local *local = hw_to_local(hw);
1749 struct ieee80211_sub_if_data *sdata, *tmp;
Jiri Bencf0706e82007-05-05 11:45:53 -07001750
1751 tasklet_kill(&local->tx_pending_tasklet);
1752 tasklet_kill(&local->tasklet);
1753
1754 rtnl_lock();
1755
1756 BUG_ON(local->reg_state != IEEE80211_DEV_REGISTERED);
1757
1758 local->reg_state = IEEE80211_DEV_UNREGISTERED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001759
Johannes Berg79010422007-09-18 17:29:21 -04001760 /*
1761 * At this point, interface list manipulations are fine
1762 * because the driver cannot be handing us frames any
1763 * more and the tasklet is killed.
1764 */
Johannes Berg5b2812e2007-09-26 14:27:23 +02001765
1766 /*
1767 * First, we remove all non-master interfaces. Do this because they
1768 * may have bss pointer dependency on the master, and when we free
1769 * the master these would be freed as well, breaking our list
1770 * iteration completely.
1771 */
1772 list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
1773 if (sdata->dev == local->mdev)
1774 continue;
1775 list_del(&sdata->list);
Jiri Bencf0706e82007-05-05 11:45:53 -07001776 __ieee80211_if_del(local, sdata);
Johannes Berg5b2812e2007-09-26 14:27:23 +02001777 }
1778
1779 /* then, finally, remove the master interface */
1780 __ieee80211_if_del(local, IEEE80211_DEV_TO_SUB_IF(local->mdev));
Jiri Bencf0706e82007-05-05 11:45:53 -07001781
1782 rtnl_unlock();
1783
Jiri Bencf0706e82007-05-05 11:45:53 -07001784 ieee80211_rx_bss_list_deinit(local->mdev);
1785 ieee80211_clear_tx_pending(local);
1786 sta_info_stop(local);
1787 rate_control_deinitialize(local);
Jiri Bence9f207f2007-05-05 11:46:38 -07001788 debugfs_hw_del(local);
Jiri Bencf0706e82007-05-05 11:45:53 -07001789
Jiri Bencf0706e82007-05-05 11:45:53 -07001790 if (skb_queue_len(&local->skb_queue)
1791 || skb_queue_len(&local->skb_queue_unreliable))
1792 printk(KERN_WARNING "%s: skb_queue not empty\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001793 wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -07001794 skb_queue_purge(&local->skb_queue);
1795 skb_queue_purge(&local->skb_queue_unreliable);
1796
1797 destroy_workqueue(local->hw.workqueue);
1798 wiphy_unregister(local->hw.wiphy);
1799 ieee80211_wep_free(local);
1800 ieee80211_led_exit(local);
Johannes Berg96d51052008-02-08 09:48:13 +01001801 ieee80211_if_free(local->mdev);
1802 local->mdev = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -07001803}
1804EXPORT_SYMBOL(ieee80211_unregister_hw);
1805
1806void ieee80211_free_hw(struct ieee80211_hw *hw)
1807{
1808 struct ieee80211_local *local = hw_to_local(hw);
1809
Jiri Bencf0706e82007-05-05 11:45:53 -07001810 wiphy_free(local->hw.wiphy);
1811}
1812EXPORT_SYMBOL(ieee80211_free_hw);
1813
Jiri Bencf0706e82007-05-05 11:45:53 -07001814static int __init ieee80211_init(void)
1815{
1816 struct sk_buff *skb;
1817 int ret;
1818
1819 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb));
1820
Johannes Berg4b475892008-01-02 15:17:03 +01001821 ret = rc80211_pid_init();
Mattias Nisslerad018372007-12-19 01:25:57 +01001822 if (ret)
Adrian Bunkd9357132008-03-04 15:26:15 -08001823 goto out;
Johannes Bergac71c692007-10-28 14:17:44 +01001824
Jiri Bencf0706e82007-05-05 11:45:53 -07001825 ret = ieee80211_wme_register();
1826 if (ret) {
1827 printk(KERN_DEBUG "ieee80211_init: failed to "
1828 "initialize WME (err=%d)\n", ret);
Johannes Berg3eadf5f2008-01-31 19:33:53 +01001829 goto out_cleanup_pid;
Jiri Bencf0706e82007-05-05 11:45:53 -07001830 }
1831
Jiri Bence9f207f2007-05-05 11:46:38 -07001832 ieee80211_debugfs_netdev_init();
1833
Jiri Bencf0706e82007-05-05 11:45:53 -07001834 return 0;
Mattias Nisslerad018372007-12-19 01:25:57 +01001835
Johannes Berg3eadf5f2008-01-31 19:33:53 +01001836 out_cleanup_pid:
Johannes Berg4b475892008-01-02 15:17:03 +01001837 rc80211_pid_exit();
Johannes Berg3eadf5f2008-01-31 19:33:53 +01001838 out:
Mattias Nisslerad018372007-12-19 01:25:57 +01001839 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07001840}
1841
Jiri Bencf0706e82007-05-05 11:45:53 -07001842static void __exit ieee80211_exit(void)
1843{
Johannes Berg4b475892008-01-02 15:17:03 +01001844 rc80211_pid_exit();
Johannes Bergac71c692007-10-28 14:17:44 +01001845
Luis Carlos Cobof7a92142008-02-23 15:17:18 +01001846 if (mesh_allocated)
1847 ieee80211s_stop();
Johannes Berg902acc72008-02-23 15:17:19 +01001848
Jiri Bencf0706e82007-05-05 11:45:53 -07001849 ieee80211_wme_unregister();
Jiri Bence9f207f2007-05-05 11:46:38 -07001850 ieee80211_debugfs_netdev_exit();
Jiri Bencf0706e82007-05-05 11:45:53 -07001851}
1852
1853
Johannes Bergca9938f2007-09-11 12:50:32 +02001854subsys_initcall(ieee80211_init);
Jiri Bencf0706e82007-05-05 11:45:53 -07001855module_exit(ieee80211_exit);
1856
1857MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1858MODULE_LICENSE("GPL");