blob: 17fe39049740ddd6bb9914884be34b44c963b6b6 [file] [log] [blame]
Johannes Berg704232c2007-04-23 12:20:05 -07001/*
2 * This is the linux wireless configuration interface.
3 *
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07004 * Copyright 2006-2008 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg704232c2007-04-23 12:20:05 -07005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Johannes Berg704232c2007-04-23 12:20:05 -070010#include <linux/list.h>
11#include <linux/nl80211.h>
12#include <linux/debugfs.h>
13#include <linux/notifier.h>
14#include <linux/device.h>
15#include <net/genetlink.h>
16#include <net/cfg80211.h>
17#include <net/wireless.h>
Johannes Berg55682962007-09-20 13:09:35 -040018#include "nl80211.h"
Johannes Berg704232c2007-04-23 12:20:05 -070019#include "core.h"
20#include "sysfs.h"
21
22/* name for sysfs, %d is appended */
23#define PHY_NAME "phy"
24
25MODULE_AUTHOR("Johannes Berg");
26MODULE_LICENSE("GPL");
27MODULE_DESCRIPTION("wireless configuration support");
28
29/* RCU might be appropriate here since we usually
30 * only read the list, and that can happen quite
31 * often because we need to do it for each command */
32LIST_HEAD(cfg80211_drv_list);
Luis R. Rodrigueza1794392009-02-21 00:04:21 -050033
34/*
Luis R. Rodrigueze38f8a72009-02-21 00:20:39 -050035 * This is used to protect the cfg80211_drv_list, cfg80211_regdomain,
36 * country_ie_regdomain, the reg_beacon_list and the the last regulatory
37 * request receipt (last_request).
Luis R. Rodrigueza1794392009-02-21 00:04:21 -050038 */
39DEFINE_MUTEX(cfg80211_mutex);
Johannes Berg704232c2007-04-23 12:20:05 -070040
41/* for debugfs */
42static struct dentry *ieee80211_debugfs_dir;
43
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -050044/* requires cfg80211_mutex to be held! */
45struct cfg80211_registered_device *cfg80211_drv_by_wiphy_idx(int wiphy_idx)
Johannes Berg55682962007-09-20 13:09:35 -040046{
47 struct cfg80211_registered_device *result = NULL, *drv;
48
Luis R. Rodriguez85fd1292009-02-21 00:04:20 -050049 if (!wiphy_idx_valid(wiphy_idx))
50 return NULL;
51
Luis R. Rodriguez761cf7e2009-02-21 00:04:25 -050052 assert_cfg80211_lock();
53
Johannes Berg55682962007-09-20 13:09:35 -040054 list_for_each_entry(drv, &cfg80211_drv_list, list) {
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -050055 if (drv->wiphy_idx == wiphy_idx) {
Johannes Berg55682962007-09-20 13:09:35 -040056 result = drv;
57 break;
58 }
59 }
60
61 return result;
62}
63
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -050064int get_wiphy_idx(struct wiphy *wiphy)
65{
66 struct cfg80211_registered_device *drv;
67 if (!wiphy)
68 return WIPHY_IDX_STALE;
69 drv = wiphy_to_dev(wiphy);
70 return drv->wiphy_idx;
71}
72
73/* requires cfg80211_drv_mutex to be held! */
74struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx)
75{
76 struct cfg80211_registered_device *drv;
77
78 if (!wiphy_idx_valid(wiphy_idx))
79 return NULL;
80
81 assert_cfg80211_lock();
82
83 drv = cfg80211_drv_by_wiphy_idx(wiphy_idx);
84 if (!drv)
85 return NULL;
86 return &drv->wiphy;
87}
88
Luis R. Rodrigueza1794392009-02-21 00:04:21 -050089/* requires cfg80211_mutex to be held! */
Johannes Berg55682962007-09-20 13:09:35 -040090static struct cfg80211_registered_device *
91__cfg80211_drv_from_info(struct genl_info *info)
92{
93 int ifindex;
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -050094 struct cfg80211_registered_device *bywiphyidx = NULL, *byifidx = NULL;
Johannes Berg55682962007-09-20 13:09:35 -040095 struct net_device *dev;
96 int err = -EINVAL;
97
Luis R. Rodriguez761cf7e2009-02-21 00:04:25 -050098 assert_cfg80211_lock();
99
Johannes Berg55682962007-09-20 13:09:35 -0400100 if (info->attrs[NL80211_ATTR_WIPHY]) {
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500101 bywiphyidx = cfg80211_drv_by_wiphy_idx(
Johannes Berg55682962007-09-20 13:09:35 -0400102 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY]));
103 err = -ENODEV;
104 }
105
106 if (info->attrs[NL80211_ATTR_IFINDEX]) {
107 ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
108 dev = dev_get_by_index(&init_net, ifindex);
109 if (dev) {
110 if (dev->ieee80211_ptr)
111 byifidx =
112 wiphy_to_dev(dev->ieee80211_ptr->wiphy);
113 dev_put(dev);
114 }
115 err = -ENODEV;
116 }
117
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500118 if (bywiphyidx && byifidx) {
119 if (bywiphyidx != byifidx)
Johannes Berg55682962007-09-20 13:09:35 -0400120 return ERR_PTR(-EINVAL);
121 else
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500122 return bywiphyidx; /* == byifidx */
Johannes Berg55682962007-09-20 13:09:35 -0400123 }
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500124 if (bywiphyidx)
125 return bywiphyidx;
Johannes Berg55682962007-09-20 13:09:35 -0400126
127 if (byifidx)
128 return byifidx;
129
130 return ERR_PTR(err);
131}
132
133struct cfg80211_registered_device *
134cfg80211_get_dev_from_info(struct genl_info *info)
135{
136 struct cfg80211_registered_device *drv;
137
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500138 mutex_lock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -0400139 drv = __cfg80211_drv_from_info(info);
140
141 /* if it is not an error we grab the lock on
142 * it to assure it won't be going away while
143 * we operate on it */
144 if (!IS_ERR(drv))
145 mutex_lock(&drv->mtx);
146
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500147 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -0400148
149 return drv;
150}
151
152struct cfg80211_registered_device *
153cfg80211_get_dev_from_ifindex(int ifindex)
154{
155 struct cfg80211_registered_device *drv = ERR_PTR(-ENODEV);
156 struct net_device *dev;
157
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500158 mutex_lock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -0400159 dev = dev_get_by_index(&init_net, ifindex);
160 if (!dev)
161 goto out;
162 if (dev->ieee80211_ptr) {
163 drv = wiphy_to_dev(dev->ieee80211_ptr->wiphy);
164 mutex_lock(&drv->mtx);
165 } else
166 drv = ERR_PTR(-ENODEV);
167 dev_put(dev);
168 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500169 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -0400170 return drv;
171}
172
173void cfg80211_put_dev(struct cfg80211_registered_device *drv)
174{
175 BUG_ON(IS_ERR(drv));
176 mutex_unlock(&drv->mtx);
177}
178
179int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
180 char *newname)
181{
Eric W. Biederman2940bb62008-05-08 14:30:18 -0700182 struct cfg80211_registered_device *drv;
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500183 int wiphy_idx, taken = -1, result, digits;
Johannes Berg55682962007-09-20 13:09:35 -0400184
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500185 mutex_lock(&cfg80211_mutex);
Eric W. Biederman2940bb62008-05-08 14:30:18 -0700186
Johannes Berg55682962007-09-20 13:09:35 -0400187 /* prohibit calling the thing phy%d when %d is not its number */
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500188 sscanf(newname, PHY_NAME "%d%n", &wiphy_idx, &taken);
189 if (taken == strlen(newname) && wiphy_idx != rdev->wiphy_idx) {
190 /* count number of places needed to print wiphy_idx */
Johannes Berg55682962007-09-20 13:09:35 -0400191 digits = 1;
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500192 while (wiphy_idx /= 10)
Johannes Berg55682962007-09-20 13:09:35 -0400193 digits++;
194 /*
195 * deny the name if it is phy<idx> where <idx> is printed
196 * without leading zeroes. taken == strlen(newname) here
197 */
Eric W. Biederman2940bb62008-05-08 14:30:18 -0700198 result = -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -0400199 if (taken == strlen(PHY_NAME) + digits)
Eric W. Biederman2940bb62008-05-08 14:30:18 -0700200 goto out_unlock;
Johannes Berg55682962007-09-20 13:09:35 -0400201 }
202
Eric W. Biederman2940bb62008-05-08 14:30:18 -0700203
204 /* Ignore nop renames */
205 result = 0;
206 if (strcmp(newname, dev_name(&rdev->wiphy.dev)) == 0)
207 goto out_unlock;
208
209 /* Ensure another device does not already have this name. */
210 list_for_each_entry(drv, &cfg80211_drv_list, list) {
211 result = -EINVAL;
212 if (strcmp(newname, dev_name(&drv->wiphy.dev)) == 0)
213 goto out_unlock;
214 }
215
216 /* this will only check for collisions in sysfs
217 * which is not even always compiled in.
218 */
Johannes Berg55682962007-09-20 13:09:35 -0400219 result = device_rename(&rdev->wiphy.dev, newname);
220 if (result)
Eric W. Biederman2940bb62008-05-08 14:30:18 -0700221 goto out_unlock;
Johannes Berg55682962007-09-20 13:09:35 -0400222
Johannes Berg33c03602008-10-08 10:23:48 +0200223 if (rdev->wiphy.debugfsdir &&
224 !debugfs_rename(rdev->wiphy.debugfsdir->d_parent,
Johannes Berg55682962007-09-20 13:09:35 -0400225 rdev->wiphy.debugfsdir,
226 rdev->wiphy.debugfsdir->d_parent,
227 newname))
228 printk(KERN_ERR "cfg80211: failed to rename debugfs dir to %s!\n",
229 newname);
230
Eric W. Biederman2940bb62008-05-08 14:30:18 -0700231 result = 0;
232out_unlock:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500233 mutex_unlock(&cfg80211_mutex);
Eric W. Biederman2940bb62008-05-08 14:30:18 -0700234 if (result == 0)
235 nl80211_notify_dev_rename(rdev);
Johannes Berg55682962007-09-20 13:09:35 -0400236
Eric W. Biederman2940bb62008-05-08 14:30:18 -0700237 return result;
Johannes Berg55682962007-09-20 13:09:35 -0400238}
239
Johannes Berg704232c2007-04-23 12:20:05 -0700240/* exported functions */
241
242struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv)
243{
Denis ChengRq638af072008-09-23 02:35:37 +0800244 static int wiphy_counter;
245
Johannes Berg704232c2007-04-23 12:20:05 -0700246 struct cfg80211_registered_device *drv;
247 int alloc_size;
248
Johannes Berg41ade002007-12-19 02:03:29 +0100249 WARN_ON(!ops->add_key && ops->del_key);
250 WARN_ON(ops->add_key && !ops->del_key);
251
Johannes Berg704232c2007-04-23 12:20:05 -0700252 alloc_size = sizeof(*drv) + sizeof_priv;
253
254 drv = kzalloc(alloc_size, GFP_KERNEL);
255 if (!drv)
256 return NULL;
257
258 drv->ops = ops;
259
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500260 mutex_lock(&cfg80211_mutex);
Johannes Berg704232c2007-04-23 12:20:05 -0700261
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500262 drv->wiphy_idx = wiphy_counter++;
Johannes Berga4d73ee2007-04-26 20:50:35 -0700263
Luis R. Rodriguez85fd1292009-02-21 00:04:20 -0500264 if (unlikely(!wiphy_idx_valid(drv->wiphy_idx))) {
Denis ChengRq638af072008-09-23 02:35:37 +0800265 wiphy_counter--;
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500266 mutex_unlock(&cfg80211_mutex);
Johannes Berg704232c2007-04-23 12:20:05 -0700267 /* ugh, wrapped! */
268 kfree(drv);
269 return NULL;
270 }
Johannes Berg704232c2007-04-23 12:20:05 -0700271
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500272 mutex_unlock(&cfg80211_mutex);
Denis ChengRq638af072008-09-23 02:35:37 +0800273
Johannes Berg704232c2007-04-23 12:20:05 -0700274 /* give it a proper name */
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500275 dev_set_name(&drv->wiphy.dev, PHY_NAME "%d", drv->wiphy_idx);
Johannes Berg704232c2007-04-23 12:20:05 -0700276
Johannes Berg704232c2007-04-23 12:20:05 -0700277 mutex_init(&drv->mtx);
278 mutex_init(&drv->devlist_mtx);
279 INIT_LIST_HEAD(&drv->netdev_list);
Johannes Berg2a519312009-02-10 21:25:55 +0100280 spin_lock_init(&drv->bss_lock);
281 INIT_LIST_HEAD(&drv->bss_list);
Johannes Berg704232c2007-04-23 12:20:05 -0700282
283 device_initialize(&drv->wiphy.dev);
284 drv->wiphy.dev.class = &ieee80211_class;
285 drv->wiphy.dev.platform_data = drv;
286
287 return &drv->wiphy;
288}
289EXPORT_SYMBOL(wiphy_new);
290
291int wiphy_register(struct wiphy *wiphy)
292{
293 struct cfg80211_registered_device *drv = wiphy_to_dev(wiphy);
294 int res;
Johannes Berg8318d782008-01-24 19:38:38 +0100295 enum ieee80211_band band;
296 struct ieee80211_supported_band *sband;
297 bool have_band = false;
298 int i;
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700299 u16 ifmodes = wiphy->interface_modes;
300
Johannes Berg2a519312009-02-10 21:25:55 +0100301 if (WARN_ON(wiphy->max_scan_ssids < 1))
302 return -EINVAL;
303
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700304 /* sanity check ifmodes */
305 WARN_ON(!ifmodes);
306 ifmodes &= ((1 << __NL80211_IFTYPE_AFTER_LAST) - 1) & ~1;
307 if (WARN_ON(ifmodes != wiphy->interface_modes))
308 wiphy->interface_modes = ifmodes;
Johannes Berg8318d782008-01-24 19:38:38 +0100309
310 /* sanity check supported bands/channels */
311 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
312 sband = wiphy->bands[band];
313 if (!sband)
314 continue;
315
316 sband->band = band;
317
Johannes Berg881d9482009-01-21 15:13:48 +0100318 if (WARN_ON(!sband->n_channels || !sband->n_bitrates))
Johannes Berg8318d782008-01-24 19:38:38 +0100319 return -EINVAL;
Johannes Berg881d9482009-01-21 15:13:48 +0100320
321 /*
322 * Since we use a u32 for rate bitmaps in
323 * ieee80211_get_response_rate, we cannot
324 * have more than 32 legacy rates.
325 */
326 if (WARN_ON(sband->n_bitrates > 32))
327 return -EINVAL;
Johannes Berg8318d782008-01-24 19:38:38 +0100328
329 for (i = 0; i < sband->n_channels; i++) {
330 sband->channels[i].orig_flags =
331 sband->channels[i].flags;
332 sband->channels[i].orig_mag =
333 sband->channels[i].max_antenna_gain;
334 sband->channels[i].orig_mpwr =
335 sband->channels[i].max_power;
336 sband->channels[i].band = band;
337 }
338
339 have_band = true;
340 }
341
342 if (!have_band) {
343 WARN_ON(1);
344 return -EINVAL;
345 }
346
347 /* check and set up bitrates */
348 ieee80211_set_bitrate_flags(wiphy);
349
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500350 mutex_lock(&cfg80211_mutex);
Johannes Berg704232c2007-04-23 12:20:05 -0700351
Johannes Bergf3b407f2008-10-21 09:57:41 +0200352 /* set up regulatory info */
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -0400353 wiphy_update_regulatory(wiphy, NL80211_REGDOM_SET_BY_CORE);
Johannes Bergf3b407f2008-10-21 09:57:41 +0200354
Johannes Berg704232c2007-04-23 12:20:05 -0700355 res = device_add(&drv->wiphy.dev);
356 if (res)
357 goto out_unlock;
358
359 list_add(&drv->list, &cfg80211_drv_list);
360
361 /* add to debugfs */
362 drv->wiphy.debugfsdir =
363 debugfs_create_dir(wiphy_name(&drv->wiphy),
364 ieee80211_debugfs_dir);
Johannes Berg33c03602008-10-08 10:23:48 +0200365 if (IS_ERR(drv->wiphy.debugfsdir))
366 drv->wiphy.debugfsdir = NULL;
Johannes Berg704232c2007-04-23 12:20:05 -0700367
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -0400368 if (wiphy->custom_regulatory) {
369 struct regulatory_request request;
370
371 request.wiphy_idx = get_wiphy_idx(wiphy);
372 request.initiator = NL80211_REGDOM_SET_BY_DRIVER;
373 request.alpha2[0] = '9';
374 request.alpha2[1] = '9';
375
376 nl80211_send_reg_change_event(&request);
377 }
378
Johannes Berg704232c2007-04-23 12:20:05 -0700379 res = 0;
380out_unlock:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500381 mutex_unlock(&cfg80211_mutex);
Johannes Berg704232c2007-04-23 12:20:05 -0700382 return res;
383}
384EXPORT_SYMBOL(wiphy_register);
385
386void wiphy_unregister(struct wiphy *wiphy)
387{
388 struct cfg80211_registered_device *drv = wiphy_to_dev(wiphy);
389
Johannes Bergf16bfc12007-04-26 20:51:12 -0700390 /* protect the device list */
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500391 mutex_lock(&cfg80211_mutex);
Johannes Berg704232c2007-04-23 12:20:05 -0700392
Johannes Bergf16bfc12007-04-26 20:51:12 -0700393 BUG_ON(!list_empty(&drv->netdev_list));
394
395 /*
396 * Try to grab drv->mtx. If a command is still in progress,
397 * hopefully the driver will refuse it since it's tearing
398 * down the device already. We wait for this command to complete
399 * before unlinking the item from the list.
400 * Note: as codified by the BUG_ON above we cannot get here if
401 * a virtual interface is still associated. Hence, we can only
402 * get to lock contention here if userspace issues a command
403 * that identified the hardware by wiphy index.
404 */
Johannes Berg704232c2007-04-23 12:20:05 -0700405 mutex_lock(&drv->mtx);
Johannes Bergf16bfc12007-04-26 20:51:12 -0700406 /* unlock again before freeing */
Johannes Berg704232c2007-04-23 12:20:05 -0700407 mutex_unlock(&drv->mtx);
408
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800409 /* If this device got a regulatory hint tell core its
410 * free to listen now to a new shiny device regulatory hint */
411 reg_device_remove(wiphy);
412
Johannes Bergf16bfc12007-04-26 20:51:12 -0700413 list_del(&drv->list);
Johannes Berg704232c2007-04-23 12:20:05 -0700414 device_del(&drv->wiphy.dev);
415 debugfs_remove(drv->wiphy.debugfsdir);
416
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500417 mutex_unlock(&cfg80211_mutex);
Johannes Berg704232c2007-04-23 12:20:05 -0700418}
419EXPORT_SYMBOL(wiphy_unregister);
420
421void cfg80211_dev_free(struct cfg80211_registered_device *drv)
422{
Johannes Berg2a519312009-02-10 21:25:55 +0100423 struct cfg80211_internal_bss *scan, *tmp;
Johannes Berg704232c2007-04-23 12:20:05 -0700424 mutex_destroy(&drv->mtx);
425 mutex_destroy(&drv->devlist_mtx);
Johannes Berg2a519312009-02-10 21:25:55 +0100426 list_for_each_entry_safe(scan, tmp, &drv->bss_list, list)
Johannes Berg78c1c7e2009-02-10 21:25:57 +0100427 cfg80211_put_bss(&scan->pub);
Johannes Berg704232c2007-04-23 12:20:05 -0700428 kfree(drv);
429}
430
431void wiphy_free(struct wiphy *wiphy)
432{
433 put_device(&wiphy->dev);
434}
435EXPORT_SYMBOL(wiphy_free);
436
437static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
438 unsigned long state,
439 void *ndev)
440{
441 struct net_device *dev = ndev;
442 struct cfg80211_registered_device *rdev;
443
444 if (!dev->ieee80211_ptr)
445 return 0;
446
447 rdev = wiphy_to_dev(dev->ieee80211_ptr->wiphy);
448
Johannes Berg60719ff2008-09-16 14:55:09 +0200449 WARN_ON(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_UNSPECIFIED);
450
Johannes Berg704232c2007-04-23 12:20:05 -0700451 switch (state) {
452 case NETDEV_REGISTER:
453 mutex_lock(&rdev->devlist_mtx);
454 list_add(&dev->ieee80211_ptr->list, &rdev->netdev_list);
455 if (sysfs_create_link(&dev->dev.kobj, &rdev->wiphy.dev.kobj,
456 "phy80211")) {
457 printk(KERN_ERR "wireless: failed to add phy80211 "
458 "symlink to netdev!\n");
459 }
460 dev->ieee80211_ptr->netdev = dev;
461 mutex_unlock(&rdev->devlist_mtx);
462 break;
463 case NETDEV_UNREGISTER:
464 mutex_lock(&rdev->devlist_mtx);
465 if (!list_empty(&dev->ieee80211_ptr->list)) {
466 sysfs_remove_link(&dev->dev.kobj, "phy80211");
467 list_del_init(&dev->ieee80211_ptr->list);
468 }
469 mutex_unlock(&rdev->devlist_mtx);
470 break;
471 }
472
473 return 0;
474}
475
476static struct notifier_block cfg80211_netdev_notifier = {
477 .notifier_call = cfg80211_netdev_notifier_call,
478};
479
480static int cfg80211_init(void)
481{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700482 int err;
483
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700484 err = wiphy_sysfs_init();
Johannes Berg704232c2007-04-23 12:20:05 -0700485 if (err)
486 goto out_fail_sysfs;
487
488 err = register_netdevice_notifier(&cfg80211_netdev_notifier);
489 if (err)
490 goto out_fail_notifier;
491
Johannes Berg55682962007-09-20 13:09:35 -0400492 err = nl80211_init();
493 if (err)
494 goto out_fail_nl80211;
495
Johannes Berg704232c2007-04-23 12:20:05 -0700496 ieee80211_debugfs_dir = debugfs_create_dir("ieee80211", NULL);
497
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700498 err = regulatory_init();
499 if (err)
500 goto out_fail_reg;
501
Johannes Berg704232c2007-04-23 12:20:05 -0700502 return 0;
503
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700504out_fail_reg:
505 debugfs_remove(ieee80211_debugfs_dir);
Johannes Berg55682962007-09-20 13:09:35 -0400506out_fail_nl80211:
507 unregister_netdevice_notifier(&cfg80211_netdev_notifier);
Johannes Berg704232c2007-04-23 12:20:05 -0700508out_fail_notifier:
509 wiphy_sysfs_exit();
510out_fail_sysfs:
511 return err;
512}
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700513
Johannes Berg3a462462007-09-10 13:44:45 +0200514subsys_initcall(cfg80211_init);
Johannes Berg704232c2007-04-23 12:20:05 -0700515
516static void cfg80211_exit(void)
517{
518 debugfs_remove(ieee80211_debugfs_dir);
Johannes Berg55682962007-09-20 13:09:35 -0400519 nl80211_exit();
Johannes Berg704232c2007-04-23 12:20:05 -0700520 unregister_netdevice_notifier(&cfg80211_netdev_notifier);
521 wiphy_sysfs_exit();
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700522 regulatory_exit();
Johannes Berg704232c2007-04-23 12:20:05 -0700523}
524module_exit(cfg80211_exit);