blob: cd7dff9c75f4828e061cef3aff1994527a9cd157 [file] [log] [blame]
Johannes Berg704232c2007-04-23 12:20:05 -07001/*
2 * This is the linux wireless configuration interface.
3 *
Johannes Berg08645122009-05-11 13:54:58 +02004 * Copyright 2006-2009 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>
Johannes Berg1f87f7d2009-06-02 13:01:41 +020015#include <linux/rtnetlink.h>
Johannes Berg704232c2007-04-23 12:20:05 -070016#include <net/genetlink.h>
17#include <net/cfg80211.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"
Luis R. Rodriguez1ac61302009-05-02 00:37:21 -040021#include "debugfs.h"
Johannes Berga9a11622009-07-27 12:01:53 +020022#include "wext-compat.h"
Johannes Berg704232c2007-04-23 12:20:05 -070023
24/* name for sysfs, %d is appended */
25#define PHY_NAME "phy"
26
27MODULE_AUTHOR("Johannes Berg");
28MODULE_LICENSE("GPL");
29MODULE_DESCRIPTION("wireless configuration support");
30
31/* RCU might be appropriate here since we usually
32 * only read the list, and that can happen quite
33 * often because we need to do it for each command */
Johannes Berg79c97e92009-07-07 03:56:12 +020034LIST_HEAD(cfg80211_rdev_list);
Luis R. Rodrigueza1794392009-02-21 00:04:21 -050035
36/*
Luis R. Rodriguezabc73812009-07-30 17:38:08 -070037 * This is used to protect the cfg80211_rdev_list
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! */
Johannes Berg79c97e92009-07-07 03:56:12 +020045struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx)
Johannes Berg55682962007-09-20 13:09:35 -040046{
Johannes Berg79c97e92009-07-07 03:56:12 +020047 struct cfg80211_registered_device *result = NULL, *rdev;
Johannes Berg55682962007-09-20 13:09:35 -040048
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 Berg79c97e92009-07-07 03:56:12 +020054 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
55 if (rdev->wiphy_idx == wiphy_idx) {
56 result = rdev;
Johannes Berg55682962007-09-20 13:09:35 -040057 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{
Johannes Berg79c97e92009-07-07 03:56:12 +020066 struct cfg80211_registered_device *rdev;
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -050067 if (!wiphy)
68 return WIPHY_IDX_STALE;
Johannes Berg79c97e92009-07-07 03:56:12 +020069 rdev = wiphy_to_dev(wiphy);
70 return rdev->wiphy_idx;
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -050071}
72
Johannes Berg79c97e92009-07-07 03:56:12 +020073/* requires cfg80211_rdev_mutex to be held! */
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -050074struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx)
75{
Johannes Berg79c97e92009-07-07 03:56:12 +020076 struct cfg80211_registered_device *rdev;
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -050077
78 if (!wiphy_idx_valid(wiphy_idx))
79 return NULL;
80
81 assert_cfg80211_lock();
82
Johannes Berg79c97e92009-07-07 03:56:12 +020083 rdev = cfg80211_rdev_by_wiphy_idx(wiphy_idx);
84 if (!rdev)
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -050085 return NULL;
Johannes Berg79c97e92009-07-07 03:56:12 +020086 return &rdev->wiphy;
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -050087}
88
Luis R. Rodrigueza1794392009-02-21 00:04:21 -050089/* requires cfg80211_mutex to be held! */
Johannes Berg4bbf4d52009-03-24 09:35:46 +010090struct cfg80211_registered_device *
Johannes Berg79c97e92009-07-07 03:56:12 +020091__cfg80211_rdev_from_info(struct genl_info *info)
Johannes Berg55682962007-09-20 13:09:35 -040092{
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]) {
Johannes Berg79c97e92009-07-07 03:56:12 +0200101 bywiphyidx = cfg80211_rdev_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]);
Johannes Berg463d0182009-07-14 00:33:35 +0200108 dev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg55682962007-09-20 13:09:35 -0400109 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{
Johannes Berg79c97e92009-07-07 03:56:12 +0200136 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -0400137
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500138 mutex_lock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +0200139 rdev = __cfg80211_rdev_from_info(info);
Johannes Berg55682962007-09-20 13:09:35 -0400140
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 */
Johannes Berg79c97e92009-07-07 03:56:12 +0200144 if (!IS_ERR(rdev))
145 mutex_lock(&rdev->mtx);
Johannes Berg55682962007-09-20 13:09:35 -0400146
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500147 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -0400148
Johannes Berg79c97e92009-07-07 03:56:12 +0200149 return rdev;
Johannes Berg55682962007-09-20 13:09:35 -0400150}
151
152struct cfg80211_registered_device *
Johannes Berg463d0182009-07-14 00:33:35 +0200153cfg80211_get_dev_from_ifindex(struct net *net, int ifindex)
Johannes Berg55682962007-09-20 13:09:35 -0400154{
Johannes Berg79c97e92009-07-07 03:56:12 +0200155 struct cfg80211_registered_device *rdev = ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400156 struct net_device *dev;
157
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500158 mutex_lock(&cfg80211_mutex);
Johannes Berg463d0182009-07-14 00:33:35 +0200159 dev = dev_get_by_index(net, ifindex);
Johannes Berg55682962007-09-20 13:09:35 -0400160 if (!dev)
161 goto out;
162 if (dev->ieee80211_ptr) {
Johannes Berg79c97e92009-07-07 03:56:12 +0200163 rdev = wiphy_to_dev(dev->ieee80211_ptr->wiphy);
164 mutex_lock(&rdev->mtx);
Johannes Berg55682962007-09-20 13:09:35 -0400165 } else
Johannes Berg79c97e92009-07-07 03:56:12 +0200166 rdev = ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400167 dev_put(dev);
168 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500169 mutex_unlock(&cfg80211_mutex);
Johannes Berg79c97e92009-07-07 03:56:12 +0200170 return rdev;
Johannes Berg55682962007-09-20 13:09:35 -0400171}
172
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100173/* requires cfg80211_mutex to be held */
Johannes Berg55682962007-09-20 13:09:35 -0400174int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
175 char *newname)
176{
Johannes Berg79c97e92009-07-07 03:56:12 +0200177 struct cfg80211_registered_device *rdev2;
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500178 int wiphy_idx, taken = -1, result, digits;
Johannes Berg55682962007-09-20 13:09:35 -0400179
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100180 assert_cfg80211_lock();
Eric W. Biederman2940bb62008-05-08 14:30:18 -0700181
Johannes Berg55682962007-09-20 13:09:35 -0400182 /* prohibit calling the thing phy%d when %d is not its number */
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500183 sscanf(newname, PHY_NAME "%d%n", &wiphy_idx, &taken);
184 if (taken == strlen(newname) && wiphy_idx != rdev->wiphy_idx) {
185 /* count number of places needed to print wiphy_idx */
Johannes Berg55682962007-09-20 13:09:35 -0400186 digits = 1;
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500187 while (wiphy_idx /= 10)
Johannes Berg55682962007-09-20 13:09:35 -0400188 digits++;
189 /*
190 * deny the name if it is phy<idx> where <idx> is printed
191 * without leading zeroes. taken == strlen(newname) here
192 */
193 if (taken == strlen(PHY_NAME) + digits)
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100194 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -0400195 }
196
Eric W. Biederman2940bb62008-05-08 14:30:18 -0700197
198 /* Ignore nop renames */
Eric W. Biederman2940bb62008-05-08 14:30:18 -0700199 if (strcmp(newname, dev_name(&rdev->wiphy.dev)) == 0)
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100200 return 0;
Eric W. Biederman2940bb62008-05-08 14:30:18 -0700201
202 /* Ensure another device does not already have this name. */
Johannes Berg79c97e92009-07-07 03:56:12 +0200203 list_for_each_entry(rdev2, &cfg80211_rdev_list, list)
204 if (strcmp(newname, dev_name(&rdev2->wiphy.dev)) == 0)
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100205 return -EINVAL;
Eric W. Biederman2940bb62008-05-08 14:30:18 -0700206
Johannes Berg55682962007-09-20 13:09:35 -0400207 result = device_rename(&rdev->wiphy.dev, newname);
208 if (result)
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100209 return result;
Johannes Berg55682962007-09-20 13:09:35 -0400210
Johannes Berg33c03602008-10-08 10:23:48 +0200211 if (rdev->wiphy.debugfsdir &&
212 !debugfs_rename(rdev->wiphy.debugfsdir->d_parent,
Johannes Berg55682962007-09-20 13:09:35 -0400213 rdev->wiphy.debugfsdir,
214 rdev->wiphy.debugfsdir->d_parent,
215 newname))
216 printk(KERN_ERR "cfg80211: failed to rename debugfs dir to %s!\n",
217 newname);
218
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100219 nl80211_notify_dev_rename(rdev);
Johannes Berg55682962007-09-20 13:09:35 -0400220
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100221 return 0;
Johannes Berg55682962007-09-20 13:09:35 -0400222}
223
Johannes Berg463d0182009-07-14 00:33:35 +0200224int cfg80211_switch_netns(struct cfg80211_registered_device *rdev,
225 struct net *net)
226{
227 struct wireless_dev *wdev;
228 int err = 0;
229
230 if (!rdev->wiphy.netnsok)
231 return -EOPNOTSUPP;
232
233 list_for_each_entry(wdev, &rdev->netdev_list, list) {
234 wdev->netdev->features &= ~NETIF_F_NETNS_LOCAL;
235 err = dev_change_net_namespace(wdev->netdev, net, "wlan%d");
236 if (err)
237 break;
238 wdev->netdev->features |= NETIF_F_NETNS_LOCAL;
239 }
240
241 if (err) {
242 /* failed -- clean up to old netns */
243 net = wiphy_net(&rdev->wiphy);
244
245 list_for_each_entry_continue_reverse(wdev, &rdev->netdev_list,
246 list) {
247 wdev->netdev->features &= ~NETIF_F_NETNS_LOCAL;
248 err = dev_change_net_namespace(wdev->netdev, net,
249 "wlan%d");
250 WARN_ON(err);
251 wdev->netdev->features |= NETIF_F_NETNS_LOCAL;
252 }
253 }
254
255 wiphy_net_set(&rdev->wiphy, net);
256
257 return err;
258}
259
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200260static void cfg80211_rfkill_poll(struct rfkill *rfkill, void *data)
261{
Johannes Berg79c97e92009-07-07 03:56:12 +0200262 struct cfg80211_registered_device *rdev = data;
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200263
Johannes Berg79c97e92009-07-07 03:56:12 +0200264 rdev->ops->rfkill_poll(&rdev->wiphy);
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200265}
266
267static int cfg80211_rfkill_set_block(void *data, bool blocked)
268{
Johannes Berg79c97e92009-07-07 03:56:12 +0200269 struct cfg80211_registered_device *rdev = data;
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200270 struct wireless_dev *wdev;
271
272 if (!blocked)
273 return 0;
274
275 rtnl_lock();
Johannes Berg79c97e92009-07-07 03:56:12 +0200276 mutex_lock(&rdev->devlist_mtx);
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200277
Johannes Berg79c97e92009-07-07 03:56:12 +0200278 list_for_each_entry(wdev, &rdev->netdev_list, list)
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200279 dev_close(wdev->netdev);
280
Johannes Berg79c97e92009-07-07 03:56:12 +0200281 mutex_unlock(&rdev->devlist_mtx);
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200282 rtnl_unlock();
283
284 return 0;
285}
286
287static void cfg80211_rfkill_sync_work(struct work_struct *work)
288{
Johannes Berg79c97e92009-07-07 03:56:12 +0200289 struct cfg80211_registered_device *rdev;
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200290
Johannes Berg79c97e92009-07-07 03:56:12 +0200291 rdev = container_of(work, struct cfg80211_registered_device, rfkill_sync);
292 cfg80211_rfkill_set_block(rdev, rfkill_blocked(rdev->rfkill));
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200293}
294
Johannes Berg667503dd2009-07-07 03:56:11 +0200295static void cfg80211_process_events(struct wireless_dev *wdev)
296{
297 struct cfg80211_event *ev;
298 unsigned long flags;
299
300 spin_lock_irqsave(&wdev->event_lock, flags);
301 while (!list_empty(&wdev->event_list)) {
302 ev = list_first_entry(&wdev->event_list,
303 struct cfg80211_event, list);
304 list_del(&ev->list);
305 spin_unlock_irqrestore(&wdev->event_lock, flags);
306
307 wdev_lock(wdev);
308 switch (ev->type) {
309 case EVENT_CONNECT_RESULT:
310 __cfg80211_connect_result(
311 wdev->netdev, ev->cr.bssid,
312 ev->cr.req_ie, ev->cr.req_ie_len,
313 ev->cr.resp_ie, ev->cr.resp_ie_len,
314 ev->cr.status,
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200315 ev->cr.status == WLAN_STATUS_SUCCESS,
316 NULL);
Johannes Berg667503dd2009-07-07 03:56:11 +0200317 break;
318 case EVENT_ROAMED:
319 __cfg80211_roamed(wdev, ev->rm.bssid,
320 ev->rm.req_ie, ev->rm.req_ie_len,
321 ev->rm.resp_ie, ev->rm.resp_ie_len);
322 break;
323 case EVENT_DISCONNECTED:
324 __cfg80211_disconnected(wdev->netdev,
325 ev->dc.ie, ev->dc.ie_len,
326 ev->dc.reason, true);
327 break;
328 case EVENT_IBSS_JOINED:
329 __cfg80211_ibss_joined(wdev->netdev, ev->ij.bssid);
330 break;
331 }
332 wdev_unlock(wdev);
333
334 kfree(ev);
335
336 spin_lock_irqsave(&wdev->event_lock, flags);
337 }
338 spin_unlock_irqrestore(&wdev->event_lock, flags);
339}
340
341static void cfg80211_event_work(struct work_struct *work)
342{
343 struct cfg80211_registered_device *rdev;
344 struct wireless_dev *wdev;
345
346 rdev = container_of(work, struct cfg80211_registered_device,
347 event_work);
348
349 rtnl_lock();
350 cfg80211_lock_rdev(rdev);
351 mutex_lock(&rdev->devlist_mtx);
352
353 list_for_each_entry(wdev, &rdev->netdev_list, list)
354 cfg80211_process_events(wdev);
355
356 mutex_unlock(&rdev->devlist_mtx);
357 cfg80211_unlock_rdev(rdev);
358 rtnl_unlock();
359}
360
Johannes Berg704232c2007-04-23 12:20:05 -0700361/* exported functions */
362
David Kilroy3dcf6702009-05-16 23:13:46 +0100363struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv)
Johannes Berg704232c2007-04-23 12:20:05 -0700364{
Denis ChengRq638af072008-09-23 02:35:37 +0800365 static int wiphy_counter;
366
Johannes Berg79c97e92009-07-07 03:56:12 +0200367 struct cfg80211_registered_device *rdev;
Johannes Berg704232c2007-04-23 12:20:05 -0700368 int alloc_size;
369
Johannes Berg0b20633d2009-07-07 03:56:13 +0200370 WARN_ON(ops->add_key && (!ops->del_key || !ops->set_default_key));
371 WARN_ON(ops->auth && (!ops->assoc || !ops->deauth || !ops->disassoc));
372 WARN_ON(ops->connect && !ops->disconnect);
373 WARN_ON(ops->join_ibss && !ops->leave_ibss);
374 WARN_ON(ops->add_virtual_intf && !ops->del_virtual_intf);
375 WARN_ON(ops->add_station && !ops->del_station);
376 WARN_ON(ops->add_mpath && !ops->del_mpath);
Johannes Berg41ade002007-12-19 02:03:29 +0100377
Johannes Berg79c97e92009-07-07 03:56:12 +0200378 alloc_size = sizeof(*rdev) + sizeof_priv;
Johannes Berg704232c2007-04-23 12:20:05 -0700379
Johannes Berg79c97e92009-07-07 03:56:12 +0200380 rdev = kzalloc(alloc_size, GFP_KERNEL);
381 if (!rdev)
Johannes Berg704232c2007-04-23 12:20:05 -0700382 return NULL;
383
Johannes Berg79c97e92009-07-07 03:56:12 +0200384 rdev->ops = ops;
Johannes Berg704232c2007-04-23 12:20:05 -0700385
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500386 mutex_lock(&cfg80211_mutex);
Johannes Berg704232c2007-04-23 12:20:05 -0700387
Johannes Berg79c97e92009-07-07 03:56:12 +0200388 rdev->wiphy_idx = wiphy_counter++;
Johannes Berga4d73ee2007-04-26 20:50:35 -0700389
Johannes Berg79c97e92009-07-07 03:56:12 +0200390 if (unlikely(!wiphy_idx_valid(rdev->wiphy_idx))) {
Denis ChengRq638af072008-09-23 02:35:37 +0800391 wiphy_counter--;
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500392 mutex_unlock(&cfg80211_mutex);
Johannes Berg704232c2007-04-23 12:20:05 -0700393 /* ugh, wrapped! */
Johannes Berg79c97e92009-07-07 03:56:12 +0200394 kfree(rdev);
Johannes Berg704232c2007-04-23 12:20:05 -0700395 return NULL;
396 }
Johannes Berg704232c2007-04-23 12:20:05 -0700397
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500398 mutex_unlock(&cfg80211_mutex);
Denis ChengRq638af072008-09-23 02:35:37 +0800399
Johannes Berg704232c2007-04-23 12:20:05 -0700400 /* give it a proper name */
Johannes Berg79c97e92009-07-07 03:56:12 +0200401 dev_set_name(&rdev->wiphy.dev, PHY_NAME "%d", rdev->wiphy_idx);
Johannes Berg704232c2007-04-23 12:20:05 -0700402
Johannes Berg79c97e92009-07-07 03:56:12 +0200403 mutex_init(&rdev->mtx);
404 mutex_init(&rdev->devlist_mtx);
405 INIT_LIST_HEAD(&rdev->netdev_list);
406 spin_lock_init(&rdev->bss_lock);
407 INIT_LIST_HEAD(&rdev->bss_list);
408 INIT_WORK(&rdev->scan_done_wk, __cfg80211_scan_done);
Johannes Berg704232c2007-04-23 12:20:05 -0700409
Johannes Berg79c97e92009-07-07 03:56:12 +0200410 device_initialize(&rdev->wiphy.dev);
411 rdev->wiphy.dev.class = &ieee80211_class;
412 rdev->wiphy.dev.platform_data = rdev;
Johannes Berg704232c2007-04-23 12:20:05 -0700413
Johannes Berg463d0182009-07-14 00:33:35 +0200414 wiphy_net_set(&rdev->wiphy, &init_net);
415
Johannes Berg79c97e92009-07-07 03:56:12 +0200416 rdev->rfkill_ops.set_block = cfg80211_rfkill_set_block;
417 rdev->rfkill = rfkill_alloc(dev_name(&rdev->wiphy.dev),
418 &rdev->wiphy.dev, RFKILL_TYPE_WLAN,
419 &rdev->rfkill_ops, rdev);
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200420
Johannes Berg79c97e92009-07-07 03:56:12 +0200421 if (!rdev->rfkill) {
422 kfree(rdev);
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200423 return NULL;
424 }
425
Johannes Berg79c97e92009-07-07 03:56:12 +0200426 INIT_WORK(&rdev->rfkill_sync, cfg80211_rfkill_sync_work);
427 INIT_WORK(&rdev->conn_work, cfg80211_conn_work);
428 INIT_WORK(&rdev->event_work, cfg80211_event_work);
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200429
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200430 /*
431 * Initialize wiphy parameters to IEEE 802.11 MIB default values.
432 * Fragmentation and RTS threshold are disabled by default with the
433 * special -1 value.
434 */
Johannes Berg79c97e92009-07-07 03:56:12 +0200435 rdev->wiphy.retry_short = 7;
436 rdev->wiphy.retry_long = 4;
437 rdev->wiphy.frag_threshold = (u32) -1;
438 rdev->wiphy.rts_threshold = (u32) -1;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200439
Johannes Berg79c97e92009-07-07 03:56:12 +0200440 return &rdev->wiphy;
Johannes Berg704232c2007-04-23 12:20:05 -0700441}
442EXPORT_SYMBOL(wiphy_new);
443
444int wiphy_register(struct wiphy *wiphy)
445{
Johannes Berg79c97e92009-07-07 03:56:12 +0200446 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg704232c2007-04-23 12:20:05 -0700447 int res;
Johannes Berg8318d782008-01-24 19:38:38 +0100448 enum ieee80211_band band;
449 struct ieee80211_supported_band *sband;
450 bool have_band = false;
451 int i;
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700452 u16 ifmodes = wiphy->interface_modes;
453
454 /* sanity check ifmodes */
455 WARN_ON(!ifmodes);
456 ifmodes &= ((1 << __NL80211_IFTYPE_AFTER_LAST) - 1) & ~1;
457 if (WARN_ON(ifmodes != wiphy->interface_modes))
458 wiphy->interface_modes = ifmodes;
Johannes Berg8318d782008-01-24 19:38:38 +0100459
460 /* sanity check supported bands/channels */
461 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
462 sband = wiphy->bands[band];
463 if (!sband)
464 continue;
465
466 sband->band = band;
467
Johannes Berg881d9482009-01-21 15:13:48 +0100468 if (WARN_ON(!sband->n_channels || !sband->n_bitrates))
Johannes Berg8318d782008-01-24 19:38:38 +0100469 return -EINVAL;
Johannes Berg881d9482009-01-21 15:13:48 +0100470
471 /*
472 * Since we use a u32 for rate bitmaps in
473 * ieee80211_get_response_rate, we cannot
474 * have more than 32 legacy rates.
475 */
476 if (WARN_ON(sband->n_bitrates > 32))
477 return -EINVAL;
Johannes Berg8318d782008-01-24 19:38:38 +0100478
479 for (i = 0; i < sband->n_channels; i++) {
480 sband->channels[i].orig_flags =
481 sband->channels[i].flags;
482 sband->channels[i].orig_mag =
483 sband->channels[i].max_antenna_gain;
484 sband->channels[i].orig_mpwr =
485 sband->channels[i].max_power;
486 sband->channels[i].band = band;
487 }
488
489 have_band = true;
490 }
491
492 if (!have_band) {
493 WARN_ON(1);
494 return -EINVAL;
495 }
496
497 /* check and set up bitrates */
498 ieee80211_set_bitrate_flags(wiphy);
499
Johannes Berg79c97e92009-07-07 03:56:12 +0200500 res = device_add(&rdev->wiphy.dev);
Johannes Berg704232c2007-04-23 12:20:05 -0700501 if (res)
Johannes Berg2f0accc2009-06-10 16:50:29 +0200502 return res;
Johannes Berg704232c2007-04-23 12:20:05 -0700503
Johannes Berg79c97e92009-07-07 03:56:12 +0200504 res = rfkill_register(rdev->rfkill);
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200505 if (res)
506 goto out_rm_dev;
507
Johannes Berg2f0accc2009-06-10 16:50:29 +0200508 mutex_lock(&cfg80211_mutex);
509
510 /* set up regulatory info */
511 wiphy_update_regulatory(wiphy, NL80211_REGDOM_SET_BY_CORE);
512
Johannes Berg79c97e92009-07-07 03:56:12 +0200513 list_add(&rdev->list, &cfg80211_rdev_list);
Johannes Berg704232c2007-04-23 12:20:05 -0700514
Johannes Berg2f0accc2009-06-10 16:50:29 +0200515 mutex_unlock(&cfg80211_mutex);
516
Johannes Berg704232c2007-04-23 12:20:05 -0700517 /* add to debugfs */
Johannes Berg79c97e92009-07-07 03:56:12 +0200518 rdev->wiphy.debugfsdir =
519 debugfs_create_dir(wiphy_name(&rdev->wiphy),
Johannes Berg704232c2007-04-23 12:20:05 -0700520 ieee80211_debugfs_dir);
Johannes Berg79c97e92009-07-07 03:56:12 +0200521 if (IS_ERR(rdev->wiphy.debugfsdir))
522 rdev->wiphy.debugfsdir = NULL;
Johannes Berg704232c2007-04-23 12:20:05 -0700523
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -0400524 if (wiphy->custom_regulatory) {
525 struct regulatory_request request;
526
527 request.wiphy_idx = get_wiphy_idx(wiphy);
528 request.initiator = NL80211_REGDOM_SET_BY_DRIVER;
529 request.alpha2[0] = '9';
530 request.alpha2[1] = '9';
531
532 nl80211_send_reg_change_event(&request);
533 }
534
Johannes Berg79c97e92009-07-07 03:56:12 +0200535 cfg80211_debugfs_rdev_add(rdev);
Luis R. Rodriguez1ac61302009-05-02 00:37:21 -0400536
Johannes Berg2f0accc2009-06-10 16:50:29 +0200537 return 0;
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200538
539 out_rm_dev:
Johannes Berg79c97e92009-07-07 03:56:12 +0200540 device_del(&rdev->wiphy.dev);
Johannes Berg704232c2007-04-23 12:20:05 -0700541 return res;
542}
543EXPORT_SYMBOL(wiphy_register);
544
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200545void wiphy_rfkill_start_polling(struct wiphy *wiphy)
546{
Johannes Berg79c97e92009-07-07 03:56:12 +0200547 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200548
Johannes Berg79c97e92009-07-07 03:56:12 +0200549 if (!rdev->ops->rfkill_poll)
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200550 return;
Johannes Berg79c97e92009-07-07 03:56:12 +0200551 rdev->rfkill_ops.poll = cfg80211_rfkill_poll;
552 rfkill_resume_polling(rdev->rfkill);
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200553}
554EXPORT_SYMBOL(wiphy_rfkill_start_polling);
555
556void wiphy_rfkill_stop_polling(struct wiphy *wiphy)
557{
Johannes Berg79c97e92009-07-07 03:56:12 +0200558 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200559
Johannes Berg79c97e92009-07-07 03:56:12 +0200560 rfkill_pause_polling(rdev->rfkill);
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200561}
562EXPORT_SYMBOL(wiphy_rfkill_stop_polling);
563
Johannes Berg704232c2007-04-23 12:20:05 -0700564void wiphy_unregister(struct wiphy *wiphy)
565{
Johannes Berg79c97e92009-07-07 03:56:12 +0200566 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg704232c2007-04-23 12:20:05 -0700567
Johannes Berg79c97e92009-07-07 03:56:12 +0200568 rfkill_unregister(rdev->rfkill);
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200569
Johannes Bergf16bfc12007-04-26 20:51:12 -0700570 /* protect the device list */
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500571 mutex_lock(&cfg80211_mutex);
Johannes Berg704232c2007-04-23 12:20:05 -0700572
Johannes Berg79c97e92009-07-07 03:56:12 +0200573 BUG_ON(!list_empty(&rdev->netdev_list));
Johannes Bergf16bfc12007-04-26 20:51:12 -0700574
575 /*
Johannes Berg79c97e92009-07-07 03:56:12 +0200576 * Try to grab rdev->mtx. If a command is still in progress,
Johannes Bergf16bfc12007-04-26 20:51:12 -0700577 * hopefully the driver will refuse it since it's tearing
578 * down the device already. We wait for this command to complete
579 * before unlinking the item from the list.
580 * Note: as codified by the BUG_ON above we cannot get here if
581 * a virtual interface is still associated. Hence, we can only
582 * get to lock contention here if userspace issues a command
583 * that identified the hardware by wiphy index.
584 */
Johannes Berg79c97e92009-07-07 03:56:12 +0200585 mutex_lock(&rdev->mtx);
Johannes Bergf16bfc12007-04-26 20:51:12 -0700586 /* unlock again before freeing */
Johannes Berg79c97e92009-07-07 03:56:12 +0200587 mutex_unlock(&rdev->mtx);
Johannes Berg704232c2007-04-23 12:20:05 -0700588
Johannes Berg79c97e92009-07-07 03:56:12 +0200589 cfg80211_debugfs_rdev_del(rdev);
Luis R. Rodriguez1ac61302009-05-02 00:37:21 -0400590
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800591 /* If this device got a regulatory hint tell core its
592 * free to listen now to a new shiny device regulatory hint */
593 reg_device_remove(wiphy);
594
Johannes Berg79c97e92009-07-07 03:56:12 +0200595 list_del(&rdev->list);
596 device_del(&rdev->wiphy.dev);
597 debugfs_remove(rdev->wiphy.debugfsdir);
Johannes Berg704232c2007-04-23 12:20:05 -0700598
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500599 mutex_unlock(&cfg80211_mutex);
Johannes Berg66825882009-07-13 13:24:44 +0200600
601 cancel_work_sync(&rdev->conn_work);
602 cancel_work_sync(&rdev->scan_done_wk);
603 kfree(rdev->scan_req);
604 flush_work(&rdev->event_work);
Johannes Berg704232c2007-04-23 12:20:05 -0700605}
606EXPORT_SYMBOL(wiphy_unregister);
607
Johannes Berg79c97e92009-07-07 03:56:12 +0200608void cfg80211_dev_free(struct cfg80211_registered_device *rdev)
Johannes Berg704232c2007-04-23 12:20:05 -0700609{
Johannes Berg2a519312009-02-10 21:25:55 +0100610 struct cfg80211_internal_bss *scan, *tmp;
Johannes Berg79c97e92009-07-07 03:56:12 +0200611 rfkill_destroy(rdev->rfkill);
612 mutex_destroy(&rdev->mtx);
613 mutex_destroy(&rdev->devlist_mtx);
614 list_for_each_entry_safe(scan, tmp, &rdev->bss_list, list)
Johannes Berg78c1c7e2009-02-10 21:25:57 +0100615 cfg80211_put_bss(&scan->pub);
Johannes Berg79c97e92009-07-07 03:56:12 +0200616 kfree(rdev);
Johannes Berg704232c2007-04-23 12:20:05 -0700617}
618
619void wiphy_free(struct wiphy *wiphy)
620{
621 put_device(&wiphy->dev);
622}
623EXPORT_SYMBOL(wiphy_free);
624
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200625void wiphy_rfkill_set_hw_state(struct wiphy *wiphy, bool blocked)
626{
Johannes Berg79c97e92009-07-07 03:56:12 +0200627 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200628
Johannes Berg79c97e92009-07-07 03:56:12 +0200629 if (rfkill_set_hw_state(rdev->rfkill, blocked))
630 schedule_work(&rdev->rfkill_sync);
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200631}
632EXPORT_SYMBOL(wiphy_rfkill_set_hw_state);
633
Johannes Berg704232c2007-04-23 12:20:05 -0700634static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
635 unsigned long state,
636 void *ndev)
637{
638 struct net_device *dev = ndev;
Johannes Berg2a783c12009-07-01 21:26:45 +0200639 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg704232c2007-04-23 12:20:05 -0700640 struct cfg80211_registered_device *rdev;
641
Johannes Berg2a783c12009-07-01 21:26:45 +0200642 if (!wdev)
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200643 return NOTIFY_DONE;
Johannes Berg704232c2007-04-23 12:20:05 -0700644
Johannes Berg2a783c12009-07-01 21:26:45 +0200645 rdev = wiphy_to_dev(wdev->wiphy);
Johannes Berg704232c2007-04-23 12:20:05 -0700646
Johannes Berg2a783c12009-07-01 21:26:45 +0200647 WARN_ON(wdev->iftype == NL80211_IFTYPE_UNSPECIFIED);
Johannes Berg60719ff2008-09-16 14:55:09 +0200648
Johannes Berg704232c2007-04-23 12:20:05 -0700649 switch (state) {
650 case NETDEV_REGISTER:
Johannes Berg667503dd2009-07-07 03:56:11 +0200651 mutex_init(&wdev->mtx);
652 INIT_LIST_HEAD(&wdev->event_list);
653 spin_lock_init(&wdev->event_lock);
Johannes Berg704232c2007-04-23 12:20:05 -0700654 mutex_lock(&rdev->devlist_mtx);
Johannes Berg2a783c12009-07-01 21:26:45 +0200655 list_add(&wdev->list, &rdev->netdev_list);
Johannes Berg463d0182009-07-14 00:33:35 +0200656 /* can only change netns with wiphy */
657 dev->features |= NETIF_F_NETNS_LOCAL;
658
Johannes Berg704232c2007-04-23 12:20:05 -0700659 if (sysfs_create_link(&dev->dev.kobj, &rdev->wiphy.dev.kobj,
660 "phy80211")) {
661 printk(KERN_ERR "wireless: failed to add phy80211 "
662 "symlink to netdev!\n");
663 }
Johannes Berg2a783c12009-07-01 21:26:45 +0200664 wdev->netdev = dev;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200665 wdev->sme_state = CFG80211_SME_IDLE;
Johannes Bergbc92afd2009-07-01 21:26:57 +0200666 mutex_unlock(&rdev->devlist_mtx);
Johannes Berg08645122009-05-11 13:54:58 +0200667#ifdef CONFIG_WIRELESS_EXT
Johannes Berga9a11622009-07-27 12:01:53 +0200668 if (!dev->wireless_handlers)
669 dev->wireless_handlers = &cfg80211_wext_handler;
Johannes Berg2a783c12009-07-01 21:26:45 +0200670 wdev->wext.default_key = -1;
671 wdev->wext.default_mgmt_key = -1;
Johannes Bergf2129352009-07-01 21:26:56 +0200672 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
Johannes Bergbc92afd2009-07-01 21:26:57 +0200673 wdev->wext.ps = CONFIG_CFG80211_DEFAULT_PS_VALUE;
674 wdev->wext.ps_timeout = 500;
675 if (rdev->ops->set_power_mgmt)
676 if (rdev->ops->set_power_mgmt(wdev->wiphy, dev,
677 wdev->wext.ps,
678 wdev->wext.ps_timeout)) {
679 /* assume this means it's off */
680 wdev->wext.ps = false;
681 }
Johannes Berg08645122009-05-11 13:54:58 +0200682#endif
Johannes Berg704232c2007-04-23 12:20:05 -0700683 break;
Johannes Berg04a773a2009-04-19 21:24:32 +0200684 case NETDEV_GOING_DOWN:
Samuel Ortizb23aa672009-07-01 21:26:54 +0200685 switch (wdev->iftype) {
686 case NL80211_IFTYPE_ADHOC:
687 cfg80211_leave_ibss(rdev, dev, true);
688 break;
689 case NL80211_IFTYPE_STATION:
Johannes Berg667503dd2009-07-07 03:56:11 +0200690 wdev_lock(wdev);
Johannes Bergf2129352009-07-01 21:26:56 +0200691#ifdef CONFIG_WIRELESS_EXT
692 kfree(wdev->wext.ie);
693 wdev->wext.ie = NULL;
694 wdev->wext.ie_len = 0;
Johannes Berg0eb14642009-07-02 15:49:03 +0200695 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
Johannes Bergf2129352009-07-01 21:26:56 +0200696#endif
Johannes Berg667503dd2009-07-07 03:56:11 +0200697 __cfg80211_disconnect(rdev, dev,
698 WLAN_REASON_DEAUTH_LEAVING, true);
Johannes Berg19957bb2009-07-02 17:20:43 +0200699 cfg80211_mlme_down(rdev, dev);
Johannes Berg667503dd2009-07-07 03:56:11 +0200700 wdev_unlock(wdev);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200701 break;
702 default:
703 break;
704 }
Johannes Berg04a773a2009-04-19 21:24:32 +0200705 break;
706 case NETDEV_UP:
707#ifdef CONFIG_WIRELESS_EXT
Johannes Berg667503dd2009-07-07 03:56:11 +0200708 cfg80211_lock_rdev(rdev);
709 wdev_lock(wdev);
Johannes Bergf2129352009-07-01 21:26:56 +0200710 switch (wdev->iftype) {
711 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200712 cfg80211_ibss_wext_join(rdev, wdev);
Johannes Berg04a773a2009-04-19 21:24:32 +0200713 break;
Johannes Bergf2129352009-07-01 21:26:56 +0200714 case NL80211_IFTYPE_STATION:
Johannes Bergfffd0932009-07-08 14:22:54 +0200715 cfg80211_mgd_wext_connect(rdev, wdev);
Johannes Berg04a773a2009-04-19 21:24:32 +0200716 break;
Johannes Bergf2129352009-07-01 21:26:56 +0200717 default:
718 break;
719 }
Johannes Berg667503dd2009-07-07 03:56:11 +0200720 wdev_unlock(wdev);
721 cfg80211_unlock_rdev(rdev);
Johannes Berg04a773a2009-04-19 21:24:32 +0200722#endif
Johannes Berg2a783c12009-07-01 21:26:45 +0200723 break;
Johannes Berg704232c2007-04-23 12:20:05 -0700724 case NETDEV_UNREGISTER:
725 mutex_lock(&rdev->devlist_mtx);
Johannes Berge40cbdac2009-07-30 14:04:01 +0200726 /*
727 * It is possible to get NETDEV_UNREGISTER
728 * multiple times. To detect that, check
729 * that the interface is still on the list
730 * of registered interfaces, and only then
731 * remove and clean it up.
732 */
Johannes Berg2a783c12009-07-01 21:26:45 +0200733 if (!list_empty(&wdev->list)) {
Johannes Berg704232c2007-04-23 12:20:05 -0700734 sysfs_remove_link(&dev->dev.kobj, "phy80211");
Johannes Berg2a783c12009-07-01 21:26:45 +0200735 list_del_init(&wdev->list);
Johannes Berge40cbdac2009-07-30 14:04:01 +0200736 mutex_destroy(&wdev->mtx);
737#ifdef CONFIG_WIRELESS_EXT
738 kfree(wdev->wext.keys);
739#endif
Johannes Berg704232c2007-04-23 12:20:05 -0700740 }
741 mutex_unlock(&rdev->devlist_mtx);
742 break;
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200743 case NETDEV_PRE_UP:
Johannes Berg0b20633d2009-07-07 03:56:13 +0200744 if (!(wdev->wiphy->interface_modes & BIT(wdev->iftype)))
745 return notifier_from_errno(-EOPNOTSUPP);
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200746 if (rfkill_blocked(rdev->rfkill))
747 return notifier_from_errno(-ERFKILL);
748 break;
Johannes Berg704232c2007-04-23 12:20:05 -0700749 }
750
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200751 return NOTIFY_DONE;
Johannes Berg704232c2007-04-23 12:20:05 -0700752}
753
754static struct notifier_block cfg80211_netdev_notifier = {
755 .notifier_call = cfg80211_netdev_notifier_call,
756};
757
Johannes Berg463d0182009-07-14 00:33:35 +0200758static void __net_exit cfg80211_pernet_exit(struct net *net)
759{
760 struct cfg80211_registered_device *rdev;
761
762 rtnl_lock();
763 mutex_lock(&cfg80211_mutex);
764 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
765 if (net_eq(wiphy_net(&rdev->wiphy), net))
766 WARN_ON(cfg80211_switch_netns(rdev, &init_net));
767 }
768 mutex_unlock(&cfg80211_mutex);
769 rtnl_unlock();
770}
771
772static struct pernet_operations cfg80211_pernet_ops = {
773 .exit = cfg80211_pernet_exit,
774};
775
776static int __init cfg80211_init(void)
Johannes Berg704232c2007-04-23 12:20:05 -0700777{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700778 int err;
779
Johannes Berg463d0182009-07-14 00:33:35 +0200780 err = register_pernet_device(&cfg80211_pernet_ops);
781 if (err)
782 goto out_fail_pernet;
783
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700784 err = wiphy_sysfs_init();
Johannes Berg704232c2007-04-23 12:20:05 -0700785 if (err)
786 goto out_fail_sysfs;
787
788 err = register_netdevice_notifier(&cfg80211_netdev_notifier);
789 if (err)
790 goto out_fail_notifier;
791
Johannes Berg55682962007-09-20 13:09:35 -0400792 err = nl80211_init();
793 if (err)
794 goto out_fail_nl80211;
795
Johannes Berg704232c2007-04-23 12:20:05 -0700796 ieee80211_debugfs_dir = debugfs_create_dir("ieee80211", NULL);
797
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700798 err = regulatory_init();
799 if (err)
800 goto out_fail_reg;
801
Johannes Berg704232c2007-04-23 12:20:05 -0700802 return 0;
803
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700804out_fail_reg:
805 debugfs_remove(ieee80211_debugfs_dir);
Johannes Berg55682962007-09-20 13:09:35 -0400806out_fail_nl80211:
807 unregister_netdevice_notifier(&cfg80211_netdev_notifier);
Johannes Berg704232c2007-04-23 12:20:05 -0700808out_fail_notifier:
809 wiphy_sysfs_exit();
810out_fail_sysfs:
Johannes Berg463d0182009-07-14 00:33:35 +0200811 unregister_pernet_device(&cfg80211_pernet_ops);
812out_fail_pernet:
Johannes Berg704232c2007-04-23 12:20:05 -0700813 return err;
814}
Johannes Berg3a462462007-09-10 13:44:45 +0200815subsys_initcall(cfg80211_init);
Johannes Berg704232c2007-04-23 12:20:05 -0700816
817static void cfg80211_exit(void)
818{
819 debugfs_remove(ieee80211_debugfs_dir);
Johannes Berg55682962007-09-20 13:09:35 -0400820 nl80211_exit();
Johannes Berg704232c2007-04-23 12:20:05 -0700821 unregister_netdevice_notifier(&cfg80211_netdev_notifier);
822 wiphy_sysfs_exit();
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700823 regulatory_exit();
Johannes Berg463d0182009-07-14 00:33:35 +0200824 unregister_pernet_device(&cfg80211_pernet_ops);
Johannes Berg704232c2007-04-23 12:20:05 -0700825}
826module_exit(cfg80211_exit);