2008-03-29 07:21:06 +08:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* Portions of this file are derived from the ipw3945 project, as well
|
|
|
|
* as portions of the ieee80211 subsystem header files.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of version 2 of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
|
|
|
|
*
|
|
|
|
* The full GNU General Public License is included in this distribution in the
|
|
|
|
* file called LICENSE.
|
|
|
|
*
|
|
|
|
* Contact Information:
|
|
|
|
* James P. Ketrenos <ipw2100-admin@linux.intel.com>
|
|
|
|
* Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
|
|
|
|
*****************************************************************************/
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
|
|
|
|
#include <net/mac80211.h>
|
|
|
|
|
|
|
|
#include "iwl-eeprom.h"
|
2008-04-25 02:55:38 +08:00
|
|
|
#include "iwl-dev.h"
|
2008-04-04 07:05:21 +08:00
|
|
|
#include "iwl-core.h"
|
2008-03-29 07:21:06 +08:00
|
|
|
#include "iwl-helpers.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* software rf-kill from user */
|
|
|
|
static int iwl_rfkill_soft_rf_kill(void *data, enum rfkill_state state)
|
|
|
|
{
|
|
|
|
struct iwl_priv *priv = data;
|
|
|
|
int err = 0;
|
|
|
|
|
2008-07-01 23:49:50 +08:00
|
|
|
if (!priv->rfkill)
|
2008-03-29 07:21:06 +08:00
|
|
|
return 0;
|
|
|
|
|
2008-04-16 07:01:46 +08:00
|
|
|
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
|
|
|
|
return 0;
|
|
|
|
|
2008-06-28 01:04:25 +08:00
|
|
|
IWL_DEBUG_RF_KILL("we received soft RFKILL set to state %d\n", state);
|
2008-03-29 07:21:06 +08:00
|
|
|
mutex_lock(&priv->mutex);
|
|
|
|
|
|
|
|
switch (state) {
|
2008-06-27 22:27:47 +08:00
|
|
|
case RFKILL_STATE_UNBLOCKED:
|
2008-07-01 23:49:50 +08:00
|
|
|
if (iwl_is_rfkill_hw(priv)) {
|
2008-03-29 07:21:06 +08:00
|
|
|
err = -EBUSY;
|
2008-07-01 23:49:50 +08:00
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
iwl_radio_kill_sw_enable_radio(priv);
|
2008-03-29 07:21:06 +08:00
|
|
|
break;
|
2008-06-27 22:27:47 +08:00
|
|
|
case RFKILL_STATE_SOFT_BLOCKED:
|
2008-06-13 15:44:55 +08:00
|
|
|
iwl_radio_kill_sw_disable_radio(priv);
|
2008-03-29 07:21:06 +08:00
|
|
|
break;
|
2008-06-27 22:27:47 +08:00
|
|
|
default:
|
|
|
|
IWL_WARNING("we recieved unexpected RFKILL state %d\n", state);
|
|
|
|
break;
|
2008-03-29 07:21:06 +08:00
|
|
|
}
|
2008-07-01 23:49:50 +08:00
|
|
|
out_unlock:
|
2008-03-29 07:21:06 +08:00
|
|
|
mutex_unlock(&priv->mutex);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int iwl_rfkill_init(struct iwl_priv *priv)
|
|
|
|
{
|
|
|
|
struct device *device = wiphy_dev(priv->hw->wiphy);
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
BUG_ON(device == NULL);
|
|
|
|
|
2008-04-04 07:05:24 +08:00
|
|
|
IWL_DEBUG_RF_KILL("Initializing RFKILL.\n");
|
2008-07-01 23:49:50 +08:00
|
|
|
priv->rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN);
|
|
|
|
if (!priv->rfkill) {
|
2008-04-04 07:05:24 +08:00
|
|
|
IWL_ERROR("Unable to allocate rfkill device.\n");
|
2008-03-29 07:21:06 +08:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2008-07-01 23:49:50 +08:00
|
|
|
priv->rfkill->name = priv->cfg->name;
|
|
|
|
priv->rfkill->data = priv;
|
|
|
|
priv->rfkill->state = RFKILL_STATE_UNBLOCKED;
|
|
|
|
priv->rfkill->toggle_radio = iwl_rfkill_soft_rf_kill;
|
|
|
|
priv->rfkill->user_claim_unsupported = 1;
|
2008-03-29 07:21:06 +08:00
|
|
|
|
2008-07-01 23:49:50 +08:00
|
|
|
priv->rfkill->dev.class->suspend = NULL;
|
|
|
|
priv->rfkill->dev.class->resume = NULL;
|
2008-03-29 07:21:06 +08:00
|
|
|
|
2008-07-01 23:49:50 +08:00
|
|
|
ret = rfkill_register(priv->rfkill);
|
2008-04-04 07:05:24 +08:00
|
|
|
if (ret) {
|
|
|
|
IWL_ERROR("Unable to register rfkill: %d\n", ret);
|
2008-07-01 15:44:48 +08:00
|
|
|
goto free_rfkill;
|
2008-04-04 07:05:24 +08:00
|
|
|
}
|
2008-03-29 07:21:06 +08:00
|
|
|
|
2008-04-04 07:05:24 +08:00
|
|
|
IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
|
2008-03-29 07:21:06 +08:00
|
|
|
return ret;
|
|
|
|
|
2008-07-01 15:44:48 +08:00
|
|
|
free_rfkill:
|
2008-07-01 23:49:50 +08:00
|
|
|
if (priv->rfkill != NULL)
|
|
|
|
rfkill_free(priv->rfkill);
|
|
|
|
priv->rfkill = NULL;
|
2008-03-29 07:21:06 +08:00
|
|
|
|
|
|
|
error:
|
2008-04-04 07:05:24 +08:00
|
|
|
IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
|
2008-03-29 07:21:06 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(iwl_rfkill_init);
|
|
|
|
|
|
|
|
void iwl_rfkill_unregister(struct iwl_priv *priv)
|
|
|
|
{
|
|
|
|
|
2008-07-01 23:49:50 +08:00
|
|
|
if (priv->rfkill)
|
|
|
|
rfkill_unregister(priv->rfkill);
|
2008-03-29 07:21:06 +08:00
|
|
|
|
2008-07-01 23:49:50 +08:00
|
|
|
priv->rfkill = NULL;
|
2008-03-29 07:21:06 +08:00
|
|
|
}
|
2008-04-04 07:05:24 +08:00
|
|
|
EXPORT_SYMBOL(iwl_rfkill_unregister);
|
2008-03-29 07:21:06 +08:00
|
|
|
|
|
|
|
/* set rf-kill to the right state. */
|
|
|
|
void iwl_rfkill_set_hw_state(struct iwl_priv *priv)
|
|
|
|
{
|
2008-07-01 23:49:50 +08:00
|
|
|
if (!priv->rfkill)
|
2008-03-29 07:21:06 +08:00
|
|
|
return;
|
|
|
|
|
2008-07-01 23:49:50 +08:00
|
|
|
if (iwl_is_rfkill_hw(priv)) {
|
|
|
|
rfkill_force_state(priv->rfkill, RFKILL_STATE_HARD_BLOCKED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!iwl_is_rfkill_sw(priv))
|
|
|
|
rfkill_force_state(priv->rfkill, RFKILL_STATE_UNBLOCKED);
|
2008-03-29 07:21:06 +08:00
|
|
|
else
|
2008-07-01 23:49:50 +08:00
|
|
|
rfkill_force_state(priv->rfkill, RFKILL_STATE_SOFT_BLOCKED);
|
2008-03-29 07:21:06 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(iwl_rfkill_set_hw_state);
|