iwl-rfkill.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2008 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. * James P. Ketrenos <ipw2100-admin@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/version.h>
  31. #include <linux/init.h>
  32. #include <net/mac80211.h>
  33. #include "iwl-eeprom.h"
  34. #include "iwl-dev.h"
  35. #include "iwl-core.h"
  36. #include "iwl-helpers.h"
  37. /* software rf-kill from user */
  38. static int iwl_rfkill_soft_rf_kill(void *data, enum rfkill_state state)
  39. {
  40. struct iwl_priv *priv = data;
  41. int err = 0;
  42. if (!priv->rfkill)
  43. return 0;
  44. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  45. return 0;
  46. IWL_DEBUG_RF_KILL("we received soft RFKILL set to state %d\n", state);
  47. mutex_lock(&priv->mutex);
  48. switch (state) {
  49. case RFKILL_STATE_UNBLOCKED:
  50. if (iwl_is_rfkill_hw(priv)) {
  51. err = -EBUSY;
  52. goto out_unlock;
  53. }
  54. iwl_radio_kill_sw_enable_radio(priv);
  55. break;
  56. case RFKILL_STATE_SOFT_BLOCKED:
  57. iwl_radio_kill_sw_disable_radio(priv);
  58. break;
  59. default:
  60. IWL_WARNING("we recieved unexpected RFKILL state %d\n", state);
  61. break;
  62. }
  63. out_unlock:
  64. mutex_unlock(&priv->mutex);
  65. return err;
  66. }
  67. int iwl_rfkill_init(struct iwl_priv *priv)
  68. {
  69. struct device *device = wiphy_dev(priv->hw->wiphy);
  70. int ret = 0;
  71. BUG_ON(device == NULL);
  72. IWL_DEBUG_RF_KILL("Initializing RFKILL.\n");
  73. priv->rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN);
  74. if (!priv->rfkill) {
  75. IWL_ERROR("Unable to allocate rfkill device.\n");
  76. ret = -ENOMEM;
  77. goto error;
  78. }
  79. priv->rfkill->name = priv->cfg->name;
  80. priv->rfkill->data = priv;
  81. priv->rfkill->state = RFKILL_STATE_UNBLOCKED;
  82. priv->rfkill->toggle_radio = iwl_rfkill_soft_rf_kill;
  83. priv->rfkill->user_claim_unsupported = 1;
  84. priv->rfkill->dev.class->suspend = NULL;
  85. priv->rfkill->dev.class->resume = NULL;
  86. ret = rfkill_register(priv->rfkill);
  87. if (ret) {
  88. IWL_ERROR("Unable to register rfkill: %d\n", ret);
  89. goto free_rfkill;
  90. }
  91. IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
  92. return ret;
  93. free_rfkill:
  94. if (priv->rfkill != NULL)
  95. rfkill_free(priv->rfkill);
  96. priv->rfkill = NULL;
  97. error:
  98. IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
  99. return ret;
  100. }
  101. EXPORT_SYMBOL(iwl_rfkill_init);
  102. void iwl_rfkill_unregister(struct iwl_priv *priv)
  103. {
  104. if (priv->rfkill)
  105. rfkill_unregister(priv->rfkill);
  106. priv->rfkill = NULL;
  107. }
  108. EXPORT_SYMBOL(iwl_rfkill_unregister);
  109. /* set rf-kill to the right state. */
  110. void iwl_rfkill_set_hw_state(struct iwl_priv *priv)
  111. {
  112. if (!priv->rfkill)
  113. return;
  114. if (iwl_is_rfkill_hw(priv)) {
  115. rfkill_force_state(priv->rfkill, RFKILL_STATE_HARD_BLOCKED);
  116. return;
  117. }
  118. if (!iwl_is_rfkill_sw(priv))
  119. rfkill_force_state(priv->rfkill, RFKILL_STATE_UNBLOCKED);
  120. else
  121. rfkill_force_state(priv->rfkill, RFKILL_STATE_SOFT_BLOCKED);
  122. }
  123. EXPORT_SYMBOL(iwl_rfkill_set_hw_state);