1/* 2 * Copyright 2002-2005, Instant802 Networks, Inc. 3 * Copyright 2005-2006, Devicescape Software, Inc. 4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 2 as 8 * published by the Free Software Foundation. 9 */ 10 11#include <net/mac80211.h> 12#include <linux/module.h> 13#include <linux/init.h> 14#include <linux/netdevice.h> 15#include <linux/types.h> 16#include <linux/slab.h> 17#include <linux/skbuff.h> 18#include <linux/etherdevice.h> 19#include <linux/if_arp.h> 20#include <linux/rtnetlink.h> 21#include <linux/bitmap.h> 22#include <linux/pm_qos_params.h> 23#include <linux/inetdevice.h> 24#include <net/net_namespace.h> 25#include <net/cfg80211.h> 26 27#include "ieee80211_i.h" 28#include "driver-ops.h" 29#include "rate.h" 30#include "mesh.h" 31#include "wep.h" 32#include "led.h" 33#include "cfg.h" 34#include "debugfs.h" 35 36 37bool ieee80211_disable_40mhz_24ghz; 38module_param(ieee80211_disable_40mhz_24ghz, bool, 0644); 39MODULE_PARM_DESC(ieee80211_disable_40mhz_24ghz, 40 "Disable 40MHz support in the 2.4GHz band"); 41 42void ieee80211_configure_filter(struct ieee80211_local *local) 43{ 44 u64 mc; 45 unsigned int changed_flags; 46 unsigned int new_flags = 0; 47 48 if (atomic_read(&local->iff_promiscs)) 49 new_flags |= FIF_PROMISC_IN_BSS; 50 51 if (atomic_read(&local->iff_allmultis)) 52 new_flags |= FIF_ALLMULTI; 53 54 if (local->monitors || local->scanning) 55 new_flags |= FIF_BCN_PRBRESP_PROMISC; 56 57 if (local->fif_fcsfail) 58 new_flags |= FIF_FCSFAIL; 59 60 if (local->fif_plcpfail) 61 new_flags |= FIF_PLCPFAIL; 62 63 if (local->fif_control) 64 new_flags |= FIF_CONTROL; 65 66 if (local->fif_other_bss) 67 new_flags |= FIF_OTHER_BSS; 68 69 if (local->fif_pspoll) 70 new_flags |= FIF_PSPOLL; 71 72 spin_lock_bh(&local->filter_lock); 73 changed_flags = local->filter_flags ^ new_flags; 74 75 mc = drv_prepare_multicast(local, &local->mc_list); 76 spin_unlock_bh(&local->filter_lock); 77 78 /* be a bit nasty */ 79 new_flags |= (1<<31); 80 81 drv_configure_filter(local, changed_flags, &new_flags, mc); 82 83 WARN_ON(new_flags & (1<<31)); 84 85 local->filter_flags = new_flags & ~(1<<31); 86} 87 88static void ieee80211_reconfig_filter(struct work_struct *work) 89{ 90 struct ieee80211_local *local = 91 container_of(work, struct ieee80211_local, reconfig_filter); 92 93 ieee80211_configure_filter(local); 94} 95 96int ieee80211_hw_config(struct ieee80211_local *local, u32 changed) 97{ 98 struct ieee80211_channel *chan, *scan_chan; 99 int ret = 0; 100 int power; 101 enum nl80211_channel_type channel_type; 102 103 might_sleep(); 104 105 scan_chan = local->scan_channel; 106 107 if (scan_chan) { 108 chan = scan_chan; 109 channel_type = NL80211_CHAN_NO_HT; 110 local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL; 111 } else if (local->tmp_channel && 112 local->oper_channel != local->tmp_channel) { 113 chan = scan_chan = local->tmp_channel; 114 channel_type = local->tmp_channel_type; 115 local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL; 116 } else { 117 chan = local->oper_channel; 118 channel_type = local->_oper_channel_type; 119 local->hw.conf.flags &= ~IEEE80211_CONF_OFFCHANNEL; 120 } 121 122 if (chan != local->hw.conf.channel || 123 channel_type != local->hw.conf.channel_type) { 124 local->hw.conf.channel = chan; 125 local->hw.conf.channel_type = channel_type; 126 changed |= IEEE80211_CONF_CHANGE_CHANNEL; 127 } 128 129 if (!conf_is_ht(&local->hw.conf)) { 130 /* 131 * mac80211.h documents that this is only valid 132 * when the channel is set to an HT type, and 133 * that otherwise STATIC is used. 134 */ 135 local->hw.conf.smps_mode = IEEE80211_SMPS_STATIC; 136 } else if (local->hw.conf.smps_mode != local->smps_mode) { 137 local->hw.conf.smps_mode = local->smps_mode; 138 changed |= IEEE80211_CONF_CHANGE_SMPS; 139 } 140 141 if (scan_chan) 142 power = chan->max_power; 143 else 144 power = local->power_constr_level ? 145 (chan->max_power - local->power_constr_level) : 146 chan->max_power; 147 148 if (local->user_power_level >= 0) 149 power = min(power, local->user_power_level); 150 151 if (local->hw.conf.power_level != power) { 152 changed |= IEEE80211_CONF_CHANGE_POWER; 153 local->hw.conf.power_level = power; 154 } 155 156 if (changed && local->open_count) { 157 ret = drv_config(local, changed); 158 /* WARN_ON(ret); */ 159 } 160 161 return ret; 162} 163 164void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata, 165 u32 changed) 166{ 167 struct ieee80211_local *local = sdata->local; 168 static const u8 zero[ETH_ALEN] = { 0 }; 169 170 if (!changed) 171 return; 172 173 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 174 /* 175 * While not associated, claim a BSSID of all-zeroes 176 * so that drivers don't do any weird things with the 177 * BSSID at that time. 178 */ 179 if (sdata->vif.bss_conf.assoc) 180 sdata->vif.bss_conf.bssid = sdata->u.mgd.bssid; 181 else 182 sdata->vif.bss_conf.bssid = zero; 183 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 184 sdata->vif.bss_conf.bssid = sdata->u.ibss.bssid; 185 else if (sdata->vif.type == NL80211_IFTYPE_AP) 186 sdata->vif.bss_conf.bssid = sdata->vif.addr; 187 else if (ieee80211_vif_is_mesh(&sdata->vif)) { 188 sdata->vif.bss_conf.bssid = zero; 189 } else { 190 WARN_ON(1); 191 return; 192 } 193 194 switch (sdata->vif.type) { 195 case NL80211_IFTYPE_AP: 196 case NL80211_IFTYPE_ADHOC: 197 case NL80211_IFTYPE_MESH_POINT: 198 break; 199 default: 200 /* do not warn to simplify caller in scan.c */ 201 changed &= ~BSS_CHANGED_BEACON_ENABLED; 202 if (WARN_ON(changed & BSS_CHANGED_BEACON)) 203 return; 204 break; 205 } 206 207 if (changed & BSS_CHANGED_BEACON_ENABLED) { 208 if (local->quiescing || !ieee80211_sdata_running(sdata) || 209 test_bit(SCAN_SW_SCANNING, &local->scanning)) { 210 sdata->vif.bss_conf.enable_beacon = false; 211 } else { 212 /* 213 * Beacon should be enabled, but AP mode must 214 * check whether there is a beacon configured. 215 */ 216 switch (sdata->vif.type) { 217 case NL80211_IFTYPE_AP: 218 sdata->vif.bss_conf.enable_beacon = 219 !!sdata->u.ap.beacon; 220 break; 221 case NL80211_IFTYPE_ADHOC: 222 sdata->vif.bss_conf.enable_beacon = 223 !!sdata->u.ibss.presp; 224 break; 225 case NL80211_IFTYPE_MESH_POINT: 226 sdata->vif.bss_conf.enable_beacon = true; 227 break; 228 default: 229 /* not reached */ 230 WARN_ON(1); 231 break; 232 } 233 } 234 } 235 236 drv_bss_info_changed(local, sdata, &sdata->vif.bss_conf, changed); 237} 238 239u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata) 240{ 241 sdata->vif.bss_conf.use_cts_prot = false; 242 sdata->vif.bss_conf.use_short_preamble = false; 243 sdata->vif.bss_conf.use_short_slot = false; 244 return BSS_CHANGED_ERP_CTS_PROT | 245 BSS_CHANGED_ERP_PREAMBLE | 246 BSS_CHANGED_ERP_SLOT; 247} 248 249static void ieee80211_tasklet_handler(unsigned long data) 250{ 251 struct ieee80211_local *local = (struct ieee80211_local *) data; 252 struct sk_buff *skb; 253 254 while ((skb = skb_dequeue(&local->skb_queue)) || 255 (skb = skb_dequeue(&local->skb_queue_unreliable))) { 256 switch (skb->pkt_type) { 257 case IEEE80211_RX_MSG: 258 /* Clear skb->pkt_type in order to not confuse kernel 259 * netstack. */ 260 skb->pkt_type = 0; 261 ieee80211_rx(local_to_hw(local), skb); 262 break; 263 case IEEE80211_TX_STATUS_MSG: 264 skb->pkt_type = 0; 265 ieee80211_tx_status(local_to_hw(local), skb); 266 break; 267 default: 268 WARN(1, "mac80211: Packet is of unknown type %d\n", 269 skb->pkt_type); 270 dev_kfree_skb(skb); 271 break; 272 } 273 } 274} 275 276static void ieee80211_restart_work(struct work_struct *work) 277{ 278 struct ieee80211_local *local = 279 container_of(work, struct ieee80211_local, restart_work); 280 281 rtnl_lock(); 282 ieee80211_reconfig(local); 283 rtnl_unlock(); 284} 285 286void ieee80211_restart_hw(struct ieee80211_hw *hw) 287{ 288 struct ieee80211_local *local = hw_to_local(hw); 289 290 trace_api_restart_hw(local); 291 292 /* use this reason, __ieee80211_resume will unblock it */ 293 ieee80211_stop_queues_by_reason(hw, 294 IEEE80211_QUEUE_STOP_REASON_SUSPEND); 295 296 schedule_work(&local->restart_work); 297} 298EXPORT_SYMBOL(ieee80211_restart_hw); 299 300static void ieee80211_recalc_smps_work(struct work_struct *work) 301{ 302 struct ieee80211_local *local = 303 container_of(work, struct ieee80211_local, recalc_smps); 304 305 mutex_lock(&local->iflist_mtx); 306 ieee80211_recalc_smps(local, NULL); 307 mutex_unlock(&local->iflist_mtx); 308} 309 310#ifdef CONFIG_INET 311static int ieee80211_ifa_changed(struct notifier_block *nb, 312 unsigned long data, void *arg) 313{ 314 struct in_ifaddr *ifa = arg; 315 struct ieee80211_local *local = 316 container_of(nb, struct ieee80211_local, 317 ifa_notifier); 318 struct net_device *ndev = ifa->ifa_dev->dev; 319 struct wireless_dev *wdev = ndev->ieee80211_ptr; 320 struct in_device *idev; 321 struct ieee80211_sub_if_data *sdata; 322 struct ieee80211_bss_conf *bss_conf; 323 struct ieee80211_if_managed *ifmgd; 324 int c = 0; 325 326 if (!netif_running(ndev)) 327 return NOTIFY_DONE; 328 329 /* Make sure it's our interface that got changed */ 330 if (!wdev) 331 return NOTIFY_DONE; 332 333 if (wdev->wiphy != local->hw.wiphy) 334 return NOTIFY_DONE; 335 336 sdata = IEEE80211_DEV_TO_SUB_IF(ndev); 337 bss_conf = &sdata->vif.bss_conf; 338 339 /* ARP filtering is only supported in managed mode */ 340 if (sdata->vif.type != NL80211_IFTYPE_STATION) 341 return NOTIFY_DONE; 342 343 idev = sdata->dev->ip_ptr; 344 if (!idev) 345 return NOTIFY_DONE; 346 347 ifmgd = &sdata->u.mgd; 348 mutex_lock(&ifmgd->mtx); 349 350 /* Copy the addresses to the bss_conf list */ 351 ifa = idev->ifa_list; 352 while (c < IEEE80211_BSS_ARP_ADDR_LIST_LEN && ifa) { 353 bss_conf->arp_addr_list[c] = ifa->ifa_address; 354 ifa = ifa->ifa_next; 355 c++; 356 } 357 358 /* If not all addresses fit the list, disable filtering */ 359 if (ifa) { 360 sdata->arp_filter_state = false; 361 c = 0; 362 } else { 363 sdata->arp_filter_state = true; 364 } 365 bss_conf->arp_addr_cnt = c; 366 367 /* Configure driver only if associated */ 368 if (ifmgd->associated) { 369 bss_conf->arp_filter_enabled = sdata->arp_filter_state; 370 ieee80211_bss_info_change_notify(sdata, 371 BSS_CHANGED_ARP_FILTER); 372 } 373 374 mutex_unlock(&ifmgd->mtx); 375 376 return NOTIFY_DONE; 377} 378#endif 379 380struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len, 381 const struct ieee80211_ops *ops) 382{ 383 struct ieee80211_local *local; 384 int priv_size, i; 385 struct wiphy *wiphy; 386 387 /* Ensure 32-byte alignment of our private data and hw private data. 388 * We use the wiphy priv data for both our ieee80211_local and for 389 * the driver's private data 390 * 391 * In memory it'll be like this: 392 * 393 * +-------------------------+ 394 * | struct wiphy | 395 * +-------------------------+ 396 * | struct ieee80211_local | 397 * +-------------------------+ 398 * | driver's private data | 399 * +-------------------------+ 400 * 401 */ 402 priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len; 403 404 wiphy = wiphy_new(&mac80211_config_ops, priv_size); 405 406 if (!wiphy) 407 return NULL; 408 409 wiphy->flags |= WIPHY_FLAG_NETNS_OK | 410 WIPHY_FLAG_4ADDR_AP | 411 WIPHY_FLAG_4ADDR_STATION; 412 wiphy->privid = mac80211_wiphy_privid; 413 414 wiphy->bss_priv_size = sizeof(struct ieee80211_bss); 415 416 local = wiphy_priv(wiphy); 417 418 local->hw.wiphy = wiphy; 419 420 local->hw.priv = (char *)local + ALIGN(sizeof(*local), NETDEV_ALIGN); 421 422 BUG_ON(!ops->tx); 423 BUG_ON(!ops->start); 424 BUG_ON(!ops->stop); 425 BUG_ON(!ops->config); 426 BUG_ON(!ops->add_interface); 427 BUG_ON(!ops->remove_interface); 428 BUG_ON(!ops->configure_filter); 429 local->ops = ops; 430 431 /* set up some defaults */ 432 local->hw.queues = 1; 433 local->hw.max_rates = 1; 434 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long; 435 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short; 436 local->user_power_level = -1; 437 local->uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES; 438 local->uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN; 439 440 INIT_LIST_HEAD(&local->interfaces); 441 442 __hw_addr_init(&local->mc_list); 443 444 mutex_init(&local->iflist_mtx); 445 mutex_init(&local->scan_mtx); 446 447 mutex_init(&local->key_mtx); 448 spin_lock_init(&local->filter_lock); 449 spin_lock_init(&local->queue_stop_reason_lock); 450 451 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work); 452 453 ieee80211_work_init(local); 454 455 INIT_WORK(&local->restart_work, ieee80211_restart_work); 456 457 INIT_WORK(&local->reconfig_filter, ieee80211_reconfig_filter); 458 INIT_WORK(&local->recalc_smps, ieee80211_recalc_smps_work); 459 local->smps_mode = IEEE80211_SMPS_OFF; 460 461 INIT_WORK(&local->dynamic_ps_enable_work, 462 ieee80211_dynamic_ps_enable_work); 463 INIT_WORK(&local->dynamic_ps_disable_work, 464 ieee80211_dynamic_ps_disable_work); 465 setup_timer(&local->dynamic_ps_timer, 466 ieee80211_dynamic_ps_timer, (unsigned long) local); 467 468 sta_info_init(local); 469 470 for (i = 0; i < IEEE80211_MAX_QUEUES; i++) { 471 skb_queue_head_init(&local->pending[i]); 472 atomic_set(&local->agg_queue_stop[i], 0); 473 } 474 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending, 475 (unsigned long)local); 476 477 tasklet_init(&local->tasklet, 478 ieee80211_tasklet_handler, 479 (unsigned long) local); 480 481 skb_queue_head_init(&local->skb_queue); 482 skb_queue_head_init(&local->skb_queue_unreliable); 483 484 return local_to_hw(local); 485} 486EXPORT_SYMBOL(ieee80211_alloc_hw); 487 488int ieee80211_register_hw(struct ieee80211_hw *hw) 489{ 490 struct ieee80211_local *local = hw_to_local(hw); 491 int result; 492 enum ieee80211_band band; 493 int channels, max_bitrates; 494 bool supp_ht; 495 static const u32 cipher_suites[] = { 496 WLAN_CIPHER_SUITE_WEP40, 497 WLAN_CIPHER_SUITE_WEP104, 498 WLAN_CIPHER_SUITE_TKIP, 499 WLAN_CIPHER_SUITE_CCMP, 500 501 /* keep last -- depends on hw flags! */ 502 WLAN_CIPHER_SUITE_AES_CMAC 503 }; 504 505 /* 506 * generic code guarantees at least one band, 507 * set this very early because much code assumes 508 * that hw.conf.channel is assigned 509 */ 510 channels = 0; 511 max_bitrates = 0; 512 supp_ht = false; 513 for (band = 0; band < IEEE80211_NUM_BANDS; band++) { 514 struct ieee80211_supported_band *sband; 515 516 sband = local->hw.wiphy->bands[band]; 517 if (!sband) 518 continue; 519 if (!local->oper_channel) { 520 /* init channel we're on */ 521 local->hw.conf.channel = 522 local->oper_channel = &sband->channels[0]; 523 local->hw.conf.channel_type = NL80211_CHAN_NO_HT; 524 } 525 channels += sband->n_channels; 526 527 if (max_bitrates < sband->n_bitrates) 528 max_bitrates = sband->n_bitrates; 529 supp_ht = supp_ht || sband->ht_cap.ht_supported; 530 } 531 532 local->int_scan_req = kzalloc(sizeof(*local->int_scan_req) + 533 sizeof(void *) * channels, GFP_KERNEL); 534 if (!local->int_scan_req) 535 return -ENOMEM; 536 537 /* if low-level driver supports AP, we also support VLAN */ 538 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) 539 local->hw.wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN); 540 541 /* mac80211 always supports monitor */ 542 local->hw.wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR); 543 544 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) 545 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; 546 else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) 547 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC; 548 549 WARN((local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD) 550 && (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK), 551 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"); 552 553 /* 554 * Calculate scan IE length -- we need this to alloc 555 * memory and to subtract from the driver limit. It 556 * includes the (extended) supported rates and HT 557 * information -- SSID is the driver's responsibility. 558 */ 559 local->scan_ies_len = 4 + max_bitrates; /* (ext) supp rates */ 560 if (supp_ht) 561 local->scan_ies_len += 2 + sizeof(struct ieee80211_ht_cap); 562 563 if (!local->ops->hw_scan) { 564 /* For hw_scan, driver needs to set these up. */ 565 local->hw.wiphy->max_scan_ssids = 4; 566 local->hw.wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN; 567 } 568 569 /* 570 * If the driver supports any scan IEs, then assume the 571 * limit includes the IEs mac80211 will add, otherwise 572 * leave it at zero and let the driver sort it out; we 573 * still pass our IEs to the driver but userspace will 574 * not be allowed to in that case. 575 */ 576 if (local->hw.wiphy->max_scan_ie_len) 577 local->hw.wiphy->max_scan_ie_len -= local->scan_ies_len; 578 579 local->hw.wiphy->cipher_suites = cipher_suites; 580 local->hw.wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); 581 if (!(local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) 582 local->hw.wiphy->n_cipher_suites--; 583 584 result = wiphy_register(local->hw.wiphy); 585 if (result < 0) 586 goto fail_wiphy_register; 587 588 /* 589 * We use the number of queues for feature tests (QoS, HT) internally 590 * so restrict them appropriately. 591 */ 592 if (hw->queues > IEEE80211_MAX_QUEUES) 593 hw->queues = IEEE80211_MAX_QUEUES; 594 595 local->workqueue = 596 create_singlethread_workqueue(wiphy_name(local->hw.wiphy)); 597 if (!local->workqueue) { 598 result = -ENOMEM; 599 goto fail_workqueue; 600 } 601 602 /* 603 * The hardware needs headroom for sending the frame, 604 * and we need some headroom for passing the frame to monitor 605 * interfaces, but never both at the same time. 606 */ 607 BUILD_BUG_ON(IEEE80211_TX_STATUS_HEADROOM != 608 sizeof(struct ieee80211_tx_status_rtap_hdr)); 609 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom, 610 sizeof(struct ieee80211_tx_status_rtap_hdr)); 611 612 debugfs_hw_add(local); 613 614 /* 615 * if the driver doesn't specify a max listen interval we 616 * use 5 which should be a safe default 617 */ 618 if (local->hw.max_listen_interval == 0) 619 local->hw.max_listen_interval = 5; 620 621 local->hw.conf.listen_interval = local->hw.max_listen_interval; 622 623 local->dynamic_ps_forced_timeout = -1; 624 625 result = sta_info_start(local); 626 if (result < 0) 627 goto fail_sta_info; 628 629 result = ieee80211_wep_init(local); 630 if (result < 0) 631 printk(KERN_DEBUG "%s: Failed to initialize wep: %d\n", 632 wiphy_name(local->hw.wiphy), result); 633 634 rtnl_lock(); 635 636 result = ieee80211_init_rate_ctrl_alg(local, 637 hw->rate_control_algorithm); 638 if (result < 0) { 639 printk(KERN_DEBUG "%s: Failed to initialize rate control " 640 "algorithm\n", wiphy_name(local->hw.wiphy)); 641 goto fail_rate; 642 } 643 644 /* add one default STA interface if supported */ 645 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION)) { 646 result = ieee80211_if_add(local, "wlan%d", NULL, 647 NL80211_IFTYPE_STATION, NULL); 648 if (result) 649 printk(KERN_WARNING "%s: Failed to add default virtual iface\n", 650 wiphy_name(local->hw.wiphy)); 651 } 652 653 rtnl_unlock(); 654 655 ieee80211_led_init(local); 656 657 local->network_latency_notifier.notifier_call = 658 ieee80211_max_network_latency; 659 result = pm_qos_add_notifier(PM_QOS_NETWORK_LATENCY, 660 &local->network_latency_notifier); 661 if (result) { 662 rtnl_lock(); 663 goto fail_pm_qos; 664 } 665 666#ifdef CONFIG_INET 667 local->ifa_notifier.notifier_call = ieee80211_ifa_changed; 668 result = register_inetaddr_notifier(&local->ifa_notifier); 669 if (result) 670 goto fail_ifa; 671#endif 672 673 return 0; 674 675#ifdef CONFIG_INET 676 fail_ifa: 677 pm_qos_remove_notifier(PM_QOS_NETWORK_LATENCY, 678 &local->network_latency_notifier); 679 rtnl_lock(); 680#endif 681 fail_pm_qos: 682 ieee80211_led_exit(local); 683 ieee80211_remove_interfaces(local); 684 fail_rate: 685 rtnl_unlock(); 686 ieee80211_wep_free(local); 687 sta_info_stop(local); 688 fail_sta_info: 689 destroy_workqueue(local->workqueue); 690 fail_workqueue: 691 wiphy_unregister(local->hw.wiphy); 692 fail_wiphy_register: 693 kfree(local->int_scan_req); 694 return result; 695} 696EXPORT_SYMBOL(ieee80211_register_hw); 697 698void ieee80211_unregister_hw(struct ieee80211_hw *hw) 699{ 700 struct ieee80211_local *local = hw_to_local(hw); 701 702 tasklet_kill(&local->tx_pending_tasklet); 703 tasklet_kill(&local->tasklet); 704 705 pm_qos_remove_notifier(PM_QOS_NETWORK_LATENCY, 706 &local->network_latency_notifier); 707#ifdef CONFIG_INET 708 unregister_inetaddr_notifier(&local->ifa_notifier); 709#endif 710 711 rtnl_lock(); 712 713 /* 714 * At this point, interface list manipulations are fine 715 * because the driver cannot be handing us frames any 716 * more and the tasklet is killed. 717 */ 718 ieee80211_remove_interfaces(local); 719 720 rtnl_unlock(); 721 722 /* 723 * Now all work items will be gone, but the 724 * timer might still be armed, so delete it 725 */ 726 del_timer_sync(&local->work_timer); 727 728 cancel_work_sync(&local->reconfig_filter); 729 730 ieee80211_clear_tx_pending(local); 731 sta_info_stop(local); 732 rate_control_deinitialize(local); 733 734 if (skb_queue_len(&local->skb_queue) || 735 skb_queue_len(&local->skb_queue_unreliable)) 736 printk(KERN_WARNING "%s: skb_queue not empty\n", 737 wiphy_name(local->hw.wiphy)); 738 skb_queue_purge(&local->skb_queue); 739 skb_queue_purge(&local->skb_queue_unreliable); 740 741 destroy_workqueue(local->workqueue); 742 wiphy_unregister(local->hw.wiphy); 743 ieee80211_wep_free(local); 744 ieee80211_led_exit(local); 745 kfree(local->int_scan_req); 746} 747EXPORT_SYMBOL(ieee80211_unregister_hw); 748 749void ieee80211_free_hw(struct ieee80211_hw *hw) 750{ 751 struct ieee80211_local *local = hw_to_local(hw); 752 753 mutex_destroy(&local->iflist_mtx); 754 mutex_destroy(&local->scan_mtx); 755 756 wiphy_free(local->hw.wiphy); 757} 758EXPORT_SYMBOL(ieee80211_free_hw); 759 760static int __init ieee80211_init(void) 761{ 762 struct sk_buff *skb; 763 int ret; 764 765 BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb)); 766 BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) + 767 IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb)); 768 769 ret = rc80211_minstrel_init(); 770 if (ret) 771 return ret; 772 773 ret = rc80211_minstrel_ht_init(); 774 if (ret) 775 goto err_minstrel; 776 777 ret = rc80211_pid_init(); 778 if (ret) 779 goto err_pid; 780 781 ret = ieee80211_iface_init(); 782 if (ret) 783 goto err_netdev; 784 785 return 0; 786 err_netdev: 787 rc80211_pid_exit(); 788 err_pid: 789 rc80211_minstrel_ht_exit(); 790 err_minstrel: 791 rc80211_minstrel_exit(); 792 793 return ret; 794} 795 796static void __exit ieee80211_exit(void) 797{ 798 rc80211_pid_exit(); 799 rc80211_minstrel_ht_exit(); 800 rc80211_minstrel_exit(); 801 802 /* 803 * For key todo, it'll be empty by now but the work 804 * might still be scheduled. 805 */ 806 flush_scheduled_work(); 807 808 if (mesh_allocated) 809 ieee80211s_stop(); 810 811 ieee80211_iface_exit(); 812} 813 814 815subsys_initcall(ieee80211_init); 816module_exit(ieee80211_exit); 817 818MODULE_DESCRIPTION("IEEE 802.11 subsystem"); 819MODULE_LICENSE("GPL"); 820