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