FILE
core.c
File preview with syntax highlighting.
linux-6.19.14/net/wireless/core.c
1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * This is the linux wireless configuration interface. 4 * 5 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> 6 * Copyright 2013-2014 Intel Mobile Communications GmbH 7 * Copyright 2015-2017 Intel Deutschland GmbH 8 * Copyright (C) 2018-2025 Intel Corporation 9 */ 10 11#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 12 13#include <linux/if.h> 14#include <linux/module.h> 15#include <linux/err.h> 16#include <linux/list.h> 17#include <linux/slab.h> 18#include <linux/nl80211.h> 19#include <linux/debugfs.h> 20#include <linux/notifier.h> 21#include <linux/device.h> 22#include <linux/etherdevice.h> 23#include <linux/rtnetlink.h> 24#include <linux/sched.h> 25#include <net/genetlink.h> 26#include <net/cfg80211.h> 27#include "nl80211.h" 28#include "core.h" 29#include "sysfs.h" 30#include "debugfs.h" 31#include "wext-compat.h" 32#include "rdev-ops.h" 33 34/* name for sysfs, %d is appended */ 35#define PHY_NAME "phy" 36 37/* maximum length of radio debugfs directory name */ 38#define RADIO_DEBUGFSDIR_MAX_LEN 8 39 40MODULE_AUTHOR("Johannes Berg"); 41MODULE_LICENSE("GPL"); 42MODULE_DESCRIPTION("wireless configuration support"); 43MODULE_ALIAS_GENL_FAMILY(NL80211_GENL_NAME); 44 45/* RCU-protected (and RTNL for writers) */ 46LIST_HEAD(cfg80211_rdev_list); 47int cfg80211_rdev_list_generation; 48 49/* for debugfs */ 50static struct dentry *ieee80211_debugfs_dir; 51 52/* for the cleanup, scan and event works */ 53struct workqueue_struct *cfg80211_wq; 54 55static bool cfg80211_disable_40mhz_24ghz; 56module_param(cfg80211_disable_40mhz_24ghz, bool, 0644); 57MODULE_PARM_DESC(cfg80211_disable_40mhz_24ghz, 58 "Disable 40MHz support in the 2.4GHz band"); 59 60struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx) 61{ 62 struct cfg80211_registered_device *result = NULL, *rdev; 63 64 ASSERT_RTNL(); 65 66 for_each_rdev(rdev) { 67 if (rdev->wiphy_idx == wiphy_idx) { 68 result = rdev; 69 break; 70 } 71 } 72 73 return result; 74} 75 76int get_wiphy_idx(struct wiphy *wiphy) 77{ 78 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 79 80 return rdev->wiphy_idx; 81} 82 83struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx) 84{ 85 struct cfg80211_registered_device *rdev; 86 87 ASSERT_RTNL(); 88 89 rdev = cfg80211_rdev_by_wiphy_idx(wiphy_idx); 90 if (!rdev) 91 return NULL; 92 return &rdev->wiphy; 93} 94 95static int cfg80211_dev_check_name(struct cfg80211_registered_device *rdev, 96 const char *newname) 97{ 98 struct cfg80211_registered_device *rdev2; 99 int wiphy_idx, taken = -1, digits; 100 101 ASSERT_RTNL(); 102 103 if (strlen(newname) > NL80211_WIPHY_NAME_MAXLEN) 104 return -EINVAL; 105 106 /* prohibit calling the thing phy%d when %d is not its number */ 107 sscanf(newname, PHY_NAME "%d%n", &wiphy_idx, &taken); 108 if (taken == strlen(newname) && wiphy_idx != rdev->wiphy_idx) { 109 /* count number of places needed to print wiphy_idx */ 110 digits = 1; 111 while (wiphy_idx /= 10) 112 digits++; 113 /* 114 * deny the name if it is phy<idx> where <idx> is printed 115 * without leading zeroes. taken == strlen(newname) here 116 */ 117 if (taken == strlen(PHY_NAME) + digits) 118 return -EINVAL; 119 } 120 121 /* Ensure another device does not already have this name. */ 122 for_each_rdev(rdev2) 123 if (strcmp(newname, wiphy_name(&rdev2->wiphy)) == 0) 124 return -EINVAL; 125 126 return 0; 127} 128 129int cfg80211_dev_rename(struct cfg80211_registered_device *rdev, 130 char *newname) 131{ 132 int result; 133 134 ASSERT_RTNL(); 135 lockdep_assert_wiphy(&rdev->wiphy); 136 137 /* Ignore nop renames */ 138 if (strcmp(newname, wiphy_name(&rdev->wiphy)) == 0) 139 return 0; 140 141 result = cfg80211_dev_check_name(rdev, newname); 142 if (result < 0) 143 return result; 144 145 result = device_rename(&rdev->wiphy.dev, newname); 146 if (result) 147 return result; 148 149 debugfs_change_name(rdev->wiphy.debugfsdir, "%s", newname); 150 151 nl80211_notify_wiphy(rdev, NL80211_CMD_NEW_WIPHY); 152 153 return 0; 154} 155 156int cfg80211_switch_netns(struct cfg80211_registered_device *rdev, 157 struct net *net) 158{ 159 struct wireless_dev *wdev; 160 int err = 0; 161 162 if (!(rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK)) 163 return -EOPNOTSUPP; 164 165 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 166 if (!wdev->netdev) 167 continue; 168 wdev->netdev->netns_immutable = false; 169 err = dev_change_net_namespace(wdev->netdev, net, "wlan%d"); 170 if (err) 171 break; 172 wdev->netdev->netns_immutable = true; 173 } 174 175 if (err) { 176 /* failed -- clean up to old netns */ 177 net = wiphy_net(&rdev->wiphy); 178 179 list_for_each_entry_continue_reverse(wdev, 180 &rdev->wiphy.wdev_list, 181 list) { 182 if (!wdev->netdev) 183 continue; 184 wdev->netdev->netns_immutable = false; 185 err = dev_change_net_namespace(wdev->netdev, net, 186 "wlan%d"); 187 WARN_ON(err); 188 wdev->netdev->netns_immutable = true; 189 } 190 191 return err; 192 } 193 194 guard(wiphy)(&rdev->wiphy); 195 196 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 197 if (!wdev->netdev) 198 continue; 199 nl80211_notify_iface(rdev, wdev, NL80211_CMD_DEL_INTERFACE); 200 } 201 202 nl80211_notify_wiphy(rdev, NL80211_CMD_DEL_WIPHY); 203 204 wiphy_net_set(&rdev->wiphy, net); 205 206 err = device_rename(&rdev->wiphy.dev, dev_name(&rdev->wiphy.dev)); 207 WARN_ON(err); 208 209 nl80211_notify_wiphy(rdev, NL80211_CMD_NEW_WIPHY); 210 211 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 212 if (!wdev->netdev) 213 continue; 214 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE); 215 } 216 217 return 0; 218} 219 220static void cfg80211_rfkill_poll(struct rfkill *rfkill, void *data) 221{ 222 struct cfg80211_registered_device *rdev = data; 223 224 guard(wiphy)(&rdev->wiphy); 225 226 rdev_rfkill_poll(rdev); 227} 228 229void cfg80211_stop_p2p_device(struct cfg80211_registered_device *rdev, 230 struct wireless_dev *wdev) 231{ 232 lockdep_assert_held(&rdev->wiphy.mtx); 233 234 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)) 235 return; 236 237 if (!wdev_running(wdev)) 238 return; 239 240 rdev_stop_p2p_device(rdev, wdev); 241 wdev->is_running = false; 242 243 rdev->opencount--; 244 245 if (rdev->scan_req && rdev->scan_req->req.wdev == wdev) { 246 if (WARN_ON(!rdev->scan_req->notified && 247 (!rdev->int_scan_req || 248 !rdev->int_scan_req->notified))) 249 rdev->scan_req->info.aborted = true; 250 ___cfg80211_scan_done(rdev, false); 251 } 252} 253 254void cfg80211_stop_nan(struct cfg80211_registered_device *rdev, 255 struct wireless_dev *wdev) 256{ 257 lockdep_assert_held(&rdev->wiphy.mtx); 258 259 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_NAN)) 260 return; 261 262 if (!wdev_running(wdev)) 263 return; 264 265 rdev_stop_nan(rdev, wdev); 266 wdev->is_running = false; 267 268 rdev->opencount--; 269} 270 271void cfg80211_shutdown_all_interfaces(struct wiphy *wiphy) 272{ 273 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 274 struct wireless_dev *wdev; 275 276 ASSERT_RTNL(); 277 278 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 279 if (wdev->netdev) { 280 dev_close(wdev->netdev); 281 continue; 282 } 283 284 /* otherwise, check iftype */ 285 286 guard(wiphy)(wiphy); 287 288 switch (wdev->iftype) { 289 case NL80211_IFTYPE_P2P_DEVICE: 290 cfg80211_stop_p2p_device(rdev, wdev); 291 break; 292 case NL80211_IFTYPE_NAN: 293 cfg80211_stop_nan(rdev, wdev); 294 break; 295 default: 296 break; 297 } 298 } 299} 300EXPORT_SYMBOL_GPL(cfg80211_shutdown_all_interfaces); 301 302static int cfg80211_rfkill_set_block(void *data, bool blocked) 303{ 304 struct cfg80211_registered_device *rdev = data; 305 306 if (!blocked) 307 return 0; 308 309 rtnl_lock(); 310 cfg80211_shutdown_all_interfaces(&rdev->wiphy); 311 rtnl_unlock(); 312 313 return 0; 314} 315 316static void cfg80211_rfkill_block_work(struct work_struct *work) 317{ 318 struct cfg80211_registered_device *rdev; 319 320 rdev = container_of(work, struct cfg80211_registered_device, 321 rfkill_block); 322 cfg80211_rfkill_set_block(rdev, true); 323} 324 325static void cfg80211_event_work(struct work_struct *work) 326{ 327 struct cfg80211_registered_device *rdev; 328 329 rdev = container_of(work, struct cfg80211_registered_device, 330 event_work); 331 332 guard(wiphy)(&rdev->wiphy); 333 334 cfg80211_process_rdev_events(rdev); 335} 336 337void cfg80211_destroy_ifaces(struct cfg80211_registered_device *rdev) 338{ 339 struct wireless_dev *wdev, *tmp; 340 341 ASSERT_RTNL(); 342 343 list_for_each_entry_safe(wdev, tmp, &rdev->wiphy.wdev_list, list) { 344 if (wdev->nl_owner_dead) { 345 if (wdev->netdev) 346 dev_close(wdev->netdev); 347 348 guard(wiphy)(&rdev->wiphy); 349 350 cfg80211_leave(rdev, wdev); 351 cfg80211_remove_virtual_intf(rdev, wdev); 352 } 353 } 354} 355 356static void cfg80211_destroy_iface_wk(struct work_struct *work) 357{ 358 struct cfg80211_registered_device *rdev; 359 360 rdev = container_of(work, struct cfg80211_registered_device, 361 destroy_work); 362 363 rtnl_lock(); 364 cfg80211_destroy_ifaces(rdev); 365 rtnl_unlock(); 366} 367 368static void cfg80211_sched_scan_stop_wk(struct wiphy *wiphy, 369 struct wiphy_work *work) 370{ 371 struct cfg80211_registered_device *rdev; 372 struct cfg80211_sched_scan_request *req, *tmp; 373 374 rdev = container_of(work, struct cfg80211_registered_device, 375 sched_scan_stop_wk); 376 377 list_for_each_entry_safe(req, tmp, &rdev->sched_scan_req_list, list) { 378 if (req->nl_owner_dead) 379 cfg80211_stop_sched_scan_req(rdev, req, false); 380 } 381} 382 383static void cfg80211_propagate_radar_detect_wk(struct work_struct *work) 384{ 385 struct cfg80211_registered_device *rdev; 386 387 rdev = container_of(work, struct cfg80211_registered_device, 388 propagate_radar_detect_wk); 389 390 rtnl_lock(); 391 392 regulatory_propagate_dfs_state(&rdev->wiphy, &rdev->radar_chandef, 393 NL80211_DFS_UNAVAILABLE, 394 NL80211_RADAR_DETECTED); 395 396 rtnl_unlock(); 397} 398 399static void cfg80211_propagate_cac_done_wk(struct work_struct *work) 400{ 401 struct cfg80211_registered_device *rdev; 402 403 rdev = container_of(work, struct cfg80211_registered_device, 404 propagate_cac_done_wk); 405 406 rtnl_lock(); 407 408 regulatory_propagate_dfs_state(&rdev->wiphy, &rdev->cac_done_chandef, 409 NL80211_DFS_AVAILABLE, 410 NL80211_RADAR_CAC_FINISHED); 411 412 rtnl_unlock(); 413} 414 415static void cfg80211_wiphy_work(struct work_struct *work) 416{ 417 struct cfg80211_registered_device *rdev; 418 struct wiphy_work *wk; 419 420 rdev = container_of(work, struct cfg80211_registered_device, wiphy_work); 421 422 trace_wiphy_work_worker_start(&rdev->wiphy); 423 424 guard(wiphy)(&rdev->wiphy); 425 if (rdev->suspended) 426 return; 427 428 spin_lock_irq(&rdev->wiphy_work_lock); 429 wk = list_first_entry_or_null(&rdev->wiphy_work_list, 430 struct wiphy_work, entry); 431 if (wk) { 432 list_del_init(&wk->entry); 433 if (!list_empty(&rdev->wiphy_work_list)) 434 queue_work(system_dfl_wq, work); 435 spin_unlock_irq(&rdev->wiphy_work_lock); 436 437 trace_wiphy_work_run(&rdev->wiphy, wk); 438 wk->func(&rdev->wiphy, wk); 439 } else { 440 spin_unlock_irq(&rdev->wiphy_work_lock); 441 } 442} 443 444/* exported functions */ 445 446struct wiphy *wiphy_new_nm(const struct cfg80211_ops *ops, int sizeof_priv, 447 const char *requested_name) 448{ 449 static atomic_t wiphy_counter = ATOMIC_INIT(0); 450 451 struct cfg80211_registered_device *rdev; 452 int alloc_size; 453 454 WARN_ON(ops->add_key && (!ops->del_key || !ops->set_default_key)); 455 WARN_ON(ops->auth && (!ops->assoc || !ops->deauth || !ops->disassoc)); 456 WARN_ON(ops->connect && !ops->disconnect); 457 WARN_ON(ops->join_ibss && !ops->leave_ibss); 458 WARN_ON(ops->add_virtual_intf && !ops->del_virtual_intf); 459 WARN_ON(ops->add_station && !ops->del_station); 460 WARN_ON(ops->add_mpath && !ops->del_mpath); 461 WARN_ON(ops->join_mesh && !ops->leave_mesh); 462 WARN_ON(ops->start_p2p_device && !ops->stop_p2p_device); 463 WARN_ON(ops->start_ap && !ops->stop_ap); 464 WARN_ON(ops->join_ocb && !ops->leave_ocb); 465 WARN_ON(ops->suspend && !ops->resume); 466 WARN_ON(ops->sched_scan_start && !ops->sched_scan_stop); 467 WARN_ON(ops->remain_on_channel && !ops->cancel_remain_on_channel); 468 WARN_ON(ops->tdls_channel_switch && !ops->tdls_cancel_channel_switch); 469 WARN_ON(ops->add_tx_ts && !ops->del_tx_ts); 470 471 alloc_size = sizeof(*rdev) + sizeof_priv; 472 473 rdev = kzalloc(alloc_size, GFP_KERNEL); 474 if (!rdev) 475 return NULL; 476 477 rdev->ops = ops; 478 479 rdev->wiphy_idx = atomic_inc_return(&wiphy_counter); 480 481 if (unlikely(rdev->wiphy_idx < 0)) { 482 /* ugh, wrapped! */ 483 atomic_dec(&wiphy_counter); 484 kfree(rdev); 485 return NULL; 486 } 487 488 /* atomic_inc_return makes it start at 1, make it start at 0 */ 489 rdev->wiphy_idx--; 490 491 /* give it a proper name */ 492 if (requested_name && requested_name[0]) { 493 int rv; 494 495 rtnl_lock(); 496 rv = cfg80211_dev_check_name(rdev, requested_name); 497 498 if (rv < 0) { 499 rtnl_unlock(); 500 goto use_default_name; 501 } 502 503 rv = dev_set_name(&rdev->wiphy.dev, "%s", requested_name); 504 rtnl_unlock(); 505 if (rv) 506 goto use_default_name; 507 } else { 508 int rv; 509 510use_default_name: 511 /* NOTE: This is *probably* safe w/out holding rtnl because of 512 * the restrictions on phy names. Probably this call could 513 * fail if some other part of the kernel (re)named a device 514 * phyX. But, might should add some locking and check return 515 * value, and use a different name if this one exists? 516 */ 517 rv = dev_set_name(&rdev->wiphy.dev, PHY_NAME "%d", rdev->wiphy_idx); 518 if (rv < 0) { 519 kfree(rdev); 520 return NULL; 521 } 522 } 523 524 mutex_init(&rdev->wiphy.mtx); 525 INIT_LIST_HEAD(&rdev->wiphy.wdev_list); 526 INIT_LIST_HEAD(&rdev->beacon_registrations); 527 spin_lock_init(&rdev->beacon_registrations_lock); 528 spin_lock_init(&rdev->bss_lock); 529 INIT_LIST_HEAD(&rdev->bss_list); 530 INIT_LIST_HEAD(&rdev->sched_scan_req_list); 531 wiphy_work_init(&rdev->scan_done_wk, __cfg80211_scan_done); 532 INIT_DELAYED_WORK(&rdev->dfs_update_channels_wk, 533 cfg80211_dfs_channels_update_work); 534#ifdef CONFIG_CFG80211_WEXT 535 rdev->wiphy.wext = &cfg80211_wext_handler; 536#endif 537 538 device_initialize(&rdev->wiphy.dev); 539 rdev->wiphy.dev.class = &ieee80211_class; 540 rdev->wiphy.dev.platform_data = rdev; 541 device_enable_async_suspend(&rdev->wiphy.dev); 542 543 INIT_WORK(&rdev->destroy_work, cfg80211_destroy_iface_wk); 544 wiphy_work_init(&rdev->sched_scan_stop_wk, cfg80211_sched_scan_stop_wk); 545 INIT_WORK(&rdev->sched_scan_res_wk, cfg80211_sched_scan_results_wk); 546 INIT_WORK(&rdev->propagate_radar_detect_wk, 547 cfg80211_propagate_radar_detect_wk); 548 INIT_WORK(&rdev->propagate_cac_done_wk, cfg80211_propagate_cac_done_wk); 549 INIT_WORK(&rdev->mgmt_registrations_update_wk, 550 cfg80211_mgmt_registrations_update_wk); 551 spin_lock_init(&rdev->mgmt_registrations_lock); 552 INIT_WORK(&rdev->wiphy_work, cfg80211_wiphy_work); 553 INIT_LIST_HEAD(&rdev->wiphy_work_list); 554 spin_lock_init(&rdev->wiphy_work_lock); 555 556#ifdef CONFIG_CFG80211_DEFAULT_PS 557 rdev->wiphy.flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; 558#endif 559 560 wiphy_net_set(&rdev->wiphy, &init_net); 561 562 rdev->rfkill_ops.set_block = cfg80211_rfkill_set_block; 563 rdev->wiphy.rfkill = rfkill_alloc(dev_name(&rdev->wiphy.dev), 564 &rdev->wiphy.dev, RFKILL_TYPE_WLAN, 565 &rdev->rfkill_ops, rdev); 566 567 if (!rdev->wiphy.rfkill) { 568 wiphy_free(&rdev->wiphy); 569 return NULL; 570 } 571 572 INIT_WORK(&rdev->rfkill_block, cfg80211_rfkill_block_work); 573 INIT_WORK(&rdev->conn_work, cfg80211_conn_work); 574 INIT_WORK(&rdev->event_work, cfg80211_event_work); 575 INIT_WORK(&rdev->background_cac_abort_wk, 576 cfg80211_background_cac_abort_wk); 577 INIT_DELAYED_WORK(&rdev->background_cac_done_wk, 578 cfg80211_background_cac_done_wk); 579 580 init_waitqueue_head(&rdev->dev_wait); 581 582 /* 583 * Initialize wiphy parameters to IEEE 802.11 MIB default values. 584 * Fragmentation and RTS threshold are disabled by default with the 585 * special -1 value. 586 */ 587 rdev->wiphy.retry_short = 7; 588 rdev->wiphy.retry_long = 4; 589 rdev->wiphy.frag_threshold = (u32) -1; 590 rdev->wiphy.rts_threshold = (u32) -1; 591 rdev->wiphy.coverage_class = 0; 592 593 rdev->wiphy.max_num_csa_counters = 1; 594 595 rdev->wiphy.max_sched_scan_plans = 1; 596 rdev->wiphy.max_sched_scan_plan_interval = U32_MAX; 597 598 return &rdev->wiphy; 599} 600EXPORT_SYMBOL(wiphy_new_nm); 601 602static 603int wiphy_verify_iface_combinations(struct wiphy *wiphy, 604 const struct ieee80211_iface_combination *iface_comb, 605 int n_iface_comb, 606 bool combined_radio) 607{ 608 const struct ieee80211_iface_combination *c; 609 int i, j; 610 611 for (i = 0; i < n_iface_comb; i++) { 612 u32 cnt = 0; 613 u16 all_iftypes = 0; 614 615 c = &iface_comb[i]; 616 617 /* 618 * Combinations with just one interface aren't real, 619 * however we make an exception for DFS. 620 */ 621 if (WARN_ON((c->max_interfaces < 2) && !c->radar_detect_widths)) 622 return -EINVAL; 623 624 /* Need at least one channel */ 625 if (WARN_ON(!c->num_different_channels)) 626 return -EINVAL; 627 628 /* DFS only works on one channel. Avoid this check 629 * for multi-radio global combination, since it hold 630 * the capabilities of all radio combinations. 631 */ 632 if (!combined_radio && 633 WARN_ON(c->radar_detect_widths && 634 c->num_different_channels > 1)) 635 return -EINVAL; 636 637 if (WARN_ON(!c->n_limits)) 638 return -EINVAL; 639 640 for (j = 0; j < c->n_limits; j++) { 641 u16 types = c->limits[j].types; 642 643 /* interface types shouldn't overlap */ 644 if (WARN_ON(types & all_iftypes)) 645 return -EINVAL; 646 all_iftypes |= types; 647 648 if (WARN_ON(!c->limits[j].max)) 649 return -EINVAL; 650 651 /* Shouldn't list software iftypes in combinations! */ 652 if (WARN_ON(wiphy->software_iftypes & types)) 653 return -EINVAL; 654 655 /* Only a single P2P_DEVICE can be allowed, avoid this 656 * check for multi-radio global combination, since it 657 * hold the capabilities of all radio combinations. 658 */ 659 if (!combined_radio && 660 WARN_ON(types & BIT(NL80211_IFTYPE_P2P_DEVICE) && 661 c->limits[j].max > 1)) 662 return -EINVAL; 663 664 /* Only a single NAN can be allowed */ 665 if (WARN_ON(types & BIT(NL80211_IFTYPE_NAN) && 666 c->limits[j].max > 1)) 667 return -EINVAL; 668 669 /* 670 * This isn't well-defined right now. If you have an 671 * IBSS interface, then its beacon interval may change 672 * by joining other networks, and nothing prevents it 673 * from doing that. 674 * So technically we probably shouldn't even allow AP 675 * and IBSS in the same interface, but it seems that 676 * some drivers support that, possibly only with fixed 677 * beacon intervals for IBSS. 678 */ 679 if (WARN_ON(types & BIT(NL80211_IFTYPE_ADHOC) && 680 c->beacon_int_min_gcd)) { 681 return -EINVAL; 682 } 683 684 cnt += c->limits[j].max; 685 /* 686 * Don't advertise an unsupported type 687 * in a combination. 688 */ 689 if (WARN_ON((wiphy->interface_modes & types) != types)) 690 return -EINVAL; 691 } 692 693 if (WARN_ON(all_iftypes & BIT(NL80211_IFTYPE_WDS))) 694 return -EINVAL; 695 696 /* You can't even choose that many! */ 697 if (WARN_ON(cnt < c->max_interfaces)) 698 return -EINVAL; 699 } 700 701 return 0; 702} 703 704static int wiphy_verify_combinations(struct wiphy *wiphy) 705{ 706 int i, ret; 707 bool combined_radio = false; 708 709 if (wiphy->n_radio) { 710 for (i = 0; i < wiphy->n_radio; i++) { 711 const struct wiphy_radio *radio = &wiphy->radio[i]; 712 713 ret = wiphy_verify_iface_combinations(wiphy, 714 radio->iface_combinations, 715 radio->n_iface_combinations, 716 false); 717 if (ret) 718 return ret; 719 } 720 721 combined_radio = true; 722 } 723 724 ret = wiphy_verify_iface_combinations(wiphy, 725 wiphy->iface_combinations, 726 wiphy->n_iface_combinations, 727 combined_radio); 728 729 return ret; 730} 731 732int wiphy_register(struct wiphy *wiphy) 733{ 734 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 735 int res; 736 enum nl80211_band band; 737 struct ieee80211_supported_band *sband; 738 bool have_band = false; 739 int i; 740 u16 ifmodes = wiphy->interface_modes; 741 742#ifdef CONFIG_PM 743 if (WARN_ON(wiphy->wowlan && 744 (wiphy->wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && 745 !(wiphy->wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY))) 746 return -EINVAL; 747 if (WARN_ON(wiphy->wowlan && 748 !wiphy->wowlan->flags && !wiphy->wowlan->n_patterns && 749 !wiphy->wowlan->tcp)) 750 return -EINVAL; 751#endif 752 if (WARN_ON((wiphy->features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH) && 753 (!rdev->ops->tdls_channel_switch || 754 !rdev->ops->tdls_cancel_channel_switch))) 755 return -EINVAL; 756 757 if (WARN_ON((wiphy->interface_modes & BIT(NL80211_IFTYPE_NAN)) && 758 (!rdev->ops->start_nan || !rdev->ops->stop_nan || 759 !rdev->ops->add_nan_func || !rdev->ops->del_nan_func || 760 !(wiphy->nan_supported_bands & BIT(NL80211_BAND_2GHZ))))) 761 return -EINVAL; 762 763 if (WARN_ON(wiphy->interface_modes & BIT(NL80211_IFTYPE_WDS))) 764 return -EINVAL; 765 766 if (WARN_ON(wiphy->pmsr_capa && !wiphy->pmsr_capa->ftm.supported)) 767 return -EINVAL; 768 769 if (wiphy->pmsr_capa && wiphy->pmsr_capa->ftm.supported) { 770 if (WARN_ON(!wiphy->pmsr_capa->ftm.asap && 771 !wiphy->pmsr_capa->ftm.non_asap)) 772 return -EINVAL; 773 if (WARN_ON(!wiphy->pmsr_capa->ftm.preambles || 774 !wiphy->pmsr_capa->ftm.bandwidths)) 775 return -EINVAL; 776 if (WARN_ON(wiphy->pmsr_capa->ftm.preambles & 777 ~(BIT(NL80211_PREAMBLE_LEGACY) | 778 BIT(NL80211_PREAMBLE_HT) | 779 BIT(NL80211_PREAMBLE_VHT) | 780 BIT(NL80211_PREAMBLE_HE) | 781 BIT(NL80211_PREAMBLE_DMG)))) 782 return -EINVAL; 783 if (WARN_ON((wiphy->pmsr_capa->ftm.trigger_based || 784 wiphy->pmsr_capa->ftm.non_trigger_based) && 785 !(wiphy->pmsr_capa->ftm.preambles & 786 BIT(NL80211_PREAMBLE_HE)))) 787 return -EINVAL; 788 if (WARN_ON(wiphy->pmsr_capa->ftm.bandwidths & 789 ~(BIT(NL80211_CHAN_WIDTH_20_NOHT) | 790 BIT(NL80211_CHAN_WIDTH_20) | 791 BIT(NL80211_CHAN_WIDTH_40) | 792 BIT(NL80211_CHAN_WIDTH_80) | 793 BIT(NL80211_CHAN_WIDTH_80P80) | 794 BIT(NL80211_CHAN_WIDTH_160) | 795 BIT(NL80211_CHAN_WIDTH_320) | 796 BIT(NL80211_CHAN_WIDTH_5) | 797 BIT(NL80211_CHAN_WIDTH_10)))) 798 return -EINVAL; 799 } 800 801 if (WARN_ON((wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) && 802 (wiphy->regulatory_flags & 803 (REGULATORY_CUSTOM_REG | 804 REGULATORY_STRICT_REG | 805 REGULATORY_COUNTRY_IE_FOLLOW_POWER | 806 REGULATORY_COUNTRY_IE_IGNORE)))) 807 return -EINVAL; 808 809 if (WARN_ON(wiphy->coalesce && 810 (!wiphy->coalesce->n_rules || 811 !wiphy->coalesce->n_patterns) && 812 (!wiphy->coalesce->pattern_min_len || 813 wiphy->coalesce->pattern_min_len > 814 wiphy->coalesce->pattern_max_len))) 815 return -EINVAL; 816 817 if (WARN_ON(wiphy->ap_sme_capa && 818 !(wiphy->flags & WIPHY_FLAG_HAVE_AP_SME))) 819 return -EINVAL; 820 821 if (WARN_ON(wiphy->addresses && !wiphy->n_addresses)) 822 return -EINVAL; 823 824 if (WARN_ON(wiphy->addresses && 825 !is_zero_ether_addr(wiphy->perm_addr) && 826 memcmp(wiphy->perm_addr, wiphy->addresses[0].addr, 827 ETH_ALEN))) 828 return -EINVAL; 829 830 if (WARN_ON(wiphy->max_acl_mac_addrs && 831 (!(wiphy->flags & WIPHY_FLAG_HAVE_AP_SME) || 832 !rdev->ops->set_mac_acl))) 833 return -EINVAL; 834 835 /* assure only valid behaviours are flagged by driver 836 * hence subtract 2 as bit 0 is invalid. 837 */ 838 if (WARN_ON(wiphy->bss_select_support && 839 (wiphy->bss_select_support & ~(BIT(__NL80211_BSS_SELECT_ATTR_AFTER_LAST) - 2)))) 840 return -EINVAL; 841 842 if (WARN_ON(wiphy_ext_feature_isset(&rdev->wiphy, 843 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X) && 844 (!rdev->ops->set_pmk || !rdev->ops->del_pmk))) 845 return -EINVAL; 846 847 if (WARN_ON(!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && 848 rdev->ops->update_connect_params)) 849 return -EINVAL; 850 851 if (wiphy->addresses) 852 memcpy(wiphy->perm_addr, wiphy->addresses[0].addr, ETH_ALEN); 853 854 /* sanity check ifmodes */ 855 WARN_ON(!ifmodes); 856 ifmodes &= ((1 << NUM_NL80211_IFTYPES) - 1) & ~1; 857 if (WARN_ON(ifmodes != wiphy->interface_modes)) 858 wiphy->interface_modes = ifmodes; 859 860 res = wiphy_verify_combinations(wiphy); 861 if (res) 862 return res; 863 864 /* sanity check supported bands/channels */ 865 for (band = 0; band < NUM_NL80211_BANDS; band++) { 866 const struct ieee80211_sband_iftype_data *iftd; 867 u16 types = 0; 868 bool have_he = false; 869 870 sband = wiphy->bands[band]; 871 if (!sband) 872 continue; 873 874 sband->band = band; 875 if (WARN_ON(!sband->n_channels)) 876 return -EINVAL; 877 /* 878 * on 60GHz or sub-1Ghz band, there are no legacy rates, so 879 * n_bitrates is 0 880 */ 881 if (WARN_ON((band != NL80211_BAND_60GHZ && 882 band != NL80211_BAND_S1GHZ) && 883 !sband->n_bitrates)) 884 return -EINVAL; 885 886 if (WARN_ON(band == NL80211_BAND_6GHZ && 887 (sband->ht_cap.ht_supported || 888 sband->vht_cap.vht_supported))) 889 return -EINVAL; 890 891 /* 892 * Since cfg80211_disable_40mhz_24ghz is global, we can 893 * modify the sband's ht data even if the driver uses a 894 * global structure for that. 895 */ 896 if (cfg80211_disable_40mhz_24ghz && 897 band == NL80211_BAND_2GHZ && 898 sband->ht_cap.ht_supported) { 899 sband->ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; 900 sband->ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_40; 901 } 902 903 /* 904 * Since we use a u32 for rate bitmaps in 905 * ieee80211_get_response_rate, we cannot 906 * have more than 32 legacy rates. 907 */ 908 if (WARN_ON(sband->n_bitrates > 32)) 909 return -EINVAL; 910 911 for (i = 0; i < sband->n_channels; i++) { 912 sband->channels[i].orig_flags = 913 sband->channels[i].flags; 914 sband->channels[i].orig_mag = INT_MAX; 915 sband->channels[i].orig_mpwr = 916 sband->channels[i].max_power; 917 sband->channels[i].band = band; 918 919 if (WARN_ON(sband->channels[i].freq_offset >= 1000)) 920 return -EINVAL; 921 } 922 923 for_each_sband_iftype_data(sband, i, iftd) { 924 bool has_ap, has_non_ap; 925 u32 ap_bits = BIT(NL80211_IFTYPE_AP) | 926 BIT(NL80211_IFTYPE_P2P_GO); 927 928 if (WARN_ON(!iftd->types_mask)) 929 return -EINVAL; 930 if (WARN_ON(types & iftd->types_mask)) 931 return -EINVAL; 932 933 /* at least one piece of information must be present */ 934 if (WARN_ON(!iftd->he_cap.has_he)) 935 return -EINVAL; 936 937 types |= iftd->types_mask; 938 939 if (i == 0) 940 have_he = iftd->he_cap.has_he; 941 else 942 have_he = have_he && 943 iftd->he_cap.has_he; 944 945 has_ap = iftd->types_mask & ap_bits; 946 has_non_ap = iftd->types_mask & ~ap_bits; 947 948 /* 949 * For EHT 20 MHz STA, the capabilities format differs 950 * but to simplify, don't check 20 MHz but rather check 951 * only if AP and non-AP were mentioned at the same time, 952 * reject if so. 953 */ 954 if (WARN_ON(iftd->eht_cap.has_eht && 955 has_ap && has_non_ap)) 956 return -EINVAL; 957 } 958 959 if (WARN_ON(!have_he && band == NL80211_BAND_6GHZ)) 960 return -EINVAL; 961 962 have_band = true; 963 } 964 965 if (!have_band) { 966 WARN_ON(1); 967 return -EINVAL; 968 } 969 970 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { 971 /* 972 * Validate we have a policy (can be explicitly set to 973 * VENDOR_CMD_RAW_DATA which is non-NULL) and also that 974 * we have at least one of doit/dumpit. 975 */ 976 if (WARN_ON(!rdev->wiphy.vendor_commands[i].policy)) 977 return -EINVAL; 978 if (WARN_ON(!rdev->wiphy.vendor_commands[i].doit && 979 !rdev->wiphy.vendor_commands[i].dumpit)) 980 return -EINVAL; 981 } 982 983#ifdef CONFIG_PM 984 if (WARN_ON(rdev->wiphy.wowlan && rdev->wiphy.wowlan->n_patterns && 985 (!rdev->wiphy.wowlan->pattern_min_len || 986 rdev->wiphy.wowlan->pattern_min_len > 987 rdev->wiphy.wowlan->pattern_max_len))) 988 return -EINVAL; 989#endif 990 991 if (!wiphy->max_num_akm_suites) 992 wiphy->max_num_akm_suites = NL80211_MAX_NR_AKM_SUITES; 993 else if (wiphy->max_num_akm_suites < NL80211_MAX_NR_AKM_SUITES || 994 wiphy->max_num_akm_suites > CFG80211_MAX_NUM_AKM_SUITES) 995 return -EINVAL; 996 997 /* Allocate radio configuration space for multi-radio wiphy */ 998 if (wiphy->n_radio > 0) { 999 int idx; 1000 1001 wiphy->radio_cfg = kcalloc(wiphy->n_radio, 1002 sizeof(*wiphy->radio_cfg), 1003 GFP_KERNEL); 1004 if (!wiphy->radio_cfg) 1005 return -ENOMEM; 1006 /* 1007 * Initialize wiphy radio parameters to IEEE 802.11 1008 * MIB default values. RTS threshold is disabled by 1009 * default with the special -1 value. 1010 */ 1011 for (idx = 0; idx < wiphy->n_radio; idx++) 1012 wiphy->radio_cfg[idx].rts_threshold = (u32)-1; 1013 } 1014 1015 /* check and set up bitrates */ 1016 ieee80211_set_bitrate_flags(wiphy); 1017 1018 rdev->wiphy.features |= NL80211_FEATURE_SCAN_FLUSH; 1019 1020 if (rdev->wiphy.bss_param_support & WIPHY_BSS_PARAM_P2P_CTWINDOW) 1021 rdev->wiphy.features |= NL80211_FEATURE_P2P_GO_CTWIN; 1022 else if (rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN) 1023 rdev->wiphy.bss_param_support |= WIPHY_BSS_PARAM_P2P_CTWINDOW; 1024 if (rdev->wiphy.bss_param_support & WIPHY_BSS_PARAM_P2P_OPPPS) 1025 rdev->wiphy.features |= NL80211_FEATURE_P2P_GO_OPPPS; 1026 else if (rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS) 1027 rdev->wiphy.bss_param_support |= WIPHY_BSS_PARAM_P2P_OPPPS; 1028 1029 rtnl_lock(); 1030 wiphy_lock(&rdev->wiphy); 1031 res = device_add(&rdev->wiphy.dev); 1032 if (res) { 1033 wiphy_unlock(&rdev->wiphy); 1034 rtnl_unlock(); 1035 return res; 1036 } 1037 1038 list_add_rcu(&rdev->list, &cfg80211_rdev_list); 1039 cfg80211_rdev_list_generation++; 1040 1041 /* add to debugfs */ 1042 rdev->wiphy.debugfsdir = debugfs_create_dir(wiphy_name(&rdev->wiphy), 1043 ieee80211_debugfs_dir); 1044 if (wiphy->n_radio > 0) { 1045 int idx; 1046 char radio_name[RADIO_DEBUGFSDIR_MAX_LEN]; 1047 1048 for (idx = 0; idx < wiphy->n_radio; idx++) { 1049 scnprintf(radio_name, sizeof(radio_name), "radio%d", 1050 idx); 1051 wiphy->radio_cfg[idx].radio_debugfsdir = 1052 debugfs_create_dir(radio_name, 1053 rdev->wiphy.debugfsdir); 1054 } 1055 } 1056 1057 cfg80211_debugfs_rdev_add(rdev); 1058 nl80211_notify_wiphy(rdev, NL80211_CMD_NEW_WIPHY); 1059 wiphy_unlock(&rdev->wiphy); 1060 1061 /* set up regulatory info */ 1062 wiphy_regulatory_register(wiphy); 1063 1064 if (wiphy->regulatory_flags & REGULATORY_CUSTOM_REG) { 1065 struct regulatory_request request = { 1066 .wiphy_idx = get_wiphy_idx(wiphy), 1067 .initiator = NL80211_REGDOM_SET_BY_DRIVER, 1068 .alpha2[0] = '9', 1069 .alpha2[1] = '9', 1070 }; 1071 1072 nl80211_send_reg_change_event(&request); 1073 } 1074 1075 /* Check that nobody globally advertises any capabilities they do not 1076 * advertise on all possible interface types. 1077 */ 1078 if (wiphy->extended_capabilities_len && 1079 wiphy->num_iftype_ext_capab && 1080 wiphy->iftype_ext_capab) { 1081 u8 supported_on_all, j; 1082 const struct wiphy_iftype_ext_capab *capab; 1083 1084 capab = wiphy->iftype_ext_capab; 1085 for (j = 0; j < wiphy->extended_capabilities_len; j++) { 1086 if (capab[0].extended_capabilities_len > j) 1087 supported_on_all = 1088 capab[0].extended_capabilities[j]; 1089 else 1090 supported_on_all = 0x00; 1091 for (i = 1; i < wiphy->num_iftype_ext_capab; i++) { 1092 if (j >= capab[i].extended_capabilities_len) { 1093 supported_on_all = 0x00; 1094 break; 1095 } 1096 supported_on_all &= 1097 capab[i].extended_capabilities[j]; 1098 } 1099 if (WARN_ON(wiphy->extended_capabilities[j] & 1100 ~supported_on_all)) 1101 break; 1102 } 1103 } 1104 1105 rdev->wiphy.registered = true; 1106 rtnl_unlock(); 1107 1108 res = rfkill_register(rdev->wiphy.rfkill); 1109 if (res) { 1110 rfkill_destroy(rdev->wiphy.rfkill); 1111 rdev->wiphy.rfkill = NULL; 1112 wiphy_unregister(&rdev->wiphy); 1113 return res; 1114 } 1115 1116 return 0; 1117} 1118EXPORT_SYMBOL(wiphy_register); 1119 1120void wiphy_rfkill_start_polling(struct wiphy *wiphy) 1121{ 1122 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 1123 1124 if (!rdev->ops->rfkill_poll) 1125 return; 1126 rdev->rfkill_ops.poll = cfg80211_rfkill_poll; 1127 rfkill_resume_polling(wiphy->rfkill); 1128} 1129EXPORT_SYMBOL(wiphy_rfkill_start_polling); 1130 1131void cfg80211_process_wiphy_works(struct cfg80211_registered_device *rdev, 1132 struct wiphy_work *end) 1133{ 1134 unsigned int runaway_limit = 100; 1135 unsigned long flags; 1136 1137 lockdep_assert_held(&rdev->wiphy.mtx); 1138 1139 spin_lock_irqsave(&rdev->wiphy_work_lock, flags); 1140 while (!list_empty(&rdev->wiphy_work_list)) { 1141 struct wiphy_work *wk; 1142 1143 wk = list_first_entry(&rdev->wiphy_work_list, 1144 struct wiphy_work, entry); 1145 list_del_init(&wk->entry); 1146 spin_unlock_irqrestore(&rdev->wiphy_work_lock, flags); 1147 1148 trace_wiphy_work_run(&rdev->wiphy, wk); 1149 wk->func(&rdev->wiphy, wk); 1150 1151 spin_lock_irqsave(&rdev->wiphy_work_lock, flags); 1152 1153 if (wk == end) 1154 break; 1155 1156 if (WARN_ON(--runaway_limit == 0)) 1157 INIT_LIST_HEAD(&rdev->wiphy_work_list); 1158 } 1159 spin_unlock_irqrestore(&rdev->wiphy_work_lock, flags); 1160} 1161 1162void wiphy_unregister(struct wiphy *wiphy) 1163{ 1164 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 1165 1166 wait_event(rdev->dev_wait, ({ 1167 int __count; 1168 wiphy_lock(&rdev->wiphy); 1169 __count = rdev->opencount; 1170 wiphy_unlock(&rdev->wiphy); 1171 __count == 0; })); 1172 1173 if (rdev->wiphy.rfkill) 1174 rfkill_unregister(rdev->wiphy.rfkill); 1175 1176 rtnl_lock(); 1177 wiphy_lock(&rdev->wiphy); 1178 nl80211_notify_wiphy(rdev, NL80211_CMD_DEL_WIPHY); 1179 rdev->wiphy.registered = false; 1180 1181 WARN_ON(!list_empty(&rdev->wiphy.wdev_list)); 1182 1183 /* 1184 * First remove the hardware from everywhere, this makes 1185 * it impossible to find from userspace. 1186 */ 1187 debugfs_remove_recursive(rdev->wiphy.debugfsdir); 1188 list_del_rcu(&rdev->list); 1189 synchronize_rcu(); 1190 1191 /* 1192 * If this device got a regulatory hint tell core its 1193 * free to listen now to a new shiny device regulatory hint 1194 */ 1195 wiphy_regulatory_deregister(wiphy); 1196 1197 cfg80211_rdev_list_generation++; 1198 device_del(&rdev->wiphy.dev); 1199 1200#ifdef CONFIG_PM 1201 if (rdev->wiphy.wowlan_config && rdev->ops->set_wakeup) 1202 rdev_set_wakeup(rdev, false); 1203#endif 1204 1205 /* surely nothing is reachable now, clean up work */ 1206 cfg80211_process_wiphy_works(rdev, NULL); 1207 wiphy_unlock(&rdev->wiphy); 1208 rtnl_unlock(); 1209 1210 /* this has nothing to do now but make sure it's gone */ 1211 cancel_work_sync(&rdev->wiphy_work); 1212 1213 cancel_work_sync(&rdev->rfkill_block); 1214 cancel_work_sync(&rdev->conn_work); 1215 flush_work(&rdev->event_work); 1216 cancel_delayed_work_sync(&rdev->dfs_update_channels_wk); 1217 cancel_delayed_work_sync(&rdev->background_cac_done_wk); 1218 flush_work(&rdev->destroy_work); 1219 flush_work(&rdev->propagate_radar_detect_wk); 1220 flush_work(&rdev->propagate_cac_done_wk); 1221 flush_work(&rdev->mgmt_registrations_update_wk); 1222 flush_work(&rdev->background_cac_abort_wk); 1223 1224 cfg80211_rdev_free_wowlan(rdev); 1225 cfg80211_free_coalesce(rdev->coalesce); 1226 rdev->coalesce = NULL; 1227} 1228EXPORT_SYMBOL(wiphy_unregister); 1229 1230void cfg80211_dev_free(struct cfg80211_registered_device *rdev) 1231{ 1232 struct cfg80211_internal_bss *scan, *tmp; 1233 struct cfg80211_beacon_registration *reg, *treg; 1234 unsigned long flags; 1235 1236 spin_lock_irqsave(&rdev->wiphy_work_lock, flags); 1237 WARN_ON(!list_empty(&rdev->wiphy_work_list)); 1238 spin_unlock_irqrestore(&rdev->wiphy_work_lock, flags); 1239 cancel_work_sync(&rdev->wiphy_work); 1240 1241 rfkill_destroy(rdev->wiphy.rfkill); 1242 list_for_each_entry_safe(reg, treg, &rdev->beacon_registrations, list) { 1243 list_del(®->list); 1244 kfree(reg); 1245 } 1246 list_for_each_entry_safe(scan, tmp, &rdev->bss_list, list) 1247 cfg80211_put_bss(&rdev->wiphy, &scan->pub); 1248 mutex_destroy(&rdev->wiphy.mtx); 1249 1250 /* 1251 * The 'regd' can only be non-NULL if we never finished 1252 * initializing the wiphy and thus never went through the 1253 * unregister path - e.g. in failure scenarios. Thus, it 1254 * cannot have been visible to anyone if non-NULL, so we 1255 * can just free it here. 1256 */ 1257 kfree(rcu_dereference_raw(rdev->wiphy.regd)); 1258 1259 kfree(rdev); 1260} 1261 1262void wiphy_free(struct wiphy *wiphy) 1263{ 1264 kfree(wiphy->radio_cfg); 1265 put_device(&wiphy->dev); 1266} 1267EXPORT_SYMBOL(wiphy_free); 1268 1269void wiphy_rfkill_set_hw_state_reason(struct wiphy *wiphy, bool blocked, 1270 enum rfkill_hard_block_reasons reason) 1271{ 1272 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 1273 1274 if (rfkill_set_hw_state_reason(wiphy->rfkill, blocked, reason)) 1275 schedule_work(&rdev->rfkill_block); 1276} 1277EXPORT_SYMBOL(wiphy_rfkill_set_hw_state_reason); 1278 1279static void _cfg80211_unregister_wdev(struct wireless_dev *wdev, 1280 bool unregister_netdev) 1281{ 1282 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 1283 struct cfg80211_cqm_config *cqm_config; 1284 unsigned int link_id; 1285 1286 ASSERT_RTNL(); 1287 lockdep_assert_held(&rdev->wiphy.mtx); 1288 1289 nl80211_notify_iface(rdev, wdev, NL80211_CMD_DEL_INTERFACE); 1290 1291 wdev->registered = false; 1292 1293 if (wdev->netdev) { 1294 sysfs_remove_link(&wdev->netdev->dev.kobj, "phy80211"); 1295 if (unregister_netdev) 1296 unregister_netdevice(wdev->netdev); 1297 } 1298 1299 list_del_rcu(&wdev->list); 1300 synchronize_net(); 1301 rdev->devlist_generation++; 1302 1303 cfg80211_mlme_purge_registrations(wdev); 1304 1305 switch (wdev->iftype) { 1306 case NL80211_IFTYPE_P2P_DEVICE: 1307 cfg80211_stop_p2p_device(rdev, wdev); 1308 break; 1309 case NL80211_IFTYPE_NAN: 1310 cfg80211_stop_nan(rdev, wdev); 1311 break; 1312 default: 1313 break; 1314 } 1315 1316#ifdef CONFIG_CFG80211_WEXT 1317 kfree_sensitive(wdev->wext.keys); 1318 wdev->wext.keys = NULL; 1319#endif 1320 wiphy_work_cancel(wdev->wiphy, &wdev->cqm_rssi_work); 1321 /* deleted from the list, so can't be found from nl80211 any more */ 1322 cqm_config = rcu_access_pointer(wdev->cqm_config); 1323 kfree_rcu(cqm_config, rcu_head); 1324 RCU_INIT_POINTER(wdev->cqm_config, NULL); 1325 1326 /* 1327 * Ensure that all events have been processed and 1328 * freed. 1329 */ 1330 cfg80211_process_wdev_events(wdev); 1331 1332 if (wdev->iftype == NL80211_IFTYPE_STATION || 1333 wdev->iftype == NL80211_IFTYPE_P2P_CLIENT) { 1334 for (link_id = 0; link_id < ARRAY_SIZE(wdev->links); link_id++) { 1335 struct cfg80211_internal_bss *curbss; 1336 1337 curbss = wdev->links[link_id].client.current_bss; 1338 1339 if (WARN_ON(curbss)) { 1340 cfg80211_unhold_bss(curbss); 1341 cfg80211_put_bss(wdev->wiphy, &curbss->pub); 1342 wdev->links[link_id].client.current_bss = NULL; 1343 } 1344 } 1345 } 1346 1347 wdev->connected = false; 1348} 1349 1350void cfg80211_unregister_wdev(struct wireless_dev *wdev) 1351{ 1352 _cfg80211_unregister_wdev(wdev, true); 1353} 1354EXPORT_SYMBOL(cfg80211_unregister_wdev); 1355 1356static const struct device_type wiphy_type = { 1357 .name = "wlan", 1358}; 1359 1360void cfg80211_update_iface_num(struct cfg80211_registered_device *rdev, 1361 enum nl80211_iftype iftype, int num) 1362{ 1363 lockdep_assert_held(&rdev->wiphy.mtx); 1364 1365 rdev->num_running_ifaces += num; 1366 if (iftype == NL80211_IFTYPE_MONITOR) 1367 rdev->num_running_monitor_ifaces += num; 1368} 1369 1370void cfg80211_leave(struct cfg80211_registered_device *rdev, 1371 struct wireless_dev *wdev) 1372{ 1373 struct net_device *dev = wdev->netdev; 1374 struct cfg80211_sched_scan_request *pos, *tmp; 1375 1376 lockdep_assert_held(&rdev->wiphy.mtx); 1377 1378 cfg80211_pmsr_wdev_down(wdev); 1379 1380 cfg80211_stop_radar_detection(wdev); 1381 cfg80211_stop_background_radar_detection(wdev); 1382 1383 switch (wdev->iftype) { 1384 case NL80211_IFTYPE_ADHOC: 1385 cfg80211_leave_ibss(rdev, dev, true); 1386 break; 1387 case NL80211_IFTYPE_P2P_CLIENT: 1388 case NL80211_IFTYPE_STATION: 1389 list_for_each_entry_safe(pos, tmp, &rdev->sched_scan_req_list, 1390 list) { 1391 if (dev == pos->dev) 1392 cfg80211_stop_sched_scan_req(rdev, pos, false); 1393 } 1394 1395#ifdef CONFIG_CFG80211_WEXT 1396 kfree(wdev->wext.ie); 1397 wdev->wext.ie = NULL; 1398 wdev->wext.ie_len = 0; 1399 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; 1400#endif 1401 cfg80211_disconnect(rdev, dev, 1402 WLAN_REASON_DEAUTH_LEAVING, true); 1403 break; 1404 case NL80211_IFTYPE_MESH_POINT: 1405 cfg80211_leave_mesh(rdev, dev); 1406 break; 1407 case NL80211_IFTYPE_AP: 1408 case NL80211_IFTYPE_P2P_GO: 1409 cfg80211_stop_ap(rdev, dev, -1, true); 1410 break; 1411 case NL80211_IFTYPE_OCB: 1412 cfg80211_leave_ocb(rdev, dev); 1413 break; 1414 case NL80211_IFTYPE_P2P_DEVICE: 1415 cfg80211_stop_p2p_device(rdev, wdev); 1416 break; 1417 case NL80211_IFTYPE_NAN: 1418 cfg80211_stop_nan(rdev, wdev); 1419 break; 1420 case NL80211_IFTYPE_AP_VLAN: 1421 case NL80211_IFTYPE_MONITOR: 1422 /* nothing to do */ 1423 break; 1424 case NL80211_IFTYPE_UNSPECIFIED: 1425 case NL80211_IFTYPE_WDS: 1426 case NUM_NL80211_IFTYPES: 1427 /* invalid */ 1428 break; 1429 } 1430} 1431 1432void cfg80211_stop_iface(struct wiphy *wiphy, struct wireless_dev *wdev, 1433 gfp_t gfp) 1434{ 1435 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 1436 struct cfg80211_event *ev; 1437 unsigned long flags; 1438 1439 trace_cfg80211_stop_iface(wiphy, wdev); 1440 1441 ev = kzalloc(sizeof(*ev), gfp); 1442 if (!ev) 1443 return; 1444 1445 ev->type = EVENT_STOPPED; 1446 1447 spin_lock_irqsave(&wdev->event_lock, flags); 1448 list_add_tail(&ev->list, &wdev->event_list); 1449 spin_unlock_irqrestore(&wdev->event_lock, flags); 1450 queue_work(cfg80211_wq, &rdev->event_work); 1451} 1452EXPORT_SYMBOL(cfg80211_stop_iface); 1453 1454void cfg80211_init_wdev(struct wireless_dev *wdev) 1455{ 1456 INIT_LIST_HEAD(&wdev->event_list); 1457 spin_lock_init(&wdev->event_lock); 1458 INIT_LIST_HEAD(&wdev->mgmt_registrations); 1459 INIT_LIST_HEAD(&wdev->pmsr_list); 1460 spin_lock_init(&wdev->pmsr_lock); 1461 INIT_WORK(&wdev->pmsr_free_wk, cfg80211_pmsr_free_wk); 1462 1463#ifdef CONFIG_CFG80211_WEXT 1464 wdev->wext.default_key = -1; 1465 wdev->wext.default_mgmt_key = -1; 1466 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; 1467#endif 1468 1469 wiphy_work_init(&wdev->cqm_rssi_work, cfg80211_cqm_rssi_notify_work); 1470 1471 if (wdev->wiphy->flags & WIPHY_FLAG_PS_ON_BY_DEFAULT) 1472 wdev->ps = true; 1473 else 1474 wdev->ps = false; 1475 /* allow mac80211 to determine the timeout */ 1476 wdev->ps_timeout = -1; 1477 1478 wdev->radio_mask = BIT(wdev->wiphy->n_radio) - 1; 1479 1480 if ((wdev->iftype == NL80211_IFTYPE_STATION || 1481 wdev->iftype == NL80211_IFTYPE_P2P_CLIENT || 1482 wdev->iftype == NL80211_IFTYPE_ADHOC) && !wdev->use_4addr) 1483 wdev->netdev->priv_flags |= IFF_DONT_BRIDGE; 1484 1485 INIT_WORK(&wdev->disconnect_wk, cfg80211_autodisconnect_wk); 1486} 1487 1488void cfg80211_register_wdev(struct cfg80211_registered_device *rdev, 1489 struct wireless_dev *wdev) 1490{ 1491 ASSERT_RTNL(); 1492 lockdep_assert_held(&rdev->wiphy.mtx); 1493 1494 /* 1495 * We get here also when the interface changes network namespaces, 1496 * as it's registered into the new one, but we don't want it to 1497 * change ID in that case. Checking if the ID is already assigned 1498 * works, because 0 isn't considered a valid ID and the memory is 1499 * 0-initialized. 1500 */ 1501 if (!wdev->identifier) 1502 wdev->identifier = ++rdev->wdev_id; 1503 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list); 1504 rdev->devlist_generation++; 1505 wdev->registered = true; 1506 1507 if (wdev->netdev && 1508 sysfs_create_link(&wdev->netdev->dev.kobj, &rdev->wiphy.dev.kobj, 1509 "phy80211")) 1510 pr_err("failed to add phy80211 symlink to netdev!\n"); 1511 1512 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE); 1513} 1514 1515int cfg80211_register_netdevice(struct net_device *dev) 1516{ 1517 struct wireless_dev *wdev = dev->ieee80211_ptr; 1518 struct cfg80211_registered_device *rdev; 1519 int ret; 1520 1521 ASSERT_RTNL(); 1522 1523 if (WARN_ON(!wdev)) 1524 return -EINVAL; 1525 1526 rdev = wiphy_to_rdev(wdev->wiphy); 1527 1528 lockdep_assert_held(&rdev->wiphy.mtx); 1529 1530 /* we'll take care of this */ 1531 wdev->registered = true; 1532 wdev->registering = true; 1533 ret = register_netdevice(dev); 1534 if (ret) 1535 goto out; 1536 1537 cfg80211_register_wdev(rdev, wdev); 1538 ret = 0; 1539out: 1540 wdev->registering = false; 1541 if (ret) 1542 wdev->registered = false; 1543 return ret; 1544} 1545EXPORT_SYMBOL(cfg80211_register_netdevice); 1546 1547static int cfg80211_netdev_notifier_call(struct notifier_block *nb, 1548 unsigned long state, void *ptr) 1549{ 1550 struct net_device *dev = netdev_notifier_info_to_dev(ptr); 1551 struct wireless_dev *wdev = dev->ieee80211_ptr; 1552 struct cfg80211_registered_device *rdev; 1553 struct cfg80211_sched_scan_request *pos, *tmp; 1554 1555 if (!wdev) 1556 return NOTIFY_DONE; 1557 1558 rdev = wiphy_to_rdev(wdev->wiphy); 1559 1560 WARN_ON(wdev->iftype == NL80211_IFTYPE_UNSPECIFIED); 1561 1562 switch (state) { 1563 case NETDEV_POST_INIT: 1564 SET_NETDEV_DEVTYPE(dev, &wiphy_type); 1565 wdev->netdev = dev; 1566 /* can only change netns with wiphy */ 1567 dev->netns_immutable = true; 1568 1569 cfg80211_init_wdev(wdev); 1570 break; 1571 case NETDEV_REGISTER: 1572 if (!wdev->registered) { 1573 guard(wiphy)(&rdev->wiphy); 1574 1575 cfg80211_register_wdev(rdev, wdev); 1576 } 1577 break; 1578 case NETDEV_UNREGISTER: 1579 /* 1580 * It is possible to get NETDEV_UNREGISTER multiple times, 1581 * so check wdev->registered. 1582 */ 1583 if (wdev->registered && !wdev->registering) { 1584 guard(wiphy)(&rdev->wiphy); 1585 1586 _cfg80211_unregister_wdev(wdev, false); 1587 } 1588 break; 1589 case NETDEV_GOING_DOWN: 1590 scoped_guard(wiphy, &rdev->wiphy) { 1591 cfg80211_leave(rdev, wdev); 1592 cfg80211_remove_links(wdev); 1593 } 1594 /* since we just did cfg80211_leave() nothing to do there */ 1595 cancel_work_sync(&wdev->disconnect_wk); 1596 cancel_work_sync(&wdev->pmsr_free_wk); 1597 break; 1598 case NETDEV_DOWN: 1599 wiphy_lock(&rdev->wiphy); 1600 cfg80211_update_iface_num(rdev, wdev->iftype, -1); 1601 if (rdev->scan_req && rdev->scan_req->req.wdev == wdev) { 1602 if (WARN_ON(!rdev->scan_req->notified && 1603 (!rdev->int_scan_req || 1604 !rdev->int_scan_req->notified))) 1605 rdev->scan_req->info.aborted = true; 1606 ___cfg80211_scan_done(rdev, false); 1607 } 1608 1609 list_for_each_entry_safe(pos, tmp, 1610 &rdev->sched_scan_req_list, list) { 1611 if (WARN_ON(pos->dev == wdev->netdev)) 1612 cfg80211_stop_sched_scan_req(rdev, pos, false); 1613 } 1614 1615 rdev->opencount--; 1616 wiphy_unlock(&rdev->wiphy); 1617 wake_up(&rdev->dev_wait); 1618 break; 1619 case NETDEV_UP: 1620 wiphy_lock(&rdev->wiphy); 1621 cfg80211_update_iface_num(rdev, wdev->iftype, 1); 1622 switch (wdev->iftype) { 1623#ifdef CONFIG_CFG80211_WEXT 1624 case NL80211_IFTYPE_ADHOC: 1625 cfg80211_ibss_wext_join(rdev, wdev); 1626 break; 1627 case NL80211_IFTYPE_STATION: 1628 cfg80211_mgd_wext_connect(rdev, wdev); 1629 break; 1630#endif 1631#ifdef CONFIG_MAC80211_MESH 1632 case NL80211_IFTYPE_MESH_POINT: 1633 { 1634 /* backward compat code... */ 1635 struct mesh_setup setup; 1636 memcpy(&setup, &default_mesh_setup, 1637 sizeof(setup)); 1638 /* back compat only needed for mesh_id */ 1639 setup.mesh_id = wdev->u.mesh.id; 1640 setup.mesh_id_len = wdev->u.mesh.id_up_len; 1641 if (wdev->u.mesh.id_up_len) 1642 __cfg80211_join_mesh(rdev, dev, 1643 &setup, 1644 &default_mesh_config); 1645 break; 1646 } 1647#endif 1648 default: 1649 break; 1650 } 1651 rdev->opencount++; 1652 1653 /* 1654 * Configure power management to the driver here so that its 1655 * correctly set also after interface type changes etc. 1656 */ 1657 if ((wdev->iftype == NL80211_IFTYPE_STATION || 1658 wdev->iftype == NL80211_IFTYPE_P2P_CLIENT) && 1659 rdev->ops->set_power_mgmt && 1660 rdev_set_power_mgmt(rdev, dev, wdev->ps, 1661 wdev->ps_timeout)) { 1662 /* assume this means it's off */ 1663 wdev->ps = false; 1664 } 1665 wiphy_unlock(&rdev->wiphy); 1666 break; 1667 case NETDEV_PRE_UP: 1668 if (!cfg80211_iftype_allowed(wdev->wiphy, wdev->iftype, 1669 wdev->use_4addr, 0)) 1670 return notifier_from_errno(-EOPNOTSUPP); 1671 1672 if (rfkill_blocked(rdev->wiphy.rfkill)) 1673 return notifier_from_errno(-ERFKILL); 1674 break; 1675 default: 1676 return NOTIFY_DONE; 1677 } 1678 1679 wireless_nlevent_flush(); 1680 1681 return NOTIFY_OK; 1682} 1683 1684static struct notifier_block cfg80211_netdev_notifier = { 1685 .notifier_call = cfg80211_netdev_notifier_call, 1686}; 1687 1688static void __net_exit cfg80211_pernet_exit(struct net *net) 1689{ 1690 struct cfg80211_registered_device *rdev; 1691 1692 rtnl_lock(); 1693 for_each_rdev(rdev) { 1694 if (net_eq(wiphy_net(&rdev->wiphy), net)) 1695 WARN_ON(cfg80211_switch_netns(rdev, &init_net)); 1696 } 1697 rtnl_unlock(); 1698} 1699 1700static struct pernet_operations cfg80211_pernet_ops = { 1701 .exit = cfg80211_pernet_exit, 1702}; 1703 1704void wiphy_work_queue(struct wiphy *wiphy, struct wiphy_work *work) 1705{ 1706 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 1707 unsigned long flags; 1708 1709 trace_wiphy_work_queue(wiphy, work); 1710 1711 spin_lock_irqsave(&rdev->wiphy_work_lock, flags); 1712 if (list_empty(&work->entry)) 1713 list_add_tail(&work->entry, &rdev->wiphy_work_list); 1714 spin_unlock_irqrestore(&rdev->wiphy_work_lock, flags); 1715 1716 queue_work(system_dfl_wq, &rdev->wiphy_work); 1717} 1718EXPORT_SYMBOL_GPL(wiphy_work_queue); 1719 1720void wiphy_work_cancel(struct wiphy *wiphy, struct wiphy_work *work) 1721{ 1722 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 1723 unsigned long flags; 1724 1725 lockdep_assert_held(&wiphy->mtx); 1726 1727 trace_wiphy_work_cancel(wiphy, work); 1728 1729 spin_lock_irqsave(&rdev->wiphy_work_lock, flags); 1730 if (!list_empty(&work->entry)) 1731 list_del_init(&work->entry); 1732 spin_unlock_irqrestore(&rdev->wiphy_work_lock, flags); 1733} 1734EXPORT_SYMBOL_GPL(wiphy_work_cancel); 1735 1736void wiphy_work_flush(struct wiphy *wiphy, struct wiphy_work *work) 1737{ 1738 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 1739 unsigned long flags; 1740 bool run; 1741 1742 trace_wiphy_work_flush(wiphy, work); 1743 1744 spin_lock_irqsave(&rdev->wiphy_work_lock, flags); 1745 run = !work || !list_empty(&work->entry); 1746 spin_unlock_irqrestore(&rdev->wiphy_work_lock, flags); 1747 1748 if (run) 1749 cfg80211_process_wiphy_works(rdev, work); 1750} 1751EXPORT_SYMBOL_GPL(wiphy_work_flush); 1752 1753void wiphy_delayed_work_timer(struct timer_list *t) 1754{ 1755 struct wiphy_delayed_work *dwork = timer_container_of(dwork, t, timer); 1756 1757 wiphy_work_queue(dwork->wiphy, &dwork->work); 1758} 1759EXPORT_SYMBOL(wiphy_delayed_work_timer); 1760 1761void wiphy_delayed_work_queue(struct wiphy *wiphy, 1762 struct wiphy_delayed_work *dwork, 1763 unsigned long delay) 1764{ 1765 trace_wiphy_delayed_work_queue(wiphy, &dwork->work, delay); 1766 1767 if (!delay) { 1768 timer_delete(&dwork->timer); 1769 wiphy_work_queue(wiphy, &dwork->work); 1770 return; 1771 } 1772 1773 dwork->wiphy = wiphy; 1774 mod_timer(&dwork->timer, jiffies + delay); 1775} 1776EXPORT_SYMBOL_GPL(wiphy_delayed_work_queue); 1777 1778void wiphy_delayed_work_cancel(struct wiphy *wiphy, 1779 struct wiphy_delayed_work *dwork) 1780{ 1781 lockdep_assert_held(&wiphy->mtx); 1782 1783 timer_delete_sync(&dwork->timer); 1784 wiphy_work_cancel(wiphy, &dwork->work); 1785} 1786EXPORT_SYMBOL_GPL(wiphy_delayed_work_cancel); 1787 1788void wiphy_delayed_work_flush(struct wiphy *wiphy, 1789 struct wiphy_delayed_work *dwork) 1790{ 1791 lockdep_assert_held(&wiphy->mtx); 1792 1793 timer_delete_sync(&dwork->timer); 1794 wiphy_work_flush(wiphy, &dwork->work); 1795} 1796EXPORT_SYMBOL_GPL(wiphy_delayed_work_flush); 1797 1798bool wiphy_delayed_work_pending(struct wiphy *wiphy, 1799 struct wiphy_delayed_work *dwork) 1800{ 1801 return timer_pending(&dwork->timer); 1802} 1803EXPORT_SYMBOL_GPL(wiphy_delayed_work_pending); 1804 1805enum hrtimer_restart wiphy_hrtimer_work_timer(struct hrtimer *t) 1806{ 1807 struct wiphy_hrtimer_work *hrwork = 1808 container_of(t, struct wiphy_hrtimer_work, timer); 1809 1810 wiphy_work_queue(hrwork->wiphy, &hrwork->work); 1811 1812 return HRTIMER_NORESTART; 1813} 1814EXPORT_SYMBOL_GPL(wiphy_hrtimer_work_timer); 1815 1816void wiphy_hrtimer_work_queue(struct wiphy *wiphy, 1817 struct wiphy_hrtimer_work *hrwork, 1818 ktime_t delay) 1819{ 1820 trace_wiphy_hrtimer_work_queue(wiphy, &hrwork->work, delay); 1821 1822 if (!delay) { 1823 hrtimer_cancel(&hrwork->timer); 1824 wiphy_work_queue(wiphy, &hrwork->work); 1825 return; 1826 } 1827 1828 hrwork->wiphy = wiphy; 1829 hrtimer_start_range_ns(&hrwork->timer, delay, 1830 1000 * NSEC_PER_USEC, HRTIMER_MODE_REL); 1831} 1832EXPORT_SYMBOL_GPL(wiphy_hrtimer_work_queue); 1833 1834void wiphy_hrtimer_work_cancel(struct wiphy *wiphy, 1835 struct wiphy_hrtimer_work *hrwork) 1836{ 1837 lockdep_assert_held(&wiphy->mtx); 1838 1839 hrtimer_cancel(&hrwork->timer); 1840 wiphy_work_cancel(wiphy, &hrwork->work); 1841} 1842EXPORT_SYMBOL_GPL(wiphy_hrtimer_work_cancel); 1843 1844void wiphy_hrtimer_work_flush(struct wiphy *wiphy, 1845 struct wiphy_hrtimer_work *hrwork) 1846{ 1847 lockdep_assert_held(&wiphy->mtx); 1848 1849 hrtimer_cancel(&hrwork->timer); 1850 wiphy_work_flush(wiphy, &hrwork->work); 1851} 1852EXPORT_SYMBOL_GPL(wiphy_hrtimer_work_flush); 1853 1854bool wiphy_hrtimer_work_pending(struct wiphy *wiphy, 1855 struct wiphy_hrtimer_work *hrwork) 1856{ 1857 return hrtimer_is_queued(&hrwork->timer); 1858} 1859EXPORT_SYMBOL_GPL(wiphy_hrtimer_work_pending); 1860 1861static int __init cfg80211_init(void) 1862{ 1863 int err; 1864 1865 err = register_pernet_device(&cfg80211_pernet_ops); 1866 if (err) 1867 goto out_fail_pernet; 1868 1869 err = wiphy_sysfs_init(); 1870 if (err) 1871 goto out_fail_sysfs; 1872 1873 err = register_netdevice_notifier(&cfg80211_netdev_notifier); 1874 if (err) 1875 goto out_fail_notifier; 1876 1877 err = nl80211_init(); 1878 if (err) 1879 goto out_fail_nl80211; 1880 1881 ieee80211_debugfs_dir = debugfs_create_dir("ieee80211", NULL); 1882 1883 err = regulatory_init(); 1884 if (err) 1885 goto out_fail_reg; 1886 1887 cfg80211_wq = alloc_ordered_workqueue("cfg80211", WQ_MEM_RECLAIM); 1888 if (!cfg80211_wq) { 1889 err = -ENOMEM; 1890 goto out_fail_wq; 1891 } 1892 1893 return 0; 1894 1895out_fail_wq: 1896 regulatory_exit(); 1897out_fail_reg: 1898 debugfs_remove(ieee80211_debugfs_dir); 1899 nl80211_exit(); 1900out_fail_nl80211: 1901 unregister_netdevice_notifier(&cfg80211_netdev_notifier); 1902out_fail_notifier: 1903 wiphy_sysfs_exit(); 1904out_fail_sysfs: 1905 unregister_pernet_device(&cfg80211_pernet_ops); 1906out_fail_pernet: 1907 return err; 1908} 1909fs_initcall(cfg80211_init); 1910 1911static void __exit cfg80211_exit(void) 1912{ 1913 debugfs_remove(ieee80211_debugfs_dir); 1914 nl80211_exit(); 1915 unregister_netdevice_notifier(&cfg80211_netdev_notifier); 1916 wiphy_sysfs_exit(); 1917 regulatory_exit(); 1918 unregister_pernet_device(&cfg80211_pernet_ops); 1919 destroy_workqueue(cfg80211_wq); 1920} 1921module_exit(cfg80211_exit);
~/
Read-only file preview.