Commit | Line | Data |
---|---|---|
f0706e82 JB |
1 | /* |
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> | |
f0706e82 | 23 | #include <linux/bitmap.h> |
881d966b | 24 | #include <net/net_namespace.h> |
f0706e82 JB |
25 | #include <net/cfg80211.h> |
26 | ||
f0706e82 | 27 | #include "ieee80211_i.h" |
2c8dccc7 | 28 | #include "rate.h" |
f7a92144 | 29 | #include "mesh.h" |
f0706e82 | 30 | #include "wep.h" |
f0706e82 JB |
31 | #include "wme.h" |
32 | #include "aes_ccm.h" | |
2c8dccc7 | 33 | #include "led.h" |
e0eb6859 | 34 | #include "cfg.h" |
e9f207f0 JB |
35 | #include "debugfs.h" |
36 | #include "debugfs_netdev.h" | |
f0706e82 | 37 | |
d3c990fb RR |
38 | #define SUPP_MCS_SET_LEN 16 |
39 | ||
b306f453 JB |
40 | /* |
41 | * For seeing transmitted packets on monitor interfaces | |
42 | * we have a radiotap header too. | |
43 | */ | |
44 | struct ieee80211_tx_status_rtap_hdr { | |
45 | struct ieee80211_radiotap_header hdr; | |
46 | __le16 tx_flags; | |
47 | u8 data_retries; | |
48 | } __attribute__ ((packed)); | |
49 | ||
b2c258fb | 50 | /* common interface routines */ |
b306f453 | 51 | |
b95cce35 | 52 | static int header_parse_80211(const struct sk_buff *skb, unsigned char *haddr) |
b2c258fb JB |
53 | { |
54 | memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */ | |
55 | return ETH_ALEN; | |
56 | } | |
f0706e82 | 57 | |
4150c572 JB |
58 | /* must be called under mdev tx lock */ |
59 | static void ieee80211_configure_filter(struct ieee80211_local *local) | |
60 | { | |
61 | unsigned int changed_flags; | |
62 | unsigned int new_flags = 0; | |
63 | ||
53918994 | 64 | if (atomic_read(&local->iff_promiscs)) |
4150c572 JB |
65 | new_flags |= FIF_PROMISC_IN_BSS; |
66 | ||
53918994 | 67 | if (atomic_read(&local->iff_allmultis)) |
4150c572 JB |
68 | new_flags |= FIF_ALLMULTI; |
69 | ||
70 | if (local->monitors) | |
8cc9a739 MW |
71 | 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; | |
4150c572 JB |
84 | |
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 | ||
b2c258fb | 100 | /* master interface */ |
f0706e82 | 101 | |
b2c258fb JB |
102 | static 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; | |
f0706e82 | 107 | |
79010420 JB |
108 | /* we hold the RTNL here so can safely walk the list */ |
109 | list_for_each_entry(sdata, &local->interfaces, list) { | |
b2c258fb JB |
110 | if (sdata->dev != dev && netif_running(sdata->dev)) { |
111 | res = 0; | |
112 | break; | |
113 | } | |
114 | } | |
b2c258fb JB |
115 | return res; |
116 | } | |
f0706e82 | 117 | |
b2c258fb | 118 | static int ieee80211_master_stop(struct net_device *dev) |
f0706e82 | 119 | { |
b2c258fb JB |
120 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
121 | struct ieee80211_sub_if_data *sdata; | |
f0706e82 | 122 | |
79010420 JB |
123 | /* we hold the RTNL here so can safely walk the list */ |
124 | list_for_each_entry(sdata, &local->interfaces, list) | |
b2c258fb JB |
125 | if (sdata->dev != dev && netif_running(sdata->dev)) |
126 | dev_close(sdata->dev); | |
f0706e82 | 127 | |
b2c258fb JB |
128 | return 0; |
129 | } | |
f0706e82 | 130 | |
4150c572 JB |
131 | static 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 | ||
b2c258fb | 138 | /* regular interfaces */ |
f0706e82 | 139 | |
b2c258fb | 140 | static int ieee80211_change_mtu(struct net_device *dev, int new_mtu) |
f0706e82 | 141 | { |
f7a92144 LCC |
142 | 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 | ||
b2c258fb JB |
147 | /* FIX: what would be proper limits for MTU? |
148 | * This interface uses 802.3 frames. */ | |
f7a92144 LCC |
149 | if (new_mtu < 256 || |
150 | new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6 - meshhdrlen) { | |
b2c258fb JB |
151 | printk(KERN_WARNING "%s: invalid MTU %d\n", |
152 | dev->name, new_mtu); | |
153 | return -EINVAL; | |
154 | } | |
f0706e82 | 155 | |
b2c258fb JB |
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; | |
f0706e82 JB |
160 | return 0; |
161 | } | |
162 | ||
b2c258fb JB |
163 | static 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 | } | |
f0706e82 | 178 | |
b2c258fb | 179 | static int ieee80211_open(struct net_device *dev) |
e2ebc74d | 180 | { |
b2c258fb JB |
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; | |
ceffefd1 | 185 | bool need_hw_reconfig = 0; |
44213b5e | 186 | struct sta_info *sta; |
f0706e82 | 187 | |
b2c258fb | 188 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
0ec3ca44 | 189 | |
79010420 JB |
190 | /* we hold the RTNL here so can safely walk the list */ |
191 | list_for_each_entry(nsdata, &local->interfaces, list) { | |
b2c258fb | 192 | struct net_device *ndev = nsdata->dev; |
e2ebc74d | 193 | |
665e8aaf JB |
194 | 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 | ||
0ec3ca44 JB |
240 | /* |
241 | * check whether it may have the same address | |
242 | */ | |
51fb61e7 JB |
243 | if (!identical_mac_addr_allowed(sdata->vif.type, |
244 | nsdata->vif.type)) | |
0ec3ca44 | 245 | return -ENOTUNIQ; |
0ec3ca44 JB |
246 | |
247 | /* | |
248 | * can only add VLANs to enabled APs | |
249 | */ | |
51fb61e7 | 250 | if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN && |
665e8aaf | 251 | nsdata->vif.type == IEEE80211_IF_TYPE_AP) |
0ec3ca44 | 252 | sdata->u.vlan.ap = nsdata; |
b2c258fb JB |
253 | } |
254 | } | |
f0706e82 | 255 | |
51fb61e7 | 256 | switch (sdata->vif.type) { |
0ec3ca44 JB |
257 | case IEEE80211_IF_TYPE_WDS: |
258 | if (is_zero_ether_addr(sdata->u.wds.remote_addr)) | |
259 | return -ENOLINK; | |
44213b5e JB |
260 | |
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) { | |
93e5deb1 | 271 | /* STA has been freed */ |
44213b5e JB |
272 | return res; |
273 | } | |
0ec3ca44 JB |
274 | break; |
275 | case IEEE80211_IF_TYPE_VLAN: | |
276 | if (!sdata->u.vlan.ap) | |
277 | return -ENOLINK; | |
278 | break; | |
fb1c1cd6 | 279 | case IEEE80211_IF_TYPE_AP: |
fb1c1cd6 JB |
280 | case IEEE80211_IF_TYPE_STA: |
281 | case IEEE80211_IF_TYPE_MNTR: | |
282 | case IEEE80211_IF_TYPE_IBSS: | |
6032f934 | 283 | case IEEE80211_IF_TYPE_MESH_POINT: |
fb1c1cd6 JB |
284 | /* no special treatment */ |
285 | break; | |
a2897552 JB |
286 | case IEEE80211_IF_TYPE_INVALID: |
287 | /* cannot happen */ | |
288 | WARN_ON(1); | |
289 | break; | |
0ec3ca44 | 290 | } |
f0706e82 | 291 | |
b2c258fb JB |
292 | if (local->open_count == 0) { |
293 | res = 0; | |
4150c572 JB |
294 | if (local->ops->start) |
295 | res = local->ops->start(local_to_hw(local)); | |
296 | if (res) | |
b2c258fb | 297 | return res; |
ceffefd1 | 298 | need_hw_reconfig = 1; |
cdcb006f | 299 | ieee80211_led_radio(local, local->hw.conf.radio_enabled); |
b2c258fb | 300 | } |
f0706e82 | 301 | |
51fb61e7 | 302 | switch (sdata->vif.type) { |
0ec3ca44 JB |
303 | 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; | |
4150c572 | 307 | case IEEE80211_IF_TYPE_MNTR: |
3d30d949 MW |
308 | if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) { |
309 | local->cooked_mntrs++; | |
310 | break; | |
311 | } | |
312 | ||
4150c572 | 313 | /* must be before the call to ieee80211_configure_filter */ |
b2c258fb | 314 | local->monitors++; |
8cc9a739 | 315 | if (local->monitors == 1) |
4150c572 | 316 | local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP; |
8cc9a739 MW |
317 | |
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); | |
4150c572 JB |
330 | 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: | |
32bfd35d | 336 | conf.vif = &sdata->vif; |
51fb61e7 | 337 | conf.type = sdata->vif.type; |
4150c572 JB |
338 | 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 | ||
b2c258fb | 345 | ieee80211_if_config(dev); |
d9430a32 | 346 | ieee80211_reset_erp_info(dev); |
11a843b7 | 347 | ieee80211_enable_keys(sdata); |
4150c572 | 348 | |
51fb61e7 | 349 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA && |
ddd3d2be | 350 | !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)) |
4150c572 JB |
351 | netif_carrier_off(dev); |
352 | else | |
353 | netif_carrier_on(dev); | |
d9430a32 | 354 | } |
f0706e82 | 355 | |
4150c572 JB |
356 | if (local->open_count == 0) { |
357 | res = dev_open(local->mdev); | |
358 | WARN_ON(res); | |
4150c572 JB |
359 | tasklet_enable(&local->tx_pending_tasklet); |
360 | tasklet_enable(&local->tasklet); | |
361 | } | |
362 | ||
c1428b3f JB |
363 | /* |
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 | ||
4150c572 | 374 | local->open_count++; |
ceffefd1 MB |
375 | if (need_hw_reconfig) |
376 | ieee80211_hw_config(local); | |
f0706e82 | 377 | |
64f851e4 JN |
378 | /* |
379 | * ieee80211_sta_work is disabled while network interface | |
380 | * is down. Therefore, some configuration changes may not | |
381 | * yet be effective. Trigger execution of ieee80211_sta_work | |
382 | * to fix this. | |
383 | */ | |
384 | if(sdata->vif.type == IEEE80211_IF_TYPE_STA || | |
385 | sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { | |
386 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; | |
387 | queue_work(local->hw.workqueue, &ifsta->work); | |
388 | } | |
389 | ||
b2c258fb | 390 | netif_start_queue(dev); |
4150c572 | 391 | |
b2c258fb | 392 | return 0; |
f0706e82 | 393 | } |
f0706e82 | 394 | |
4150c572 | 395 | static int ieee80211_stop(struct net_device *dev) |
f0706e82 | 396 | { |
44213b5e JB |
397 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
398 | struct ieee80211_local *local = sdata->local; | |
4150c572 | 399 | struct ieee80211_if_init_conf conf; |
07db2183 | 400 | struct sta_info *sta; |
4150c572 | 401 | |
44213b5e JB |
402 | /* |
403 | * Stop TX on this interface first. | |
404 | */ | |
405 | netif_stop_queue(dev); | |
4150c572 | 406 | |
44213b5e JB |
407 | /* |
408 | * Now delete all active aggregation sessions. | |
409 | */ | |
d0709a65 JB |
410 | rcu_read_lock(); |
411 | ||
412 | list_for_each_entry_rcu(sta, &local->sta_list, list) { | |
413 | if (sta->sdata == sdata) | |
85249e5f | 414 | ieee80211_sta_tear_down_BA_sessions(dev, sta->addr); |
07db2183 RR |
415 | } |
416 | ||
d0709a65 JB |
417 | rcu_read_unlock(); |
418 | ||
44213b5e JB |
419 | /* |
420 | * Remove all stations associated with this interface. | |
421 | * | |
422 | * This must be done before calling ops->remove_interface() | |
423 | * because otherwise we can later invoke ops->sta_notify() | |
424 | * whenever the STAs are removed, and that invalidates driver | |
425 | * assumptions about always getting a vif pointer that is valid | |
426 | * (because if we remove a STA after ops->remove_interface() | |
427 | * the driver will have removed the vif info already!) | |
428 | * | |
429 | * We could relax this and only unlink the stations from the | |
430 | * hash table and list but keep them on a per-sdata list that | |
431 | * will be inserted back again when the interface is brought | |
432 | * up again, but I don't currently see a use case for that, | |
433 | * except with WDS which gets a STA entry created when it is | |
434 | * brought up. | |
435 | */ | |
436 | sta_info_flush(local, sdata); | |
4150c572 | 437 | |
c1428b3f JB |
438 | /* |
439 | * Don't count this interface for promisc/allmulti while it | |
440 | * is down. dev_mc_unsync() will invoke set_multicast_list | |
441 | * on the master interface which will sync these down to the | |
442 | * hardware as filter flags. | |
443 | */ | |
444 | if (sdata->flags & IEEE80211_SDATA_ALLMULTI) | |
445 | atomic_dec(&local->iff_allmultis); | |
446 | ||
447 | if (sdata->flags & IEEE80211_SDATA_PROMISC) | |
448 | atomic_dec(&local->iff_promiscs); | |
449 | ||
4150c572 JB |
450 | dev_mc_unsync(local->mdev, dev); |
451 | ||
5dfdaf58 | 452 | /* APs need special treatment */ |
51fb61e7 | 453 | if (sdata->vif.type == IEEE80211_IF_TYPE_AP) { |
0ec3ca44 | 454 | struct ieee80211_sub_if_data *vlan, *tmp; |
5dfdaf58 | 455 | struct beacon_data *old_beacon = sdata->u.ap.beacon; |
0ec3ca44 | 456 | |
5dfdaf58 JB |
457 | /* remove beacon */ |
458 | rcu_assign_pointer(sdata->u.ap.beacon, NULL); | |
459 | synchronize_rcu(); | |
460 | kfree(old_beacon); | |
461 | ||
462 | /* down all dependent devices, that is VLANs */ | |
0ec3ca44 JB |
463 | list_for_each_entry_safe(vlan, tmp, &sdata->u.ap.vlans, |
464 | u.vlan.list) | |
465 | dev_close(vlan->dev); | |
466 | WARN_ON(!list_empty(&sdata->u.ap.vlans)); | |
467 | } | |
468 | ||
4150c572 | 469 | local->open_count--; |
f0706e82 | 470 | |
51fb61e7 | 471 | switch (sdata->vif.type) { |
0ec3ca44 JB |
472 | case IEEE80211_IF_TYPE_VLAN: |
473 | list_del(&sdata->u.vlan.list); | |
474 | sdata->u.vlan.ap = NULL; | |
475 | /* no need to tell driver */ | |
476 | break; | |
4150c572 | 477 | case IEEE80211_IF_TYPE_MNTR: |
3d30d949 MW |
478 | if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) { |
479 | local->cooked_mntrs--; | |
480 | break; | |
481 | } | |
482 | ||
4150c572 | 483 | local->monitors--; |
8cc9a739 | 484 | if (local->monitors == 0) |
8b393f1d | 485 | local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP; |
8cc9a739 MW |
486 | |
487 | if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) | |
488 | local->fif_fcsfail--; | |
489 | if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL) | |
490 | local->fif_plcpfail--; | |
491 | if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) | |
492 | local->fif_control--; | |
493 | if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS) | |
494 | local->fif_other_bss--; | |
495 | ||
496 | netif_tx_lock_bh(local->mdev); | |
497 | ieee80211_configure_filter(local); | |
498 | netif_tx_unlock_bh(local->mdev); | |
4150c572 | 499 | break; |
f7a92144 | 500 | case IEEE80211_IF_TYPE_MESH_POINT: |
b2c258fb JB |
501 | case IEEE80211_IF_TYPE_STA: |
502 | case IEEE80211_IF_TYPE_IBSS: | |
503 | sdata->u.sta.state = IEEE80211_DISABLED; | |
504 | del_timer_sync(&sdata->u.sta.timer); | |
2a8a9a88 | 505 | /* |
79010420 JB |
506 | * When we get here, the interface is marked down. |
507 | * Call synchronize_rcu() to wait for the RX path | |
508 | * should it be using the interface and enqueuing | |
509 | * frames at this very time on another CPU. | |
2a8a9a88 | 510 | */ |
79010420 | 511 | synchronize_rcu(); |
b2c258fb | 512 | skb_queue_purge(&sdata->u.sta.skb_queue); |
2a8a9a88 | 513 | |
ece8eddd ZY |
514 | if (local->scan_dev == sdata->dev) { |
515 | if (!local->ops->hw_scan) { | |
516 | local->sta_sw_scanning = 0; | |
517 | cancel_delayed_work(&local->scan_work); | |
518 | } else | |
519 | local->sta_hw_scanning = 0; | |
b2c258fb | 520 | } |
ece8eddd | 521 | |
b2c258fb | 522 | flush_workqueue(local->hw.workqueue); |
a10605e5 ZY |
523 | |
524 | sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED; | |
525 | kfree(sdata->u.sta.extra_ie); | |
526 | sdata->u.sta.extra_ie = NULL; | |
527 | sdata->u.sta.extra_ie_len = 0; | |
4150c572 JB |
528 | /* fall through */ |
529 | default: | |
32bfd35d | 530 | conf.vif = &sdata->vif; |
51fb61e7 | 531 | conf.type = sdata->vif.type; |
4150c572 | 532 | conf.mac_addr = dev->dev_addr; |
11a843b7 JB |
533 | /* disable all keys for as long as this netdev is down */ |
534 | ieee80211_disable_keys(sdata); | |
4150c572 | 535 | local->ops->remove_interface(local_to_hw(local), &conf); |
f0706e82 JB |
536 | } |
537 | ||
b2c258fb JB |
538 | if (local->open_count == 0) { |
539 | if (netif_running(local->mdev)) | |
540 | dev_close(local->mdev); | |
4150c572 | 541 | |
b2c258fb JB |
542 | if (local->ops->stop) |
543 | local->ops->stop(local_to_hw(local)); | |
4150c572 | 544 | |
cdcb006f ID |
545 | ieee80211_led_radio(local, 0); |
546 | ||
b2c258fb JB |
547 | tasklet_disable(&local->tx_pending_tasklet); |
548 | tasklet_disable(&local->tasklet); | |
549 | } | |
b2c258fb | 550 | |
f0706e82 JB |
551 | return 0; |
552 | } | |
553 | ||
eadc8d9e RR |
554 | int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid) |
555 | { | |
556 | struct ieee80211_local *local = hw_to_local(hw); | |
557 | struct sta_info *sta; | |
558 | struct ieee80211_sub_if_data *sdata; | |
559 | u16 start_seq_num = 0; | |
560 | u8 *state; | |
561 | int ret; | |
562 | DECLARE_MAC_BUF(mac); | |
563 | ||
564 | if (tid >= STA_TID_NUM) | |
565 | return -EINVAL; | |
566 | ||
567 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
568 | printk(KERN_DEBUG "Open BA session requested for %s tid %u\n", | |
569 | print_mac(mac, ra), tid); | |
570 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
571 | ||
d0709a65 JB |
572 | rcu_read_lock(); |
573 | ||
eadc8d9e RR |
574 | sta = sta_info_get(local, ra); |
575 | if (!sta) { | |
576 | printk(KERN_DEBUG "Could not find the station\n"); | |
d0709a65 | 577 | rcu_read_unlock(); |
eadc8d9e RR |
578 | return -ENOENT; |
579 | } | |
580 | ||
581 | spin_lock_bh(&sta->ampdu_mlme.ampdu_tx); | |
582 | ||
583 | /* we have tried too many times, receiver does not want A-MPDU */ | |
cee24a3e | 584 | if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) { |
eadc8d9e RR |
585 | ret = -EBUSY; |
586 | goto start_ba_exit; | |
587 | } | |
588 | ||
cee24a3e | 589 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
eadc8d9e RR |
590 | /* check if the TID is not in aggregation flow already */ |
591 | if (*state != HT_AGG_STATE_IDLE) { | |
592 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
593 | printk(KERN_DEBUG "BA request denied - session is not " | |
594 | "idle on tid %u\n", tid); | |
595 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
596 | ret = -EAGAIN; | |
597 | goto start_ba_exit; | |
598 | } | |
599 | ||
cee24a3e RR |
600 | /* prepare A-MPDU MLME for Tx aggregation */ |
601 | sta->ampdu_mlme.tid_tx[tid] = | |
602 | kmalloc(sizeof(struct tid_ampdu_tx), GFP_ATOMIC); | |
603 | if (!sta->ampdu_mlme.tid_tx[tid]) { | |
604 | if (net_ratelimit()) | |
605 | printk(KERN_ERR "allocate tx mlme to tid %d failed\n", | |
606 | tid); | |
607 | ret = -ENOMEM; | |
608 | goto start_ba_exit; | |
609 | } | |
610 | /* Tx timer */ | |
611 | sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.function = | |
612 | sta_addba_resp_timer_expired; | |
613 | sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.data = | |
614 | (unsigned long)&sta->timer_to_tid[tid]; | |
615 | init_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer); | |
616 | ||
eadc8d9e RR |
617 | /* ensure that TX flow won't interrupt us |
618 | * until the end of the call to requeue function */ | |
619 | spin_lock_bh(&local->mdev->queue_lock); | |
620 | ||
621 | /* create a new queue for this aggregation */ | |
9e723492 | 622 | ret = ieee80211_ht_agg_queue_add(local, sta, tid); |
eadc8d9e RR |
623 | |
624 | /* case no queue is available to aggregation | |
625 | * don't switch to aggregation */ | |
626 | if (ret) { | |
627 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
cee24a3e | 628 | printk(KERN_DEBUG "BA request denied - queue unavailable for" |
eadc8d9e RR |
629 | " tid %d\n", tid); |
630 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
cee24a3e | 631 | goto start_ba_err; |
eadc8d9e | 632 | } |
d0709a65 | 633 | sdata = sta->sdata; |
eadc8d9e RR |
634 | |
635 | /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the | |
636 | * call back right away, it must see that the flow has begun */ | |
637 | *state |= HT_ADDBA_REQUESTED_MSK; | |
638 | ||
639 | if (local->ops->ampdu_action) | |
640 | ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START, | |
641 | ra, tid, &start_seq_num); | |
642 | ||
643 | if (ret) { | |
644 | /* No need to requeue the packets in the agg queue, since we | |
645 | * held the tx lock: no packet could be enqueued to the newly | |
646 | * allocated queue */ | |
9e723492 | 647 | ieee80211_ht_agg_queue_remove(local, sta, tid, 0); |
eadc8d9e | 648 | #ifdef CONFIG_MAC80211_HT_DEBUG |
cee24a3e RR |
649 | printk(KERN_DEBUG "BA request denied - HW unavailable for" |
650 | " tid %d\n", tid); | |
eadc8d9e | 651 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
eadc8d9e | 652 | *state = HT_AGG_STATE_IDLE; |
cee24a3e | 653 | goto start_ba_err; |
eadc8d9e RR |
654 | } |
655 | ||
656 | /* Will put all the packets in the new SW queue */ | |
9e723492 | 657 | ieee80211_requeue(local, ieee802_1d_to_ac[tid]); |
eadc8d9e RR |
658 | spin_unlock_bh(&local->mdev->queue_lock); |
659 | ||
eadc8d9e RR |
660 | /* send an addBA request */ |
661 | sta->ampdu_mlme.dialog_token_allocator++; | |
cee24a3e | 662 | sta->ampdu_mlme.tid_tx[tid]->dialog_token = |
eadc8d9e | 663 | sta->ampdu_mlme.dialog_token_allocator; |
cee24a3e | 664 | sta->ampdu_mlme.tid_tx[tid]->ssn = start_seq_num; |
eadc8d9e | 665 | |
d0709a65 | 666 | ieee80211_send_addba_request(sta->sdata->dev, ra, tid, |
cee24a3e RR |
667 | sta->ampdu_mlme.tid_tx[tid]->dialog_token, |
668 | sta->ampdu_mlme.tid_tx[tid]->ssn, | |
eadc8d9e RR |
669 | 0x40, 5000); |
670 | ||
671 | /* activate the timer for the recipient's addBA response */ | |
cee24a3e | 672 | sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.expires = |
eadc8d9e | 673 | jiffies + ADDBA_RESP_INTERVAL; |
cee24a3e | 674 | add_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer); |
eadc8d9e | 675 | printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid); |
cee24a3e | 676 | goto start_ba_exit; |
eadc8d9e | 677 | |
cee24a3e RR |
678 | start_ba_err: |
679 | kfree(sta->ampdu_mlme.tid_tx[tid]); | |
680 | sta->ampdu_mlme.tid_tx[tid] = NULL; | |
681 | spin_unlock_bh(&local->mdev->queue_lock); | |
682 | ret = -EBUSY; | |
eadc8d9e RR |
683 | start_ba_exit: |
684 | spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx); | |
d0709a65 | 685 | rcu_read_unlock(); |
eadc8d9e RR |
686 | return ret; |
687 | } | |
688 | EXPORT_SYMBOL(ieee80211_start_tx_ba_session); | |
689 | ||
690 | int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw, | |
691 | u8 *ra, u16 tid, | |
692 | enum ieee80211_back_parties initiator) | |
693 | { | |
694 | struct ieee80211_local *local = hw_to_local(hw); | |
695 | struct sta_info *sta; | |
696 | u8 *state; | |
697 | int ret = 0; | |
698 | DECLARE_MAC_BUF(mac); | |
699 | ||
700 | if (tid >= STA_TID_NUM) | |
701 | return -EINVAL; | |
702 | ||
d0709a65 | 703 | rcu_read_lock(); |
eadc8d9e | 704 | sta = sta_info_get(local, ra); |
d0709a65 JB |
705 | if (!sta) { |
706 | rcu_read_unlock(); | |
eadc8d9e | 707 | return -ENOENT; |
d0709a65 | 708 | } |
eadc8d9e RR |
709 | |
710 | /* check if the TID is in aggregation */ | |
cee24a3e | 711 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
eadc8d9e RR |
712 | spin_lock_bh(&sta->ampdu_mlme.ampdu_tx); |
713 | ||
714 | if (*state != HT_AGG_STATE_OPERATIONAL) { | |
eadc8d9e RR |
715 | ret = -ENOENT; |
716 | goto stop_BA_exit; | |
717 | } | |
718 | ||
513a1025 RR |
719 | #ifdef CONFIG_MAC80211_HT_DEBUG |
720 | printk(KERN_DEBUG "Tx BA session stop requested for %s tid %u\n", | |
721 | print_mac(mac, ra), tid); | |
722 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
723 | ||
eadc8d9e RR |
724 | ieee80211_stop_queue(hw, sta->tid_to_tx_q[tid]); |
725 | ||
726 | *state = HT_AGG_STATE_REQ_STOP_BA_MSK | | |
727 | (initiator << HT_AGG_STATE_INITIATOR_SHIFT); | |
728 | ||
729 | if (local->ops->ampdu_action) | |
730 | ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_STOP, | |
731 | ra, tid, NULL); | |
732 | ||
733 | /* case HW denied going back to legacy */ | |
734 | if (ret) { | |
735 | WARN_ON(ret != -EBUSY); | |
736 | *state = HT_AGG_STATE_OPERATIONAL; | |
737 | ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]); | |
738 | goto stop_BA_exit; | |
739 | } | |
740 | ||
741 | stop_BA_exit: | |
742 | spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx); | |
d0709a65 | 743 | rcu_read_unlock(); |
eadc8d9e RR |
744 | return ret; |
745 | } | |
746 | EXPORT_SYMBOL(ieee80211_stop_tx_ba_session); | |
747 | ||
748 | void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid) | |
749 | { | |
750 | struct ieee80211_local *local = hw_to_local(hw); | |
751 | struct sta_info *sta; | |
752 | u8 *state; | |
753 | DECLARE_MAC_BUF(mac); | |
754 | ||
755 | if (tid >= STA_TID_NUM) { | |
756 | printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n", | |
757 | tid, STA_TID_NUM); | |
758 | return; | |
759 | } | |
760 | ||
d0709a65 | 761 | rcu_read_lock(); |
eadc8d9e RR |
762 | sta = sta_info_get(local, ra); |
763 | if (!sta) { | |
d0709a65 | 764 | rcu_read_unlock(); |
eadc8d9e RR |
765 | printk(KERN_DEBUG "Could not find station: %s\n", |
766 | print_mac(mac, ra)); | |
767 | return; | |
768 | } | |
769 | ||
cee24a3e | 770 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
eadc8d9e RR |
771 | spin_lock_bh(&sta->ampdu_mlme.ampdu_tx); |
772 | ||
773 | if (!(*state & HT_ADDBA_REQUESTED_MSK)) { | |
774 | printk(KERN_DEBUG "addBA was not requested yet, state is %d\n", | |
775 | *state); | |
776 | spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx); | |
d0709a65 | 777 | rcu_read_unlock(); |
eadc8d9e RR |
778 | return; |
779 | } | |
780 | ||
781 | WARN_ON_ONCE(*state & HT_ADDBA_DRV_READY_MSK); | |
782 | ||
783 | *state |= HT_ADDBA_DRV_READY_MSK; | |
784 | ||
785 | if (*state == HT_AGG_STATE_OPERATIONAL) { | |
786 | printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid); | |
787 | ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]); | |
788 | } | |
789 | spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx); | |
d0709a65 | 790 | rcu_read_unlock(); |
eadc8d9e RR |
791 | } |
792 | EXPORT_SYMBOL(ieee80211_start_tx_ba_cb); | |
793 | ||
794 | void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid) | |
795 | { | |
796 | struct ieee80211_local *local = hw_to_local(hw); | |
797 | struct sta_info *sta; | |
798 | u8 *state; | |
799 | int agg_queue; | |
800 | DECLARE_MAC_BUF(mac); | |
801 | ||
802 | if (tid >= STA_TID_NUM) { | |
803 | printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n", | |
804 | tid, STA_TID_NUM); | |
805 | return; | |
806 | } | |
807 | ||
513a1025 RR |
808 | #ifdef CONFIG_MAC80211_HT_DEBUG |
809 | printk(KERN_DEBUG "Stopping Tx BA session for %s tid %d\n", | |
eadc8d9e | 810 | print_mac(mac, ra), tid); |
513a1025 | 811 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
eadc8d9e | 812 | |
d0709a65 | 813 | rcu_read_lock(); |
eadc8d9e RR |
814 | sta = sta_info_get(local, ra); |
815 | if (!sta) { | |
816 | printk(KERN_DEBUG "Could not find station: %s\n", | |
817 | print_mac(mac, ra)); | |
d0709a65 | 818 | rcu_read_unlock(); |
eadc8d9e RR |
819 | return; |
820 | } | |
cee24a3e | 821 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
eadc8d9e RR |
822 | |
823 | spin_lock_bh(&sta->ampdu_mlme.ampdu_tx); | |
824 | if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) { | |
825 | printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n"); | |
eadc8d9e | 826 | spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx); |
d0709a65 | 827 | rcu_read_unlock(); |
eadc8d9e RR |
828 | return; |
829 | } | |
830 | ||
831 | if (*state & HT_AGG_STATE_INITIATOR_MSK) | |
d0709a65 | 832 | ieee80211_send_delba(sta->sdata->dev, ra, tid, |
eadc8d9e RR |
833 | WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE); |
834 | ||
835 | agg_queue = sta->tid_to_tx_q[tid]; | |
836 | ||
837 | /* avoid ordering issues: we are the only one that can modify | |
838 | * the content of the qdiscs */ | |
839 | spin_lock_bh(&local->mdev->queue_lock); | |
840 | /* remove the queue for this aggregation */ | |
9e723492 | 841 | ieee80211_ht_agg_queue_remove(local, sta, tid, 1); |
eadc8d9e RR |
842 | spin_unlock_bh(&local->mdev->queue_lock); |
843 | ||
844 | /* we just requeued the all the frames that were in the removed | |
845 | * queue, and since we might miss a softirq we do netif_schedule. | |
846 | * ieee80211_wake_queue is not used here as this queue is not | |
847 | * necessarily stopped */ | |
848 | netif_schedule(local->mdev); | |
849 | *state = HT_AGG_STATE_IDLE; | |
cee24a3e RR |
850 | sta->ampdu_mlme.addba_req_num[tid] = 0; |
851 | kfree(sta->ampdu_mlme.tid_tx[tid]); | |
852 | sta->ampdu_mlme.tid_tx[tid] = NULL; | |
eadc8d9e RR |
853 | spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx); |
854 | ||
d0709a65 | 855 | rcu_read_unlock(); |
eadc8d9e RR |
856 | } |
857 | EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb); | |
858 | ||
859 | void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw, | |
860 | const u8 *ra, u16 tid) | |
861 | { | |
862 | struct ieee80211_local *local = hw_to_local(hw); | |
863 | struct ieee80211_ra_tid *ra_tid; | |
864 | struct sk_buff *skb = dev_alloc_skb(0); | |
865 | ||
866 | if (unlikely(!skb)) { | |
867 | if (net_ratelimit()) | |
868 | printk(KERN_WARNING "%s: Not enough memory, " | |
869 | "dropping start BA session", skb->dev->name); | |
870 | return; | |
871 | } | |
872 | ra_tid = (struct ieee80211_ra_tid *) &skb->cb; | |
873 | memcpy(&ra_tid->ra, ra, ETH_ALEN); | |
874 | ra_tid->tid = tid; | |
875 | ||
876 | skb->pkt_type = IEEE80211_ADDBA_MSG; | |
877 | skb_queue_tail(&local->skb_queue, skb); | |
878 | tasklet_schedule(&local->tasklet); | |
879 | } | |
880 | EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe); | |
881 | ||
882 | void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw, | |
883 | const u8 *ra, u16 tid) | |
884 | { | |
885 | struct ieee80211_local *local = hw_to_local(hw); | |
886 | struct ieee80211_ra_tid *ra_tid; | |
887 | struct sk_buff *skb = dev_alloc_skb(0); | |
888 | ||
889 | if (unlikely(!skb)) { | |
890 | if (net_ratelimit()) | |
891 | printk(KERN_WARNING "%s: Not enough memory, " | |
892 | "dropping stop BA session", skb->dev->name); | |
893 | return; | |
894 | } | |
895 | ra_tid = (struct ieee80211_ra_tid *) &skb->cb; | |
896 | memcpy(&ra_tid->ra, ra, ETH_ALEN); | |
897 | ra_tid->tid = tid; | |
898 | ||
899 | skb->pkt_type = IEEE80211_DELBA_MSG; | |
900 | skb_queue_tail(&local->skb_queue, skb); | |
901 | tasklet_schedule(&local->tasklet); | |
902 | } | |
903 | EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe); | |
904 | ||
f0706e82 JB |
905 | static void ieee80211_set_multicast_list(struct net_device *dev) |
906 | { | |
907 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
908 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4150c572 | 909 | int allmulti, promisc, sdata_allmulti, sdata_promisc; |
f0706e82 | 910 | |
4150c572 JB |
911 | allmulti = !!(dev->flags & IFF_ALLMULTI); |
912 | promisc = !!(dev->flags & IFF_PROMISC); | |
b52f2198 JB |
913 | sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI); |
914 | sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC); | |
4150c572 JB |
915 | |
916 | if (allmulti != sdata_allmulti) { | |
917 | if (dev->flags & IFF_ALLMULTI) | |
53918994 | 918 | atomic_inc(&local->iff_allmultis); |
4150c572 | 919 | else |
53918994 | 920 | atomic_dec(&local->iff_allmultis); |
13262ffd | 921 | sdata->flags ^= IEEE80211_SDATA_ALLMULTI; |
f0706e82 | 922 | } |
4150c572 JB |
923 | |
924 | if (promisc != sdata_promisc) { | |
925 | if (dev->flags & IFF_PROMISC) | |
53918994 | 926 | atomic_inc(&local->iff_promiscs); |
4150c572 | 927 | else |
53918994 | 928 | atomic_dec(&local->iff_promiscs); |
13262ffd | 929 | sdata->flags ^= IEEE80211_SDATA_PROMISC; |
f0706e82 | 930 | } |
4150c572 JB |
931 | |
932 | dev_mc_sync(local->mdev, dev); | |
f0706e82 JB |
933 | } |
934 | ||
3b04ddde SH |
935 | static const struct header_ops ieee80211_header_ops = { |
936 | .create = eth_header, | |
937 | .parse = header_parse_80211, | |
938 | .rebuild = eth_rebuild_header, | |
939 | .cache = eth_header_cache, | |
940 | .cache_update = eth_header_cache_update, | |
941 | }; | |
942 | ||
f9d540ee | 943 | /* Must not be called for mdev */ |
b2c258fb | 944 | void ieee80211_if_setup(struct net_device *dev) |
f0706e82 | 945 | { |
b2c258fb JB |
946 | ether_setup(dev); |
947 | dev->hard_start_xmit = ieee80211_subif_start_xmit; | |
948 | dev->wireless_handlers = &ieee80211_iw_handler_def; | |
949 | dev->set_multicast_list = ieee80211_set_multicast_list; | |
950 | dev->change_mtu = ieee80211_change_mtu; | |
b2c258fb JB |
951 | dev->open = ieee80211_open; |
952 | dev->stop = ieee80211_stop; | |
b2c258fb JB |
953 | dev->destructor = ieee80211_if_free; |
954 | } | |
f0706e82 | 955 | |
b2c258fb JB |
956 | /* everything else */ |
957 | ||
b2c258fb JB |
958 | static int __ieee80211_if_config(struct net_device *dev, |
959 | struct sk_buff *beacon, | |
960 | struct ieee80211_tx_control *control) | |
961 | { | |
962 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
963 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
964 | struct ieee80211_if_conf conf; | |
b2c258fb JB |
965 | |
966 | if (!local->ops->config_interface || !netif_running(dev)) | |
f0706e82 | 967 | return 0; |
f0706e82 | 968 | |
b2c258fb | 969 | memset(&conf, 0, sizeof(conf)); |
51fb61e7 JB |
970 | conf.type = sdata->vif.type; |
971 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA || | |
972 | sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { | |
4150c572 | 973 | conf.bssid = sdata->u.sta.bssid; |
b2c258fb JB |
974 | conf.ssid = sdata->u.sta.ssid; |
975 | conf.ssid_len = sdata->u.sta.ssid_len; | |
902acc78 | 976 | } else if (ieee80211_vif_is_mesh(&sdata->vif)) { |
f7a92144 LCC |
977 | conf.beacon = beacon; |
978 | ieee80211_start_mesh(dev); | |
51fb61e7 | 979 | } else if (sdata->vif.type == IEEE80211_IF_TYPE_AP) { |
b2c258fb JB |
980 | conf.ssid = sdata->u.ap.ssid; |
981 | conf.ssid_len = sdata->u.ap.ssid_len; | |
b2c258fb JB |
982 | conf.beacon = beacon; |
983 | conf.beacon_control = control; | |
f0706e82 | 984 | } |
b2c258fb | 985 | return local->ops->config_interface(local_to_hw(local), |
32bfd35d | 986 | &sdata->vif, &conf); |
f0706e82 JB |
987 | } |
988 | ||
b2c258fb JB |
989 | int ieee80211_if_config(struct net_device *dev) |
990 | { | |
f7a92144 LCC |
991 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
992 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
993 | if (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT && | |
994 | (local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE)) | |
995 | return ieee80211_if_config_beacon(dev); | |
b2c258fb JB |
996 | return __ieee80211_if_config(dev, NULL, NULL); |
997 | } | |
f0706e82 | 998 | |
b2c258fb | 999 | int ieee80211_if_config_beacon(struct net_device *dev) |
f0706e82 | 1000 | { |
f0706e82 | 1001 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
b2c258fb | 1002 | struct ieee80211_tx_control control; |
32bfd35d | 1003 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
b2c258fb | 1004 | struct sk_buff *skb; |
f0706e82 | 1005 | |
b2c258fb | 1006 | if (!(local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE)) |
f0706e82 | 1007 | return 0; |
32bfd35d JB |
1008 | skb = ieee80211_beacon_get(local_to_hw(local), &sdata->vif, |
1009 | &control); | |
b2c258fb JB |
1010 | if (!skb) |
1011 | return -ENOMEM; | |
1012 | return __ieee80211_if_config(dev, skb, &control); | |
1013 | } | |
f0706e82 | 1014 | |
b2c258fb JB |
1015 | int ieee80211_hw_config(struct ieee80211_local *local) |
1016 | { | |
b2c258fb JB |
1017 | struct ieee80211_channel *chan; |
1018 | int ret = 0; | |
f0706e82 | 1019 | |
8318d78a | 1020 | if (local->sta_sw_scanning) |
b2c258fb | 1021 | chan = local->scan_channel; |
8318d78a | 1022 | else |
b2c258fb | 1023 | chan = local->oper_channel; |
f0706e82 | 1024 | |
8318d78a JB |
1025 | local->hw.conf.channel = chan; |
1026 | ||
1027 | if (!local->hw.conf.power_level) | |
1028 | local->hw.conf.power_level = chan->max_power; | |
1029 | else | |
1030 | local->hw.conf.power_level = min(chan->max_power, | |
1031 | local->hw.conf.power_level); | |
1032 | ||
1033 | local->hw.conf.max_antenna_gain = chan->max_antenna_gain; | |
f0706e82 | 1034 | |
b2c258fb | 1035 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
8318d78a JB |
1036 | printk(KERN_DEBUG "%s: HW CONFIG: freq=%d\n", |
1037 | wiphy_name(local->hw.wiphy), chan->center_freq); | |
1038 | #endif | |
b2c258fb | 1039 | |
f7c4daed | 1040 | if (local->open_count) |
b2c258fb | 1041 | ret = local->ops->config(local_to_hw(local), &local->hw.conf); |
f0706e82 | 1042 | |
b2c258fb JB |
1043 | return ret; |
1044 | } | |
f0706e82 | 1045 | |
d3c990fb | 1046 | /** |
38668c05 TW |
1047 | * ieee80211_handle_ht should be used only after legacy configuration |
1048 | * has been determined namely band, as ht configuration depends upon | |
1049 | * the hardware's HT abilities for a _specific_ band. | |
d3c990fb | 1050 | */ |
38668c05 | 1051 | u32 ieee80211_handle_ht(struct ieee80211_local *local, int enable_ht, |
d3c990fb RR |
1052 | struct ieee80211_ht_info *req_ht_cap, |
1053 | struct ieee80211_ht_bss_info *req_bss_cap) | |
1054 | { | |
1055 | struct ieee80211_conf *conf = &local->hw.conf; | |
8318d78a | 1056 | struct ieee80211_supported_band *sband; |
38668c05 TW |
1057 | struct ieee80211_ht_info ht_conf; |
1058 | struct ieee80211_ht_bss_info ht_bss_conf; | |
d3c990fb | 1059 | int i; |
38668c05 | 1060 | u32 changed = 0; |
d3c990fb | 1061 | |
8318d78a JB |
1062 | sband = local->hw.wiphy->bands[conf->channel->band]; |
1063 | ||
d3c990fb | 1064 | /* HT is not supported */ |
8318d78a | 1065 | if (!sband->ht_info.ht_supported) { |
d3c990fb | 1066 | conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE; |
38668c05 | 1067 | return 0; |
d3c990fb RR |
1068 | } |
1069 | ||
38668c05 TW |
1070 | memset(&ht_conf, 0, sizeof(struct ieee80211_ht_info)); |
1071 | memset(&ht_bss_conf, 0, sizeof(struct ieee80211_ht_bss_info)); | |
1072 | ||
1073 | if (enable_ht) { | |
1074 | if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)) | |
1075 | changed |= BSS_CHANGED_HT; | |
1076 | ||
d3c990fb | 1077 | conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE; |
38668c05 TW |
1078 | ht_conf.ht_supported = 1; |
1079 | ||
1080 | ht_conf.cap = req_ht_cap->cap & sband->ht_info.cap; | |
1081 | ht_conf.cap &= ~(IEEE80211_HT_CAP_MIMO_PS); | |
1082 | ht_conf.cap |= sband->ht_info.cap & IEEE80211_HT_CAP_MIMO_PS; | |
1083 | ||
d3c990fb | 1084 | for (i = 0; i < SUPP_MCS_SET_LEN; i++) |
38668c05 TW |
1085 | ht_conf.supp_mcs_set[i] = |
1086 | sband->ht_info.supp_mcs_set[i] & | |
1087 | req_ht_cap->supp_mcs_set[i]; | |
1088 | ||
1089 | ht_bss_conf.primary_channel = req_bss_cap->primary_channel; | |
1090 | ht_bss_conf.bss_cap = req_bss_cap->bss_cap; | |
1091 | ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode; | |
1092 | ||
1093 | ht_conf.ampdu_factor = req_ht_cap->ampdu_factor; | |
1094 | ht_conf.ampdu_density = req_ht_cap->ampdu_density; | |
1095 | ||
1096 | /* if bss configuration changed store the new one */ | |
1097 | if (memcmp(&conf->ht_conf, &ht_conf, sizeof(ht_conf)) || | |
1098 | memcmp(&conf->ht_bss_conf, &ht_bss_conf, sizeof(ht_bss_conf))) { | |
1099 | changed |= BSS_CHANGED_HT; | |
1100 | memcpy(&conf->ht_conf, &ht_conf, sizeof(ht_conf)); | |
1101 | memcpy(&conf->ht_bss_conf, &ht_bss_conf, sizeof(ht_bss_conf)); | |
1102 | } | |
1103 | } else { | |
1104 | if (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) | |
1105 | changed |= BSS_CHANGED_HT; | |
1106 | conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE; | |
d3c990fb RR |
1107 | } |
1108 | ||
38668c05 | 1109 | return changed; |
d3c990fb RR |
1110 | } |
1111 | ||
471b3efd JB |
1112 | void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata, |
1113 | u32 changed) | |
d9430a32 | 1114 | { |
471b3efd JB |
1115 | struct ieee80211_local *local = sdata->local; |
1116 | ||
1117 | if (!changed) | |
1118 | return; | |
1119 | ||
1120 | if (local->ops->bss_info_changed) | |
1121 | local->ops->bss_info_changed(local_to_hw(local), | |
1122 | &sdata->vif, | |
1123 | &sdata->bss_conf, | |
1124 | changed); | |
d9430a32 DD |
1125 | } |
1126 | ||
1127 | void ieee80211_reset_erp_info(struct net_device *dev) | |
1128 | { | |
1129 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1130 | ||
471b3efd JB |
1131 | sdata->bss_conf.use_cts_prot = 0; |
1132 | sdata->bss_conf.use_short_preamble = 0; | |
1133 | ieee80211_bss_info_change_notify(sdata, | |
1134 | BSS_CHANGED_ERP_CTS_PROT | | |
1135 | BSS_CHANGED_ERP_PREAMBLE); | |
d9430a32 DD |
1136 | } |
1137 | ||
f0706e82 JB |
1138 | void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw, |
1139 | struct sk_buff *skb, | |
1140 | struct ieee80211_tx_status *status) | |
1141 | { | |
1142 | struct ieee80211_local *local = hw_to_local(hw); | |
1143 | struct ieee80211_tx_status *saved; | |
1144 | int tmp; | |
1145 | ||
1146 | skb->dev = local->mdev; | |
1147 | saved = kmalloc(sizeof(struct ieee80211_tx_status), GFP_ATOMIC); | |
1148 | if (unlikely(!saved)) { | |
1149 | if (net_ratelimit()) | |
1150 | printk(KERN_WARNING "%s: Not enough memory, " | |
1151 | "dropping tx status", skb->dev->name); | |
1152 | /* should be dev_kfree_skb_irq, but due to this function being | |
1153 | * named _irqsafe instead of just _irq we can't be sure that | |
1154 | * people won't call it from non-irq contexts */ | |
1155 | dev_kfree_skb_any(skb); | |
1156 | return; | |
1157 | } | |
1158 | memcpy(saved, status, sizeof(struct ieee80211_tx_status)); | |
1159 | /* copy pointer to saved status into skb->cb for use by tasklet */ | |
1160 | memcpy(skb->cb, &saved, sizeof(saved)); | |
1161 | ||
1162 | skb->pkt_type = IEEE80211_TX_STATUS_MSG; | |
1163 | skb_queue_tail(status->control.flags & IEEE80211_TXCTL_REQ_TX_STATUS ? | |
1164 | &local->skb_queue : &local->skb_queue_unreliable, skb); | |
1165 | tmp = skb_queue_len(&local->skb_queue) + | |
1166 | skb_queue_len(&local->skb_queue_unreliable); | |
1167 | while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT && | |
1168 | (skb = skb_dequeue(&local->skb_queue_unreliable))) { | |
1169 | memcpy(&saved, skb->cb, sizeof(saved)); | |
1170 | kfree(saved); | |
1171 | dev_kfree_skb_irq(skb); | |
1172 | tmp--; | |
1173 | I802_DEBUG_INC(local->tx_status_drop); | |
1174 | } | |
1175 | tasklet_schedule(&local->tasklet); | |
1176 | } | |
1177 | EXPORT_SYMBOL(ieee80211_tx_status_irqsafe); | |
1178 | ||
1179 | static void ieee80211_tasklet_handler(unsigned long data) | |
1180 | { | |
1181 | struct ieee80211_local *local = (struct ieee80211_local *) data; | |
1182 | struct sk_buff *skb; | |
1183 | struct ieee80211_rx_status rx_status; | |
1184 | struct ieee80211_tx_status *tx_status; | |
eadc8d9e | 1185 | struct ieee80211_ra_tid *ra_tid; |
f0706e82 JB |
1186 | |
1187 | while ((skb = skb_dequeue(&local->skb_queue)) || | |
1188 | (skb = skb_dequeue(&local->skb_queue_unreliable))) { | |
1189 | switch (skb->pkt_type) { | |
1190 | case IEEE80211_RX_MSG: | |
1191 | /* status is in skb->cb */ | |
1192 | memcpy(&rx_status, skb->cb, sizeof(rx_status)); | |
51fb61e7 | 1193 | /* Clear skb->pkt_type in order to not confuse kernel |
f0706e82 JB |
1194 | * netstack. */ |
1195 | skb->pkt_type = 0; | |
1196 | __ieee80211_rx(local_to_hw(local), skb, &rx_status); | |
1197 | break; | |
1198 | case IEEE80211_TX_STATUS_MSG: | |
1199 | /* get pointer to saved status out of skb->cb */ | |
1200 | memcpy(&tx_status, skb->cb, sizeof(tx_status)); | |
1201 | skb->pkt_type = 0; | |
1202 | ieee80211_tx_status(local_to_hw(local), | |
1203 | skb, tx_status); | |
1204 | kfree(tx_status); | |
1205 | break; | |
eadc8d9e RR |
1206 | case IEEE80211_DELBA_MSG: |
1207 | ra_tid = (struct ieee80211_ra_tid *) &skb->cb; | |
1208 | ieee80211_stop_tx_ba_cb(local_to_hw(local), | |
1209 | ra_tid->ra, ra_tid->tid); | |
1210 | dev_kfree_skb(skb); | |
1211 | break; | |
1212 | case IEEE80211_ADDBA_MSG: | |
1213 | ra_tid = (struct ieee80211_ra_tid *) &skb->cb; | |
1214 | ieee80211_start_tx_ba_cb(local_to_hw(local), | |
1215 | ra_tid->ra, ra_tid->tid); | |
1216 | dev_kfree_skb(skb); | |
1217 | break ; | |
f0706e82 JB |
1218 | default: /* should never get here! */ |
1219 | printk(KERN_ERR "%s: Unknown message type (%d)\n", | |
dd1cd4c6 | 1220 | wiphy_name(local->hw.wiphy), skb->pkt_type); |
f0706e82 JB |
1221 | dev_kfree_skb(skb); |
1222 | break; | |
1223 | } | |
1224 | } | |
1225 | } | |
1226 | ||
f0706e82 JB |
1227 | /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to |
1228 | * make a prepared TX frame (one that has been given to hw) to look like brand | |
1229 | * new IEEE 802.11 frame that is ready to go through TX processing again. | |
1230 | * Also, tx_packet_data in cb is restored from tx_control. */ | |
1231 | static void ieee80211_remove_tx_extra(struct ieee80211_local *local, | |
1232 | struct ieee80211_key *key, | |
1233 | struct sk_buff *skb, | |
1234 | struct ieee80211_tx_control *control) | |
1235 | { | |
1236 | int hdrlen, iv_len, mic_len; | |
1237 | struct ieee80211_tx_packet_data *pkt_data; | |
1238 | ||
1239 | pkt_data = (struct ieee80211_tx_packet_data *)skb->cb; | |
32bfd35d | 1240 | pkt_data->ifindex = vif_to_sdata(control->vif)->dev->ifindex; |
e8bf9649 JS |
1241 | pkt_data->flags = 0; |
1242 | if (control->flags & IEEE80211_TXCTL_REQ_TX_STATUS) | |
1243 | pkt_data->flags |= IEEE80211_TXPD_REQ_TX_STATUS; | |
1244 | if (control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT) | |
1245 | pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT; | |
1246 | if (control->flags & IEEE80211_TXCTL_REQUEUE) | |
1247 | pkt_data->flags |= IEEE80211_TXPD_REQUEUE; | |
678f5f71 JB |
1248 | if (control->flags & IEEE80211_TXCTL_EAPOL_FRAME) |
1249 | pkt_data->flags |= IEEE80211_TXPD_EAPOL_FRAME; | |
f0706e82 JB |
1250 | pkt_data->queue = control->queue; |
1251 | ||
1252 | hdrlen = ieee80211_get_hdrlen_from_skb(skb); | |
1253 | ||
1254 | if (!key) | |
1255 | goto no_key; | |
1256 | ||
8f20fc24 | 1257 | switch (key->conf.alg) { |
f0706e82 JB |
1258 | case ALG_WEP: |
1259 | iv_len = WEP_IV_LEN; | |
1260 | mic_len = WEP_ICV_LEN; | |
1261 | break; | |
1262 | case ALG_TKIP: | |
1263 | iv_len = TKIP_IV_LEN; | |
1264 | mic_len = TKIP_ICV_LEN; | |
1265 | break; | |
1266 | case ALG_CCMP: | |
1267 | iv_len = CCMP_HDR_LEN; | |
1268 | mic_len = CCMP_MIC_LEN; | |
1269 | break; | |
1270 | default: | |
1271 | goto no_key; | |
1272 | } | |
1273 | ||
8f20fc24 | 1274 | if (skb->len >= mic_len && |
11a843b7 | 1275 | !(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) |
f0706e82 JB |
1276 | skb_trim(skb, skb->len - mic_len); |
1277 | if (skb->len >= iv_len && skb->len > hdrlen) { | |
1278 | memmove(skb->data + iv_len, skb->data, hdrlen); | |
1279 | skb_pull(skb, iv_len); | |
1280 | } | |
1281 | ||
1282 | no_key: | |
1283 | { | |
1284 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | |
1285 | u16 fc = le16_to_cpu(hdr->frame_control); | |
1286 | if ((fc & 0x8C) == 0x88) /* QoS Control Field */ { | |
1287 | fc &= ~IEEE80211_STYPE_QOS_DATA; | |
1288 | hdr->frame_control = cpu_to_le16(fc); | |
1289 | memmove(skb->data + 2, skb->data, hdrlen - 2); | |
1290 | skb_pull(skb, 2); | |
1291 | } | |
1292 | } | |
1293 | } | |
1294 | ||
d46e144b JB |
1295 | static void ieee80211_handle_filtered_frame(struct ieee80211_local *local, |
1296 | struct sta_info *sta, | |
1297 | struct sk_buff *skb, | |
1298 | struct ieee80211_tx_status *status) | |
1299 | { | |
1300 | sta->tx_filtered_count++; | |
1301 | ||
1302 | /* | |
1303 | * Clear the TX filter mask for this STA when sending the next | |
1304 | * packet. If the STA went to power save mode, this will happen | |
1305 | * happen when it wakes up for the next time. | |
1306 | */ | |
1307 | sta->flags |= WLAN_STA_CLEAR_PS_FILT; | |
1308 | ||
1309 | /* | |
1310 | * This code races in the following way: | |
1311 | * | |
1312 | * (1) STA sends frame indicating it will go to sleep and does so | |
1313 | * (2) hardware/firmware adds STA to filter list, passes frame up | |
1314 | * (3) hardware/firmware processes TX fifo and suppresses a frame | |
1315 | * (4) we get TX status before having processed the frame and | |
1316 | * knowing that the STA has gone to sleep. | |
1317 | * | |
1318 | * This is actually quite unlikely even when both those events are | |
1319 | * processed from interrupts coming in quickly after one another or | |
1320 | * even at the same time because we queue both TX status events and | |
1321 | * RX frames to be processed by a tasklet and process them in the | |
1322 | * same order that they were received or TX status last. Hence, there | |
1323 | * is no race as long as the frame RX is processed before the next TX | |
1324 | * status, which drivers can ensure, see below. | |
1325 | * | |
1326 | * Note that this can only happen if the hardware or firmware can | |
1327 | * actually add STAs to the filter list, if this is done by the | |
1328 | * driver in response to set_tim() (which will only reduce the race | |
1329 | * this whole filtering tries to solve, not completely solve it) | |
1330 | * this situation cannot happen. | |
1331 | * | |
1332 | * To completely solve this race drivers need to make sure that they | |
1333 | * (a) don't mix the irq-safe/not irq-safe TX status/RX processing | |
1334 | * functions and | |
1335 | * (b) always process RX events before TX status events if ordering | |
1336 | * can be unknown, for example with different interrupt status | |
1337 | * bits. | |
1338 | */ | |
1339 | if (sta->flags & WLAN_STA_PS && | |
1340 | skb_queue_len(&sta->tx_filtered) < STA_MAX_TX_BUFFER) { | |
1341 | ieee80211_remove_tx_extra(local, sta->key, skb, | |
1342 | &status->control); | |
1343 | skb_queue_tail(&sta->tx_filtered, skb); | |
1344 | return; | |
1345 | } | |
1346 | ||
1347 | if (!(sta->flags & WLAN_STA_PS) && | |
1348 | !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) { | |
1349 | /* Software retry the packet once */ | |
1350 | status->control.flags |= IEEE80211_TXCTL_REQUEUE; | |
1351 | ieee80211_remove_tx_extra(local, sta->key, skb, | |
1352 | &status->control); | |
1353 | dev_queue_xmit(skb); | |
1354 | return; | |
1355 | } | |
1356 | ||
1357 | if (net_ratelimit()) | |
1358 | printk(KERN_DEBUG "%s: dropped TX filtered frame, " | |
1359 | "queue_len=%d PS=%d @%lu\n", | |
1360 | wiphy_name(local->hw.wiphy), | |
1361 | skb_queue_len(&sta->tx_filtered), | |
1362 | !!(sta->flags & WLAN_STA_PS), jiffies); | |
1363 | dev_kfree_skb(skb); | |
1364 | } | |
1365 | ||
f0706e82 JB |
1366 | void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb, |
1367 | struct ieee80211_tx_status *status) | |
1368 | { | |
1369 | struct sk_buff *skb2; | |
1370 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | |
1371 | struct ieee80211_local *local = hw_to_local(hw); | |
1372 | u16 frag, type; | |
b306f453 JB |
1373 | struct ieee80211_tx_status_rtap_hdr *rthdr; |
1374 | struct ieee80211_sub_if_data *sdata; | |
3d30d949 | 1375 | struct net_device *prev_dev = NULL; |
f0706e82 JB |
1376 | |
1377 | if (!status) { | |
1378 | printk(KERN_ERR | |
1379 | "%s: ieee80211_tx_status called with NULL status\n", | |
dd1cd4c6 | 1380 | wiphy_name(local->hw.wiphy)); |
f0706e82 JB |
1381 | dev_kfree_skb(skb); |
1382 | return; | |
1383 | } | |
1384 | ||
d0709a65 JB |
1385 | rcu_read_lock(); |
1386 | ||
f0706e82 JB |
1387 | if (status->excessive_retries) { |
1388 | struct sta_info *sta; | |
1389 | sta = sta_info_get(local, hdr->addr1); | |
1390 | if (sta) { | |
1391 | if (sta->flags & WLAN_STA_PS) { | |
d46e144b JB |
1392 | /* |
1393 | * The STA is in power save mode, so assume | |
f0706e82 JB |
1394 | * that this TX packet failed because of that. |
1395 | */ | |
1396 | status->excessive_retries = 0; | |
1397 | status->flags |= IEEE80211_TX_STATUS_TX_FILTERED; | |
d46e144b JB |
1398 | ieee80211_handle_filtered_frame(local, sta, |
1399 | skb, status); | |
d0709a65 | 1400 | rcu_read_unlock(); |
d46e144b | 1401 | return; |
f0706e82 | 1402 | } |
f0706e82 JB |
1403 | } |
1404 | } | |
1405 | ||
1406 | if (status->flags & IEEE80211_TX_STATUS_TX_FILTERED) { | |
1407 | struct sta_info *sta; | |
1408 | sta = sta_info_get(local, hdr->addr1); | |
1409 | if (sta) { | |
d46e144b JB |
1410 | ieee80211_handle_filtered_frame(local, sta, skb, |
1411 | status); | |
d0709a65 | 1412 | rcu_read_unlock(); |
f0706e82 JB |
1413 | return; |
1414 | } | |
1abbe498 MN |
1415 | } else |
1416 | rate_control_tx_status(local->mdev, skb, status); | |
f0706e82 | 1417 | |
d0709a65 JB |
1418 | rcu_read_unlock(); |
1419 | ||
f0706e82 JB |
1420 | ieee80211_led_tx(local, 0); |
1421 | ||
1422 | /* SNMP counters | |
1423 | * Fragments are passed to low-level drivers as separate skbs, so these | |
1424 | * are actually fragments, not frames. Update frame counters only for | |
1425 | * the first fragment of the frame. */ | |
1426 | ||
1427 | frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG; | |
1428 | type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE; | |
1429 | ||
1430 | if (status->flags & IEEE80211_TX_STATUS_ACK) { | |
1431 | if (frag == 0) { | |
1432 | local->dot11TransmittedFrameCount++; | |
1433 | if (is_multicast_ether_addr(hdr->addr1)) | |
1434 | local->dot11MulticastTransmittedFrameCount++; | |
1435 | if (status->retry_count > 0) | |
1436 | local->dot11RetryCount++; | |
1437 | if (status->retry_count > 1) | |
1438 | local->dot11MultipleRetryCount++; | |
1439 | } | |
1440 | ||
1441 | /* This counter shall be incremented for an acknowledged MPDU | |
1442 | * with an individual address in the address 1 field or an MPDU | |
1443 | * with a multicast address in the address 1 field of type Data | |
1444 | * or Management. */ | |
1445 | if (!is_multicast_ether_addr(hdr->addr1) || | |
1446 | type == IEEE80211_FTYPE_DATA || | |
1447 | type == IEEE80211_FTYPE_MGMT) | |
1448 | local->dot11TransmittedFragmentCount++; | |
1449 | } else { | |
1450 | if (frag == 0) | |
1451 | local->dot11FailedCount++; | |
1452 | } | |
1453 | ||
b306f453 JB |
1454 | /* this was a transmitted frame, but now we want to reuse it */ |
1455 | skb_orphan(skb); | |
1456 | ||
3d30d949 MW |
1457 | /* |
1458 | * This is a bit racy but we can avoid a lot of work | |
1459 | * with this test... | |
1460 | */ | |
1461 | if (!local->monitors && !local->cooked_mntrs) { | |
f0706e82 JB |
1462 | dev_kfree_skb(skb); |
1463 | return; | |
1464 | } | |
1465 | ||
b306f453 | 1466 | /* send frame to monitor interfaces now */ |
f0706e82 | 1467 | |
b306f453 JB |
1468 | if (skb_headroom(skb) < sizeof(*rthdr)) { |
1469 | printk(KERN_ERR "ieee80211_tx_status: headroom too small\n"); | |
f0706e82 JB |
1470 | dev_kfree_skb(skb); |
1471 | return; | |
1472 | } | |
f0706e82 | 1473 | |
b306f453 JB |
1474 | rthdr = (struct ieee80211_tx_status_rtap_hdr*) |
1475 | skb_push(skb, sizeof(*rthdr)); | |
1476 | ||
1477 | memset(rthdr, 0, sizeof(*rthdr)); | |
1478 | rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr)); | |
1479 | rthdr->hdr.it_present = | |
1480 | cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) | | |
1481 | (1 << IEEE80211_RADIOTAP_DATA_RETRIES)); | |
1482 | ||
1483 | if (!(status->flags & IEEE80211_TX_STATUS_ACK) && | |
1484 | !is_multicast_ether_addr(hdr->addr1)) | |
1485 | rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL); | |
1486 | ||
1487 | if ((status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS) && | |
1488 | (status->control.flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) | |
1489 | rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS); | |
1490 | else if (status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS) | |
1491 | rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS); | |
1492 | ||
1493 | rthdr->data_retries = status->retry_count; | |
1494 | ||
3d30d949 MW |
1495 | /* XXX: is this sufficient for BPF? */ |
1496 | skb_set_mac_header(skb, 0); | |
1497 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
1498 | skb->pkt_type = PACKET_OTHERHOST; | |
1499 | skb->protocol = htons(ETH_P_802_2); | |
1500 | memset(skb->cb, 0, sizeof(skb->cb)); | |
1501 | ||
79010420 | 1502 | rcu_read_lock(); |
79010420 | 1503 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
51fb61e7 | 1504 | if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR) { |
b306f453 JB |
1505 | if (!netif_running(sdata->dev)) |
1506 | continue; | |
3d30d949 MW |
1507 | |
1508 | if (prev_dev) { | |
79010420 | 1509 | skb2 = skb_clone(skb, GFP_ATOMIC); |
3d30d949 MW |
1510 | if (skb2) { |
1511 | skb2->dev = prev_dev; | |
1512 | netif_rx(skb2); | |
1513 | } | |
1514 | } | |
1515 | ||
1516 | prev_dev = sdata->dev; | |
b306f453 JB |
1517 | } |
1518 | } | |
3d30d949 MW |
1519 | if (prev_dev) { |
1520 | skb->dev = prev_dev; | |
1521 | netif_rx(skb); | |
1522 | skb = NULL; | |
1523 | } | |
79010420 | 1524 | rcu_read_unlock(); |
3d30d949 | 1525 | dev_kfree_skb(skb); |
f0706e82 JB |
1526 | } |
1527 | EXPORT_SYMBOL(ieee80211_tx_status); | |
1528 | ||
f0706e82 JB |
1529 | struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len, |
1530 | const struct ieee80211_ops *ops) | |
1531 | { | |
f0706e82 | 1532 | struct ieee80211_local *local; |
f0706e82 JB |
1533 | int priv_size; |
1534 | struct wiphy *wiphy; | |
1535 | ||
1536 | /* Ensure 32-byte alignment of our private data and hw private data. | |
1537 | * We use the wiphy priv data for both our ieee80211_local and for | |
1538 | * the driver's private data | |
1539 | * | |
1540 | * In memory it'll be like this: | |
1541 | * | |
1542 | * +-------------------------+ | |
1543 | * | struct wiphy | | |
1544 | * +-------------------------+ | |
1545 | * | struct ieee80211_local | | |
1546 | * +-------------------------+ | |
1547 | * | driver's private data | | |
1548 | * +-------------------------+ | |
1549 | * | |
1550 | */ | |
1551 | priv_size = ((sizeof(struct ieee80211_local) + | |
1552 | NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) + | |
1553 | priv_data_len; | |
1554 | ||
1555 | wiphy = wiphy_new(&mac80211_config_ops, priv_size); | |
1556 | ||
1557 | if (!wiphy) | |
1558 | return NULL; | |
1559 | ||
1560 | wiphy->privid = mac80211_wiphy_privid; | |
1561 | ||
1562 | local = wiphy_priv(wiphy); | |
1563 | local->hw.wiphy = wiphy; | |
1564 | ||
1565 | local->hw.priv = (char *)local + | |
1566 | ((sizeof(struct ieee80211_local) + | |
1567 | NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST); | |
1568 | ||
4480f15c | 1569 | BUG_ON(!ops->tx); |
4150c572 JB |
1570 | BUG_ON(!ops->start); |
1571 | BUG_ON(!ops->stop); | |
4480f15c JB |
1572 | BUG_ON(!ops->config); |
1573 | BUG_ON(!ops->add_interface); | |
4150c572 JB |
1574 | BUG_ON(!ops->remove_interface); |
1575 | BUG_ON(!ops->configure_filter); | |
f0706e82 JB |
1576 | local->ops = ops; |
1577 | ||
f0706e82 JB |
1578 | local->hw.queues = 1; /* default */ |
1579 | ||
f0706e82 JB |
1580 | local->bridge_packets = 1; |
1581 | ||
1582 | local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; | |
1583 | local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD; | |
1584 | local->short_retry_limit = 7; | |
1585 | local->long_retry_limit = 4; | |
1586 | local->hw.conf.radio_enabled = 1; | |
f0706e82 | 1587 | |
79010420 | 1588 | INIT_LIST_HEAD(&local->interfaces); |
f0706e82 | 1589 | |
b16bd15c JB |
1590 | spin_lock_init(&local->key_lock); |
1591 | ||
f0706e82 | 1592 | INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work); |
f0706e82 JB |
1593 | |
1594 | sta_info_init(local); | |
1595 | ||
f0706e82 JB |
1596 | tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending, |
1597 | (unsigned long)local); | |
1598 | tasklet_disable(&local->tx_pending_tasklet); | |
1599 | ||
1600 | tasklet_init(&local->tasklet, | |
1601 | ieee80211_tasklet_handler, | |
1602 | (unsigned long) local); | |
1603 | tasklet_disable(&local->tasklet); | |
1604 | ||
1605 | skb_queue_head_init(&local->skb_queue); | |
1606 | skb_queue_head_init(&local->skb_queue_unreliable); | |
1607 | ||
1608 | return local_to_hw(local); | |
1609 | } | |
1610 | EXPORT_SYMBOL(ieee80211_alloc_hw); | |
1611 | ||
1612 | int ieee80211_register_hw(struct ieee80211_hw *hw) | |
1613 | { | |
1614 | struct ieee80211_local *local = hw_to_local(hw); | |
1615 | const char *name; | |
1616 | int result; | |
8318d78a | 1617 | enum ieee80211_band band; |
96d51056 JB |
1618 | struct net_device *mdev; |
1619 | struct ieee80211_sub_if_data *sdata; | |
8318d78a JB |
1620 | |
1621 | /* | |
1622 | * generic code guarantees at least one band, | |
1623 | * set this very early because much code assumes | |
1624 | * that hw.conf.channel is assigned | |
1625 | */ | |
1626 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
1627 | struct ieee80211_supported_band *sband; | |
1628 | ||
1629 | sband = local->hw.wiphy->bands[band]; | |
1630 | if (sband) { | |
1631 | /* init channel we're on */ | |
1632 | local->hw.conf.channel = | |
1633 | local->oper_channel = | |
1634 | local->scan_channel = &sband->channels[0]; | |
1635 | break; | |
1636 | } | |
1637 | } | |
f0706e82 JB |
1638 | |
1639 | result = wiphy_register(local->hw.wiphy); | |
1640 | if (result < 0) | |
1641 | return result; | |
1642 | ||
96d51056 JB |
1643 | /* for now, mdev needs sub_if_data :/ */ |
1644 | mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data), | |
1645 | "wmaster%d", ether_setup); | |
1646 | if (!mdev) | |
1647 | goto fail_mdev_alloc; | |
1648 | ||
1649 | sdata = IEEE80211_DEV_TO_SUB_IF(mdev); | |
1650 | mdev->ieee80211_ptr = &sdata->wdev; | |
1651 | sdata->wdev.wiphy = local->hw.wiphy; | |
1652 | ||
1653 | local->mdev = mdev; | |
1654 | ||
1655 | ieee80211_rx_bss_list_init(mdev); | |
1656 | ||
1657 | mdev->hard_start_xmit = ieee80211_master_start_xmit; | |
1658 | mdev->open = ieee80211_master_open; | |
1659 | mdev->stop = ieee80211_master_stop; | |
1660 | mdev->type = ARPHRD_IEEE80211; | |
1661 | mdev->header_ops = &ieee80211_header_ops; | |
1662 | mdev->set_multicast_list = ieee80211_master_set_multicast_list; | |
1663 | ||
1664 | sdata->vif.type = IEEE80211_IF_TYPE_AP; | |
1665 | sdata->dev = mdev; | |
1666 | sdata->local = local; | |
1667 | sdata->u.ap.force_unicast_rateidx = -1; | |
1668 | sdata->u.ap.max_ratectrl_rateidx = -1; | |
1669 | ieee80211_if_sdata_init(sdata); | |
1670 | ||
1671 | /* no RCU needed since we're still during init phase */ | |
1672 | list_add_tail(&sdata->list, &local->interfaces); | |
1673 | ||
f0706e82 JB |
1674 | name = wiphy_dev(local->hw.wiphy)->driver->name; |
1675 | local->hw.workqueue = create_singlethread_workqueue(name); | |
1676 | if (!local->hw.workqueue) { | |
1677 | result = -ENOMEM; | |
1678 | goto fail_workqueue; | |
1679 | } | |
1680 | ||
b306f453 JB |
1681 | /* |
1682 | * The hardware needs headroom for sending the frame, | |
1683 | * and we need some headroom for passing the frame to monitor | |
1684 | * interfaces, but never both at the same time. | |
1685 | */ | |
33ccad35 JB |
1686 | local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom, |
1687 | sizeof(struct ieee80211_tx_status_rtap_hdr)); | |
b306f453 | 1688 | |
e9f207f0 JB |
1689 | debugfs_hw_add(local); |
1690 | ||
f0706e82 JB |
1691 | local->hw.conf.beacon_int = 1000; |
1692 | ||
1693 | local->wstats_flags |= local->hw.max_rssi ? | |
1694 | IW_QUAL_LEVEL_UPDATED : IW_QUAL_LEVEL_INVALID; | |
1695 | local->wstats_flags |= local->hw.max_signal ? | |
1696 | IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID; | |
1697 | local->wstats_flags |= local->hw.max_noise ? | |
1698 | IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID; | |
1699 | if (local->hw.max_rssi < 0 || local->hw.max_noise < 0) | |
1700 | local->wstats_flags |= IW_QUAL_DBM; | |
1701 | ||
1702 | result = sta_info_start(local); | |
1703 | if (result < 0) | |
1704 | goto fail_sta_info; | |
1705 | ||
1706 | rtnl_lock(); | |
1707 | result = dev_alloc_name(local->mdev, local->mdev->name); | |
1708 | if (result < 0) | |
1709 | goto fail_dev; | |
1710 | ||
1711 | memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN); | |
1712 | SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy)); | |
1713 | ||
1714 | result = register_netdevice(local->mdev); | |
1715 | if (result < 0) | |
1716 | goto fail_dev; | |
1717 | ||
e9f207f0 | 1718 | ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev)); |
5b2812e9 | 1719 | ieee80211_if_set_type(local->mdev, IEEE80211_IF_TYPE_AP); |
e9f207f0 | 1720 | |
830f9038 JB |
1721 | result = ieee80211_init_rate_ctrl_alg(local, |
1722 | hw->rate_control_algorithm); | |
f0706e82 JB |
1723 | if (result < 0) { |
1724 | printk(KERN_DEBUG "%s: Failed to initialize rate control " | |
dd1cd4c6 | 1725 | "algorithm\n", wiphy_name(local->hw.wiphy)); |
f0706e82 JB |
1726 | goto fail_rate; |
1727 | } | |
1728 | ||
1729 | result = ieee80211_wep_init(local); | |
1730 | ||
1731 | if (result < 0) { | |
1732 | printk(KERN_DEBUG "%s: Failed to initialize wep\n", | |
dd1cd4c6 | 1733 | wiphy_name(local->hw.wiphy)); |
f0706e82 JB |
1734 | goto fail_wep; |
1735 | } | |
1736 | ||
1737 | ieee80211_install_qdisc(local->mdev); | |
1738 | ||
1739 | /* add one default STA interface */ | |
1740 | result = ieee80211_if_add(local->mdev, "wlan%d", NULL, | |
ee385855 | 1741 | IEEE80211_IF_TYPE_STA, NULL); |
f0706e82 JB |
1742 | if (result) |
1743 | printk(KERN_WARNING "%s: Failed to add default virtual iface\n", | |
dd1cd4c6 | 1744 | wiphy_name(local->hw.wiphy)); |
f0706e82 JB |
1745 | |
1746 | local->reg_state = IEEE80211_DEV_REGISTERED; | |
1747 | rtnl_unlock(); | |
1748 | ||
1749 | ieee80211_led_init(local); | |
1750 | ||
1751 | return 0; | |
1752 | ||
1753 | fail_wep: | |
1754 | rate_control_deinitialize(local); | |
1755 | fail_rate: | |
e9f207f0 | 1756 | ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev)); |
f0706e82 JB |
1757 | unregister_netdevice(local->mdev); |
1758 | fail_dev: | |
1759 | rtnl_unlock(); | |
1760 | sta_info_stop(local); | |
1761 | fail_sta_info: | |
e9f207f0 | 1762 | debugfs_hw_del(local); |
f0706e82 JB |
1763 | destroy_workqueue(local->hw.workqueue); |
1764 | fail_workqueue: | |
96d51056 JB |
1765 | ieee80211_if_free(local->mdev); |
1766 | local->mdev = NULL; | |
1767 | fail_mdev_alloc: | |
f0706e82 JB |
1768 | wiphy_unregister(local->hw.wiphy); |
1769 | return result; | |
1770 | } | |
1771 | EXPORT_SYMBOL(ieee80211_register_hw); | |
1772 | ||
f0706e82 JB |
1773 | void ieee80211_unregister_hw(struct ieee80211_hw *hw) |
1774 | { | |
1775 | struct ieee80211_local *local = hw_to_local(hw); | |
1776 | struct ieee80211_sub_if_data *sdata, *tmp; | |
f0706e82 JB |
1777 | |
1778 | tasklet_kill(&local->tx_pending_tasklet); | |
1779 | tasklet_kill(&local->tasklet); | |
1780 | ||
1781 | rtnl_lock(); | |
1782 | ||
1783 | BUG_ON(local->reg_state != IEEE80211_DEV_REGISTERED); | |
1784 | ||
1785 | local->reg_state = IEEE80211_DEV_UNREGISTERED; | |
f0706e82 | 1786 | |
79010420 JB |
1787 | /* |
1788 | * At this point, interface list manipulations are fine | |
1789 | * because the driver cannot be handing us frames any | |
1790 | * more and the tasklet is killed. | |
1791 | */ | |
5b2812e9 JB |
1792 | |
1793 | /* | |
1794 | * First, we remove all non-master interfaces. Do this because they | |
1795 | * may have bss pointer dependency on the master, and when we free | |
1796 | * the master these would be freed as well, breaking our list | |
1797 | * iteration completely. | |
1798 | */ | |
1799 | list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) { | |
1800 | if (sdata->dev == local->mdev) | |
1801 | continue; | |
1802 | list_del(&sdata->list); | |
f0706e82 | 1803 | __ieee80211_if_del(local, sdata); |
5b2812e9 JB |
1804 | } |
1805 | ||
1806 | /* then, finally, remove the master interface */ | |
1807 | __ieee80211_if_del(local, IEEE80211_DEV_TO_SUB_IF(local->mdev)); | |
f0706e82 JB |
1808 | |
1809 | rtnl_unlock(); | |
1810 | ||
f0706e82 JB |
1811 | ieee80211_rx_bss_list_deinit(local->mdev); |
1812 | ieee80211_clear_tx_pending(local); | |
1813 | sta_info_stop(local); | |
1814 | rate_control_deinitialize(local); | |
e9f207f0 | 1815 | debugfs_hw_del(local); |
f0706e82 | 1816 | |
f0706e82 JB |
1817 | if (skb_queue_len(&local->skb_queue) |
1818 | || skb_queue_len(&local->skb_queue_unreliable)) | |
1819 | printk(KERN_WARNING "%s: skb_queue not empty\n", | |
dd1cd4c6 | 1820 | wiphy_name(local->hw.wiphy)); |
f0706e82 JB |
1821 | skb_queue_purge(&local->skb_queue); |
1822 | skb_queue_purge(&local->skb_queue_unreliable); | |
1823 | ||
1824 | destroy_workqueue(local->hw.workqueue); | |
1825 | wiphy_unregister(local->hw.wiphy); | |
1826 | ieee80211_wep_free(local); | |
1827 | ieee80211_led_exit(local); | |
96d51056 JB |
1828 | ieee80211_if_free(local->mdev); |
1829 | local->mdev = NULL; | |
f0706e82 JB |
1830 | } |
1831 | EXPORT_SYMBOL(ieee80211_unregister_hw); | |
1832 | ||
1833 | void ieee80211_free_hw(struct ieee80211_hw *hw) | |
1834 | { | |
1835 | struct ieee80211_local *local = hw_to_local(hw); | |
1836 | ||
f0706e82 JB |
1837 | wiphy_free(local->hw.wiphy); |
1838 | } | |
1839 | EXPORT_SYMBOL(ieee80211_free_hw); | |
1840 | ||
f0706e82 JB |
1841 | static int __init ieee80211_init(void) |
1842 | { | |
1843 | struct sk_buff *skb; | |
1844 | int ret; | |
1845 | ||
1846 | BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb)); | |
1847 | ||
4b475898 | 1848 | ret = rc80211_pid_init(); |
ad018375 | 1849 | if (ret) |
d9357136 | 1850 | goto out; |
ac71c691 | 1851 | |
f0706e82 JB |
1852 | ret = ieee80211_wme_register(); |
1853 | if (ret) { | |
1854 | printk(KERN_DEBUG "ieee80211_init: failed to " | |
1855 | "initialize WME (err=%d)\n", ret); | |
3eadf5f4 | 1856 | goto out_cleanup_pid; |
f0706e82 JB |
1857 | } |
1858 | ||
e9f207f0 JB |
1859 | ieee80211_debugfs_netdev_init(); |
1860 | ||
f0706e82 | 1861 | return 0; |
ad018375 | 1862 | |
3eadf5f4 | 1863 | out_cleanup_pid: |
4b475898 | 1864 | rc80211_pid_exit(); |
3eadf5f4 | 1865 | out: |
ad018375 | 1866 | return ret; |
f0706e82 JB |
1867 | } |
1868 | ||
f0706e82 JB |
1869 | static void __exit ieee80211_exit(void) |
1870 | { | |
4b475898 | 1871 | rc80211_pid_exit(); |
ac71c691 | 1872 | |
3b96766f JB |
1873 | /* |
1874 | * For key todo, it'll be empty by now but the work | |
1875 | * might still be scheduled. | |
1876 | */ | |
1877 | flush_scheduled_work(); | |
1878 | ||
f7a92144 LCC |
1879 | if (mesh_allocated) |
1880 | ieee80211s_stop(); | |
902acc78 | 1881 | |
f0706e82 | 1882 | ieee80211_wme_unregister(); |
e9f207f0 | 1883 | ieee80211_debugfs_netdev_exit(); |
f0706e82 JB |
1884 | } |
1885 | ||
1886 | ||
ca9938fe | 1887 | subsys_initcall(ieee80211_init); |
f0706e82 JB |
1888 | module_exit(ieee80211_exit); |
1889 | ||
1890 | MODULE_DESCRIPTION("IEEE 802.11 subsystem"); | |
1891 | MODULE_LICENSE("GPL"); |