blob: 85b1391375c003746849f8da5fe928e147825e37 [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 Bergb2c258f2007-07-27 15:43:23 +0200186
187 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400188
Johannes Berg79010422007-09-18 17:29:21 -0400189 /* we hold the RTNL here so can safely walk the list */
190 list_for_each_entry(nsdata, &local->interfaces, list) {
Johannes Bergb2c258f2007-07-27 15:43:23 +0200191 struct net_device *ndev = nsdata->dev;
192
Johannes Berg665e8aa2008-02-21 01:10:07 +0100193 if (ndev != dev && ndev != local->mdev && netif_running(ndev)) {
194 /*
195 * Allow only a single IBSS interface to be up at any
196 * time. This is restricted because beacon distribution
197 * cannot work properly if both are in the same IBSS.
198 *
199 * To remove this restriction we'd have to disallow them
200 * from setting the same SSID on different IBSS interfaces
201 * belonging to the same hardware. Then, however, we're
202 * faced with having to adopt two different TSF timers...
203 */
204 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
205 nsdata->vif.type == IEEE80211_IF_TYPE_IBSS)
206 return -EBUSY;
207
208 /*
209 * Disallow multiple IBSS/STA mode interfaces.
210 *
211 * This is a technical restriction, it is possible although
212 * most likely not IEEE 802.11 compliant to have multiple
213 * STAs with just a single hardware (the TSF timer will not
214 * be adjusted properly.)
215 *
216 * However, because mac80211 uses the master device's BSS
217 * information for each STA/IBSS interface, doing this will
218 * currently corrupt that BSS information completely, unless,
219 * a not very useful case, both STAs are associated to the
220 * same BSS.
221 *
222 * To remove this restriction, the BSS information needs to
223 * be embedded in the STA/IBSS mode sdata instead of using
224 * the master device's BSS structure.
225 */
226 if ((sdata->vif.type == IEEE80211_IF_TYPE_STA ||
227 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) &&
228 (nsdata->vif.type == IEEE80211_IF_TYPE_STA ||
229 nsdata->vif.type == IEEE80211_IF_TYPE_IBSS))
230 return -EBUSY;
231
232 /*
233 * The remaining checks are only performed for interfaces
234 * with the same MAC address.
235 */
236 if (compare_ether_addr(dev->dev_addr, ndev->dev_addr))
237 continue;
238
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400239 /*
240 * check whether it may have the same address
241 */
Johannes Berg51fb61e2007-12-19 01:31:27 +0100242 if (!identical_mac_addr_allowed(sdata->vif.type,
243 nsdata->vif.type))
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400244 return -ENOTUNIQ;
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400245
246 /*
247 * can only add VLANs to enabled APs
248 */
Johannes Berg51fb61e2007-12-19 01:31:27 +0100249 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN &&
Johannes Berg665e8aa2008-02-21 01:10:07 +0100250 nsdata->vif.type == IEEE80211_IF_TYPE_AP)
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400251 sdata->u.vlan.ap = nsdata;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200252 }
253 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200254
Johannes Berg51fb61e2007-12-19 01:31:27 +0100255 switch (sdata->vif.type) {
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400256 case IEEE80211_IF_TYPE_WDS:
257 if (is_zero_ether_addr(sdata->u.wds.remote_addr))
258 return -ENOLINK;
259 break;
260 case IEEE80211_IF_TYPE_VLAN:
261 if (!sdata->u.vlan.ap)
262 return -ENOLINK;
263 break;
Johannes Bergfb1c1cd2007-09-26 15:19:43 +0200264 case IEEE80211_IF_TYPE_AP:
Johannes Bergfb1c1cd2007-09-26 15:19:43 +0200265 case IEEE80211_IF_TYPE_STA:
266 case IEEE80211_IF_TYPE_MNTR:
267 case IEEE80211_IF_TYPE_IBSS:
Johannes Berg6032f932008-02-23 15:17:07 +0100268 case IEEE80211_IF_TYPE_MESH_POINT:
Johannes Bergfb1c1cd2007-09-26 15:19:43 +0200269 /* no special treatment */
270 break;
Johannes Berga2897552007-09-28 14:01:25 +0200271 case IEEE80211_IF_TYPE_INVALID:
272 /* cannot happen */
273 WARN_ON(1);
274 break;
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400275 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200276
Johannes Bergb2c258f2007-07-27 15:43:23 +0200277 if (local->open_count == 0) {
278 res = 0;
Johannes Berg4150c572007-09-17 01:29:23 -0400279 if (local->ops->start)
280 res = local->ops->start(local_to_hw(local));
281 if (res)
Johannes Bergb2c258f2007-07-27 15:43:23 +0200282 return res;
Michael Bueschceffefd2008-02-10 14:16:52 +0100283 need_hw_reconfig = 1;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100284 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200285 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200286
Johannes Berg51fb61e2007-12-19 01:31:27 +0100287 switch (sdata->vif.type) {
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400288 case IEEE80211_IF_TYPE_VLAN:
289 list_add(&sdata->u.vlan.list, &sdata->u.vlan.ap->u.ap.vlans);
290 /* no need to tell driver */
291 break;
Johannes Berg4150c572007-09-17 01:29:23 -0400292 case IEEE80211_IF_TYPE_MNTR:
Michael Wu3d30d942008-01-31 19:48:27 +0100293 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
294 local->cooked_mntrs++;
295 break;
296 }
297
Johannes Berg4150c572007-09-17 01:29:23 -0400298 /* must be before the call to ieee80211_configure_filter */
Johannes Bergb2c258f2007-07-27 15:43:23 +0200299 local->monitors++;
Michael Wu8cc9a732008-01-31 19:48:23 +0100300 if (local->monitors == 1)
Johannes Berg4150c572007-09-17 01:29:23 -0400301 local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
Michael Wu8cc9a732008-01-31 19:48:23 +0100302
303 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
304 local->fif_fcsfail++;
305 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
306 local->fif_plcpfail++;
307 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
308 local->fif_control++;
309 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
310 local->fif_other_bss++;
311
312 netif_tx_lock_bh(local->mdev);
313 ieee80211_configure_filter(local);
314 netif_tx_unlock_bh(local->mdev);
Johannes Berg4150c572007-09-17 01:29:23 -0400315 break;
316 case IEEE80211_IF_TYPE_STA:
317 case IEEE80211_IF_TYPE_IBSS:
318 sdata->u.sta.flags &= ~IEEE80211_STA_PREV_BSSID_SET;
319 /* fall through */
320 default:
Johannes Berg32bfd352007-12-19 01:31:26 +0100321 conf.vif = &sdata->vif;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100322 conf.type = sdata->vif.type;
Johannes Berg4150c572007-09-17 01:29:23 -0400323 conf.mac_addr = dev->dev_addr;
324 res = local->ops->add_interface(local_to_hw(local), &conf);
325 if (res && !local->open_count && local->ops->stop)
326 local->ops->stop(local_to_hw(local));
327 if (res)
328 return res;
329
Johannes Bergb2c258f2007-07-27 15:43:23 +0200330 ieee80211_if_config(dev);
Daniel Draked9430a32007-07-27 15:43:24 +0200331 ieee80211_reset_erp_info(dev);
Johannes Berg11a843b2007-08-28 17:01:55 -0400332 ieee80211_enable_keys(sdata);
Johannes Berg4150c572007-09-17 01:29:23 -0400333
Johannes Berg51fb61e2007-12-19 01:31:27 +0100334 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200335 !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME))
Johannes Berg4150c572007-09-17 01:29:23 -0400336 netif_carrier_off(dev);
337 else
338 netif_carrier_on(dev);
Daniel Draked9430a32007-07-27 15:43:24 +0200339 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200340
Johannes Berg4150c572007-09-17 01:29:23 -0400341 if (local->open_count == 0) {
342 res = dev_open(local->mdev);
343 WARN_ON(res);
Johannes Berg4150c572007-09-17 01:29:23 -0400344 tasklet_enable(&local->tx_pending_tasklet);
345 tasklet_enable(&local->tasklet);
346 }
347
Johannes Bergc1428b32007-11-16 02:54:53 +0100348 /*
349 * set_multicast_list will be invoked by the networking core
350 * which will check whether any increments here were done in
351 * error and sync them down to the hardware as filter flags.
352 */
353 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
354 atomic_inc(&local->iff_allmultis);
355
356 if (sdata->flags & IEEE80211_SDATA_PROMISC)
357 atomic_inc(&local->iff_promiscs);
358
Johannes Berg4150c572007-09-17 01:29:23 -0400359 local->open_count++;
Michael Bueschceffefd2008-02-10 14:16:52 +0100360 if (need_hw_reconfig)
361 ieee80211_hw_config(local);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200362
363 netif_start_queue(dev);
Johannes Berg4150c572007-09-17 01:29:23 -0400364
Johannes Bergb2c258f2007-07-27 15:43:23 +0200365 return 0;
366}
367
Johannes Berg4150c572007-09-17 01:29:23 -0400368static int ieee80211_stop(struct net_device *dev)
Johannes Bergb2c258f2007-07-27 15:43:23 +0200369{
Johannes Berg4150c572007-09-17 01:29:23 -0400370 struct ieee80211_sub_if_data *sdata;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200371 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg4150c572007-09-17 01:29:23 -0400372 struct ieee80211_if_init_conf conf;
Ron Rindjunsky07db2182007-12-25 17:00:33 +0200373 struct sta_info *sta;
374 int i;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200375
Johannes Berg4150c572007-09-17 01:29:23 -0400376 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
377
Johannes Bergd0709a62008-02-25 16:27:46 +0100378 rcu_read_lock();
379
380 list_for_each_entry_rcu(sta, &local->sta_list, list) {
381 if (sta->sdata == sdata)
Ron Rindjunsky5b3d71d2008-01-13 18:21:58 +0200382 for (i = 0; i < STA_TID_NUM; i++)
Johannes Bergd0709a62008-02-25 16:27:46 +0100383 ieee80211_sta_stop_rx_ba_session(sdata->dev,
Ron Rindjunsky5b3d71d2008-01-13 18:21:58 +0200384 sta->addr, i,
385 WLAN_BACK_RECIPIENT,
Ron Rindjunsky07db2182007-12-25 17:00:33 +0200386 WLAN_REASON_QSTA_LEAVE_QBSS);
387 }
388
Johannes Bergd0709a62008-02-25 16:27:46 +0100389 rcu_read_unlock();
390
Johannes Berg4150c572007-09-17 01:29:23 -0400391 netif_stop_queue(dev);
392
Johannes Bergc1428b32007-11-16 02:54:53 +0100393 /*
394 * Don't count this interface for promisc/allmulti while it
395 * is down. dev_mc_unsync() will invoke set_multicast_list
396 * on the master interface which will sync these down to the
397 * hardware as filter flags.
398 */
399 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
400 atomic_dec(&local->iff_allmultis);
401
402 if (sdata->flags & IEEE80211_SDATA_PROMISC)
403 atomic_dec(&local->iff_promiscs);
404
Johannes Berg4150c572007-09-17 01:29:23 -0400405 dev_mc_unsync(local->mdev, dev);
406
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100407 /* APs need special treatment */
Johannes Berg51fb61e2007-12-19 01:31:27 +0100408 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400409 struct ieee80211_sub_if_data *vlan, *tmp;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100410 struct beacon_data *old_beacon = sdata->u.ap.beacon;
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400411
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100412 /* remove beacon */
413 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
414 synchronize_rcu();
415 kfree(old_beacon);
416
417 /* down all dependent devices, that is VLANs */
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400418 list_for_each_entry_safe(vlan, tmp, &sdata->u.ap.vlans,
419 u.vlan.list)
420 dev_close(vlan->dev);
421 WARN_ON(!list_empty(&sdata->u.ap.vlans));
422 }
423
Johannes Berg4150c572007-09-17 01:29:23 -0400424 local->open_count--;
425
Johannes Berg51fb61e2007-12-19 01:31:27 +0100426 switch (sdata->vif.type) {
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400427 case IEEE80211_IF_TYPE_VLAN:
428 list_del(&sdata->u.vlan.list);
429 sdata->u.vlan.ap = NULL;
430 /* no need to tell driver */
431 break;
Johannes Berg4150c572007-09-17 01:29:23 -0400432 case IEEE80211_IF_TYPE_MNTR:
Michael Wu3d30d942008-01-31 19:48:27 +0100433 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
434 local->cooked_mntrs--;
435 break;
436 }
437
Johannes Berg4150c572007-09-17 01:29:23 -0400438 local->monitors--;
Michael Wu8cc9a732008-01-31 19:48:23 +0100439 if (local->monitors == 0)
Michael Wu8b393f12007-11-28 01:57:08 -0500440 local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
Michael Wu8cc9a732008-01-31 19:48:23 +0100441
442 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
443 local->fif_fcsfail--;
444 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
445 local->fif_plcpfail--;
446 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
447 local->fif_control--;
448 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
449 local->fif_other_bss--;
450
451 netif_tx_lock_bh(local->mdev);
452 ieee80211_configure_filter(local);
453 netif_tx_unlock_bh(local->mdev);
Johannes Berg4150c572007-09-17 01:29:23 -0400454 break;
Luis Carlos Cobof7a92142008-02-23 15:17:18 +0100455 case IEEE80211_IF_TYPE_MESH_POINT:
Johannes Bergd0709a62008-02-25 16:27:46 +0100456 sta_info_flush(local, sdata);
Luis Carlos Cobof7a92142008-02-23 15:17:18 +0100457 /* fall through */
Johannes Bergb2c258f2007-07-27 15:43:23 +0200458 case IEEE80211_IF_TYPE_STA:
459 case IEEE80211_IF_TYPE_IBSS:
460 sdata->u.sta.state = IEEE80211_DISABLED;
461 del_timer_sync(&sdata->u.sta.timer);
Johannes Berg2a8a9a82007-08-28 17:01:52 -0400462 /*
Johannes Berg79010422007-09-18 17:29:21 -0400463 * When we get here, the interface is marked down.
464 * Call synchronize_rcu() to wait for the RX path
465 * should it be using the interface and enqueuing
466 * frames at this very time on another CPU.
Johannes Berg2a8a9a82007-08-28 17:01:52 -0400467 */
Johannes Berg79010422007-09-18 17:29:21 -0400468 synchronize_rcu();
Johannes Bergb2c258f2007-07-27 15:43:23 +0200469 skb_queue_purge(&sdata->u.sta.skb_queue);
Johannes Berg2a8a9a82007-08-28 17:01:52 -0400470
Zhu Yiece8edd2007-11-22 10:53:21 +0800471 if (local->scan_dev == sdata->dev) {
472 if (!local->ops->hw_scan) {
473 local->sta_sw_scanning = 0;
474 cancel_delayed_work(&local->scan_work);
475 } else
476 local->sta_hw_scanning = 0;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200477 }
Zhu Yiece8edd2007-11-22 10:53:21 +0800478
Johannes Bergb2c258f2007-07-27 15:43:23 +0200479 flush_workqueue(local->hw.workqueue);
Zhu Yia10605e2007-11-22 11:10:22 +0800480
481 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
482 kfree(sdata->u.sta.extra_ie);
483 sdata->u.sta.extra_ie = NULL;
484 sdata->u.sta.extra_ie_len = 0;
Johannes Berg4150c572007-09-17 01:29:23 -0400485 /* fall through */
486 default:
Johannes Berg32bfd352007-12-19 01:31:26 +0100487 conf.vif = &sdata->vif;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100488 conf.type = sdata->vif.type;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200489 conf.mac_addr = dev->dev_addr;
Johannes Berg4150c572007-09-17 01:29:23 -0400490 /* disable all keys for as long as this netdev is down */
491 ieee80211_disable_keys(sdata);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200492 local->ops->remove_interface(local_to_hw(local), &conf);
493 }
494
Johannes Berg4150c572007-09-17 01:29:23 -0400495 if (local->open_count == 0) {
496 if (netif_running(local->mdev))
497 dev_close(local->mdev);
498
Johannes Berg4150c572007-09-17 01:29:23 -0400499 if (local->ops->stop)
500 local->ops->stop(local_to_hw(local));
501
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100502 ieee80211_led_radio(local, 0);
503
Johannes Berg4150c572007-09-17 01:29:23 -0400504 tasklet_disable(&local->tx_pending_tasklet);
505 tasklet_disable(&local->tasklet);
506 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200507
508 return 0;
509}
510
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200511int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
512{
513 struct ieee80211_local *local = hw_to_local(hw);
514 struct sta_info *sta;
515 struct ieee80211_sub_if_data *sdata;
516 u16 start_seq_num = 0;
517 u8 *state;
518 int ret;
519 DECLARE_MAC_BUF(mac);
520
521 if (tid >= STA_TID_NUM)
522 return -EINVAL;
523
524#ifdef CONFIG_MAC80211_HT_DEBUG
525 printk(KERN_DEBUG "Open BA session requested for %s tid %u\n",
526 print_mac(mac, ra), tid);
527#endif /* CONFIG_MAC80211_HT_DEBUG */
528
Johannes Bergd0709a62008-02-25 16:27:46 +0100529 rcu_read_lock();
530
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200531 sta = sta_info_get(local, ra);
532 if (!sta) {
533 printk(KERN_DEBUG "Could not find the station\n");
Johannes Bergd0709a62008-02-25 16:27:46 +0100534 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200535 return -ENOENT;
536 }
537
538 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
539
540 /* we have tried too many times, receiver does not want A-MPDU */
541 if (sta->ampdu_mlme.tid_tx[tid].addba_req_num > HT_AGG_MAX_RETRIES) {
542 ret = -EBUSY;
543 goto start_ba_exit;
544 }
545
546 state = &sta->ampdu_mlme.tid_tx[tid].state;
547 /* check if the TID is not in aggregation flow already */
548 if (*state != HT_AGG_STATE_IDLE) {
549#ifdef CONFIG_MAC80211_HT_DEBUG
550 printk(KERN_DEBUG "BA request denied - session is not "
551 "idle on tid %u\n", tid);
552#endif /* CONFIG_MAC80211_HT_DEBUG */
553 ret = -EAGAIN;
554 goto start_ba_exit;
555 }
556
557 /* ensure that TX flow won't interrupt us
558 * until the end of the call to requeue function */
559 spin_lock_bh(&local->mdev->queue_lock);
560
561 /* create a new queue for this aggregation */
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200562 ret = ieee80211_ht_agg_queue_add(local, sta, tid);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200563
564 /* case no queue is available to aggregation
565 * don't switch to aggregation */
566 if (ret) {
567#ifdef CONFIG_MAC80211_HT_DEBUG
568 printk(KERN_DEBUG "BA request denied - no queue available for"
569 " tid %d\n", tid);
570#endif /* CONFIG_MAC80211_HT_DEBUG */
571 spin_unlock_bh(&local->mdev->queue_lock);
572 goto start_ba_exit;
573 }
Johannes Bergd0709a62008-02-25 16:27:46 +0100574 sdata = sta->sdata;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200575
576 /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
577 * call back right away, it must see that the flow has begun */
578 *state |= HT_ADDBA_REQUESTED_MSK;
579
580 if (local->ops->ampdu_action)
581 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START,
582 ra, tid, &start_seq_num);
583
584 if (ret) {
585 /* No need to requeue the packets in the agg queue, since we
586 * held the tx lock: no packet could be enqueued to the newly
587 * allocated queue */
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200588 ieee80211_ht_agg_queue_remove(local, sta, tid, 0);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200589#ifdef CONFIG_MAC80211_HT_DEBUG
590 printk(KERN_DEBUG "BA request denied - HW or queue unavailable"
591 " for tid %d\n", tid);
592#endif /* CONFIG_MAC80211_HT_DEBUG */
593 spin_unlock_bh(&local->mdev->queue_lock);
594 *state = HT_AGG_STATE_IDLE;
595 goto start_ba_exit;
596 }
597
598 /* Will put all the packets in the new SW queue */
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200599 ieee80211_requeue(local, ieee802_1d_to_ac[tid]);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200600 spin_unlock_bh(&local->mdev->queue_lock);
601
602 /* We have most probably almost emptied the legacy queue */
603 /* ieee80211_wake_queue(local_to_hw(local), ieee802_1d_to_ac[tid]); */
604
605 /* send an addBA request */
606 sta->ampdu_mlme.dialog_token_allocator++;
607 sta->ampdu_mlme.tid_tx[tid].dialog_token =
608 sta->ampdu_mlme.dialog_token_allocator;
609 sta->ampdu_mlme.tid_tx[tid].ssn = start_seq_num;
610
Johannes Bergd0709a62008-02-25 16:27:46 +0100611 ieee80211_send_addba_request(sta->sdata->dev, ra, tid,
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200612 sta->ampdu_mlme.tid_tx[tid].dialog_token,
613 sta->ampdu_mlme.tid_tx[tid].ssn,
614 0x40, 5000);
615
616 /* activate the timer for the recipient's addBA response */
617 sta->ampdu_mlme.tid_tx[tid].addba_resp_timer.expires =
618 jiffies + ADDBA_RESP_INTERVAL;
619 add_timer(&sta->ampdu_mlme.tid_tx[tid].addba_resp_timer);
620 printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
621
622start_ba_exit:
623 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100624 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200625 return ret;
626}
627EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
628
629int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
630 u8 *ra, u16 tid,
631 enum ieee80211_back_parties initiator)
632{
633 struct ieee80211_local *local = hw_to_local(hw);
634 struct sta_info *sta;
635 u8 *state;
636 int ret = 0;
637 DECLARE_MAC_BUF(mac);
638
639 if (tid >= STA_TID_NUM)
640 return -EINVAL;
641
642#ifdef CONFIG_MAC80211_HT_DEBUG
643 printk(KERN_DEBUG "Stop a BA session requested for %s tid %u\n",
644 print_mac(mac, ra), tid);
645#endif /* CONFIG_MAC80211_HT_DEBUG */
646
Johannes Bergd0709a62008-02-25 16:27:46 +0100647 rcu_read_lock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200648 sta = sta_info_get(local, ra);
Johannes Bergd0709a62008-02-25 16:27:46 +0100649 if (!sta) {
650 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200651 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +0100652 }
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200653
654 /* check if the TID is in aggregation */
655 state = &sta->ampdu_mlme.tid_tx[tid].state;
656 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
657
658 if (*state != HT_AGG_STATE_OPERATIONAL) {
659#ifdef CONFIG_MAC80211_HT_DEBUG
660 printk(KERN_DEBUG "Try to stop Tx aggregation on"
661 " non active TID\n");
662#endif /* CONFIG_MAC80211_HT_DEBUG */
663 ret = -ENOENT;
664 goto stop_BA_exit;
665 }
666
667 ieee80211_stop_queue(hw, sta->tid_to_tx_q[tid]);
668
669 *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
670 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
671
672 if (local->ops->ampdu_action)
673 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_STOP,
674 ra, tid, NULL);
675
676 /* case HW denied going back to legacy */
677 if (ret) {
678 WARN_ON(ret != -EBUSY);
679 *state = HT_AGG_STATE_OPERATIONAL;
680 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
681 goto stop_BA_exit;
682 }
683
684stop_BA_exit:
685 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100686 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200687 return ret;
688}
689EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
690
691void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
692{
693 struct ieee80211_local *local = hw_to_local(hw);
694 struct sta_info *sta;
695 u8 *state;
696 DECLARE_MAC_BUF(mac);
697
698 if (tid >= STA_TID_NUM) {
699 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
700 tid, STA_TID_NUM);
701 return;
702 }
703
Johannes Bergd0709a62008-02-25 16:27:46 +0100704 rcu_read_lock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200705 sta = sta_info_get(local, ra);
706 if (!sta) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100707 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200708 printk(KERN_DEBUG "Could not find station: %s\n",
709 print_mac(mac, ra));
710 return;
711 }
712
713 state = &sta->ampdu_mlme.tid_tx[tid].state;
714 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
715
716 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
717 printk(KERN_DEBUG "addBA was not requested yet, state is %d\n",
718 *state);
719 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100720 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200721 return;
722 }
723
724 WARN_ON_ONCE(*state & HT_ADDBA_DRV_READY_MSK);
725
726 *state |= HT_ADDBA_DRV_READY_MSK;
727
728 if (*state == HT_AGG_STATE_OPERATIONAL) {
729 printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid);
730 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
731 }
732 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100733 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200734}
735EXPORT_SYMBOL(ieee80211_start_tx_ba_cb);
736
737void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
738{
739 struct ieee80211_local *local = hw_to_local(hw);
740 struct sta_info *sta;
741 u8 *state;
742 int agg_queue;
743 DECLARE_MAC_BUF(mac);
744
745 if (tid >= STA_TID_NUM) {
746 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
747 tid, STA_TID_NUM);
748 return;
749 }
750
751 printk(KERN_DEBUG "Stop a BA session requested on DA %s tid %d\n",
752 print_mac(mac, ra), tid);
753
Johannes Bergd0709a62008-02-25 16:27:46 +0100754 rcu_read_lock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200755 sta = sta_info_get(local, ra);
756 if (!sta) {
757 printk(KERN_DEBUG "Could not find station: %s\n",
758 print_mac(mac, ra));
Johannes Bergd0709a62008-02-25 16:27:46 +0100759 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200760 return;
761 }
762 state = &sta->ampdu_mlme.tid_tx[tid].state;
763
764 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
765 if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) {
766 printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200767 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100768 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200769 return;
770 }
771
772 if (*state & HT_AGG_STATE_INITIATOR_MSK)
Johannes Bergd0709a62008-02-25 16:27:46 +0100773 ieee80211_send_delba(sta->sdata->dev, ra, tid,
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200774 WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
775
776 agg_queue = sta->tid_to_tx_q[tid];
777
778 /* avoid ordering issues: we are the only one that can modify
779 * the content of the qdiscs */
780 spin_lock_bh(&local->mdev->queue_lock);
781 /* remove the queue for this aggregation */
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200782 ieee80211_ht_agg_queue_remove(local, sta, tid, 1);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200783 spin_unlock_bh(&local->mdev->queue_lock);
784
785 /* we just requeued the all the frames that were in the removed
786 * queue, and since we might miss a softirq we do netif_schedule.
787 * ieee80211_wake_queue is not used here as this queue is not
788 * necessarily stopped */
789 netif_schedule(local->mdev);
790 *state = HT_AGG_STATE_IDLE;
791 sta->ampdu_mlme.tid_tx[tid].addba_req_num = 0;
792 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
793
Johannes Bergd0709a62008-02-25 16:27:46 +0100794 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200795}
796EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb);
797
798void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
799 const u8 *ra, u16 tid)
800{
801 struct ieee80211_local *local = hw_to_local(hw);
802 struct ieee80211_ra_tid *ra_tid;
803 struct sk_buff *skb = dev_alloc_skb(0);
804
805 if (unlikely(!skb)) {
806 if (net_ratelimit())
807 printk(KERN_WARNING "%s: Not enough memory, "
808 "dropping start BA session", skb->dev->name);
809 return;
810 }
811 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
812 memcpy(&ra_tid->ra, ra, ETH_ALEN);
813 ra_tid->tid = tid;
814
815 skb->pkt_type = IEEE80211_ADDBA_MSG;
816 skb_queue_tail(&local->skb_queue, skb);
817 tasklet_schedule(&local->tasklet);
818}
819EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
820
821void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
822 const u8 *ra, u16 tid)
823{
824 struct ieee80211_local *local = hw_to_local(hw);
825 struct ieee80211_ra_tid *ra_tid;
826 struct sk_buff *skb = dev_alloc_skb(0);
827
828 if (unlikely(!skb)) {
829 if (net_ratelimit())
830 printk(KERN_WARNING "%s: Not enough memory, "
831 "dropping stop BA session", skb->dev->name);
832 return;
833 }
834 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
835 memcpy(&ra_tid->ra, ra, ETH_ALEN);
836 ra_tid->tid = tid;
837
838 skb->pkt_type = IEEE80211_DELBA_MSG;
839 skb_queue_tail(&local->skb_queue, skb);
840 tasklet_schedule(&local->tasklet);
841}
842EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
843
Johannes Bergb2c258f2007-07-27 15:43:23 +0200844static void ieee80211_set_multicast_list(struct net_device *dev)
845{
846 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
847 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg4150c572007-09-17 01:29:23 -0400848 int allmulti, promisc, sdata_allmulti, sdata_promisc;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200849
Johannes Berg4150c572007-09-17 01:29:23 -0400850 allmulti = !!(dev->flags & IFF_ALLMULTI);
851 promisc = !!(dev->flags & IFF_PROMISC);
Johannes Bergb52f2192007-11-16 01:49:11 +0100852 sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
853 sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC);
Johannes Berg4150c572007-09-17 01:29:23 -0400854
855 if (allmulti != sdata_allmulti) {
856 if (dev->flags & IFF_ALLMULTI)
Johannes Berg53918992007-09-26 15:19:47 +0200857 atomic_inc(&local->iff_allmultis);
Johannes Berg4150c572007-09-17 01:29:23 -0400858 else
Johannes Berg53918992007-09-26 15:19:47 +0200859 atomic_dec(&local->iff_allmultis);
Jiri Slaby13262ff2007-08-28 17:01:54 -0400860 sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200861 }
Johannes Berg4150c572007-09-17 01:29:23 -0400862
863 if (promisc != sdata_promisc) {
864 if (dev->flags & IFF_PROMISC)
Johannes Berg53918992007-09-26 15:19:47 +0200865 atomic_inc(&local->iff_promiscs);
Johannes Berg4150c572007-09-17 01:29:23 -0400866 else
Johannes Berg53918992007-09-26 15:19:47 +0200867 atomic_dec(&local->iff_promiscs);
Jiri Slaby13262ff2007-08-28 17:01:54 -0400868 sdata->flags ^= IEEE80211_SDATA_PROMISC;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200869 }
Johannes Berg4150c572007-09-17 01:29:23 -0400870
871 dev_mc_sync(local->mdev, dev);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200872}
873
Stephen Hemminger3b04ddd2007-10-09 01:40:57 -0700874static const struct header_ops ieee80211_header_ops = {
875 .create = eth_header,
876 .parse = header_parse_80211,
877 .rebuild = eth_rebuild_header,
878 .cache = eth_header_cache,
879 .cache_update = eth_header_cache_update,
880};
881
Johannes Bergf9d540e2007-09-28 14:02:09 +0200882/* Must not be called for mdev */
Johannes Bergb2c258f2007-07-27 15:43:23 +0200883void ieee80211_if_setup(struct net_device *dev)
884{
885 ether_setup(dev);
886 dev->hard_start_xmit = ieee80211_subif_start_xmit;
887 dev->wireless_handlers = &ieee80211_iw_handler_def;
888 dev->set_multicast_list = ieee80211_set_multicast_list;
889 dev->change_mtu = ieee80211_change_mtu;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200890 dev->open = ieee80211_open;
891 dev->stop = ieee80211_stop;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200892 dev->destructor = ieee80211_if_free;
893}
894
895/* WDS specialties */
896
897int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr)
898{
899 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
900 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
901 struct sta_info *sta;
Joe Perches0795af52007-10-03 17:59:30 -0700902 DECLARE_MAC_BUF(mac);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200903
Johannes Bergd0709a62008-02-25 16:27:46 +0100904 might_sleep();
905
Johannes Bergb2c258f2007-07-27 15:43:23 +0200906 if (compare_ether_addr(remote_addr, sdata->u.wds.remote_addr) == 0)
907 return 0;
908
Johannes Bergd0709a62008-02-25 16:27:46 +0100909 rcu_read_lock();
910
Johannes Bergb2c258f2007-07-27 15:43:23 +0200911 /* Create STA entry for the new peer */
Johannes Bergd0709a62008-02-25 16:27:46 +0100912 sta = sta_info_add(sdata, remote_addr);
913 if (IS_ERR(sta)) {
914 rcu_read_unlock();
Johannes Berg43ba7e92008-02-21 14:09:30 +0100915 return PTR_ERR(sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100916 }
Johannes Berg238814f2008-01-28 17:19:37 +0100917
918 sta->flags |= WLAN_STA_AUTHORIZED;
919
Johannes Bergb2c258f2007-07-27 15:43:23 +0200920 /* Remove STA entry for the old peer */
921 sta = sta_info_get(local, sdata->u.wds.remote_addr);
Johannes Bergd0709a62008-02-25 16:27:46 +0100922 if (sta)
923 sta_info_unlink(&sta);
924 else
Johannes Bergb2c258f2007-07-27 15:43:23 +0200925 printk(KERN_DEBUG "%s: could not find STA entry for WDS link "
Joe Perches0795af52007-10-03 17:59:30 -0700926 "peer %s\n",
927 dev->name, print_mac(mac, sdata->u.wds.remote_addr));
Johannes Bergb2c258f2007-07-27 15:43:23 +0200928
929 /* Update WDS link data */
930 memcpy(&sdata->u.wds.remote_addr, remote_addr, ETH_ALEN);
931
Johannes Bergd0709a62008-02-25 16:27:46 +0100932 rcu_read_unlock();
933
934 if (sta) {
935 synchronize_rcu();
936 sta_info_destroy(sta);
937 }
938
Johannes Bergb2c258f2007-07-27 15:43:23 +0200939 return 0;
940}
941
942/* everything else */
943
Johannes Bergb2c258f2007-07-27 15:43:23 +0200944static int __ieee80211_if_config(struct net_device *dev,
945 struct sk_buff *beacon,
946 struct ieee80211_tx_control *control)
947{
948 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
949 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
950 struct ieee80211_if_conf conf;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200951
952 if (!local->ops->config_interface || !netif_running(dev))
953 return 0;
954
955 memset(&conf, 0, sizeof(conf));
Johannes Berg51fb61e2007-12-19 01:31:27 +0100956 conf.type = sdata->vif.type;
957 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
958 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Johannes Berg4150c572007-09-17 01:29:23 -0400959 conf.bssid = sdata->u.sta.bssid;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200960 conf.ssid = sdata->u.sta.ssid;
961 conf.ssid_len = sdata->u.sta.ssid_len;
Johannes Berg902acc72008-02-23 15:17:19 +0100962 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Cobof7a92142008-02-23 15:17:18 +0100963 conf.beacon = beacon;
964 ieee80211_start_mesh(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100965 } else if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Johannes Bergb2c258f2007-07-27 15:43:23 +0200966 conf.ssid = sdata->u.ap.ssid;
967 conf.ssid_len = sdata->u.ap.ssid_len;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200968 conf.beacon = beacon;
969 conf.beacon_control = control;
970 }
971 return local->ops->config_interface(local_to_hw(local),
Johannes Berg32bfd352007-12-19 01:31:26 +0100972 &sdata->vif, &conf);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200973}
974
975int ieee80211_if_config(struct net_device *dev)
976{
Luis Carlos Cobof7a92142008-02-23 15:17:18 +0100977 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
978 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
979 if (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT &&
980 (local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE))
981 return ieee80211_if_config_beacon(dev);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200982 return __ieee80211_if_config(dev, NULL, NULL);
983}
984
985int ieee80211_if_config_beacon(struct net_device *dev)
986{
987 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
988 struct ieee80211_tx_control control;
Johannes Berg32bfd352007-12-19 01:31:26 +0100989 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200990 struct sk_buff *skb;
991
992 if (!(local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE))
993 return 0;
Johannes Berg32bfd352007-12-19 01:31:26 +0100994 skb = ieee80211_beacon_get(local_to_hw(local), &sdata->vif,
995 &control);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200996 if (!skb)
997 return -ENOMEM;
998 return __ieee80211_if_config(dev, skb, &control);
999}
1000
1001int ieee80211_hw_config(struct ieee80211_local *local)
1002{
Johannes Bergb2c258f2007-07-27 15:43:23 +02001003 struct ieee80211_channel *chan;
1004 int ret = 0;
1005
Johannes Berg8318d782008-01-24 19:38:38 +01001006 if (local->sta_sw_scanning)
Johannes Bergb2c258f2007-07-27 15:43:23 +02001007 chan = local->scan_channel;
Johannes Berg8318d782008-01-24 19:38:38 +01001008 else
Johannes Bergb2c258f2007-07-27 15:43:23 +02001009 chan = local->oper_channel;
Johannes Bergb2c258f2007-07-27 15:43:23 +02001010
Johannes Berg8318d782008-01-24 19:38:38 +01001011 local->hw.conf.channel = chan;
1012
1013 if (!local->hw.conf.power_level)
1014 local->hw.conf.power_level = chan->max_power;
1015 else
1016 local->hw.conf.power_level = min(chan->max_power,
1017 local->hw.conf.power_level);
1018
1019 local->hw.conf.max_antenna_gain = chan->max_antenna_gain;
Johannes Bergb2c258f2007-07-27 15:43:23 +02001020
1021#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Berg8318d782008-01-24 19:38:38 +01001022 printk(KERN_DEBUG "%s: HW CONFIG: freq=%d\n",
1023 wiphy_name(local->hw.wiphy), chan->center_freq);
1024#endif
Johannes Bergb2c258f2007-07-27 15:43:23 +02001025
Michael Bueschf7c4dae2007-09-24 18:41:49 +02001026 if (local->open_count)
Johannes Bergb2c258f2007-07-27 15:43:23 +02001027 ret = local->ops->config(local_to_hw(local), &local->hw.conf);
1028
1029 return ret;
1030}
1031
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001032/**
1033 * ieee80211_hw_config_ht should be used only after legacy configuration
1034 * has been determined, as ht configuration depends upon the hardware's
1035 * HT abilities for a _specific_ band.
1036 */
1037int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht,
1038 struct ieee80211_ht_info *req_ht_cap,
1039 struct ieee80211_ht_bss_info *req_bss_cap)
1040{
1041 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg8318d782008-01-24 19:38:38 +01001042 struct ieee80211_supported_band *sband;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001043 int i;
1044
Johannes Berg8318d782008-01-24 19:38:38 +01001045 sband = local->hw.wiphy->bands[conf->channel->band];
1046
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001047 /* HT is not supported */
Johannes Berg8318d782008-01-24 19:38:38 +01001048 if (!sband->ht_info.ht_supported) {
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001049 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
1050 return -EOPNOTSUPP;
1051 }
1052
1053 /* disable HT */
1054 if (!enable_ht) {
1055 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
1056 } else {
1057 conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE;
Johannes Berg8318d782008-01-24 19:38:38 +01001058 conf->ht_conf.cap = req_ht_cap->cap & sband->ht_info.cap;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001059 conf->ht_conf.cap &= ~(IEEE80211_HT_CAP_MIMO_PS);
1060 conf->ht_conf.cap |=
Johannes Berg8318d782008-01-24 19:38:38 +01001061 sband->ht_info.cap & IEEE80211_HT_CAP_MIMO_PS;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001062 conf->ht_bss_conf.primary_channel =
1063 req_bss_cap->primary_channel;
1064 conf->ht_bss_conf.bss_cap = req_bss_cap->bss_cap;
1065 conf->ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode;
1066 for (i = 0; i < SUPP_MCS_SET_LEN; i++)
1067 conf->ht_conf.supp_mcs_set[i] =
Johannes Berg8318d782008-01-24 19:38:38 +01001068 sband->ht_info.supp_mcs_set[i] &
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001069 req_ht_cap->supp_mcs_set[i];
1070
1071 /* In STA mode, this gives us indication
1072 * to the AP's mode of operation */
1073 conf->ht_conf.ht_supported = 1;
1074 conf->ht_conf.ampdu_factor = req_ht_cap->ampdu_factor;
1075 conf->ht_conf.ampdu_density = req_ht_cap->ampdu_density;
1076 }
1077
1078 local->ops->conf_ht(local_to_hw(local), &local->hw.conf);
1079
1080 return 0;
1081}
1082
Johannes Berg471b3ef2007-12-28 14:32:58 +01001083void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
1084 u32 changed)
Daniel Draked9430a32007-07-27 15:43:24 +02001085{
Johannes Berg471b3ef2007-12-28 14:32:58 +01001086 struct ieee80211_local *local = sdata->local;
1087
1088 if (!changed)
1089 return;
1090
1091 if (local->ops->bss_info_changed)
1092 local->ops->bss_info_changed(local_to_hw(local),
1093 &sdata->vif,
1094 &sdata->bss_conf,
1095 changed);
Daniel Draked9430a32007-07-27 15:43:24 +02001096}
1097
1098void ieee80211_reset_erp_info(struct net_device *dev)
1099{
1100 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1101
Johannes Berg471b3ef2007-12-28 14:32:58 +01001102 sdata->bss_conf.use_cts_prot = 0;
1103 sdata->bss_conf.use_short_preamble = 0;
1104 ieee80211_bss_info_change_notify(sdata,
1105 BSS_CHANGED_ERP_CTS_PROT |
1106 BSS_CHANGED_ERP_PREAMBLE);
Daniel Draked9430a32007-07-27 15:43:24 +02001107}
1108
Jiri Bencf0706e82007-05-05 11:45:53 -07001109void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
1110 struct sk_buff *skb,
1111 struct ieee80211_tx_status *status)
1112{
1113 struct ieee80211_local *local = hw_to_local(hw);
1114 struct ieee80211_tx_status *saved;
1115 int tmp;
1116
1117 skb->dev = local->mdev;
1118 saved = kmalloc(sizeof(struct ieee80211_tx_status), GFP_ATOMIC);
1119 if (unlikely(!saved)) {
1120 if (net_ratelimit())
1121 printk(KERN_WARNING "%s: Not enough memory, "
1122 "dropping tx status", skb->dev->name);
1123 /* should be dev_kfree_skb_irq, but due to this function being
1124 * named _irqsafe instead of just _irq we can't be sure that
1125 * people won't call it from non-irq contexts */
1126 dev_kfree_skb_any(skb);
1127 return;
1128 }
1129 memcpy(saved, status, sizeof(struct ieee80211_tx_status));
1130 /* copy pointer to saved status into skb->cb for use by tasklet */
1131 memcpy(skb->cb, &saved, sizeof(saved));
1132
1133 skb->pkt_type = IEEE80211_TX_STATUS_MSG;
1134 skb_queue_tail(status->control.flags & IEEE80211_TXCTL_REQ_TX_STATUS ?
1135 &local->skb_queue : &local->skb_queue_unreliable, skb);
1136 tmp = skb_queue_len(&local->skb_queue) +
1137 skb_queue_len(&local->skb_queue_unreliable);
1138 while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
1139 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
1140 memcpy(&saved, skb->cb, sizeof(saved));
1141 kfree(saved);
1142 dev_kfree_skb_irq(skb);
1143 tmp--;
1144 I802_DEBUG_INC(local->tx_status_drop);
1145 }
1146 tasklet_schedule(&local->tasklet);
1147}
1148EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
1149
1150static void ieee80211_tasklet_handler(unsigned long data)
1151{
1152 struct ieee80211_local *local = (struct ieee80211_local *) data;
1153 struct sk_buff *skb;
1154 struct ieee80211_rx_status rx_status;
1155 struct ieee80211_tx_status *tx_status;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001156 struct ieee80211_ra_tid *ra_tid;
Jiri Bencf0706e82007-05-05 11:45:53 -07001157
1158 while ((skb = skb_dequeue(&local->skb_queue)) ||
1159 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
1160 switch (skb->pkt_type) {
1161 case IEEE80211_RX_MSG:
1162 /* status is in skb->cb */
1163 memcpy(&rx_status, skb->cb, sizeof(rx_status));
Johannes Berg51fb61e2007-12-19 01:31:27 +01001164 /* Clear skb->pkt_type in order to not confuse kernel
Jiri Bencf0706e82007-05-05 11:45:53 -07001165 * netstack. */
1166 skb->pkt_type = 0;
1167 __ieee80211_rx(local_to_hw(local), skb, &rx_status);
1168 break;
1169 case IEEE80211_TX_STATUS_MSG:
1170 /* get pointer to saved status out of skb->cb */
1171 memcpy(&tx_status, skb->cb, sizeof(tx_status));
1172 skb->pkt_type = 0;
1173 ieee80211_tx_status(local_to_hw(local),
1174 skb, tx_status);
1175 kfree(tx_status);
1176 break;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001177 case IEEE80211_DELBA_MSG:
1178 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
1179 ieee80211_stop_tx_ba_cb(local_to_hw(local),
1180 ra_tid->ra, ra_tid->tid);
1181 dev_kfree_skb(skb);
1182 break;
1183 case IEEE80211_ADDBA_MSG:
1184 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
1185 ieee80211_start_tx_ba_cb(local_to_hw(local),
1186 ra_tid->ra, ra_tid->tid);
1187 dev_kfree_skb(skb);
1188 break ;
Jiri Bencf0706e82007-05-05 11:45:53 -07001189 default: /* should never get here! */
1190 printk(KERN_ERR "%s: Unknown message type (%d)\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001191 wiphy_name(local->hw.wiphy), skb->pkt_type);
Jiri Bencf0706e82007-05-05 11:45:53 -07001192 dev_kfree_skb(skb);
1193 break;
1194 }
1195 }
1196}
1197
Jiri Bencf0706e82007-05-05 11:45:53 -07001198/* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
1199 * make a prepared TX frame (one that has been given to hw) to look like brand
1200 * new IEEE 802.11 frame that is ready to go through TX processing again.
1201 * Also, tx_packet_data in cb is restored from tx_control. */
1202static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
1203 struct ieee80211_key *key,
1204 struct sk_buff *skb,
1205 struct ieee80211_tx_control *control)
1206{
1207 int hdrlen, iv_len, mic_len;
1208 struct ieee80211_tx_packet_data *pkt_data;
1209
1210 pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
Johannes Berg32bfd352007-12-19 01:31:26 +01001211 pkt_data->ifindex = vif_to_sdata(control->vif)->dev->ifindex;
Jiri Slabye8bf9642007-08-28 17:01:54 -04001212 pkt_data->flags = 0;
1213 if (control->flags & IEEE80211_TXCTL_REQ_TX_STATUS)
1214 pkt_data->flags |= IEEE80211_TXPD_REQ_TX_STATUS;
1215 if (control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)
1216 pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT;
1217 if (control->flags & IEEE80211_TXCTL_REQUEUE)
1218 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
Johannes Berg678f5f712007-12-19 01:31:23 +01001219 if (control->flags & IEEE80211_TXCTL_EAPOL_FRAME)
1220 pkt_data->flags |= IEEE80211_TXPD_EAPOL_FRAME;
Jiri Bencf0706e82007-05-05 11:45:53 -07001221 pkt_data->queue = control->queue;
1222
1223 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1224
1225 if (!key)
1226 goto no_key;
1227
Johannes Berg8f20fc22007-08-28 17:01:54 -04001228 switch (key->conf.alg) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001229 case ALG_WEP:
1230 iv_len = WEP_IV_LEN;
1231 mic_len = WEP_ICV_LEN;
1232 break;
1233 case ALG_TKIP:
1234 iv_len = TKIP_IV_LEN;
1235 mic_len = TKIP_ICV_LEN;
1236 break;
1237 case ALG_CCMP:
1238 iv_len = CCMP_HDR_LEN;
1239 mic_len = CCMP_MIC_LEN;
1240 break;
1241 default:
1242 goto no_key;
1243 }
1244
Johannes Berg8f20fc22007-08-28 17:01:54 -04001245 if (skb->len >= mic_len &&
Johannes Berg11a843b2007-08-28 17:01:55 -04001246 !(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
Jiri Bencf0706e82007-05-05 11:45:53 -07001247 skb_trim(skb, skb->len - mic_len);
1248 if (skb->len >= iv_len && skb->len > hdrlen) {
1249 memmove(skb->data + iv_len, skb->data, hdrlen);
1250 skb_pull(skb, iv_len);
1251 }
1252
1253no_key:
1254 {
1255 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1256 u16 fc = le16_to_cpu(hdr->frame_control);
1257 if ((fc & 0x8C) == 0x88) /* QoS Control Field */ {
1258 fc &= ~IEEE80211_STYPE_QOS_DATA;
1259 hdr->frame_control = cpu_to_le16(fc);
1260 memmove(skb->data + 2, skb->data, hdrlen - 2);
1261 skb_pull(skb, 2);
1262 }
1263 }
1264}
1265
Johannes Bergd46e1442008-02-20 23:59:33 +01001266static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
1267 struct sta_info *sta,
1268 struct sk_buff *skb,
1269 struct ieee80211_tx_status *status)
1270{
1271 sta->tx_filtered_count++;
1272
1273 /*
1274 * Clear the TX filter mask for this STA when sending the next
1275 * packet. If the STA went to power save mode, this will happen
1276 * happen when it wakes up for the next time.
1277 */
1278 sta->flags |= WLAN_STA_CLEAR_PS_FILT;
1279
1280 /*
1281 * This code races in the following way:
1282 *
1283 * (1) STA sends frame indicating it will go to sleep and does so
1284 * (2) hardware/firmware adds STA to filter list, passes frame up
1285 * (3) hardware/firmware processes TX fifo and suppresses a frame
1286 * (4) we get TX status before having processed the frame and
1287 * knowing that the STA has gone to sleep.
1288 *
1289 * This is actually quite unlikely even when both those events are
1290 * processed from interrupts coming in quickly after one another or
1291 * even at the same time because we queue both TX status events and
1292 * RX frames to be processed by a tasklet and process them in the
1293 * same order that they were received or TX status last. Hence, there
1294 * is no race as long as the frame RX is processed before the next TX
1295 * status, which drivers can ensure, see below.
1296 *
1297 * Note that this can only happen if the hardware or firmware can
1298 * actually add STAs to the filter list, if this is done by the
1299 * driver in response to set_tim() (which will only reduce the race
1300 * this whole filtering tries to solve, not completely solve it)
1301 * this situation cannot happen.
1302 *
1303 * To completely solve this race drivers need to make sure that they
1304 * (a) don't mix the irq-safe/not irq-safe TX status/RX processing
1305 * functions and
1306 * (b) always process RX events before TX status events if ordering
1307 * can be unknown, for example with different interrupt status
1308 * bits.
1309 */
1310 if (sta->flags & WLAN_STA_PS &&
1311 skb_queue_len(&sta->tx_filtered) < STA_MAX_TX_BUFFER) {
1312 ieee80211_remove_tx_extra(local, sta->key, skb,
1313 &status->control);
1314 skb_queue_tail(&sta->tx_filtered, skb);
1315 return;
1316 }
1317
1318 if (!(sta->flags & WLAN_STA_PS) &&
1319 !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) {
1320 /* Software retry the packet once */
1321 status->control.flags |= IEEE80211_TXCTL_REQUEUE;
1322 ieee80211_remove_tx_extra(local, sta->key, skb,
1323 &status->control);
1324 dev_queue_xmit(skb);
1325 return;
1326 }
1327
1328 if (net_ratelimit())
1329 printk(KERN_DEBUG "%s: dropped TX filtered frame, "
1330 "queue_len=%d PS=%d @%lu\n",
1331 wiphy_name(local->hw.wiphy),
1332 skb_queue_len(&sta->tx_filtered),
1333 !!(sta->flags & WLAN_STA_PS), jiffies);
1334 dev_kfree_skb(skb);
1335}
1336
Jiri Bencf0706e82007-05-05 11:45:53 -07001337void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
1338 struct ieee80211_tx_status *status)
1339{
1340 struct sk_buff *skb2;
1341 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1342 struct ieee80211_local *local = hw_to_local(hw);
1343 u16 frag, type;
Johannes Bergb306f452007-07-10 19:32:08 +02001344 struct ieee80211_tx_status_rtap_hdr *rthdr;
1345 struct ieee80211_sub_if_data *sdata;
Michael Wu3d30d942008-01-31 19:48:27 +01001346 struct net_device *prev_dev = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -07001347
1348 if (!status) {
1349 printk(KERN_ERR
1350 "%s: ieee80211_tx_status called with NULL status\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001351 wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -07001352 dev_kfree_skb(skb);
1353 return;
1354 }
1355
Johannes Bergd0709a62008-02-25 16:27:46 +01001356 rcu_read_lock();
1357
Jiri Bencf0706e82007-05-05 11:45:53 -07001358 if (status->excessive_retries) {
1359 struct sta_info *sta;
1360 sta = sta_info_get(local, hdr->addr1);
1361 if (sta) {
1362 if (sta->flags & WLAN_STA_PS) {
Johannes Bergd46e1442008-02-20 23:59:33 +01001363 /*
1364 * The STA is in power save mode, so assume
Jiri Bencf0706e82007-05-05 11:45:53 -07001365 * that this TX packet failed because of that.
1366 */
1367 status->excessive_retries = 0;
1368 status->flags |= IEEE80211_TX_STATUS_TX_FILTERED;
Johannes Bergd46e1442008-02-20 23:59:33 +01001369 ieee80211_handle_filtered_frame(local, sta,
1370 skb, status);
Johannes Bergd0709a62008-02-25 16:27:46 +01001371 rcu_read_unlock();
Johannes Bergd46e1442008-02-20 23:59:33 +01001372 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001373 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001374 }
1375 }
1376
1377 if (status->flags & IEEE80211_TX_STATUS_TX_FILTERED) {
1378 struct sta_info *sta;
1379 sta = sta_info_get(local, hdr->addr1);
1380 if (sta) {
Johannes Bergd46e1442008-02-20 23:59:33 +01001381 ieee80211_handle_filtered_frame(local, sta, skb,
1382 status);
Johannes Bergd0709a62008-02-25 16:27:46 +01001383 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07001384 return;
1385 }
Mattias Nissler1abbe492007-12-20 13:50:07 +01001386 } else
1387 rate_control_tx_status(local->mdev, skb, status);
Jiri Bencf0706e82007-05-05 11:45:53 -07001388
Johannes Bergd0709a62008-02-25 16:27:46 +01001389 rcu_read_unlock();
1390
Jiri Bencf0706e82007-05-05 11:45:53 -07001391 ieee80211_led_tx(local, 0);
1392
1393 /* SNMP counters
1394 * Fragments are passed to low-level drivers as separate skbs, so these
1395 * are actually fragments, not frames. Update frame counters only for
1396 * the first fragment of the frame. */
1397
1398 frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
1399 type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
1400
1401 if (status->flags & IEEE80211_TX_STATUS_ACK) {
1402 if (frag == 0) {
1403 local->dot11TransmittedFrameCount++;
1404 if (is_multicast_ether_addr(hdr->addr1))
1405 local->dot11MulticastTransmittedFrameCount++;
1406 if (status->retry_count > 0)
1407 local->dot11RetryCount++;
1408 if (status->retry_count > 1)
1409 local->dot11MultipleRetryCount++;
1410 }
1411
1412 /* This counter shall be incremented for an acknowledged MPDU
1413 * with an individual address in the address 1 field or an MPDU
1414 * with a multicast address in the address 1 field of type Data
1415 * or Management. */
1416 if (!is_multicast_ether_addr(hdr->addr1) ||
1417 type == IEEE80211_FTYPE_DATA ||
1418 type == IEEE80211_FTYPE_MGMT)
1419 local->dot11TransmittedFragmentCount++;
1420 } else {
1421 if (frag == 0)
1422 local->dot11FailedCount++;
1423 }
1424
Johannes Bergb306f452007-07-10 19:32:08 +02001425 /* this was a transmitted frame, but now we want to reuse it */
1426 skb_orphan(skb);
1427
Michael Wu3d30d942008-01-31 19:48:27 +01001428 /*
1429 * This is a bit racy but we can avoid a lot of work
1430 * with this test...
1431 */
1432 if (!local->monitors && !local->cooked_mntrs) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001433 dev_kfree_skb(skb);
1434 return;
1435 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001436
Johannes Bergb306f452007-07-10 19:32:08 +02001437 /* send frame to monitor interfaces now */
1438
1439 if (skb_headroom(skb) < sizeof(*rthdr)) {
1440 printk(KERN_ERR "ieee80211_tx_status: headroom too small\n");
1441 dev_kfree_skb(skb);
1442 return;
1443 }
1444
1445 rthdr = (struct ieee80211_tx_status_rtap_hdr*)
1446 skb_push(skb, sizeof(*rthdr));
1447
1448 memset(rthdr, 0, sizeof(*rthdr));
1449 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
1450 rthdr->hdr.it_present =
1451 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
1452 (1 << IEEE80211_RADIOTAP_DATA_RETRIES));
1453
1454 if (!(status->flags & IEEE80211_TX_STATUS_ACK) &&
1455 !is_multicast_ether_addr(hdr->addr1))
1456 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL);
1457
1458 if ((status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS) &&
1459 (status->control.flags & IEEE80211_TXCTL_USE_CTS_PROTECT))
1460 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS);
1461 else if (status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS)
1462 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS);
1463
1464 rthdr->data_retries = status->retry_count;
1465
Michael Wu3d30d942008-01-31 19:48:27 +01001466 /* XXX: is this sufficient for BPF? */
1467 skb_set_mac_header(skb, 0);
1468 skb->ip_summed = CHECKSUM_UNNECESSARY;
1469 skb->pkt_type = PACKET_OTHERHOST;
1470 skb->protocol = htons(ETH_P_802_2);
1471 memset(skb->cb, 0, sizeof(skb->cb));
Johannes Bergb306f452007-07-10 19:32:08 +02001472
Michael Wu3d30d942008-01-31 19:48:27 +01001473 rcu_read_lock();
1474 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Johannes Berg51fb61e2007-12-19 01:31:27 +01001475 if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR) {
Johannes Bergb306f452007-07-10 19:32:08 +02001476 if (!netif_running(sdata->dev))
1477 continue;
Michael Wu3d30d942008-01-31 19:48:27 +01001478
1479 if (prev_dev) {
Johannes Berg79010422007-09-18 17:29:21 -04001480 skb2 = skb_clone(skb, GFP_ATOMIC);
Michael Wu3d30d942008-01-31 19:48:27 +01001481 if (skb2) {
1482 skb2->dev = prev_dev;
1483 netif_rx(skb2);
1484 }
1485 }
1486
1487 prev_dev = sdata->dev;
Johannes Bergb306f452007-07-10 19:32:08 +02001488 }
1489 }
Michael Wu3d30d942008-01-31 19:48:27 +01001490 if (prev_dev) {
1491 skb->dev = prev_dev;
1492 netif_rx(skb);
1493 skb = NULL;
1494 }
Johannes Berg79010422007-09-18 17:29:21 -04001495 rcu_read_unlock();
Michael Wu3d30d942008-01-31 19:48:27 +01001496 dev_kfree_skb(skb);
Jiri Bencf0706e82007-05-05 11:45:53 -07001497}
1498EXPORT_SYMBOL(ieee80211_tx_status);
1499
Jiri Bencf0706e82007-05-05 11:45:53 -07001500struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
1501 const struct ieee80211_ops *ops)
1502{
Jiri Bencf0706e82007-05-05 11:45:53 -07001503 struct ieee80211_local *local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001504 int priv_size;
1505 struct wiphy *wiphy;
1506
1507 /* Ensure 32-byte alignment of our private data and hw private data.
1508 * We use the wiphy priv data for both our ieee80211_local and for
1509 * the driver's private data
1510 *
1511 * In memory it'll be like this:
1512 *
1513 * +-------------------------+
1514 * | struct wiphy |
1515 * +-------------------------+
1516 * | struct ieee80211_local |
1517 * +-------------------------+
1518 * | driver's private data |
1519 * +-------------------------+
1520 *
1521 */
1522 priv_size = ((sizeof(struct ieee80211_local) +
1523 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) +
1524 priv_data_len;
1525
1526 wiphy = wiphy_new(&mac80211_config_ops, priv_size);
1527
1528 if (!wiphy)
1529 return NULL;
1530
1531 wiphy->privid = mac80211_wiphy_privid;
1532
1533 local = wiphy_priv(wiphy);
1534 local->hw.wiphy = wiphy;
1535
1536 local->hw.priv = (char *)local +
1537 ((sizeof(struct ieee80211_local) +
1538 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
1539
Johannes Berg4480f15c2007-07-10 19:32:10 +02001540 BUG_ON(!ops->tx);
Johannes Berg4150c572007-09-17 01:29:23 -04001541 BUG_ON(!ops->start);
1542 BUG_ON(!ops->stop);
Johannes Berg4480f15c2007-07-10 19:32:10 +02001543 BUG_ON(!ops->config);
1544 BUG_ON(!ops->add_interface);
Johannes Berg4150c572007-09-17 01:29:23 -04001545 BUG_ON(!ops->remove_interface);
1546 BUG_ON(!ops->configure_filter);
Jiri Bencf0706e82007-05-05 11:45:53 -07001547 local->ops = ops;
1548
Jiri Bencf0706e82007-05-05 11:45:53 -07001549 local->hw.queues = 1; /* default */
1550
Jiri Bencf0706e82007-05-05 11:45:53 -07001551 local->bridge_packets = 1;
1552
1553 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
1554 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
1555 local->short_retry_limit = 7;
1556 local->long_retry_limit = 4;
1557 local->hw.conf.radio_enabled = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001558
Johannes Berg79010422007-09-18 17:29:21 -04001559 INIT_LIST_HEAD(&local->interfaces);
Jiri Bencf0706e82007-05-05 11:45:53 -07001560
1561 INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work);
Jiri Bencf0706e82007-05-05 11:45:53 -07001562
1563 sta_info_init(local);
1564
Jiri Bencf0706e82007-05-05 11:45:53 -07001565 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
1566 (unsigned long)local);
1567 tasklet_disable(&local->tx_pending_tasklet);
1568
1569 tasklet_init(&local->tasklet,
1570 ieee80211_tasklet_handler,
1571 (unsigned long) local);
1572 tasklet_disable(&local->tasklet);
1573
1574 skb_queue_head_init(&local->skb_queue);
1575 skb_queue_head_init(&local->skb_queue_unreliable);
1576
1577 return local_to_hw(local);
1578}
1579EXPORT_SYMBOL(ieee80211_alloc_hw);
1580
1581int ieee80211_register_hw(struct ieee80211_hw *hw)
1582{
1583 struct ieee80211_local *local = hw_to_local(hw);
1584 const char *name;
1585 int result;
Johannes Berg8318d782008-01-24 19:38:38 +01001586 enum ieee80211_band band;
Johannes Berg96d51052008-02-08 09:48:13 +01001587 struct net_device *mdev;
1588 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +01001589
1590 /*
1591 * generic code guarantees at least one band,
1592 * set this very early because much code assumes
1593 * that hw.conf.channel is assigned
1594 */
1595 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1596 struct ieee80211_supported_band *sband;
1597
1598 sband = local->hw.wiphy->bands[band];
1599 if (sband) {
1600 /* init channel we're on */
1601 local->hw.conf.channel =
1602 local->oper_channel =
1603 local->scan_channel = &sband->channels[0];
1604 break;
1605 }
1606 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001607
1608 result = wiphy_register(local->hw.wiphy);
1609 if (result < 0)
1610 return result;
1611
Johannes Berg96d51052008-02-08 09:48:13 +01001612 /* for now, mdev needs sub_if_data :/ */
1613 mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
1614 "wmaster%d", ether_setup);
1615 if (!mdev)
1616 goto fail_mdev_alloc;
1617
1618 sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
1619 mdev->ieee80211_ptr = &sdata->wdev;
1620 sdata->wdev.wiphy = local->hw.wiphy;
1621
1622 local->mdev = mdev;
1623
1624 ieee80211_rx_bss_list_init(mdev);
1625
1626 mdev->hard_start_xmit = ieee80211_master_start_xmit;
1627 mdev->open = ieee80211_master_open;
1628 mdev->stop = ieee80211_master_stop;
1629 mdev->type = ARPHRD_IEEE80211;
1630 mdev->header_ops = &ieee80211_header_ops;
1631 mdev->set_multicast_list = ieee80211_master_set_multicast_list;
1632
1633 sdata->vif.type = IEEE80211_IF_TYPE_AP;
1634 sdata->dev = mdev;
1635 sdata->local = local;
1636 sdata->u.ap.force_unicast_rateidx = -1;
1637 sdata->u.ap.max_ratectrl_rateidx = -1;
1638 ieee80211_if_sdata_init(sdata);
1639
1640 /* no RCU needed since we're still during init phase */
1641 list_add_tail(&sdata->list, &local->interfaces);
1642
Jiri Bencf0706e82007-05-05 11:45:53 -07001643 name = wiphy_dev(local->hw.wiphy)->driver->name;
1644 local->hw.workqueue = create_singlethread_workqueue(name);
1645 if (!local->hw.workqueue) {
1646 result = -ENOMEM;
1647 goto fail_workqueue;
1648 }
1649
Johannes Bergb306f452007-07-10 19:32:08 +02001650 /*
1651 * The hardware needs headroom for sending the frame,
1652 * and we need some headroom for passing the frame to monitor
1653 * interfaces, but never both at the same time.
1654 */
Jiri Benc33ccad32007-07-18 17:10:44 +02001655 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
1656 sizeof(struct ieee80211_tx_status_rtap_hdr));
Johannes Bergb306f452007-07-10 19:32:08 +02001657
Jiri Bence9f207f2007-05-05 11:46:38 -07001658 debugfs_hw_add(local);
1659
Jiri Bencf0706e82007-05-05 11:45:53 -07001660 local->hw.conf.beacon_int = 1000;
1661
1662 local->wstats_flags |= local->hw.max_rssi ?
1663 IW_QUAL_LEVEL_UPDATED : IW_QUAL_LEVEL_INVALID;
1664 local->wstats_flags |= local->hw.max_signal ?
1665 IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
1666 local->wstats_flags |= local->hw.max_noise ?
1667 IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
1668 if (local->hw.max_rssi < 0 || local->hw.max_noise < 0)
1669 local->wstats_flags |= IW_QUAL_DBM;
1670
1671 result = sta_info_start(local);
1672 if (result < 0)
1673 goto fail_sta_info;
1674
1675 rtnl_lock();
1676 result = dev_alloc_name(local->mdev, local->mdev->name);
1677 if (result < 0)
1678 goto fail_dev;
1679
1680 memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
1681 SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy));
1682
1683 result = register_netdevice(local->mdev);
1684 if (result < 0)
1685 goto fail_dev;
1686
Jiri Bence9f207f2007-05-05 11:46:38 -07001687 ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
Johannes Berg5b2812e2007-09-26 14:27:23 +02001688 ieee80211_if_set_type(local->mdev, IEEE80211_IF_TYPE_AP);
Jiri Bence9f207f2007-05-05 11:46:38 -07001689
Johannes Berg830f9032007-10-28 14:51:05 +01001690 result = ieee80211_init_rate_ctrl_alg(local,
1691 hw->rate_control_algorithm);
Jiri Bencf0706e82007-05-05 11:45:53 -07001692 if (result < 0) {
1693 printk(KERN_DEBUG "%s: Failed to initialize rate control "
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001694 "algorithm\n", wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -07001695 goto fail_rate;
1696 }
1697
1698 result = ieee80211_wep_init(local);
1699
1700 if (result < 0) {
1701 printk(KERN_DEBUG "%s: Failed to initialize wep\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001702 wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -07001703 goto fail_wep;
1704 }
1705
1706 ieee80211_install_qdisc(local->mdev);
1707
1708 /* add one default STA interface */
1709 result = ieee80211_if_add(local->mdev, "wlan%d", NULL,
Luis Carlos Coboee385852008-02-23 15:17:11 +01001710 IEEE80211_IF_TYPE_STA, NULL);
Jiri Bencf0706e82007-05-05 11:45:53 -07001711 if (result)
1712 printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001713 wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -07001714
1715 local->reg_state = IEEE80211_DEV_REGISTERED;
1716 rtnl_unlock();
1717
1718 ieee80211_led_init(local);
1719
1720 return 0;
1721
1722fail_wep:
1723 rate_control_deinitialize(local);
1724fail_rate:
Jiri Bence9f207f2007-05-05 11:46:38 -07001725 ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
Jiri Bencf0706e82007-05-05 11:45:53 -07001726 unregister_netdevice(local->mdev);
1727fail_dev:
1728 rtnl_unlock();
1729 sta_info_stop(local);
1730fail_sta_info:
Jiri Bence9f207f2007-05-05 11:46:38 -07001731 debugfs_hw_del(local);
Jiri Bencf0706e82007-05-05 11:45:53 -07001732 destroy_workqueue(local->hw.workqueue);
1733fail_workqueue:
Johannes Berg96d51052008-02-08 09:48:13 +01001734 ieee80211_if_free(local->mdev);
1735 local->mdev = NULL;
1736fail_mdev_alloc:
Jiri Bencf0706e82007-05-05 11:45:53 -07001737 wiphy_unregister(local->hw.wiphy);
1738 return result;
1739}
1740EXPORT_SYMBOL(ieee80211_register_hw);
1741
Jiri Bencf0706e82007-05-05 11:45:53 -07001742void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1743{
1744 struct ieee80211_local *local = hw_to_local(hw);
1745 struct ieee80211_sub_if_data *sdata, *tmp;
Jiri Bencf0706e82007-05-05 11:45:53 -07001746
1747 tasklet_kill(&local->tx_pending_tasklet);
1748 tasklet_kill(&local->tasklet);
1749
1750 rtnl_lock();
1751
1752 BUG_ON(local->reg_state != IEEE80211_DEV_REGISTERED);
1753
1754 local->reg_state = IEEE80211_DEV_UNREGISTERED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001755
Johannes Berg79010422007-09-18 17:29:21 -04001756 /*
1757 * At this point, interface list manipulations are fine
1758 * because the driver cannot be handing us frames any
1759 * more and the tasklet is killed.
1760 */
Johannes Berg5b2812e2007-09-26 14:27:23 +02001761
1762 /*
1763 * First, we remove all non-master interfaces. Do this because they
1764 * may have bss pointer dependency on the master, and when we free
1765 * the master these would be freed as well, breaking our list
1766 * iteration completely.
1767 */
1768 list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
1769 if (sdata->dev == local->mdev)
1770 continue;
1771 list_del(&sdata->list);
Jiri Bencf0706e82007-05-05 11:45:53 -07001772 __ieee80211_if_del(local, sdata);
Johannes Berg5b2812e2007-09-26 14:27:23 +02001773 }
1774
1775 /* then, finally, remove the master interface */
1776 __ieee80211_if_del(local, IEEE80211_DEV_TO_SUB_IF(local->mdev));
Jiri Bencf0706e82007-05-05 11:45:53 -07001777
1778 rtnl_unlock();
1779
Jiri Bencf0706e82007-05-05 11:45:53 -07001780 ieee80211_rx_bss_list_deinit(local->mdev);
1781 ieee80211_clear_tx_pending(local);
1782 sta_info_stop(local);
1783 rate_control_deinitialize(local);
Jiri Bence9f207f2007-05-05 11:46:38 -07001784 debugfs_hw_del(local);
Jiri Bencf0706e82007-05-05 11:45:53 -07001785
Jiri Bencf0706e82007-05-05 11:45:53 -07001786 if (skb_queue_len(&local->skb_queue)
1787 || skb_queue_len(&local->skb_queue_unreliable))
1788 printk(KERN_WARNING "%s: skb_queue not empty\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001789 wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -07001790 skb_queue_purge(&local->skb_queue);
1791 skb_queue_purge(&local->skb_queue_unreliable);
1792
1793 destroy_workqueue(local->hw.workqueue);
1794 wiphy_unregister(local->hw.wiphy);
1795 ieee80211_wep_free(local);
1796 ieee80211_led_exit(local);
Johannes Berg96d51052008-02-08 09:48:13 +01001797 ieee80211_if_free(local->mdev);
1798 local->mdev = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -07001799}
1800EXPORT_SYMBOL(ieee80211_unregister_hw);
1801
1802void ieee80211_free_hw(struct ieee80211_hw *hw)
1803{
1804 struct ieee80211_local *local = hw_to_local(hw);
1805
Jiri Bencf0706e82007-05-05 11:45:53 -07001806 wiphy_free(local->hw.wiphy);
1807}
1808EXPORT_SYMBOL(ieee80211_free_hw);
1809
Jiri Bencf0706e82007-05-05 11:45:53 -07001810static int __init ieee80211_init(void)
1811{
1812 struct sk_buff *skb;
1813 int ret;
1814
1815 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb));
1816
Johannes Berg4b475892008-01-02 15:17:03 +01001817 ret = rc80211_simple_init();
Johannes Bergac71c692007-10-28 14:17:44 +01001818 if (ret)
Johannes Berg3eadf5f2008-01-31 19:33:53 +01001819 goto out;
Mattias Nisslerad018372007-12-19 01:25:57 +01001820
Johannes Berg4b475892008-01-02 15:17:03 +01001821 ret = rc80211_pid_init();
Mattias Nisslerad018372007-12-19 01:25:57 +01001822 if (ret)
Johannes Berg3eadf5f2008-01-31 19:33:53 +01001823 goto out_cleanup_simple;
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_cleanup_simple:
1839 rc80211_simple_exit();
1840 out:
Mattias Nisslerad018372007-12-19 01:25:57 +01001841 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07001842}
1843
Jiri Bencf0706e82007-05-05 11:45:53 -07001844static void __exit ieee80211_exit(void)
1845{
Johannes Berg4b475892008-01-02 15:17:03 +01001846 rc80211_simple_exit();
1847 rc80211_pid_exit();
Johannes Bergac71c692007-10-28 14:17:44 +01001848
Luis Carlos Cobof7a92142008-02-23 15:17:18 +01001849 if (mesh_allocated)
1850 ieee80211s_stop();
Johannes Berg902acc72008-02-23 15:17:19 +01001851
Jiri Bencf0706e82007-05-05 11:45:53 -07001852 ieee80211_wme_unregister();
Jiri Bence9f207f2007-05-05 11:46:38 -07001853 ieee80211_debugfs_netdev_exit();
Jiri Bencf0706e82007-05-05 11:45:53 -07001854}
1855
1856
Johannes Bergca9938f2007-09-11 12:50:32 +02001857subsys_initcall(ieee80211_init);
Jiri Bencf0706e82007-05-05 11:45:53 -07001858module_exit(ieee80211_exit);
1859
1860MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1861MODULE_LICENSE("GPL");