main.c 19 KB

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