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