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