Linux-libre 3.16.85-gnu
[librecmc/linux-libre.git] / net / mac80211 / main.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 <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/netdevice.h>
15 #include <linux/types.h>
16 #include <linux/slab.h>
17 #include <linux/skbuff.h>
18 #include <linux/etherdevice.h>
19 #include <linux/if_arp.h>
20 #include <linux/rtnetlink.h>
21 #include <linux/bitmap.h>
22 #include <linux/pm_qos.h>
23 #include <linux/inetdevice.h>
24 #include <net/net_namespace.h>
25 #include <net/cfg80211.h>
26 #include <net/addrconf.h>
27
28 #include "ieee80211_i.h"
29 #include "driver-ops.h"
30 #include "rate.h"
31 #include "mesh.h"
32 #include "wep.h"
33 #include "led.h"
34 #include "cfg.h"
35 #include "debugfs.h"
36
37 void ieee80211_configure_filter(struct ieee80211_local *local)
38 {
39         u64 mc;
40         unsigned int changed_flags;
41         unsigned int new_flags = 0;
42
43         if (atomic_read(&local->iff_promiscs))
44                 new_flags |= FIF_PROMISC_IN_BSS;
45
46         if (atomic_read(&local->iff_allmultis))
47                 new_flags |= FIF_ALLMULTI;
48
49         if (local->monitors || test_bit(SCAN_SW_SCANNING, &local->scanning) ||
50             test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning))
51                 new_flags |= FIF_BCN_PRBRESP_PROMISC;
52
53         if (local->fif_probe_req || local->probe_req_reg)
54                 new_flags |= FIF_PROBE_REQ;
55
56         if (local->fif_fcsfail)
57                 new_flags |= FIF_FCSFAIL;
58
59         if (local->fif_plcpfail)
60                 new_flags |= FIF_PLCPFAIL;
61
62         if (local->fif_control)
63                 new_flags |= FIF_CONTROL;
64
65         if (local->fif_other_bss)
66                 new_flags |= FIF_OTHER_BSS;
67
68         if (local->fif_pspoll)
69                 new_flags |= FIF_PSPOLL;
70
71         spin_lock_bh(&local->filter_lock);
72         changed_flags = local->filter_flags ^ new_flags;
73
74         mc = drv_prepare_multicast(local, &local->mc_list);
75         spin_unlock_bh(&local->filter_lock);
76
77         /* be a bit nasty */
78         new_flags |= (1<<31);
79
80         drv_configure_filter(local, changed_flags, &new_flags, mc);
81
82         WARN_ON(new_flags & (1<<31));
83
84         local->filter_flags = new_flags & ~(1<<31);
85 }
86
87 static void ieee80211_reconfig_filter(struct work_struct *work)
88 {
89         struct ieee80211_local *local =
90                 container_of(work, struct ieee80211_local, reconfig_filter);
91
92         ieee80211_configure_filter(local);
93 }
94
95 static u32 ieee80211_hw_conf_chan(struct ieee80211_local *local)
96 {
97         struct ieee80211_sub_if_data *sdata;
98         struct cfg80211_chan_def chandef = {};
99         u32 changed = 0;
100         int power;
101         u32 offchannel_flag;
102
103         offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
104
105         if (local->scan_chandef.chan) {
106                 chandef = local->scan_chandef;
107         } else if (local->tmp_channel) {
108                 chandef.chan = local->tmp_channel;
109                 chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
110                 chandef.center_freq1 = chandef.chan->center_freq;
111         } else
112                 chandef = local->_oper_chandef;
113
114         WARN(!cfg80211_chandef_valid(&chandef),
115              "control:%d MHz width:%d center: %d/%d MHz",
116              chandef.chan->center_freq, chandef.width,
117              chandef.center_freq1, chandef.center_freq2);
118
119         if (!cfg80211_chandef_identical(&chandef, &local->_oper_chandef))
120                 local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
121         else
122                 local->hw.conf.flags &= ~IEEE80211_CONF_OFFCHANNEL;
123
124         offchannel_flag ^= local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
125
126         if (offchannel_flag ||
127             !cfg80211_chandef_identical(&local->hw.conf.chandef,
128                                         &local->_oper_chandef)) {
129                 local->hw.conf.chandef = chandef;
130                 changed |= IEEE80211_CONF_CHANGE_CHANNEL;
131         }
132
133         if (!conf_is_ht(&local->hw.conf)) {
134                 /*
135                  * mac80211.h documents that this is only valid
136                  * when the channel is set to an HT type, and
137                  * that otherwise STATIC is used.
138                  */
139                 local->hw.conf.smps_mode = IEEE80211_SMPS_STATIC;
140         } else if (local->hw.conf.smps_mode != local->smps_mode) {
141                 local->hw.conf.smps_mode = local->smps_mode;
142                 changed |= IEEE80211_CONF_CHANGE_SMPS;
143         }
144
145         power = ieee80211_chandef_max_power(&chandef);
146
147         rcu_read_lock();
148         list_for_each_entry_rcu(sdata, &local->interfaces, list) {
149                 if (!rcu_access_pointer(sdata->vif.chanctx_conf))
150                         continue;
151                 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
152                         continue;
153                 power = min(power, sdata->vif.bss_conf.txpower);
154         }
155         rcu_read_unlock();
156
157         if (local->hw.conf.power_level != power) {
158                 changed |= IEEE80211_CONF_CHANGE_POWER;
159                 local->hw.conf.power_level = power;
160         }
161
162         return changed;
163 }
164
165 int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
166 {
167         int ret = 0;
168
169         might_sleep();
170
171         if (!local->use_chanctx)
172                 changed |= ieee80211_hw_conf_chan(local);
173         else
174                 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
175                              IEEE80211_CONF_CHANGE_POWER);
176
177         if (changed && local->open_count) {
178                 ret = drv_config(local, changed);
179                 /*
180                  * Goal:
181                  * HW reconfiguration should never fail, the driver has told
182                  * us what it can support so it should live up to that promise.
183                  *
184                  * Current status:
185                  * rfkill is not integrated with mac80211 and a
186                  * configuration command can thus fail if hardware rfkill
187                  * is enabled
188                  *
189                  * FIXME: integrate rfkill with mac80211 and then add this
190                  * WARN_ON() back
191                  *
192                  */
193                 /* WARN_ON(ret); */
194         }
195
196         return ret;
197 }
198
199 void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
200                                       u32 changed)
201 {
202         struct ieee80211_local *local = sdata->local;
203
204         if (!changed || sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
205                 return;
206
207         drv_bss_info_changed(local, sdata, &sdata->vif.bss_conf, changed);
208 }
209
210 u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata)
211 {
212         sdata->vif.bss_conf.use_cts_prot = false;
213         sdata->vif.bss_conf.use_short_preamble = false;
214         sdata->vif.bss_conf.use_short_slot = false;
215         return BSS_CHANGED_ERP_CTS_PROT |
216                BSS_CHANGED_ERP_PREAMBLE |
217                BSS_CHANGED_ERP_SLOT;
218 }
219
220 static void ieee80211_tasklet_handler(unsigned long data)
221 {
222         struct ieee80211_local *local = (struct ieee80211_local *) data;
223         struct sk_buff *skb;
224
225         while ((skb = skb_dequeue(&local->skb_queue)) ||
226                (skb = skb_dequeue(&local->skb_queue_unreliable))) {
227                 switch (skb->pkt_type) {
228                 case IEEE80211_RX_MSG:
229                         /* Clear skb->pkt_type in order to not confuse kernel
230                          * netstack. */
231                         skb->pkt_type = 0;
232                         ieee80211_rx(&local->hw, skb);
233                         break;
234                 case IEEE80211_TX_STATUS_MSG:
235                         skb->pkt_type = 0;
236                         ieee80211_tx_status(&local->hw, skb);
237                         break;
238                 default:
239                         WARN(1, "mac80211: Packet is of unknown type %d\n",
240                              skb->pkt_type);
241                         dev_kfree_skb(skb);
242                         break;
243                 }
244         }
245 }
246
247 static void ieee80211_restart_work(struct work_struct *work)
248 {
249         struct ieee80211_local *local =
250                 container_of(work, struct ieee80211_local, restart_work);
251         struct ieee80211_sub_if_data *sdata;
252
253         /* wait for scan work complete */
254         flush_workqueue(local->workqueue);
255
256         WARN(test_bit(SCAN_HW_SCANNING, &local->scanning),
257              "%s called with hardware scan in progress\n", __func__);
258
259         rtnl_lock();
260         list_for_each_entry(sdata, &local->interfaces, list)
261                 flush_delayed_work(&sdata->dec_tailroom_needed_wk);
262         ieee80211_scan_cancel(local);
263         ieee80211_reconfig(local);
264         rtnl_unlock();
265 }
266
267 void ieee80211_restart_hw(struct ieee80211_hw *hw)
268 {
269         struct ieee80211_local *local = hw_to_local(hw);
270
271         trace_api_restart_hw(local);
272
273         wiphy_info(hw->wiphy,
274                    "Hardware restart was requested\n");
275
276         /* use this reason, ieee80211_reconfig will unblock it */
277         ieee80211_stop_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
278                                         IEEE80211_QUEUE_STOP_REASON_SUSPEND);
279
280         /*
281          * Stop all Rx during the reconfig. We don't want state changes
282          * or driver callbacks while this is in progress.
283          */
284         local->in_reconfig = true;
285         barrier();
286
287         schedule_work(&local->restart_work);
288 }
289 EXPORT_SYMBOL(ieee80211_restart_hw);
290
291 #ifdef CONFIG_INET
292 static int ieee80211_ifa_changed(struct notifier_block *nb,
293                                  unsigned long data, void *arg)
294 {
295         struct in_ifaddr *ifa = arg;
296         struct ieee80211_local *local =
297                 container_of(nb, struct ieee80211_local,
298                              ifa_notifier);
299         struct net_device *ndev = ifa->ifa_dev->dev;
300         struct wireless_dev *wdev = ndev->ieee80211_ptr;
301         struct in_device *idev;
302         struct ieee80211_sub_if_data *sdata;
303         struct ieee80211_bss_conf *bss_conf;
304         struct ieee80211_if_managed *ifmgd;
305         int c = 0;
306
307         /* Make sure it's our interface that got changed */
308         if (!wdev)
309                 return NOTIFY_DONE;
310
311         if (wdev->wiphy != local->hw.wiphy)
312                 return NOTIFY_DONE;
313
314         sdata = IEEE80211_DEV_TO_SUB_IF(ndev);
315         bss_conf = &sdata->vif.bss_conf;
316
317         /* ARP filtering is only supported in managed mode */
318         if (sdata->vif.type != NL80211_IFTYPE_STATION)
319                 return NOTIFY_DONE;
320
321         idev = __in_dev_get_rtnl(sdata->dev);
322         if (!idev)
323                 return NOTIFY_DONE;
324
325         ifmgd = &sdata->u.mgd;
326         sdata_lock(sdata);
327
328         /* Copy the addresses to the bss_conf list */
329         ifa = idev->ifa_list;
330         while (ifa) {
331                 if (c < IEEE80211_BSS_ARP_ADDR_LIST_LEN)
332                         bss_conf->arp_addr_list[c] = ifa->ifa_address;
333                 ifa = ifa->ifa_next;
334                 c++;
335         }
336
337         bss_conf->arp_addr_cnt = c;
338
339         /* Configure driver only if associated (which also implies it is up) */
340         if (ifmgd->associated)
341                 ieee80211_bss_info_change_notify(sdata,
342                                                  BSS_CHANGED_ARP_FILTER);
343
344         sdata_unlock(sdata);
345
346         return NOTIFY_OK;
347 }
348 #endif
349
350 #if IS_ENABLED(CONFIG_IPV6)
351 static int ieee80211_ifa6_changed(struct notifier_block *nb,
352                                   unsigned long data, void *arg)
353 {
354         struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)arg;
355         struct inet6_dev *idev = ifa->idev;
356         struct net_device *ndev = ifa->idev->dev;
357         struct ieee80211_local *local =
358                 container_of(nb, struct ieee80211_local, ifa6_notifier);
359         struct wireless_dev *wdev = ndev->ieee80211_ptr;
360         struct ieee80211_sub_if_data *sdata;
361
362         /* Make sure it's our interface that got changed */
363         if (!wdev || wdev->wiphy != local->hw.wiphy)
364                 return NOTIFY_DONE;
365
366         sdata = IEEE80211_DEV_TO_SUB_IF(ndev);
367
368         /*
369          * For now only support station mode. This is mostly because
370          * doing AP would have to handle AP_VLAN in some way ...
371          */
372         if (sdata->vif.type != NL80211_IFTYPE_STATION)
373                 return NOTIFY_DONE;
374
375         drv_ipv6_addr_change(local, sdata, idev);
376
377         return NOTIFY_OK;
378 }
379 #endif
380
381 /* There isn't a lot of sense in it, but you can transmit anything you like */
382 static const struct ieee80211_txrx_stypes
383 ieee80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
384         [NL80211_IFTYPE_ADHOC] = {
385                 .tx = 0xffff,
386                 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
387                         BIT(IEEE80211_STYPE_AUTH >> 4) |
388                         BIT(IEEE80211_STYPE_DEAUTH >> 4) |
389                         BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
390         },
391         [NL80211_IFTYPE_STATION] = {
392                 .tx = 0xffff,
393                 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
394                         BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
395         },
396         [NL80211_IFTYPE_AP] = {
397                 .tx = 0xffff,
398                 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
399                         BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
400                         BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
401                         BIT(IEEE80211_STYPE_DISASSOC >> 4) |
402                         BIT(IEEE80211_STYPE_AUTH >> 4) |
403                         BIT(IEEE80211_STYPE_DEAUTH >> 4) |
404                         BIT(IEEE80211_STYPE_ACTION >> 4),
405         },
406         [NL80211_IFTYPE_AP_VLAN] = {
407                 /* copy AP */
408                 .tx = 0xffff,
409                 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
410                         BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
411                         BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
412                         BIT(IEEE80211_STYPE_DISASSOC >> 4) |
413                         BIT(IEEE80211_STYPE_AUTH >> 4) |
414                         BIT(IEEE80211_STYPE_DEAUTH >> 4) |
415                         BIT(IEEE80211_STYPE_ACTION >> 4),
416         },
417         [NL80211_IFTYPE_P2P_CLIENT] = {
418                 .tx = 0xffff,
419                 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
420                         BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
421         },
422         [NL80211_IFTYPE_P2P_GO] = {
423                 .tx = 0xffff,
424                 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
425                         BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
426                         BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
427                         BIT(IEEE80211_STYPE_DISASSOC >> 4) |
428                         BIT(IEEE80211_STYPE_AUTH >> 4) |
429                         BIT(IEEE80211_STYPE_DEAUTH >> 4) |
430                         BIT(IEEE80211_STYPE_ACTION >> 4),
431         },
432         [NL80211_IFTYPE_MESH_POINT] = {
433                 .tx = 0xffff,
434                 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
435                         BIT(IEEE80211_STYPE_AUTH >> 4) |
436                         BIT(IEEE80211_STYPE_DEAUTH >> 4),
437         },
438         [NL80211_IFTYPE_P2P_DEVICE] = {
439                 .tx = 0xffff,
440                 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
441                         BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
442         },
443 };
444
445 static const struct ieee80211_ht_cap mac80211_ht_capa_mod_mask = {
446         .ampdu_params_info = IEEE80211_HT_AMPDU_PARM_FACTOR |
447                              IEEE80211_HT_AMPDU_PARM_DENSITY,
448
449         .cap_info = cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
450                                 IEEE80211_HT_CAP_MAX_AMSDU |
451                                 IEEE80211_HT_CAP_SGI_20 |
452                                 IEEE80211_HT_CAP_SGI_40 |
453                                 IEEE80211_HT_CAP_LDPC_CODING |
454                                 IEEE80211_HT_CAP_40MHZ_INTOLERANT),
455         .mcs = {
456                 .rx_mask = { 0xff, 0xff, 0xff, 0xff, 0xff,
457                              0xff, 0xff, 0xff, 0xff, 0xff, },
458         },
459 };
460
461 static const struct ieee80211_vht_cap mac80211_vht_capa_mod_mask = {
462         .vht_cap_info =
463                 cpu_to_le32(IEEE80211_VHT_CAP_RXLDPC |
464                             IEEE80211_VHT_CAP_SHORT_GI_80 |
465                             IEEE80211_VHT_CAP_SHORT_GI_160 |
466                             IEEE80211_VHT_CAP_RXSTBC_1 |
467                             IEEE80211_VHT_CAP_RXSTBC_2 |
468                             IEEE80211_VHT_CAP_RXSTBC_3 |
469                             IEEE80211_VHT_CAP_RXSTBC_4 |
470                             IEEE80211_VHT_CAP_TXSTBC |
471                             IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
472                             IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
473                             IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
474                             IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
475                             IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK),
476         .supp_mcs = {
477                 .rx_mcs_map = cpu_to_le16(~0),
478                 .tx_mcs_map = cpu_to_le16(~0),
479         },
480 };
481
482 static const u8 extended_capabilities[] = {
483         0, 0, 0, 0, 0, 0, 0,
484         WLAN_EXT_CAPA8_OPMODE_NOTIF,
485 };
486
487 struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
488                                         const struct ieee80211_ops *ops)
489 {
490         struct ieee80211_local *local;
491         int priv_size, i;
492         struct wiphy *wiphy;
493         bool use_chanctx;
494
495         if (WARN_ON(!ops->tx || !ops->start || !ops->stop || !ops->config ||
496                     !ops->add_interface || !ops->remove_interface ||
497                     !ops->configure_filter))
498                 return NULL;
499
500         if (WARN_ON(ops->sta_state && (ops->sta_add || ops->sta_remove)))
501                 return NULL;
502
503         /* check all or no channel context operations exist */
504         i = !!ops->add_chanctx + !!ops->remove_chanctx +
505             !!ops->change_chanctx + !!ops->assign_vif_chanctx +
506             !!ops->unassign_vif_chanctx;
507         if (WARN_ON(i != 0 && i != 5))
508                 return NULL;
509         use_chanctx = i == 5;
510
511         /* Ensure 32-byte alignment of our private data and hw private data.
512          * We use the wiphy priv data for both our ieee80211_local and for
513          * the driver's private data
514          *
515          * In memory it'll be like this:
516          *
517          * +-------------------------+
518          * | struct wiphy           |
519          * +-------------------------+
520          * | struct ieee80211_local  |
521          * +-------------------------+
522          * | driver's private data   |
523          * +-------------------------+
524          *
525          */
526         priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len;
527
528         wiphy = wiphy_new(&mac80211_config_ops, priv_size);
529
530         if (!wiphy)
531                 return NULL;
532
533         wiphy->mgmt_stypes = ieee80211_default_mgmt_stypes;
534
535         wiphy->privid = mac80211_wiphy_privid;
536
537         wiphy->flags |= WIPHY_FLAG_NETNS_OK |
538                         WIPHY_FLAG_4ADDR_AP |
539                         WIPHY_FLAG_4ADDR_STATION |
540                         WIPHY_FLAG_REPORTS_OBSS |
541                         WIPHY_FLAG_OFFCHAN_TX;
542
543         wiphy->extended_capabilities = extended_capabilities;
544         wiphy->extended_capabilities_mask = extended_capabilities;
545         wiphy->extended_capabilities_len = ARRAY_SIZE(extended_capabilities);
546
547         if (ops->remain_on_channel)
548                 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
549
550         wiphy->features |= NL80211_FEATURE_SK_TX_STATUS |
551                            NL80211_FEATURE_SAE |
552                            NL80211_FEATURE_HT_IBSS |
553                            NL80211_FEATURE_VIF_TXPOWER |
554                            NL80211_FEATURE_USERSPACE_MPM;
555
556         if (!ops->hw_scan)
557                 wiphy->features |= NL80211_FEATURE_LOW_PRIORITY_SCAN |
558                                    NL80211_FEATURE_AP_SCAN;
559
560
561         if (!ops->set_key)
562                 wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
563
564         wiphy->bss_priv_size = sizeof(struct ieee80211_bss);
565
566         local = wiphy_priv(wiphy);
567
568         local->hw.wiphy = wiphy;
569
570         local->hw.priv = (char *)local + ALIGN(sizeof(*local), NETDEV_ALIGN);
571
572         local->ops = ops;
573         local->use_chanctx = use_chanctx;
574
575         /* set up some defaults */
576         local->hw.queues = 1;
577         local->hw.max_rates = 1;
578         local->hw.max_report_rates = 0;
579         local->hw.max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
580         local->hw.max_tx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
581         local->hw.offchannel_tx_hw_queue = IEEE80211_INVAL_HW_QUEUE;
582         local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
583         local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
584         local->hw.radiotap_mcs_details = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
585                                          IEEE80211_RADIOTAP_MCS_HAVE_GI |
586                                          IEEE80211_RADIOTAP_MCS_HAVE_BW;
587         local->hw.radiotap_vht_details = IEEE80211_RADIOTAP_VHT_KNOWN_GI |
588                                          IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH;
589         local->hw.uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES;
590         local->hw.uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN;
591         local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
592         wiphy->ht_capa_mod_mask = &mac80211_ht_capa_mod_mask;
593         wiphy->vht_capa_mod_mask = &mac80211_vht_capa_mod_mask;
594
595         INIT_LIST_HEAD(&local->interfaces);
596
597         __hw_addr_init(&local->mc_list);
598
599         mutex_init(&local->iflist_mtx);
600         mutex_init(&local->mtx);
601
602         mutex_init(&local->key_mtx);
603         spin_lock_init(&local->filter_lock);
604         spin_lock_init(&local->rx_path_lock);
605         spin_lock_init(&local->queue_stop_reason_lock);
606
607         INIT_LIST_HEAD(&local->chanctx_list);
608         mutex_init(&local->chanctx_mtx);
609
610         INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
611
612         INIT_WORK(&local->restart_work, ieee80211_restart_work);
613
614         INIT_WORK(&local->radar_detected_work,
615                   ieee80211_dfs_radar_detected_work);
616
617         INIT_WORK(&local->reconfig_filter, ieee80211_reconfig_filter);
618         local->smps_mode = IEEE80211_SMPS_OFF;
619
620         INIT_WORK(&local->dynamic_ps_enable_work,
621                   ieee80211_dynamic_ps_enable_work);
622         INIT_WORK(&local->dynamic_ps_disable_work,
623                   ieee80211_dynamic_ps_disable_work);
624         setup_timer(&local->dynamic_ps_timer,
625                     ieee80211_dynamic_ps_timer, (unsigned long) local);
626
627         INIT_WORK(&local->sched_scan_stopped_work,
628                   ieee80211_sched_scan_stopped_work);
629
630         spin_lock_init(&local->ack_status_lock);
631         idr_init(&local->ack_status_frames);
632
633         sta_info_init(local);
634
635         for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
636                 skb_queue_head_init(&local->pending[i]);
637                 atomic_set(&local->agg_queue_stop[i], 0);
638         }
639         tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
640                      (unsigned long)local);
641
642         tasklet_init(&local->tasklet,
643                      ieee80211_tasklet_handler,
644                      (unsigned long) local);
645
646         skb_queue_head_init(&local->skb_queue);
647         skb_queue_head_init(&local->skb_queue_unreliable);
648
649         ieee80211_led_names(local);
650
651         ieee80211_roc_setup(local);
652
653         return &local->hw;
654 }
655 EXPORT_SYMBOL(ieee80211_alloc_hw);
656
657 static int ieee80211_init_cipher_suites(struct ieee80211_local *local)
658 {
659         bool have_wep = !(IS_ERR(local->wep_tx_tfm) ||
660                           IS_ERR(local->wep_rx_tfm));
661         bool have_mfp = local->hw.flags & IEEE80211_HW_MFP_CAPABLE;
662         const struct ieee80211_cipher_scheme *cs = local->hw.cipher_schemes;
663         int n_suites = 0, r = 0, w = 0;
664         u32 *suites;
665         static const u32 cipher_suites[] = {
666                 /* keep WEP first, it may be removed below */
667                 WLAN_CIPHER_SUITE_WEP40,
668                 WLAN_CIPHER_SUITE_WEP104,
669                 WLAN_CIPHER_SUITE_TKIP,
670                 WLAN_CIPHER_SUITE_CCMP,
671
672                 /* keep last -- depends on hw flags! */
673                 WLAN_CIPHER_SUITE_AES_CMAC
674         };
675
676         /* Driver specifies the ciphers, we have nothing to do... */
677         if (local->hw.wiphy->cipher_suites && have_wep)
678                 return 0;
679
680         /* Set up cipher suites if driver relies on mac80211 cipher defs */
681         if (!local->hw.wiphy->cipher_suites && !cs) {
682                 local->hw.wiphy->cipher_suites = cipher_suites;
683                 local->hw.wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
684
685                 if (!have_mfp)
686                         local->hw.wiphy->n_cipher_suites--;
687
688                 if (!have_wep) {
689                         local->hw.wiphy->cipher_suites += 2;
690                         local->hw.wiphy->n_cipher_suites -= 2;
691                 }
692
693                 return 0;
694         }
695
696         if (!local->hw.wiphy->cipher_suites) {
697                 /*
698                  * Driver specifies cipher schemes only
699                  * We start counting ciphers defined by schemes, TKIP and CCMP
700                  */
701                 n_suites = local->hw.n_cipher_schemes + 2;
702
703                 /* check if we have WEP40 and WEP104 */
704                 if (have_wep)
705                         n_suites += 2;
706
707                 /* check if we have AES_CMAC */
708                 if (have_mfp)
709                         n_suites++;
710
711                 suites = kmalloc(sizeof(u32) * n_suites, GFP_KERNEL);
712                 if (!suites)
713                         return -ENOMEM;
714
715                 suites[w++] = WLAN_CIPHER_SUITE_CCMP;
716                 suites[w++] = WLAN_CIPHER_SUITE_TKIP;
717
718                 if (have_wep) {
719                         suites[w++] = WLAN_CIPHER_SUITE_WEP40;
720                         suites[w++] = WLAN_CIPHER_SUITE_WEP104;
721                 }
722
723                 if (have_mfp)
724                         suites[w++] = WLAN_CIPHER_SUITE_AES_CMAC;
725
726                 for (r = 0; r < local->hw.n_cipher_schemes; r++)
727                         suites[w++] = cs[r].cipher;
728         } else {
729                 /* Driver provides cipher suites, but we need to exclude WEP */
730                 suites = kmemdup(local->hw.wiphy->cipher_suites,
731                                  sizeof(u32) * local->hw.wiphy->n_cipher_suites,
732                                  GFP_KERNEL);
733                 if (!suites)
734                         return -ENOMEM;
735
736                 for (r = 0; r < local->hw.wiphy->n_cipher_suites; r++) {
737                         u32 suite = local->hw.wiphy->cipher_suites[r];
738
739                         if (suite == WLAN_CIPHER_SUITE_WEP40 ||
740                             suite == WLAN_CIPHER_SUITE_WEP104)
741                                 continue;
742                         suites[w++] = suite;
743                 }
744         }
745
746         local->hw.wiphy->cipher_suites = suites;
747         local->hw.wiphy->n_cipher_suites = w;
748         local->wiphy_ciphers_allocated = true;
749
750         return 0;
751 }
752
753 int ieee80211_register_hw(struct ieee80211_hw *hw)
754 {
755         struct ieee80211_local *local = hw_to_local(hw);
756         int result, i;
757         enum ieee80211_band band;
758         int channels, max_bitrates;
759         bool supp_ht, supp_vht;
760         netdev_features_t feature_whitelist;
761         struct cfg80211_chan_def dflt_chandef = {};
762
763         if (hw->flags & IEEE80211_HW_QUEUE_CONTROL &&
764             (local->hw.offchannel_tx_hw_queue == IEEE80211_INVAL_HW_QUEUE ||
765              local->hw.offchannel_tx_hw_queue >= local->hw.queues))
766                 return -EINVAL;
767
768 #ifdef CONFIG_PM
769         if (hw->wiphy->wowlan && (!local->ops->suspend || !local->ops->resume))
770                 return -EINVAL;
771 #endif
772
773         if (!local->use_chanctx) {
774                 for (i = 0; i < local->hw.wiphy->n_iface_combinations; i++) {
775                         const struct ieee80211_iface_combination *comb;
776
777                         comb = &local->hw.wiphy->iface_combinations[i];
778
779                         if (comb->num_different_channels > 1)
780                                 return -EINVAL;
781                 }
782         } else {
783                 /*
784                  * WDS is currently prohibited when channel contexts are used
785                  * because there's no clear definition of which channel WDS
786                  * type interfaces use
787                  */
788                 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_WDS))
789                         return -EINVAL;
790
791                 /* DFS currently not supported with channel context drivers */
792                 for (i = 0; i < local->hw.wiphy->n_iface_combinations; i++) {
793                         const struct ieee80211_iface_combination *comb;
794
795                         comb = &local->hw.wiphy->iface_combinations[i];
796
797                         if (comb->radar_detect_widths)
798                                 return -EINVAL;
799                 }
800         }
801
802         /* Only HW csum features are currently compatible with mac80211 */
803         feature_whitelist = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
804                             NETIF_F_HW_CSUM;
805         if (WARN_ON(hw->netdev_features & ~feature_whitelist))
806                 return -EINVAL;
807
808         if (hw->max_report_rates == 0)
809                 hw->max_report_rates = hw->max_rates;
810
811         local->rx_chains = 1;
812
813         /*
814          * generic code guarantees at least one band,
815          * set this very early because much code assumes
816          * that hw.conf.channel is assigned
817          */
818         channels = 0;
819         max_bitrates = 0;
820         supp_ht = false;
821         supp_vht = false;
822         for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
823                 struct ieee80211_supported_band *sband;
824
825                 sband = local->hw.wiphy->bands[band];
826                 if (!sband)
827                         continue;
828
829                 if (!dflt_chandef.chan) {
830                         cfg80211_chandef_create(&dflt_chandef,
831                                                 &sband->channels[0],
832                                                 NL80211_CHAN_NO_HT);
833                         /* init channel we're on */
834                         if (!local->use_chanctx && !local->_oper_chandef.chan) {
835                                 local->hw.conf.chandef = dflt_chandef;
836                                 local->_oper_chandef = dflt_chandef;
837                         }
838                         local->monitor_chandef = dflt_chandef;
839                 }
840
841                 channels += sband->n_channels;
842
843                 if (max_bitrates < sband->n_bitrates)
844                         max_bitrates = sband->n_bitrates;
845                 supp_ht = supp_ht || sband->ht_cap.ht_supported;
846                 supp_vht = supp_vht || sband->vht_cap.vht_supported;
847
848                 if (sband->ht_cap.ht_supported)
849                         local->rx_chains =
850                                 max(ieee80211_mcs_to_chains(&sband->ht_cap.mcs),
851                                     local->rx_chains);
852
853                 /* TODO: consider VHT for RX chains, hopefully it's the same */
854         }
855
856         /* if low-level driver supports AP, we also support VLAN */
857         if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) {
858                 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
859                 hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_AP_VLAN);
860         }
861
862         /* mac80211 always supports monitor */
863         hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
864         hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
865
866         /* mac80211 doesn't support more than one IBSS interface right now */
867         for (i = 0; i < hw->wiphy->n_iface_combinations; i++) {
868                 const struct ieee80211_iface_combination *c;
869                 int j;
870
871                 c = &hw->wiphy->iface_combinations[i];
872
873                 for (j = 0; j < c->n_limits; j++)
874                         if ((c->limits[j].types & BIT(NL80211_IFTYPE_ADHOC)) &&
875                             c->limits[j].max > 1)
876                                 return -EINVAL;
877         }
878
879         local->int_scan_req = kzalloc(sizeof(*local->int_scan_req) +
880                                       sizeof(void *) * channels, GFP_KERNEL);
881         if (!local->int_scan_req)
882                 return -ENOMEM;
883
884         for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
885                 if (!local->hw.wiphy->bands[band])
886                         continue;
887                 local->int_scan_req->rates[band] = (u32) -1;
888         }
889
890 #ifndef CONFIG_MAC80211_MESH
891         /* mesh depends on Kconfig, but drivers should set it if they want */
892         local->hw.wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MESH_POINT);
893 #endif
894
895         /* if the underlying driver supports mesh, mac80211 will (at least)
896          * provide routing of mesh authentication frames to userspace */
897         if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_MESH_POINT))
898                 local->hw.wiphy->flags |= WIPHY_FLAG_MESH_AUTH;
899
900         /* mac80211 supports control port protocol changing */
901         local->hw.wiphy->flags |= WIPHY_FLAG_CONTROL_PORT_PROTOCOL;
902
903         if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
904                 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
905         } else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) {
906                 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
907                 if (hw->max_signal <= 0) {
908                         result = -EINVAL;
909                         goto fail_wiphy_register;
910                 }
911         }
912
913         WARN((local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)
914              && (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK),
915              "U-APSD not supported with HW_PS_NULLFUNC_STACK\n");
916
917         /*
918          * Calculate scan IE length -- we need this to alloc
919          * memory and to subtract from the driver limit. It
920          * includes the DS Params, (extended) supported rates, and HT
921          * information -- SSID is the driver's responsibility.
922          */
923         local->scan_ies_len = 4 + max_bitrates /* (ext) supp rates */ +
924                 3 /* DS Params */;
925         if (supp_ht)
926                 local->scan_ies_len += 2 + sizeof(struct ieee80211_ht_cap);
927
928         if (supp_vht)
929                 local->scan_ies_len +=
930                         2 + sizeof(struct ieee80211_vht_cap);
931
932         if (!local->ops->hw_scan) {
933                 /* For hw_scan, driver needs to set these up. */
934                 local->hw.wiphy->max_scan_ssids = 4;
935                 local->hw.wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
936         }
937
938         /*
939          * If the driver supports any scan IEs, then assume the
940          * limit includes the IEs mac80211 will add, otherwise
941          * leave it at zero and let the driver sort it out; we
942          * still pass our IEs to the driver but userspace will
943          * not be allowed to in that case.
944          */
945         if (local->hw.wiphy->max_scan_ie_len)
946                 local->hw.wiphy->max_scan_ie_len -= local->scan_ies_len;
947
948         WARN_ON(!ieee80211_cs_list_valid(local->hw.cipher_schemes,
949                                          local->hw.n_cipher_schemes));
950
951         result = ieee80211_init_cipher_suites(local);
952         if (result < 0)
953                 goto fail_wiphy_register;
954
955         if (!local->ops->remain_on_channel)
956                 local->hw.wiphy->max_remain_on_channel_duration = 5000;
957
958         /* mac80211 based drivers don't support internal TDLS setup */
959         if (local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS)
960                 local->hw.wiphy->flags |= WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
961
962         local->hw.wiphy->max_num_csa_counters = IEEE80211_MAX_CSA_COUNTERS_NUM;
963
964         result = wiphy_register(local->hw.wiphy);
965         if (result < 0)
966                 goto fail_wiphy_register;
967
968         /*
969          * We use the number of queues for feature tests (QoS, HT) internally
970          * so restrict them appropriately.
971          */
972         if (hw->queues > IEEE80211_MAX_QUEUES)
973                 hw->queues = IEEE80211_MAX_QUEUES;
974
975         local->workqueue =
976                 alloc_ordered_workqueue("%s", 0, wiphy_name(local->hw.wiphy));
977         if (!local->workqueue) {
978                 result = -ENOMEM;
979                 goto fail_workqueue;
980         }
981
982         /*
983          * The hardware needs headroom for sending the frame,
984          * and we need some headroom for passing the frame to monitor
985          * interfaces, but never both at the same time.
986          */
987         local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
988                                    IEEE80211_TX_STATUS_HEADROOM);
989
990         debugfs_hw_add(local);
991
992         /*
993          * if the driver doesn't specify a max listen interval we
994          * use 5 which should be a safe default
995          */
996         if (local->hw.max_listen_interval == 0)
997                 local->hw.max_listen_interval = 5;
998
999         local->hw.conf.listen_interval = local->hw.max_listen_interval;
1000
1001         local->dynamic_ps_forced_timeout = -1;
1002
1003         result = ieee80211_wep_init(local);
1004         if (result < 0)
1005                 wiphy_debug(local->hw.wiphy, "Failed to initialize wep: %d\n",
1006                             result);
1007
1008         local->hw.conf.flags = IEEE80211_CONF_IDLE;
1009
1010         ieee80211_led_init(local);
1011
1012         rtnl_lock();
1013
1014         result = ieee80211_init_rate_ctrl_alg(local,
1015                                               hw->rate_control_algorithm);
1016         if (result < 0) {
1017                 wiphy_debug(local->hw.wiphy,
1018                             "Failed to initialize rate control algorithm\n");
1019                 goto fail_rate;
1020         }
1021
1022         /* add one default STA interface if supported */
1023         if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION)) {
1024                 result = ieee80211_if_add(local, "wlan%d", NULL,
1025                                           NL80211_IFTYPE_STATION, NULL);
1026                 if (result)
1027                         wiphy_warn(local->hw.wiphy,
1028                                    "Failed to add default virtual iface\n");
1029         }
1030
1031         rtnl_unlock();
1032
1033         local->network_latency_notifier.notifier_call =
1034                 ieee80211_max_network_latency;
1035         result = pm_qos_add_notifier(PM_QOS_NETWORK_LATENCY,
1036                                      &local->network_latency_notifier);
1037         if (result) {
1038                 rtnl_lock();
1039                 goto fail_pm_qos;
1040         }
1041
1042 #ifdef CONFIG_INET
1043         local->ifa_notifier.notifier_call = ieee80211_ifa_changed;
1044         result = register_inetaddr_notifier(&local->ifa_notifier);
1045         if (result)
1046                 goto fail_ifa;
1047 #endif
1048
1049 #if IS_ENABLED(CONFIG_IPV6)
1050         local->ifa6_notifier.notifier_call = ieee80211_ifa6_changed;
1051         result = register_inet6addr_notifier(&local->ifa6_notifier);
1052         if (result)
1053                 goto fail_ifa6;
1054 #endif
1055
1056         return 0;
1057
1058 #if IS_ENABLED(CONFIG_IPV6)
1059  fail_ifa6:
1060 #ifdef CONFIG_INET
1061         unregister_inetaddr_notifier(&local->ifa_notifier);
1062 #endif
1063 #endif
1064 #if defined(CONFIG_INET) || defined(CONFIG_IPV6)
1065  fail_ifa:
1066         pm_qos_remove_notifier(PM_QOS_NETWORK_LATENCY,
1067                                &local->network_latency_notifier);
1068         rtnl_lock();
1069 #endif
1070  fail_pm_qos:
1071         ieee80211_led_exit(local);
1072         ieee80211_remove_interfaces(local);
1073  fail_rate:
1074         rtnl_unlock();
1075         ieee80211_wep_free(local);
1076         sta_info_stop(local);
1077         destroy_workqueue(local->workqueue);
1078  fail_workqueue:
1079         wiphy_unregister(local->hw.wiphy);
1080  fail_wiphy_register:
1081         if (local->wiphy_ciphers_allocated)
1082                 kfree(local->hw.wiphy->cipher_suites);
1083         kfree(local->int_scan_req);
1084         return result;
1085 }
1086 EXPORT_SYMBOL(ieee80211_register_hw);
1087
1088 void ieee80211_napi_add(struct ieee80211_hw *hw, struct napi_struct *napi,
1089                         struct net_device *napi_dev,
1090                         int (*poll)(struct napi_struct *, int),
1091                         int weight)
1092 {
1093         struct ieee80211_local *local = hw_to_local(hw);
1094
1095         netif_napi_add(napi_dev, napi, poll, weight);
1096         local->napi = napi;
1097 }
1098 EXPORT_SYMBOL_GPL(ieee80211_napi_add);
1099
1100 void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1101 {
1102         struct ieee80211_local *local = hw_to_local(hw);
1103
1104         tasklet_kill(&local->tx_pending_tasklet);
1105         tasklet_kill(&local->tasklet);
1106
1107         pm_qos_remove_notifier(PM_QOS_NETWORK_LATENCY,
1108                                &local->network_latency_notifier);
1109 #ifdef CONFIG_INET
1110         unregister_inetaddr_notifier(&local->ifa_notifier);
1111 #endif
1112 #if IS_ENABLED(CONFIG_IPV6)
1113         unregister_inet6addr_notifier(&local->ifa6_notifier);
1114 #endif
1115
1116         rtnl_lock();
1117
1118         /*
1119          * At this point, interface list manipulations are fine
1120          * because the driver cannot be handing us frames any
1121          * more and the tasklet is killed.
1122          */
1123         ieee80211_remove_interfaces(local);
1124
1125         rtnl_unlock();
1126
1127         cancel_work_sync(&local->restart_work);
1128         cancel_work_sync(&local->reconfig_filter);
1129         flush_work(&local->sched_scan_stopped_work);
1130
1131         ieee80211_clear_tx_pending(local);
1132         rate_control_deinitialize(local);
1133
1134         if (skb_queue_len(&local->skb_queue) ||
1135             skb_queue_len(&local->skb_queue_unreliable))
1136                 wiphy_warn(local->hw.wiphy, "skb_queue not empty\n");
1137         skb_queue_purge(&local->skb_queue);
1138         skb_queue_purge(&local->skb_queue_unreliable);
1139
1140         destroy_workqueue(local->workqueue);
1141         wiphy_unregister(local->hw.wiphy);
1142         sta_info_stop(local);
1143         ieee80211_wep_free(local);
1144         ieee80211_led_exit(local);
1145         kfree(local->int_scan_req);
1146 }
1147 EXPORT_SYMBOL(ieee80211_unregister_hw);
1148
1149 static int ieee80211_free_ack_frame(int id, void *p, void *data)
1150 {
1151         WARN_ONCE(1, "Have pending ack frames!\n");
1152         kfree_skb(p);
1153         return 0;
1154 }
1155
1156 void ieee80211_free_hw(struct ieee80211_hw *hw)
1157 {
1158         struct ieee80211_local *local = hw_to_local(hw);
1159
1160         mutex_destroy(&local->iflist_mtx);
1161         mutex_destroy(&local->mtx);
1162
1163         if (local->wiphy_ciphers_allocated)
1164                 kfree(local->hw.wiphy->cipher_suites);
1165
1166         idr_for_each(&local->ack_status_frames,
1167                      ieee80211_free_ack_frame, NULL);
1168         idr_destroy(&local->ack_status_frames);
1169
1170         kfree(rcu_access_pointer(local->tx_latency));
1171
1172         wiphy_free(local->hw.wiphy);
1173 }
1174 EXPORT_SYMBOL(ieee80211_free_hw);
1175
1176 static int __init ieee80211_init(void)
1177 {
1178         struct sk_buff *skb;
1179         int ret;
1180
1181         BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb));
1182         BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) +
1183                      IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb));
1184
1185         ret = rc80211_minstrel_init();
1186         if (ret)
1187                 return ret;
1188
1189         ret = rc80211_minstrel_ht_init();
1190         if (ret)
1191                 goto err_minstrel;
1192
1193         ret = rc80211_pid_init();
1194         if (ret)
1195                 goto err_pid;
1196
1197         ret = ieee80211_iface_init();
1198         if (ret)
1199                 goto err_netdev;
1200
1201         return 0;
1202  err_netdev:
1203         rc80211_pid_exit();
1204  err_pid:
1205         rc80211_minstrel_ht_exit();
1206  err_minstrel:
1207         rc80211_minstrel_exit();
1208
1209         return ret;
1210 }
1211
1212 static void __exit ieee80211_exit(void)
1213 {
1214         rc80211_pid_exit();
1215         rc80211_minstrel_ht_exit();
1216         rc80211_minstrel_exit();
1217
1218         ieee80211s_stop();
1219
1220         ieee80211_iface_exit();
1221
1222         rcu_barrier();
1223 }
1224
1225
1226 subsys_initcall(ieee80211_init);
1227 module_exit(ieee80211_exit);
1228
1229 MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1230 MODULE_LICENSE("GPL");