blob: 827a56263551a1a33ce03e4437aedaeea646d2d5 [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>
Johannes Berg55682962007-09-20 13:09:35 -040017#include "nl80211.h"
Johannes Berg704232c2007-04-23 12:20:05 -070018#include "core.h"
19#include "sysfs.h"
20
21/* name for sysfs, %d is appended */
22#define PHY_NAME "phy"
23
24MODULE_AUTHOR("Johannes Berg");
25MODULE_LICENSE("GPL");
26MODULE_DESCRIPTION("wireless configuration support");
27
28/* RCU might be appropriate here since we usually
29 * only read the list, and that can happen quite
30 * often because we need to do it for each command */
31LIST_HEAD(cfg80211_drv_list);
Luis R. Rodrigueza1794392009-02-21 00:04:21 -050032
33/*
Luis R. Rodrigueze38f8a72009-02-21 00:20:39 -050034 * This is used to protect the cfg80211_drv_list, cfg80211_regdomain,
35 * country_ie_regdomain, the reg_beacon_list and the the last regulatory
36 * request receipt (last_request).
Luis R. Rodrigueza1794392009-02-21 00:04:21 -050037 */
38DEFINE_MUTEX(cfg80211_mutex);
Johannes Berg704232c2007-04-23 12:20:05 -070039
40/* for debugfs */
41static struct dentry *ieee80211_debugfs_dir;
42
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -050043/* requires cfg80211_mutex to be held! */
44struct cfg80211_registered_device *cfg80211_drv_by_wiphy_idx(int wiphy_idx)
Johannes Berg55682962007-09-20 13:09:35 -040045{
46 struct cfg80211_registered_device *result = NULL, *drv;
47
Luis R. Rodriguez85fd1292009-02-21 00:04:20 -050048 if (!wiphy_idx_valid(wiphy_idx))
49 return NULL;
50
Luis R. Rodriguez761cf7e2009-02-21 00:04:25 -050051 assert_cfg80211_lock();
52
Johannes Berg55682962007-09-20 13:09:35 -040053 list_for_each_entry(drv, &cfg80211_drv_list, list) {
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -050054 if (drv->wiphy_idx == wiphy_idx) {
Johannes Berg55682962007-09-20 13:09:35 -040055 result = drv;
56 break;
57 }
58 }
59
60 return result;
61}
62
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -050063int get_wiphy_idx(struct wiphy *wiphy)
64{
65 struct cfg80211_registered_device *drv;
66 if (!wiphy)
67 return WIPHY_IDX_STALE;
68 drv = wiphy_to_dev(wiphy);
69 return drv->wiphy_idx;
70}
71
72/* requires cfg80211_drv_mutex to be held! */
73struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx)
74{
75 struct cfg80211_registered_device *drv;
76
77 if (!wiphy_idx_valid(wiphy_idx))
78 return NULL;
79
80 assert_cfg80211_lock();
81
82 drv = cfg80211_drv_by_wiphy_idx(wiphy_idx);
83 if (!drv)
84 return NULL;
85 return &drv->wiphy;
86}
87
Luis R. Rodrigueza1794392009-02-21 00:04:21 -050088/* requires cfg80211_mutex to be held! */
Johannes Berg4bbf4d52009-03-24 09:35:46 +010089struct cfg80211_registered_device *
Johannes Berg55682962007-09-20 13:09:35 -040090__cfg80211_drv_from_info(struct genl_info *info)
91{
92 int ifindex;
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -050093 struct cfg80211_registered_device *bywiphyidx = NULL, *byifidx = NULL;
Johannes Berg55682962007-09-20 13:09:35 -040094 struct net_device *dev;
95 int err = -EINVAL;
96
Luis R. Rodriguez761cf7e2009-02-21 00:04:25 -050097 assert_cfg80211_lock();
98
Johannes Berg55682962007-09-20 13:09:35 -040099 if (info->attrs[NL80211_ATTR_WIPHY]) {
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500100 bywiphyidx = cfg80211_drv_by_wiphy_idx(
Johannes Berg55682962007-09-20 13:09:35 -0400101 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY]));
102 err = -ENODEV;
103 }
104
105 if (info->attrs[NL80211_ATTR_IFINDEX]) {
106 ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
107 dev = dev_get_by_index(&init_net, ifindex);
108 if (dev) {
109 if (dev->ieee80211_ptr)
110 byifidx =
111 wiphy_to_dev(dev->ieee80211_ptr->wiphy);
112 dev_put(dev);
113 }
114 err = -ENODEV;
115 }
116
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500117 if (bywiphyidx && byifidx) {
118 if (bywiphyidx != byifidx)
Johannes Berg55682962007-09-20 13:09:35 -0400119 return ERR_PTR(-EINVAL);
120 else
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500121 return bywiphyidx; /* == byifidx */
Johannes Berg55682962007-09-20 13:09:35 -0400122 }
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500123 if (bywiphyidx)
124 return bywiphyidx;
Johannes Berg55682962007-09-20 13:09:35 -0400125
126 if (byifidx)
127 return byifidx;
128
129 return ERR_PTR(err);
130}
131
132struct cfg80211_registered_device *
133cfg80211_get_dev_from_info(struct genl_info *info)
134{
135 struct cfg80211_registered_device *drv;
136
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500137 mutex_lock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -0400138 drv = __cfg80211_drv_from_info(info);
139
140 /* if it is not an error we grab the lock on
141 * it to assure it won't be going away while
142 * we operate on it */
143 if (!IS_ERR(drv))
144 mutex_lock(&drv->mtx);
145
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500146 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -0400147
148 return drv;
149}
150
151struct cfg80211_registered_device *
152cfg80211_get_dev_from_ifindex(int ifindex)
153{
154 struct cfg80211_registered_device *drv = ERR_PTR(-ENODEV);
155 struct net_device *dev;
156
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500157 mutex_lock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -0400158 dev = dev_get_by_index(&init_net, ifindex);
159 if (!dev)
160 goto out;
161 if (dev->ieee80211_ptr) {
162 drv = wiphy_to_dev(dev->ieee80211_ptr->wiphy);
163 mutex_lock(&drv->mtx);
164 } else
165 drv = ERR_PTR(-ENODEV);
166 dev_put(dev);
167 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500168 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -0400169 return drv;
170}
171
172void cfg80211_put_dev(struct cfg80211_registered_device *drv)
173{
174 BUG_ON(IS_ERR(drv));
175 mutex_unlock(&drv->mtx);
176}
177
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100178/* requires cfg80211_mutex to be held */
Johannes Berg55682962007-09-20 13:09:35 -0400179int 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
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100185 assert_cfg80211_lock();
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 */
198 if (taken == strlen(PHY_NAME) + digits)
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100199 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -0400200 }
201
Eric W. Biederman2940bb62008-05-08 14:30:18 -0700202
203 /* Ignore nop renames */
Eric W. Biederman2940bb62008-05-08 14:30:18 -0700204 if (strcmp(newname, dev_name(&rdev->wiphy.dev)) == 0)
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100205 return 0;
Eric W. Biederman2940bb62008-05-08 14:30:18 -0700206
207 /* Ensure another device does not already have this name. */
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100208 list_for_each_entry(drv, &cfg80211_drv_list, list)
Eric W. Biederman2940bb62008-05-08 14:30:18 -0700209 if (strcmp(newname, dev_name(&drv->wiphy.dev)) == 0)
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100210 return -EINVAL;
Eric W. Biederman2940bb62008-05-08 14:30:18 -0700211
Johannes Berg55682962007-09-20 13:09:35 -0400212 result = device_rename(&rdev->wiphy.dev, newname);
213 if (result)
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100214 return result;
Johannes Berg55682962007-09-20 13:09:35 -0400215
Johannes Berg33c03602008-10-08 10:23:48 +0200216 if (rdev->wiphy.debugfsdir &&
217 !debugfs_rename(rdev->wiphy.debugfsdir->d_parent,
Johannes Berg55682962007-09-20 13:09:35 -0400218 rdev->wiphy.debugfsdir,
219 rdev->wiphy.debugfsdir->d_parent,
220 newname))
221 printk(KERN_ERR "cfg80211: failed to rename debugfs dir to %s!\n",
222 newname);
223
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100224 nl80211_notify_dev_rename(rdev);
Johannes Berg55682962007-09-20 13:09:35 -0400225
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100226 return 0;
Johannes Berg55682962007-09-20 13:09:35 -0400227}
228
Johannes Berg704232c2007-04-23 12:20:05 -0700229/* exported functions */
230
231struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv)
232{
Denis ChengRq638af072008-09-23 02:35:37 +0800233 static int wiphy_counter;
234
Johannes Berg704232c2007-04-23 12:20:05 -0700235 struct cfg80211_registered_device *drv;
236 int alloc_size;
237
Johannes Berg41ade002007-12-19 02:03:29 +0100238 WARN_ON(!ops->add_key && ops->del_key);
239 WARN_ON(ops->add_key && !ops->del_key);
240
Johannes Berg704232c2007-04-23 12:20:05 -0700241 alloc_size = sizeof(*drv) + sizeof_priv;
242
243 drv = kzalloc(alloc_size, GFP_KERNEL);
244 if (!drv)
245 return NULL;
246
247 drv->ops = ops;
248
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500249 mutex_lock(&cfg80211_mutex);
Johannes Berg704232c2007-04-23 12:20:05 -0700250
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500251 drv->wiphy_idx = wiphy_counter++;
Johannes Berga4d73ee2007-04-26 20:50:35 -0700252
Luis R. Rodriguez85fd1292009-02-21 00:04:20 -0500253 if (unlikely(!wiphy_idx_valid(drv->wiphy_idx))) {
Denis ChengRq638af072008-09-23 02:35:37 +0800254 wiphy_counter--;
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500255 mutex_unlock(&cfg80211_mutex);
Johannes Berg704232c2007-04-23 12:20:05 -0700256 /* ugh, wrapped! */
257 kfree(drv);
258 return NULL;
259 }
Johannes Berg704232c2007-04-23 12:20:05 -0700260
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500261 mutex_unlock(&cfg80211_mutex);
Denis ChengRq638af072008-09-23 02:35:37 +0800262
Johannes Berg704232c2007-04-23 12:20:05 -0700263 /* give it a proper name */
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500264 dev_set_name(&drv->wiphy.dev, PHY_NAME "%d", drv->wiphy_idx);
Johannes Berg704232c2007-04-23 12:20:05 -0700265
Johannes Berg704232c2007-04-23 12:20:05 -0700266 mutex_init(&drv->mtx);
267 mutex_init(&drv->devlist_mtx);
268 INIT_LIST_HEAD(&drv->netdev_list);
Johannes Berg2a519312009-02-10 21:25:55 +0100269 spin_lock_init(&drv->bss_lock);
270 INIT_LIST_HEAD(&drv->bss_list);
Johannes Berg704232c2007-04-23 12:20:05 -0700271
272 device_initialize(&drv->wiphy.dev);
273 drv->wiphy.dev.class = &ieee80211_class;
274 drv->wiphy.dev.platform_data = drv;
275
276 return &drv->wiphy;
277}
278EXPORT_SYMBOL(wiphy_new);
279
280int wiphy_register(struct wiphy *wiphy)
281{
282 struct cfg80211_registered_device *drv = wiphy_to_dev(wiphy);
283 int res;
Johannes Berg8318d782008-01-24 19:38:38 +0100284 enum ieee80211_band band;
285 struct ieee80211_supported_band *sband;
286 bool have_band = false;
287 int i;
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700288 u16 ifmodes = wiphy->interface_modes;
289
Johannes Berg2a519312009-02-10 21:25:55 +0100290 if (WARN_ON(wiphy->max_scan_ssids < 1))
291 return -EINVAL;
292
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700293 /* sanity check ifmodes */
294 WARN_ON(!ifmodes);
295 ifmodes &= ((1 << __NL80211_IFTYPE_AFTER_LAST) - 1) & ~1;
296 if (WARN_ON(ifmodes != wiphy->interface_modes))
297 wiphy->interface_modes = ifmodes;
Johannes Berg8318d782008-01-24 19:38:38 +0100298
299 /* sanity check supported bands/channels */
300 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
301 sband = wiphy->bands[band];
302 if (!sband)
303 continue;
304
305 sband->band = band;
306
Johannes Berg881d9482009-01-21 15:13:48 +0100307 if (WARN_ON(!sband->n_channels || !sband->n_bitrates))
Johannes Berg8318d782008-01-24 19:38:38 +0100308 return -EINVAL;
Johannes Berg881d9482009-01-21 15:13:48 +0100309
310 /*
311 * Since we use a u32 for rate bitmaps in
312 * ieee80211_get_response_rate, we cannot
313 * have more than 32 legacy rates.
314 */
315 if (WARN_ON(sband->n_bitrates > 32))
316 return -EINVAL;
Johannes Berg8318d782008-01-24 19:38:38 +0100317
318 for (i = 0; i < sband->n_channels; i++) {
319 sband->channels[i].orig_flags =
320 sband->channels[i].flags;
321 sband->channels[i].orig_mag =
322 sband->channels[i].max_antenna_gain;
323 sband->channels[i].orig_mpwr =
324 sband->channels[i].max_power;
325 sband->channels[i].band = band;
326 }
327
328 have_band = true;
329 }
330
331 if (!have_band) {
332 WARN_ON(1);
333 return -EINVAL;
334 }
335
336 /* check and set up bitrates */
337 ieee80211_set_bitrate_flags(wiphy);
338
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500339 mutex_lock(&cfg80211_mutex);
Johannes Berg704232c2007-04-23 12:20:05 -0700340
Johannes Bergf3b407f2008-10-21 09:57:41 +0200341 /* set up regulatory info */
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -0400342 wiphy_update_regulatory(wiphy, NL80211_REGDOM_SET_BY_CORE);
Johannes Bergf3b407f2008-10-21 09:57:41 +0200343
Johannes Berg704232c2007-04-23 12:20:05 -0700344 res = device_add(&drv->wiphy.dev);
345 if (res)
346 goto out_unlock;
347
348 list_add(&drv->list, &cfg80211_drv_list);
349
350 /* add to debugfs */
351 drv->wiphy.debugfsdir =
352 debugfs_create_dir(wiphy_name(&drv->wiphy),
353 ieee80211_debugfs_dir);
Johannes Berg33c03602008-10-08 10:23:48 +0200354 if (IS_ERR(drv->wiphy.debugfsdir))
355 drv->wiphy.debugfsdir = NULL;
Johannes Berg704232c2007-04-23 12:20:05 -0700356
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -0400357 if (wiphy->custom_regulatory) {
358 struct regulatory_request request;
359
360 request.wiphy_idx = get_wiphy_idx(wiphy);
361 request.initiator = NL80211_REGDOM_SET_BY_DRIVER;
362 request.alpha2[0] = '9';
363 request.alpha2[1] = '9';
364
365 nl80211_send_reg_change_event(&request);
366 }
367
Johannes Berg704232c2007-04-23 12:20:05 -0700368 res = 0;
369out_unlock:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500370 mutex_unlock(&cfg80211_mutex);
Johannes Berg704232c2007-04-23 12:20:05 -0700371 return res;
372}
373EXPORT_SYMBOL(wiphy_register);
374
375void wiphy_unregister(struct wiphy *wiphy)
376{
377 struct cfg80211_registered_device *drv = wiphy_to_dev(wiphy);
378
Johannes Bergf16bfc12007-04-26 20:51:12 -0700379 /* protect the device list */
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500380 mutex_lock(&cfg80211_mutex);
Johannes Berg704232c2007-04-23 12:20:05 -0700381
Johannes Bergf16bfc12007-04-26 20:51:12 -0700382 BUG_ON(!list_empty(&drv->netdev_list));
383
384 /*
385 * Try to grab drv->mtx. If a command is still in progress,
386 * hopefully the driver will refuse it since it's tearing
387 * down the device already. We wait for this command to complete
388 * before unlinking the item from the list.
389 * Note: as codified by the BUG_ON above we cannot get here if
390 * a virtual interface is still associated. Hence, we can only
391 * get to lock contention here if userspace issues a command
392 * that identified the hardware by wiphy index.
393 */
Johannes Berg704232c2007-04-23 12:20:05 -0700394 mutex_lock(&drv->mtx);
Johannes Bergf16bfc12007-04-26 20:51:12 -0700395 /* unlock again before freeing */
Johannes Berg704232c2007-04-23 12:20:05 -0700396 mutex_unlock(&drv->mtx);
397
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800398 /* If this device got a regulatory hint tell core its
399 * free to listen now to a new shiny device regulatory hint */
400 reg_device_remove(wiphy);
401
Johannes Bergf16bfc12007-04-26 20:51:12 -0700402 list_del(&drv->list);
Johannes Berg704232c2007-04-23 12:20:05 -0700403 device_del(&drv->wiphy.dev);
404 debugfs_remove(drv->wiphy.debugfsdir);
405
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500406 mutex_unlock(&cfg80211_mutex);
Johannes Berg704232c2007-04-23 12:20:05 -0700407}
408EXPORT_SYMBOL(wiphy_unregister);
409
410void cfg80211_dev_free(struct cfg80211_registered_device *drv)
411{
Johannes Berg2a519312009-02-10 21:25:55 +0100412 struct cfg80211_internal_bss *scan, *tmp;
Johannes Berg704232c2007-04-23 12:20:05 -0700413 mutex_destroy(&drv->mtx);
414 mutex_destroy(&drv->devlist_mtx);
Johannes Berg2a519312009-02-10 21:25:55 +0100415 list_for_each_entry_safe(scan, tmp, &drv->bss_list, list)
Johannes Berg78c1c7e2009-02-10 21:25:57 +0100416 cfg80211_put_bss(&scan->pub);
Johannes Berg704232c2007-04-23 12:20:05 -0700417 kfree(drv);
418}
419
420void wiphy_free(struct wiphy *wiphy)
421{
422 put_device(&wiphy->dev);
423}
424EXPORT_SYMBOL(wiphy_free);
425
426static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
427 unsigned long state,
428 void *ndev)
429{
430 struct net_device *dev = ndev;
431 struct cfg80211_registered_device *rdev;
432
433 if (!dev->ieee80211_ptr)
434 return 0;
435
436 rdev = wiphy_to_dev(dev->ieee80211_ptr->wiphy);
437
Johannes Berg60719ff2008-09-16 14:55:09 +0200438 WARN_ON(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_UNSPECIFIED);
439
Johannes Berg704232c2007-04-23 12:20:05 -0700440 switch (state) {
441 case NETDEV_REGISTER:
442 mutex_lock(&rdev->devlist_mtx);
443 list_add(&dev->ieee80211_ptr->list, &rdev->netdev_list);
444 if (sysfs_create_link(&dev->dev.kobj, &rdev->wiphy.dev.kobj,
445 "phy80211")) {
446 printk(KERN_ERR "wireless: failed to add phy80211 "
447 "symlink to netdev!\n");
448 }
449 dev->ieee80211_ptr->netdev = dev;
450 mutex_unlock(&rdev->devlist_mtx);
451 break;
Johannes Berg04a773a2009-04-19 21:24:32 +0200452 case NETDEV_GOING_DOWN:
453 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
454 break;
455 if (!dev->ieee80211_ptr->ssid_len)
456 break;
457 cfg80211_leave_ibss(rdev, dev);
458 break;
459 case NETDEV_UP:
460#ifdef CONFIG_WIRELESS_EXT
461 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
462 break;
463 if (!dev->ieee80211_ptr->wext.ssid_len)
464 break;
465 cfg80211_join_ibss(rdev, dev, &dev->ieee80211_ptr->wext);
466 break;
467#endif
Johannes Berg704232c2007-04-23 12:20:05 -0700468 case NETDEV_UNREGISTER:
469 mutex_lock(&rdev->devlist_mtx);
470 if (!list_empty(&dev->ieee80211_ptr->list)) {
471 sysfs_remove_link(&dev->dev.kobj, "phy80211");
472 list_del_init(&dev->ieee80211_ptr->list);
473 }
474 mutex_unlock(&rdev->devlist_mtx);
475 break;
476 }
477
478 return 0;
479}
480
481static struct notifier_block cfg80211_netdev_notifier = {
482 .notifier_call = cfg80211_netdev_notifier_call,
483};
484
485static int cfg80211_init(void)
486{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700487 int err;
488
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700489 err = wiphy_sysfs_init();
Johannes Berg704232c2007-04-23 12:20:05 -0700490 if (err)
491 goto out_fail_sysfs;
492
493 err = register_netdevice_notifier(&cfg80211_netdev_notifier);
494 if (err)
495 goto out_fail_notifier;
496
Johannes Berg55682962007-09-20 13:09:35 -0400497 err = nl80211_init();
498 if (err)
499 goto out_fail_nl80211;
500
Johannes Berg704232c2007-04-23 12:20:05 -0700501 ieee80211_debugfs_dir = debugfs_create_dir("ieee80211", NULL);
502
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700503 err = regulatory_init();
504 if (err)
505 goto out_fail_reg;
506
Johannes Berg704232c2007-04-23 12:20:05 -0700507 return 0;
508
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700509out_fail_reg:
510 debugfs_remove(ieee80211_debugfs_dir);
Johannes Berg55682962007-09-20 13:09:35 -0400511out_fail_nl80211:
512 unregister_netdevice_notifier(&cfg80211_netdev_notifier);
Johannes Berg704232c2007-04-23 12:20:05 -0700513out_fail_notifier:
514 wiphy_sysfs_exit();
515out_fail_sysfs:
516 return err;
517}
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700518
Johannes Berg3a462462007-09-10 13:44:45 +0200519subsys_initcall(cfg80211_init);
Johannes Berg704232c2007-04-23 12:20:05 -0700520
521static void cfg80211_exit(void)
522{
523 debugfs_remove(ieee80211_debugfs_dir);
Johannes Berg55682962007-09-20 13:09:35 -0400524 nl80211_exit();
Johannes Berg704232c2007-04-23 12:20:05 -0700525 unregister_netdevice_notifier(&cfg80211_netdev_notifier);
526 wiphy_sysfs_exit();
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700527 regulatory_exit();
Johannes Berg704232c2007-04-23 12:20:05 -0700528}
529module_exit(cfg80211_exit);