main.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  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. #include <net/mac80211.h>
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/netdevice.h>
  14. #include <linux/types.h>
  15. #include <linux/slab.h>
  16. #include <linux/skbuff.h>
  17. #include <linux/etherdevice.h>
  18. #include <linux/if_arp.h>
  19. #include <linux/wireless.h>
  20. #include <linux/rtnetlink.h>
  21. #include <linux/bitmap.h>
  22. #include <linux/pm_qos_params.h>
  23. #include <net/net_namespace.h>
  24. #include <net/cfg80211.h>
  25. #include "ieee80211_i.h"
  26. #include "driver-ops.h"
  27. #include "rate.h"
  28. #include "mesh.h"
  29. #include "wep.h"
  30. #include "led.h"
  31. #include "cfg.h"
  32. #include "debugfs.h"
  33. #include "debugfs_netdev.h"
  34. void ieee80211_configure_filter(struct ieee80211_local *local)
  35. {
  36. u64 mc;
  37. unsigned int changed_flags;
  38. unsigned int new_flags = 0;
  39. if (atomic_read(&local->iff_promiscs))
  40. new_flags |= FIF_PROMISC_IN_BSS;
  41. if (atomic_read(&local->iff_allmultis))
  42. new_flags |= FIF_ALLMULTI;
  43. if (local->monitors || local->scanning)
  44. new_flags |= FIF_BCN_PRBRESP_PROMISC;
  45. if (local->fif_fcsfail)
  46. new_flags |= FIF_FCSFAIL;
  47. if (local->fif_plcpfail)
  48. new_flags |= FIF_PLCPFAIL;
  49. if (local->fif_control)
  50. new_flags |= FIF_CONTROL;
  51. if (local->fif_other_bss)
  52. new_flags |= FIF_OTHER_BSS;
  53. if (local->fif_pspoll)
  54. new_flags |= FIF_PSPOLL;
  55. spin_lock_bh(&local->filter_lock);
  56. changed_flags = local->filter_flags ^ new_flags;
  57. mc = drv_prepare_multicast(local, local->mc_count, local->mc_list);
  58. spin_unlock_bh(&local->filter_lock);
  59. /* be a bit nasty */
  60. new_flags |= (1<<31);
  61. drv_configure_filter(local, changed_flags, &new_flags, mc);
  62. WARN_ON(new_flags & (1<<31));
  63. local->filter_flags = new_flags & ~(1<<31);
  64. }
  65. static void ieee80211_reconfig_filter(struct work_struct *work)
  66. {
  67. struct ieee80211_local *local =
  68. container_of(work, struct ieee80211_local, reconfig_filter);
  69. ieee80211_configure_filter(local);
  70. }
  71. int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
  72. {
  73. struct ieee80211_channel *chan, *scan_chan;
  74. int ret = 0;
  75. int power;
  76. enum nl80211_channel_type channel_type;
  77. might_sleep();
  78. scan_chan = local->scan_channel;
  79. if (scan_chan) {
  80. chan = scan_chan;
  81. channel_type = NL80211_CHAN_NO_HT;
  82. } else {
  83. chan = local->oper_channel;
  84. channel_type = local->oper_channel_type;
  85. }
  86. if (chan != local->hw.conf.channel ||
  87. channel_type != local->hw.conf.channel_type) {
  88. local->hw.conf.channel = chan;
  89. local->hw.conf.channel_type = channel_type;
  90. changed |= IEEE80211_CONF_CHANGE_CHANNEL;
  91. }
  92. if (scan_chan)
  93. power = chan->max_power;
  94. else
  95. power = local->power_constr_level ?
  96. (chan->max_power - local->power_constr_level) :
  97. chan->max_power;
  98. if (local->user_power_level >= 0)
  99. power = min(power, local->user_power_level);
  100. if (local->hw.conf.power_level != power) {
  101. changed |= IEEE80211_CONF_CHANGE_POWER;
  102. local->hw.conf.power_level = power;
  103. }
  104. if (changed && local->open_count) {
  105. ret = drv_config(local, changed);
  106. /*
  107. * Goal:
  108. * HW reconfiguration should never fail, the driver has told
  109. * us what it can support so it should live up to that promise.
  110. *
  111. * Current status:
  112. * rfkill is not integrated with mac80211 and a
  113. * configuration command can thus fail if hardware rfkill
  114. * is enabled
  115. *
  116. * FIXME: integrate rfkill with mac80211 and then add this
  117. * WARN_ON() back
  118. *
  119. */
  120. /* WARN_ON(ret); */
  121. }
  122. return ret;
  123. }
  124. void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
  125. u32 changed)
  126. {
  127. struct ieee80211_local *local = sdata->local;
  128. static const u8 zero[ETH_ALEN] = { 0 };
  129. if (!changed)
  130. return;
  131. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  132. /*
  133. * While not associated, claim a BSSID of all-zeroes
  134. * so that drivers don't do any weird things with the
  135. * BSSID at that time.
  136. */
  137. if (sdata->vif.bss_conf.assoc)
  138. sdata->vif.bss_conf.bssid = sdata->u.mgd.bssid;
  139. else
  140. sdata->vif.bss_conf.bssid = zero;
  141. } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
  142. sdata->vif.bss_conf.bssid = sdata->u.ibss.bssid;
  143. else if (sdata->vif.type == NL80211_IFTYPE_AP)
  144. sdata->vif.bss_conf.bssid = sdata->dev->dev_addr;
  145. else if (ieee80211_vif_is_mesh(&sdata->vif)) {
  146. sdata->vif.bss_conf.bssid = zero;
  147. } else {
  148. WARN_ON(1);
  149. return;
  150. }
  151. switch (sdata->vif.type) {
  152. case NL80211_IFTYPE_AP:
  153. case NL80211_IFTYPE_ADHOC:
  154. case NL80211_IFTYPE_MESH_POINT:
  155. break;
  156. default:
  157. /* do not warn to simplify caller in scan.c */
  158. changed &= ~BSS_CHANGED_BEACON_ENABLED;
  159. if (WARN_ON(changed & BSS_CHANGED_BEACON))
  160. return;
  161. break;
  162. }
  163. if (changed & BSS_CHANGED_BEACON_ENABLED) {
  164. if (local->quiescing || !netif_running(sdata->dev) ||
  165. test_bit(SCAN_SW_SCANNING, &local->scanning)) {
  166. sdata->vif.bss_conf.enable_beacon = false;
  167. } else {
  168. /*
  169. * Beacon should be enabled, but AP mode must
  170. * check whether there is a beacon configured.
  171. */
  172. switch (sdata->vif.type) {
  173. case NL80211_IFTYPE_AP:
  174. sdata->vif.bss_conf.enable_beacon =
  175. !!rcu_dereference(sdata->u.ap.beacon);
  176. break;
  177. case NL80211_IFTYPE_ADHOC:
  178. sdata->vif.bss_conf.enable_beacon =
  179. !!rcu_dereference(sdata->u.ibss.presp);
  180. break;
  181. case NL80211_IFTYPE_MESH_POINT:
  182. sdata->vif.bss_conf.enable_beacon = true;
  183. break;
  184. default:
  185. /* not reached */
  186. WARN_ON(1);
  187. break;
  188. }
  189. }
  190. }
  191. drv_bss_info_changed(local, &sdata->vif,
  192. &sdata->vif.bss_conf, changed);
  193. }
  194. u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata)
  195. {
  196. sdata->vif.bss_conf.use_cts_prot = false;
  197. sdata->vif.bss_conf.use_short_preamble = false;
  198. sdata->vif.bss_conf.use_short_slot = false;
  199. return BSS_CHANGED_ERP_CTS_PROT |
  200. BSS_CHANGED_ERP_PREAMBLE |
  201. BSS_CHANGED_ERP_SLOT;
  202. }
  203. static void ieee80211_tasklet_handler(unsigned long data)
  204. {
  205. struct ieee80211_local *local = (struct ieee80211_local *) data;
  206. struct sk_buff *skb;
  207. struct ieee80211_ra_tid *ra_tid;
  208. while ((skb = skb_dequeue(&local->skb_queue)) ||
  209. (skb = skb_dequeue(&local->skb_queue_unreliable))) {
  210. switch (skb->pkt_type) {
  211. case IEEE80211_RX_MSG:
  212. /* Clear skb->pkt_type in order to not confuse kernel
  213. * netstack. */
  214. skb->pkt_type = 0;
  215. ieee80211_rx(local_to_hw(local), skb);
  216. break;
  217. case IEEE80211_TX_STATUS_MSG:
  218. skb->pkt_type = 0;
  219. ieee80211_tx_status(local_to_hw(local), skb);
  220. break;
  221. case IEEE80211_DELBA_MSG:
  222. ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
  223. ieee80211_stop_tx_ba_cb(ra_tid->vif, ra_tid->ra,
  224. ra_tid->tid);
  225. dev_kfree_skb(skb);
  226. break;
  227. case IEEE80211_ADDBA_MSG:
  228. ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
  229. ieee80211_start_tx_ba_cb(ra_tid->vif, ra_tid->ra,
  230. ra_tid->tid);
  231. dev_kfree_skb(skb);
  232. break ;
  233. default:
  234. WARN(1, "mac80211: Packet is of unknown type %d\n",
  235. skb->pkt_type);
  236. dev_kfree_skb(skb);
  237. break;
  238. }
  239. }
  240. }
  241. static void ieee80211_restart_work(struct work_struct *work)
  242. {
  243. struct ieee80211_local *local =
  244. container_of(work, struct ieee80211_local, restart_work);
  245. rtnl_lock();
  246. ieee80211_reconfig(local);
  247. rtnl_unlock();
  248. }
  249. void ieee80211_restart_hw(struct ieee80211_hw *hw)
  250. {
  251. struct ieee80211_local *local = hw_to_local(hw);
  252. /* use this reason, __ieee80211_resume will unblock it */
  253. ieee80211_stop_queues_by_reason(hw,
  254. IEEE80211_QUEUE_STOP_REASON_SUSPEND);
  255. schedule_work(&local->restart_work);
  256. }
  257. EXPORT_SYMBOL(ieee80211_restart_hw);
  258. struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
  259. const struct ieee80211_ops *ops)
  260. {
  261. struct ieee80211_local *local;
  262. int priv_size, i;
  263. struct wiphy *wiphy;
  264. /* Ensure 32-byte alignment of our private data and hw private data.
  265. * We use the wiphy priv data for both our ieee80211_local and for
  266. * the driver's private data
  267. *
  268. * In memory it'll be like this:
  269. *
  270. * +-------------------------+
  271. * | struct wiphy |
  272. * +-------------------------+
  273. * | struct ieee80211_local |
  274. * +-------------------------+
  275. * | driver's private data |
  276. * +-------------------------+
  277. *
  278. */
  279. priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len;
  280. wiphy = wiphy_new(&mac80211_config_ops, priv_size);
  281. if (!wiphy)
  282. return NULL;
  283. wiphy->flags |= WIPHY_FLAG_NETNS_OK |
  284. WIPHY_FLAG_4ADDR_AP |
  285. WIPHY_FLAG_4ADDR_STATION;
  286. wiphy->privid = mac80211_wiphy_privid;
  287. /* Yes, putting cfg80211_bss into ieee80211_bss is a hack */
  288. wiphy->bss_priv_size = sizeof(struct ieee80211_bss) -
  289. sizeof(struct cfg80211_bss);
  290. local = wiphy_priv(wiphy);
  291. local->hw.wiphy = wiphy;
  292. local->hw.priv = (char *)local + ALIGN(sizeof(*local), NETDEV_ALIGN);
  293. BUG_ON(!ops->tx);
  294. BUG_ON(!ops->start);
  295. BUG_ON(!ops->stop);
  296. BUG_ON(!ops->config);
  297. BUG_ON(!ops->add_interface);
  298. BUG_ON(!ops->remove_interface);
  299. BUG_ON(!ops->configure_filter);
  300. local->ops = ops;
  301. /* set up some defaults */
  302. local->hw.queues = 1;
  303. local->hw.max_rates = 1;
  304. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  305. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  306. local->user_power_level = -1;
  307. INIT_LIST_HEAD(&local->interfaces);
  308. mutex_init(&local->iflist_mtx);
  309. mutex_init(&local->scan_mtx);
  310. spin_lock_init(&local->key_lock);
  311. spin_lock_init(&local->filter_lock);
  312. spin_lock_init(&local->queue_stop_reason_lock);
  313. INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
  314. INIT_WORK(&local->restart_work, ieee80211_restart_work);
  315. INIT_WORK(&local->reconfig_filter, ieee80211_reconfig_filter);
  316. INIT_WORK(&local->dynamic_ps_enable_work,
  317. ieee80211_dynamic_ps_enable_work);
  318. INIT_WORK(&local->dynamic_ps_disable_work,
  319. ieee80211_dynamic_ps_disable_work);
  320. setup_timer(&local->dynamic_ps_timer,
  321. ieee80211_dynamic_ps_timer, (unsigned long) local);
  322. sta_info_init(local);
  323. for (i = 0; i < IEEE80211_MAX_QUEUES; i++)
  324. skb_queue_head_init(&local->pending[i]);
  325. tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
  326. (unsigned long)local);
  327. tasklet_init(&local->tasklet,
  328. ieee80211_tasklet_handler,
  329. (unsigned long) local);
  330. skb_queue_head_init(&local->skb_queue);
  331. skb_queue_head_init(&local->skb_queue_unreliable);
  332. spin_lock_init(&local->ampdu_lock);
  333. return local_to_hw(local);
  334. }
  335. EXPORT_SYMBOL(ieee80211_alloc_hw);
  336. int ieee80211_register_hw(struct ieee80211_hw *hw)
  337. {
  338. struct ieee80211_local *local = hw_to_local(hw);
  339. int result;
  340. enum ieee80211_band band;
  341. int channels, i, j, max_bitrates;
  342. bool supp_ht;
  343. static const u32 cipher_suites[] = {
  344. WLAN_CIPHER_SUITE_WEP40,
  345. WLAN_CIPHER_SUITE_WEP104,
  346. WLAN_CIPHER_SUITE_TKIP,
  347. WLAN_CIPHER_SUITE_CCMP,
  348. /* keep last -- depends on hw flags! */
  349. WLAN_CIPHER_SUITE_AES_CMAC
  350. };
  351. /*
  352. * generic code guarantees at least one band,
  353. * set this very early because much code assumes
  354. * that hw.conf.channel is assigned
  355. */
  356. channels = 0;
  357. max_bitrates = 0;
  358. supp_ht = false;
  359. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  360. struct ieee80211_supported_band *sband;
  361. sband = local->hw.wiphy->bands[band];
  362. if (!sband)
  363. continue;
  364. if (!local->oper_channel) {
  365. /* init channel we're on */
  366. local->hw.conf.channel =
  367. local->oper_channel = &sband->channels[0];
  368. local->hw.conf.channel_type = NL80211_CHAN_NO_HT;
  369. }
  370. channels += sband->n_channels;
  371. if (max_bitrates < sband->n_bitrates)
  372. max_bitrates = sband->n_bitrates;
  373. supp_ht = supp_ht || sband->ht_cap.ht_supported;
  374. }
  375. local->int_scan_req = kzalloc(sizeof(*local->int_scan_req) +
  376. sizeof(void *) * channels, GFP_KERNEL);
  377. if (!local->int_scan_req)
  378. return -ENOMEM;
  379. /* if low-level driver supports AP, we also support VLAN */
  380. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_AP))
  381. local->hw.wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
  382. /* mac80211 always supports monitor */
  383. local->hw.wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
  384. if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
  385. local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  386. else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
  387. local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
  388. /*
  389. * Calculate scan IE length -- we need this to alloc
  390. * memory and to subtract from the driver limit. It
  391. * includes the (extended) supported rates and HT
  392. * information -- SSID is the driver's responsibility.
  393. */
  394. local->scan_ies_len = 4 + max_bitrates; /* (ext) supp rates */
  395. if (supp_ht)
  396. local->scan_ies_len += 2 + sizeof(struct ieee80211_ht_cap);
  397. if (!local->ops->hw_scan) {
  398. /* For hw_scan, driver needs to set these up. */
  399. local->hw.wiphy->max_scan_ssids = 4;
  400. local->hw.wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
  401. }
  402. /*
  403. * If the driver supports any scan IEs, then assume the
  404. * limit includes the IEs mac80211 will add, otherwise
  405. * leave it at zero and let the driver sort it out; we
  406. * still pass our IEs to the driver but userspace will
  407. * not be allowed to in that case.
  408. */
  409. if (local->hw.wiphy->max_scan_ie_len)
  410. local->hw.wiphy->max_scan_ie_len -= local->scan_ies_len;
  411. local->hw.wiphy->cipher_suites = cipher_suites;
  412. local->hw.wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  413. if (!(local->hw.flags & IEEE80211_HW_MFP_CAPABLE))
  414. local->hw.wiphy->n_cipher_suites--;
  415. result = wiphy_register(local->hw.wiphy);
  416. if (result < 0)
  417. goto fail_wiphy_register;
  418. /*
  419. * We use the number of queues for feature tests (QoS, HT) internally
  420. * so restrict them appropriately.
  421. */
  422. if (hw->queues > IEEE80211_MAX_QUEUES)
  423. hw->queues = IEEE80211_MAX_QUEUES;
  424. local->workqueue =
  425. create_singlethread_workqueue(wiphy_name(local->hw.wiphy));
  426. if (!local->workqueue) {
  427. result = -ENOMEM;
  428. goto fail_workqueue;
  429. }
  430. /*
  431. * The hardware needs headroom for sending the frame,
  432. * and we need some headroom for passing the frame to monitor
  433. * interfaces, but never both at the same time.
  434. */
  435. BUILD_BUG_ON(IEEE80211_TX_STATUS_HEADROOM !=
  436. sizeof(struct ieee80211_tx_status_rtap_hdr));
  437. local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
  438. sizeof(struct ieee80211_tx_status_rtap_hdr));
  439. debugfs_hw_add(local);
  440. if (local->hw.max_listen_interval == 0)
  441. local->hw.max_listen_interval = 1;
  442. local->hw.conf.listen_interval = local->hw.max_listen_interval;
  443. result = sta_info_start(local);
  444. if (result < 0)
  445. goto fail_sta_info;
  446. result = ieee80211_wep_init(local);
  447. if (result < 0) {
  448. printk(KERN_DEBUG "%s: Failed to initialize wep: %d\n",
  449. wiphy_name(local->hw.wiphy), result);
  450. goto fail_wep;
  451. }
  452. rtnl_lock();
  453. result = ieee80211_init_rate_ctrl_alg(local,
  454. hw->rate_control_algorithm);
  455. if (result < 0) {
  456. printk(KERN_DEBUG "%s: Failed to initialize rate control "
  457. "algorithm\n", wiphy_name(local->hw.wiphy));
  458. goto fail_rate;
  459. }
  460. /* add one default STA interface if supported */
  461. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION)) {
  462. result = ieee80211_if_add(local, "wlan%d", NULL,
  463. NL80211_IFTYPE_STATION, NULL);
  464. if (result)
  465. printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
  466. wiphy_name(local->hw.wiphy));
  467. }
  468. rtnl_unlock();
  469. ieee80211_led_init(local);
  470. /* alloc internal scan request */
  471. i = 0;
  472. local->int_scan_req->ssids = &local->scan_ssid;
  473. local->int_scan_req->n_ssids = 1;
  474. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  475. if (!hw->wiphy->bands[band])
  476. continue;
  477. for (j = 0; j < hw->wiphy->bands[band]->n_channels; j++) {
  478. local->int_scan_req->channels[i] =
  479. &hw->wiphy->bands[band]->channels[j];
  480. i++;
  481. }
  482. }
  483. local->int_scan_req->n_channels = i;
  484. local->network_latency_notifier.notifier_call =
  485. ieee80211_max_network_latency;
  486. result = pm_qos_add_notifier(PM_QOS_NETWORK_LATENCY,
  487. &local->network_latency_notifier);
  488. if (result) {
  489. rtnl_lock();
  490. goto fail_pm_qos;
  491. }
  492. return 0;
  493. fail_pm_qos:
  494. ieee80211_led_exit(local);
  495. ieee80211_remove_interfaces(local);
  496. fail_rate:
  497. rtnl_unlock();
  498. ieee80211_wep_free(local);
  499. fail_wep:
  500. sta_info_stop(local);
  501. fail_sta_info:
  502. destroy_workqueue(local->workqueue);
  503. fail_workqueue:
  504. wiphy_unregister(local->hw.wiphy);
  505. fail_wiphy_register:
  506. kfree(local->int_scan_req);
  507. return result;
  508. }
  509. EXPORT_SYMBOL(ieee80211_register_hw);
  510. void ieee80211_unregister_hw(struct ieee80211_hw *hw)
  511. {
  512. struct ieee80211_local *local = hw_to_local(hw);
  513. tasklet_kill(&local->tx_pending_tasklet);
  514. tasklet_kill(&local->tasklet);
  515. pm_qos_remove_notifier(PM_QOS_NETWORK_LATENCY,
  516. &local->network_latency_notifier);
  517. rtnl_lock();
  518. /*
  519. * At this point, interface list manipulations are fine
  520. * because the driver cannot be handing us frames any
  521. * more and the tasklet is killed.
  522. */
  523. ieee80211_remove_interfaces(local);
  524. rtnl_unlock();
  525. cancel_work_sync(&local->reconfig_filter);
  526. ieee80211_clear_tx_pending(local);
  527. sta_info_stop(local);
  528. rate_control_deinitialize(local);
  529. if (skb_queue_len(&local->skb_queue) ||
  530. skb_queue_len(&local->skb_queue_unreliable))
  531. printk(KERN_WARNING "%s: skb_queue not empty\n",
  532. wiphy_name(local->hw.wiphy));
  533. skb_queue_purge(&local->skb_queue);
  534. skb_queue_purge(&local->skb_queue_unreliable);
  535. destroy_workqueue(local->workqueue);
  536. wiphy_unregister(local->hw.wiphy);
  537. ieee80211_wep_free(local);
  538. ieee80211_led_exit(local);
  539. kfree(local->int_scan_req);
  540. }
  541. EXPORT_SYMBOL(ieee80211_unregister_hw);
  542. void ieee80211_free_hw(struct ieee80211_hw *hw)
  543. {
  544. struct ieee80211_local *local = hw_to_local(hw);
  545. mutex_destroy(&local->iflist_mtx);
  546. mutex_destroy(&local->scan_mtx);
  547. wiphy_free(local->hw.wiphy);
  548. }
  549. EXPORT_SYMBOL(ieee80211_free_hw);
  550. static int __init ieee80211_init(void)
  551. {
  552. struct sk_buff *skb;
  553. int ret;
  554. BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb));
  555. BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) +
  556. IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb));
  557. ret = rc80211_minstrel_init();
  558. if (ret)
  559. return ret;
  560. ret = rc80211_pid_init();
  561. if (ret)
  562. return ret;
  563. ieee80211_debugfs_netdev_init();
  564. return 0;
  565. }
  566. static void __exit ieee80211_exit(void)
  567. {
  568. rc80211_pid_exit();
  569. rc80211_minstrel_exit();
  570. /*
  571. * For key todo, it'll be empty by now but the work
  572. * might still be scheduled.
  573. */
  574. flush_scheduled_work();
  575. if (mesh_allocated)
  576. ieee80211s_stop();
  577. ieee80211_debugfs_netdev_exit();
  578. }
  579. subsys_initcall(ieee80211_init);
  580. module_exit(ieee80211_exit);
  581. MODULE_DESCRIPTION("IEEE 802.11 subsystem");
  582. MODULE_LICENSE("GPL");