main.c 21 KB

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