iwl-rfkill.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *****************************************************************************/
  28. #include <linux/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/init.h>
  31. #include <net/mac80211.h>
  32. #include "iwl-eeprom.h"
  33. #include "iwl-dev.h"
  34. #include "iwl-core.h"
  35. /* software rf-kill from user */
  36. static int iwl_rfkill_soft_rf_kill(void *data, bool blocked)
  37. {
  38. struct iwl_priv *priv = data;
  39. if (!priv->rfkill)
  40. return -EINVAL;
  41. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  42. return 0;
  43. IWL_DEBUG_RF_KILL(priv, "received soft RFKILL: block=%d\n", blocked);
  44. mutex_lock(&priv->mutex);
  45. if (iwl_is_rfkill_hw(priv))
  46. goto out_unlock;
  47. if (!blocked)
  48. iwl_radio_kill_sw_enable_radio(priv);
  49. else
  50. iwl_radio_kill_sw_disable_radio(priv);
  51. out_unlock:
  52. mutex_unlock(&priv->mutex);
  53. return 0;
  54. }
  55. static const struct rfkill_ops iwl_rfkill_ops = {
  56. .set_block = iwl_rfkill_soft_rf_kill,
  57. };
  58. int iwl_rfkill_init(struct iwl_priv *priv)
  59. {
  60. struct device *device = wiphy_dev(priv->hw->wiphy);
  61. int ret = 0;
  62. BUG_ON(device == NULL);
  63. IWL_DEBUG_RF_KILL(priv, "Initializing RFKILL.\n");
  64. priv->rfkill = rfkill_alloc(priv->cfg->name,
  65. device,
  66. RFKILL_TYPE_WLAN,
  67. &iwl_rfkill_ops, priv);
  68. if (!priv->rfkill) {
  69. IWL_ERR(priv, "Unable to allocate RFKILL device.\n");
  70. ret = -ENOMEM;
  71. goto error;
  72. }
  73. ret = rfkill_register(priv->rfkill);
  74. if (ret) {
  75. IWL_ERR(priv, "Unable to register RFKILL: %d\n", ret);
  76. goto free_rfkill;
  77. }
  78. IWL_DEBUG_RF_KILL(priv, "RFKILL initialization complete.\n");
  79. return 0;
  80. free_rfkill:
  81. rfkill_destroy(priv->rfkill);
  82. priv->rfkill = NULL;
  83. error:
  84. IWL_DEBUG_RF_KILL(priv, "RFKILL initialization complete.\n");
  85. return ret;
  86. }
  87. EXPORT_SYMBOL(iwl_rfkill_init);
  88. void iwl_rfkill_unregister(struct iwl_priv *priv)
  89. {
  90. if (priv->rfkill) {
  91. rfkill_unregister(priv->rfkill);
  92. rfkill_destroy(priv->rfkill);
  93. }
  94. priv->rfkill = NULL;
  95. }
  96. EXPORT_SYMBOL(iwl_rfkill_unregister);
  97. /* set RFKILL to the right state. */
  98. void iwl_rfkill_set_hw_state(struct iwl_priv *priv)
  99. {
  100. if (!priv->rfkill)
  101. return;
  102. if (rfkill_set_hw_state(priv->rfkill,
  103. !!iwl_is_rfkill_hw(priv)))
  104. iwl_radio_kill_sw_disable_radio(priv);
  105. else
  106. iwl_radio_kill_sw_enable_radio(priv);
  107. }
  108. EXPORT_SYMBOL(iwl_rfkill_set_hw_state);