rfkill improvements
Subsystems (5)
Johannes Berg
maintainercover rfkill improvements
So this integrates rfkill into cfg80211 with the semantics we discussed before. I've also ported iwlwifi for the fun of it but due to lack of hardware can't test it. Help would be appreciated a lot.
Note that this changes core kernel code so be prepared to compile a lot of the kernel again.
johannes
Johannes Berg
maintainerPATCH 1/4 net: introduce pre-up netdev notifier
NETDEV_UP is called after the device is set UP, but sometimes it is useful to be able to veto the device UP. Introduce a new NETDEV_PRE_UP notifier that can be used for exactly this. The first use case will be cfg80211 denying interfaces to be set UP if the device is known to be rfkill'ed.
---
John, please take this patch via your tree, I asked Dave and he's cool with that.
include/linux/notifier.h | 1 + net/core/dev.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-)
include/linux/notifier.h +1 -0
@@ -198,6 +198,7 @@ static inline int notifier_to_errno(int#define NETDEV_CHANGENAME 0x000A#define NETDEV_FEAT_CHANGE 0x000B#define NETDEV_BONDING_FAILOVER 0x000C +#define NETDEV_PRE_UP 0x000D#define SYS_DOWN 0x0001/* Notify of system down */ #define SYS_RESTART SYS_DOWN
net/core/dev.c +6 -1
@@ -1047,7 +1047,7 @@ void dev_load(struct net *net, const chaint dev_open (struct net_device *dev) {const struct net_device_ops *ops = dev->netdev_ops; -int ret =0 ; +int ret;ASSERT_RTNL ();
@@ -1064,6 +1064,11 @@ int dev_open(struct net_device *dev)if (!netif_device_present (dev))return -ENODEV ; + ret =call_netdevice_notifiers (NETDEV_PRE_UP , dev); + ret =notifier_to_errno (ret); +if (ret) +return ret; +/* * Call device private open method */
Johannes Berg
maintainerPATCH 2/4 rfkill: add function to query state
In reply to Johannes BergSometimes it is necessary to know how the state is, and it is easier to query rfkill than keep track of it somewhere else, so add a function for that. This could later be expanded to return hard/soft block, but so far that isn't necessary.
--- include/linux/rfkill.h | 12 ++++++++++++ net/rfkill/core.c | 13 +++++++++++++ 2 files changed, 25 insertions(+)
include/linux/rfkill.h +12 -0
@@ -225,6 +225,13 @@ void rfkill_set_states(struct rfkill *rf* registered drivers? */ void rfkill_set_global_sw_state (const enum rfkill_type type,bool blocked); + +/** +* rfkill_blocked - query rfkill block +* +* @rfkill: rfkill struct to query +*/ +bool rfkill_blocked (struct rfkill *rfkill);#else /* !RFKILL */ static inline struct rfkill *__must_check rfkill_alloc(const char *name,
@@ -277,6 +284,11 @@ static inline void rfkill_set_global_sw_ bool blocked) { } + +static inline bool rfkill_blocked (struct rfkill *rfkill) +{ +return false; +}#endif /* RFKILL || RFKILL_MODULE */
net/rfkill/core.c +13 -0
@@ -862,6 +862,19 @@ void rfkill_destroy(struct rfkill *rfkil }EXPORT_SYMBOL (rfkill_destroy); +bool rfkill_blocked (struct rfkill *rfkill) +{ +unsigned long flags; +u32 state; + +spin_lock_irqsave (&rfkill->lock, flags); + state = rfkill->state; +spin_unlock_irqrestore (&rfkill->lock, flags); + +return !!(state &RFKILL_BLOCK_ANY ); +} +EXPORT_SYMBOL (rfkill_blocked); +static int __init rfkill_init (void ) {
Johannes Berg
maintainerPATCH 3/4 cfg80211: add rfkill support
In reply to Johannes BergTo be easier on drivers and users, have cfg80211 register an rfkill structure that drivers can access. When soft-killed, simply take down all interfaces; when hard-killed the driver needs to notify us and we will take down the interfaces after the fact. While rfkilled, interfaces cannot be set UP.
--- include/net/cfg80211.h | 21 +++++++++-- include/net/mac80211.h | 18 ++++++++-- net/mac80211/cfg.c | 20 ++++------- net/mac80211/driver-ops.h | 7 +++ net/mac80211/iface.c | 4 +- net/mac80211/util.c | 2 - net/wireless/Kconfig | 3 + net/wireless/core.c | 81 +++++++++++++++++++++++++++++++++++++++++++-- net/wireless/core.h | 7 +++ net/wireless/wext-compat.c | 11 +++--- 10 files changed, 145 insertions(+), 29 deletions(-)
net/wireless/core.c +78 -3
@@ -12,6 +12,7 @@#include <linux/debugfs.h> #include <linux/notifier.h> #include <linux/device.h> +#include <linux/rtnetlink.h> #include <net/genetlink.h> #include <net/cfg80211.h> #include "nl80211.h"
@@ -227,6 +228,41 @@ int cfg80211_dev_rename(struct cfg80211_return 0 ; } +static void cfg80211_rfkill_poll (struct rfkill *rfkill,void *data) +{ +struct cfg80211_registered_device *drv = data; + + drv->ops->rfkill_poll (&drv->wiphy); +} + +static int cfg80211_rfkill_set_block (void *data,bool blocked) +{ +struct cfg80211_registered_device *drv = data; +struct wireless_dev *wdev; + +if (!blocked) +return 0 ; + +rtnl_lock (); +mutex_lock (&drv->devlist_mtx); + +list_for_each_entry (wdev, &drv->netdev_list, list) +dev_close (wdev->netdev); + +mutex_unlock (&drv->devlist_mtx); +rtnl_unlock (); + +return 0 ; +} + +void cfg80211_rfkill_sync_work (struct work_struct *work) +{ +struct cfg80211_registered_device *drv; + + drv = container_of(work, struct cfg80211_registered_device, rfkill_sync); +cfg80211_rfkill_set_block (drv,rfkill_blocked (drv->rfkill)); +} +/* exported functions */ struct wiphy *wiphy_new (const struct cfg80211_ops *ops,int sizeof_priv)
@@ -274,6 +310,18 @@ struct wiphy *wiphy_new(const struct cfg drv->wiphy.dev.class = &ieee80211_class; drv->wiphy.dev.platform_data = drv; + drv->rfkill_ops.set_block = cfg80211_rfkill_set_block; + drv->rfkill =rfkill_alloc (dev_name (&drv->wiphy.dev), + &drv->wiphy.dev,RFKILL_TYPE_WLAN , + &drv->rfkill_ops, drv); + +if (!drv->rfkill) { +kfree (drv); +return NULL ; + } + +INIT_WORK (&drv->rfkill_sync, cfg80211_rfkill_sync_work); +/* * Initialize wiphy parameters to IEEE 802.11 MIB default values. * Fragmentation and RTS threshold are disabled by default with the
@@ -356,6 +404,13 @@ int wiphy_register(struct wiphy *wiphy)if (res) goto out_unlock; +if (wiphy->rfkill_poll && drv->ops->rfkill_poll) + drv->rfkill_ops.poll = cfg80211_rfkill_poll; + + res =rfkill_register (drv->rfkill); +if (res) + goto out_rm_dev; +list_add (&drv->list, &cfg80211_drv_list);/* add to debugfs */
@@ -379,7 +434,11 @@ int wiphy_register(struct wiphy *wiphy)cfg80211_debugfs_drv_add (drv); res =0 ; -out_unlock: + goto out_unlock; + + out_rm_dev: +device_del (&drv->wiphy.dev); + out_unlock:mutex_unlock (&cfg80211_mutex);return res; }
@@ -389,6 +448,8 @@ void wiphy_unregister(struct wiphy *wiph {struct cfg80211_registered_device *drv =wiphy_to_dev (wiphy); +rfkill_unregister (drv->rfkill); +/* protect the device list */ mutex_lock (&cfg80211_mutex);
@@ -425,6 +486,7 @@ EXPORT_SYMBOL(wiphy_unregister);void cfg80211_dev_free (struct cfg80211_registered_device *drv) {struct cfg80211_internal_bss *scan, *tmp; +rfkill_destroy (drv->rfkill);mutex_destroy (&drv->mtx);mutex_destroy (&drv->devlist_mtx);list_for_each_entry_safe (scan, tmp, &drv->bss_list, list)
@@ -438,6 +500,15 @@ void wiphy_free(struct wiphy *wiphy) }EXPORT_SYMBOL (wiphy_free); +void wiphy_rfkill_set_hw_state (struct wiphy *wiphy,bool blocked) +{ +struct cfg80211_registered_device *drv =wiphy_to_dev (wiphy); + +if (rfkill_set_hw_state (drv->rfkill, blocked)) +schedule_work (&drv->rfkill_sync); +} +EXPORT_SYMBOL (wiphy_rfkill_set_hw_state); +static int cfg80211_netdev_notifier_call (struct notifier_block * nb,unsigned long state,void *ndev)
@@ -446,7 +517,7 @@ static int cfg80211_netdev_notifier_callstruct cfg80211_registered_device *rdev;if (!dev->ieee80211_ptr) -return 0 ; +return NOTIFY_DONE ; rdev =wiphy_to_dev (dev->ieee80211_ptr->wiphy);
@@ -492,9 +563,13 @@ static int cfg80211_netdev_notifier_call }mutex_unlock (&rdev->devlist_mtx);break ; +case NETDEV_PRE_UP : +if (rfkill_blocked (rdev->rfkill)) +return notifier_from_errno (-EINVAL ); +break ; } -return 0 ; +return NOTIFY_DONE ; }static struct notifier_block cfg80211_netdev_notifier = {
net/wireless/core.h +7 -0
@@ -11,6 +11,8 @@#include <linux/kref.h> #include <linux/rbtree.h> #include <linux/debugfs.h> +#include <linux/rfkill.h> +#include <linux/workqueue.h> #include <net/genetlink.h> #include <net/cfg80211.h> #include "reg.h"
@@ -24,6 +26,11 @@ struct cfg80211_registered_device {* any call is in progress */ struct mutex mtx; +/* rfkill support */ +struct rfkill_ops rfkill_ops; +struct rfkill *rfkill; +struct work_struct rfkill_sync; +/* ISO / IEC 3166 alpha2 for which this device is receiving * country IEs on, this can help disregard country IEs from APs * on the same alpha2 quickly. The alpha2 may differ from
include/net/cfg80211.h +17 -4
@@ -757,13 +757,11 @@ enum wiphy_params_flags {* @TX_POWER_AUTOMATIC: the dbm parameter is ignored * @TX_POWER_LIMITED: limit TX power by the dbm parameter * @TX_POWER_FIXED: fix TX power to the dbm parameter -* @TX_POWER_OFF: turn off completely (will go away) */ enum tx_power_setting {TX_POWER_AUTOMATIC ,TX_POWER_LIMITED ,TX_POWER_FIXED , -TX_POWER_OFF , };/**
@@ -855,8 +853,10 @@ enum tx_power_setting {* * @set_tx_power: set the transmit power according to the parameters * @get_tx_power: store the current TX power into the dbm variable; -* return 0 if successful; or -ENETDOWN if successful but power -* is disabled (this will go away) +* return 0 if successful +* +* @rfkill_poll: polls the hw rfkill line, use cfg80211 reporting +* functions to adjust rfkill hw state */ struct cfg80211_ops {int (*suspend)(struct wiphy *wiphy);
@@ -952,6 +952,8 @@ struct cfg80211_ops {int (*set_tx_power)(struct wiphy *wiphy,enum tx_power_setting type,int dbm);int (*get_tx_power)(struct wiphy *wiphy,int *dbm); + +void (*rfkill_poll)(struct wiphy *wiphy); };/*
@@ -990,6 +992,8 @@ struct cfg80211_ops {* @frag_threshold: Fragmentation threshold (dot11FragmentationThreshold); * -1 = fragmentation disabled, only odd values >= 256 used * @rts_threshold: RTS threshold (dot11RTSThreshold); -1 = RTS/CTS disabled +* +* @rfkill_poll: poll rfkill via rfkill_poll method, if present */ struct wiphy {/* assign these fields before you register the wiphy */
@@ -1003,6 +1007,8 @@ struct wiphy {bool custom_regulatory;bool strict_regulatory; +bool rfkill_poll; +enum cfg80211_signal_type signal_type;int bss_priv_size;
@@ -1619,4 +1625,11 @@ void cfg80211_michael_mic_failure(struct*/ void cfg80211_ibss_joined (struct net_device *dev,const u8 *bssid,gfp_t gfp); +/** +* wiphy_rfkill_set_hw_state - notify cfg80211 about hw block state +* @wiphy: the wiphy +* @blocked: block status +*/ +void wiphy_rfkill_set_hw_state (struct wiphy *wiphy,bool blocked); +#endif /* __NET_CFG80211_H */
net/wireless/Kconfig +2 -1
@@ -1,5 +1,6 @@ config CFG80211 - tristate "Improved wireless configuration API" + tristate "Improved wireless configuration API" + depends on RFKILL || !RFKILL config CFG80211_REG_DEBUG bool "cfg80211 regulatory debugging"
net/wireless/wext-compat.c +7 -4
@@ -764,6 +764,8 @@ int cfg80211_wext_siwtxpower(struct net_/* only change when not disabling */ if (!data->txpower.disabled) { +rfkill_set_sw_state (rdev->rfkill, false); +if (data->txpower.fixed) {/* * wext doesn't support negative values, see
@@ -787,7 +789,9 @@ int cfg80211_wext_siwtxpower(struct net_ } } }else { - type =TX_POWER_OFF ; +rfkill_set_sw_state (rdev->rfkill, true); +schedule_work (&rdev->rfkill_sync); +return 0 ; }return rdev->ops->set_tx_power (wdev->wiphy, type, dbm);;
@@ -811,13 +815,12 @@ int cfg80211_wext_giwtxpower(struct net_return -EOPNOTSUPP ; err = rdev->ops->get_tx_power (wdev->wiphy, &val); -/* HACK!!! */ -if (err && err != -ENETDOWN ) +if (err)return err;/* well... oh well */ data->txpower.fixed =1 ; - data->txpower.disabled = err == -ENETDOWN ; + data->txpower.disabled =rfkill_blocked (rdev->rfkill); data->txpower.value = val; data->txpower.flags =IW_TXPOW_DBM ;
net/mac80211/cfg.c +8 -12
@@ -1339,7 +1339,6 @@ static int ieee80211_set_tx_power(structstruct ieee80211_local *local =wiphy_priv (wiphy);struct ieee80211_channel *chan = local->hw.conf.channel;u32 changes =0 ; -bool radio_enabled = true;switch (type) {case TX_POWER_AUTOMATIC :
@@ -1358,14 +1357,6 @@ static int ieee80211_set_tx_power(structreturn -EINVAL ; local->user_power_level = dbm;break ; -case TX_POWER_OFF : - radio_enabled = false; -break ; - } - -if (radio_enabled != local->hw.conf.radio_enabled) { - changes |=IEEE80211_CONF_CHANGE_RADIO_ENABLED ; - local->hw.conf.radio_enabled = radio_enabled; }ieee80211_hw_config (local, changes);
@@ -1379,12 +1370,16 @@ static int ieee80211_get_tx_power(struct *dbm = local->hw.conf.power_level; -if (!local->hw.conf.radio_enabled) -return -ENETDOWN ; -return 0 ; } +static void ieee80211_rfkill_poll (struct wiphy *wiphy) +{ +struct ieee80211_local *local =wiphy_priv (wiphy); + +drv_rfkill_poll (local); +} +struct cfg80211_ops mac80211_config_ops = { .add_virtual_intf = ieee80211_add_iface, .del_virtual_intf = ieee80211_del_iface,
@@ -1426,4 +1421,5 @@ struct cfg80211_ops mac80211_config_ops .set_wiphy_params = ieee80211_set_wiphy_params, .set_tx_power = ieee80211_set_tx_power, .get_tx_power = ieee80211_get_tx_power, + .rfkill_poll = ieee80211_rfkill_poll, };
net/mac80211/iface.c +2 -2
@@ -170,7 +170,7 @@ static int ieee80211_open(struct net_dev goto err_del_bss;/* we're brought up, everything changes */ hw_reconf_flags = ~0 ; -ieee80211_led_radio (local, local->hw.conf.radio_enabled); +ieee80211_led_radio (local, true); }/*
@@ -560,7 +560,7 @@ static int ieee80211_stop(struct net_devdrv_stop (local); -ieee80211_led_radio (local,0 ); +ieee80211_led_radio (local, false);flush_workqueue (local->hw.workqueue);
net/mac80211/util.c +1 -1
@@ -1092,7 +1092,7 @@ int ieee80211_reconfig(struct ieee80211_if (local->open_count) { res =drv_start (local); -ieee80211_led_radio (local, hw->conf.radio_enabled); +ieee80211_led_radio (local, true); }/* add interfaces */
include/net/mac80211.h +16 -2
@@ -529,7 +529,7 @@ enum ieee80211_conf_flags {/** * enum ieee80211_conf_changed - denotes which configuration changed * -* @IEEE80211_CONF_CHANGE_RADIO_ENABLED: the value of radio_enabled changed +* @_IEEE80211_CONF_CHANGE_RADIO_ENABLED: DEPRECATED * @_IEEE80211_CONF_CHANGE_BEACON_INTERVAL: DEPRECATED * @IEEE80211_CONF_CHANGE_LISTEN_INTERVAL: the listen interval changed * @IEEE80211_CONF_CHANGE_RADIOTAP: the radiotap flag changed
@@ -540,7 +540,7 @@ enum ieee80211_conf_flags {* @IEEE80211_CONF_CHANGE_IDLE: Idle flag changed */ enum ieee80211_conf_changed { -IEEE80211_CONF_CHANGE_RADIO_ENABLED =BIT (0 ), + _IEEE80211_CONF_CHANGE_RADIO_ENABLED =BIT (0 ), _IEEE80211_CONF_CHANGE_BEACON_INTERVAL =BIT (1 ),IEEE80211_CONF_CHANGE_LISTEN_INTERVAL =BIT (2 ),IEEE80211_CONF_CHANGE_RADIOTAP =BIT (3 ),
@@ -559,6 +559,14 @@ __IEEE80211_CONF_CHANGE_BEACON_INTERVAL(#define IEEE80211_CONF_CHANGE_BEACON_INTERVAL \ __IEEE80211_CONF_CHANGE_BEACON_INTERVAL() +static inline __deprecated enum ieee80211_conf_changed +__IEEE80211_CONF_CHANGE_RADIO_ENABLED (void ) +{ +return _IEEE80211_CONF_CHANGE_RADIO_ENABLED; +} +#define IEEE80211_CONF_CHANGE_RADIO_ENABLED \ + __IEEE80211_CONF_CHANGE_RADIO_ENABLED() +/** * struct ieee80211_conf - configuration of the device *
@@ -1419,6 +1427,10 @@ enum ieee80211_ampdu_mlme_action {* is the first frame we expect to perform the action on. Notice * that TX/RX_STOP can pass NULL for this parameter. * Returns a negative error code on failure. +* +* @rfkill_poll: Poll rfkill hardware state. If you need this, you also +* need to set wiphy->rfkill_poll to %true before registration, +* and need to call wiphy_rfkill_set_hw_state() in the callback. */ struct ieee80211_ops {int (*tx)(struct ieee80211_hw *hw,struct sk_buff *skb);
@@ -1467,6 +1479,8 @@ struct ieee80211_ops {int (*ampdu_action)(struct ieee80211_hw *hw,enum ieee80211_ampdu_mlme_action action,struct ieee80211_sta *sta,u16 tid,u16 *ssn); + +void (*rfkill_poll)(struct ieee80211_hw *hw); };/**
net/mac80211/driver-ops.h +7 -0
@@ -181,4 +181,11 @@ static inline int drv_ampdu_action(struc sta, tid, ssn); return -EOPNOTSUPP; } + + +static inline void drv_rfkill_poll (struct ieee80211_local *local) +{ +if (local->ops->rfkill_poll) + local->ops->rfkill_poll (&local->hw); +}#endif /* __MAC80211_DRIVER_OPS */
Johannes Berg
maintainerPATCH 4/4 iwlwifi: port to cfg80211 rfkill
In reply to Johannes BergThis ports the iwlwifi rfkill code to the new API offered by cfg80211 and thus removes a lot of useless stuff. The soft- rfkill is completely removed since that is now handled by setting the interfaces down.
--- drivers/net/wireless/iwlwifi/Kconfig | 4 drivers/net/wireless/iwlwifi/Makefile | 1 drivers/net/wireless/iwlwifi/iwl-3945.h | 1 drivers/net/wireless/iwlwifi/iwl-agn.c | 40 ++------ drivers/net/wireless/iwlwifi/iwl-core.c | 138 ---------------------------- drivers/net/wireless/iwlwifi/iwl-core.h | 16 --- drivers/net/wireless/iwlwifi/iwl-debugfs.c | 2 drivers/net/wireless/iwlwifi/iwl-dev.h | 5 - drivers/net/wireless/iwlwifi/iwl-rfkill.c | 131 -------------------------- drivers/net/wireless/iwlwifi/iwl-rfkill.h | 48 --------- drivers/net/wireless/iwlwifi/iwl3945-base.c | 41 +------- 11 files changed, 18 insertions(+), 409 deletions(-)
drivers/net/wireless/iwlwifi/Kconfig +0 -4
@@ -10,10 +10,6 @@ config IWLWIFI_LEDS bool "Enable LED support in iwlagn and iwl3945 drivers" depends on IWLWIFI -config IWLWIFI_RFKILL - def_bool y - depends on IWLWIFI && RFKILL - config IWLWIFI_SPECTRUM_MEASUREMENT bool "Enable Spectrum Measurement in iwlagn driver" depends on IWLWIFI
drivers/net/wireless/iwlwifi/iwl-3945.h +0 -1
@@ -154,7 +154,6 @@ struct iwl3945_frame {#define STATUS_HCMD_SYNC_ACTIVE 1/* sync host command in progress */ #define STATUS_INT_ENABLED 2#define STATUS_RF_KILL_HW 3 -#define STATUS_RF_KILL_SW 4#define STATUS_INIT 5#define STATUS_ALIVE 6#define STATUS_READY 7
drivers/net/wireless/iwlwifi/iwl-agn.c +11 -29
@@ -755,19 +755,13 @@ static void iwl_rx_card_state_notif(struclear_bit (STATUS_RF_KILL_HW , &priv->status); -if (flags &SW_CARD_DISABLED ) -set_bit (STATUS_RF_KILL_SW , &priv->status); -else -clear_bit (STATUS_RF_KILL_SW , &priv->status); -if (!(flags &RXON_CARD_DISABLED ))iwl_scan_cancel (priv);if ((test_bit (STATUS_RF_KILL_HW , &status) != -test_bit (STATUS_RF_KILL_HW , &priv->status)) || - (test_bit (STATUS_RF_KILL_SW , &status) != -test_bit (STATUS_RF_KILL_SW , &priv->status))) -queue_work (priv->workqueue, &priv->rf_kill); +test_bit (STATUS_RF_KILL_HW , &priv->status))) +wiphy_rfkill_set_hw_state (priv->hw->wiphy, +test_bit (STATUS_RF_KILL_HW , &priv->status));else wake_up_interruptible (&priv->wait_command_queue); }
@@ -1065,7 +1059,7 @@ static void iwl_irq_tasklet(struct iwl_pset_bit (STATUS_RF_KILL_HW , &priv->status); else clear_bit(STATUS_RF_KILL_HW, &priv->status); -queue_work (priv->workqueue, &priv->rf_kill); +wiphy_rfkill_set_hw_state (priv->hw->wiphy, hw_rf_kill); } handled |=CSR_INT_BIT_RF_KILL ;
@@ -1553,12 +1547,10 @@ static void __iwl_down(struct iwl_priv *ieee80211_stop_queues (priv->hw);/* If we have not previously called iwl_init() then -* clear all bits but the RF Kill bits and return */ +* clear all bits but the RF Kill bit and return */ if (!iwl_is_init (priv)) { priv->status =test_bit (STATUS_RF_KILL_HW , &priv->status) <<STATUS_RF_KILL_HW | -test_bit (STATUS_RF_KILL_SW , &priv->status) << -STATUS_RF_KILL_SW |test_bit (STATUS_GEO_CONFIGURED , &priv->status) <<STATUS_GEO_CONFIGURED | test_bit(STATUS_EXIT_PENDING, &priv->status) <<
@@ -1567,11 +1559,9 @@ static void __iwl_down(struct iwl_priv * }/* ...otherwise clear out all the status bits but the RF Kill -* bits and continue taking the NIC down. */ +* bit and continue taking the NIC down. */ priv->status &=test_bit (STATUS_RF_KILL_HW , &priv->status) <<STATUS_RF_KILL_HW | -test_bit (STATUS_RF_KILL_SW , &priv->status) << -STATUS_RF_KILL_SW |test_bit (STATUS_GEO_CONFIGURED , &priv->status) <<STATUS_GEO_CONFIGURED | test_bit(STATUS_FW_ERROR, &priv->status) <<
@@ -1646,9 +1636,10 @@ static int __iwl_up(struct iwl_priv *priset_bit (STATUS_RF_KILL_HW , &priv->status);if (iwl_is_rfkill (priv)) { +wiphy_rfkill_set_hw_state (priv->hw->wiphy, true); +iwl_enable_interrupts (priv); -IWL_WARN (priv,"Radio disabled by %s RF Kill switch\n" , -test_bit (STATUS_RF_KILL_HW , &priv->status) ?"HW" :"SW" ); +IWL_WARN (priv,"Radio disabled by HW RF Kill switch\n" );return 0 ; }
@@ -1778,7 +1769,6 @@ static void iwl_bg_up(struct work_structmutex_lock (&priv->mutex);__iwl_up (priv);mutex_unlock (&priv->mutex); -iwl_rfkill_set_hw_state (priv); }static void iwl_bg_restart (struct work_struct *data)
@@ -1956,8 +1946,6 @@ static int iwl_mac_start(struct ieee8021mutex_unlock (&priv->mutex); -iwl_rfkill_set_hw_state (priv); -if (ret)return ret;
@@ -2507,7 +2495,6 @@ static void iwl_setup_deferred_work(struINIT_WORK (&priv->up, iwl_bg_up);INIT_WORK (&priv->restart, iwl_bg_restart);INIT_WORK (&priv->rx_replenish, iwl_bg_rx_replenish); -INIT_WORK (&priv->rf_kill, iwl_bg_rf_kill);INIT_WORK (&priv->beacon_update, iwl_bg_beacon_update);INIT_WORK (&priv->run_time_calib_work, iwl_bg_run_time_calib_work);INIT_DELAYED_WORK (&priv->init_alive_start, iwl_bg_init_alive_start);
@@ -2761,12 +2748,8 @@ static int iwl_pci_probe(struct pci_develse set_bit (STATUS_RF_KILL_HW , &priv->status); - err =iwl_rfkill_init (priv); -if (err) -IWL_ERR (priv,"Unable to initialize RFKILL system. " -"Ignoring error: %d\n" , err); -else -iwl_rfkill_set_hw_state (priv); +wiphy_rfkill_set_hw_state (priv->hw->wiphy, +test_bit (STATUS_RF_KILL_HW , &priv->status));iwl_power_initialize (priv);return 0 ;
@@ -2829,7 +2812,6 @@ static void __devexit iwl_pci_remove(striwl_synchronize_irq (priv); -iwl_rfkill_unregister (priv);iwl_dealloc_ucode_pci (priv);if (priv->rxq.bd)
drivers/net/wireless/iwlwifi/iwl-core.c +0 -138
156 lines not on this page · raw message
drivers/net/wireless/iwlwifi/iwl-core.h +1 -15
@@ -345,14 +345,6 @@ int iwl_txq_check_empty(struct iwl_priv****************************************************/ int iwl_set_tx_power (struct iwl_priv *priv,s8 tx_power,bool force); -/***************************************************** -* RF -Kill - here and not in iwl-rfkill.h to be available when -* RF-kill subsystem is not compiled. -****************************************************/ -void iwl_bg_rf_kill (struct work_struct *work); -void iwl_radio_kill_sw_disable_radio (struct iwl_priv *priv); -int iwl_radio_kill_sw_enable_radio (struct iwl_priv *priv); -/******************************************************************************* * Rate ******************************************************************************/
@@ -489,7 +481,6 @@ void iwlcore_free_geos(struct iwl_priv *#define STATUS_HCMD_SYNC_ACTIVE 1/* sync host command in progress */ #define STATUS_INT_ENABLED 2#define STATUS_RF_KILL_HW 3 -#define STATUS_RF_KILL_SW 4#define STATUS_INIT 5#define STATUS_ALIVE 6#define STATUS_READY 7
@@ -524,11 +515,6 @@ static inline int iwl_is_init(struct iwlreturn test_bit (STATUS_INIT , &priv->status); } -static inline int iwl_is_rfkill_sw (struct iwl_priv *priv) -{ -return test_bit (STATUS_RF_KILL_SW , &priv->status); -} -static inline int iwl_is_rfkill_hw (struct iwl_priv *priv) {return test_bit (STATUS_RF_KILL_HW , &priv->status);
@@ -536,7 +522,7 @@ static inline int iwl_is_rfkill_hw(strucstatic inline int iwl_is_rfkill (struct iwl_priv *priv) { -return iwl_is_rfkill_hw (priv) ||iwl_is_rfkill_sw (priv); +return iwl_is_rfkill_hw (priv); }static inline int iwl_is_ready_rf (struct iwl_priv *priv)
drivers/net/wireless/iwlwifi/iwl-debugfs.c +0 -2
@@ -442,8 +442,6 @@ static ssize_t iwl_dbgfs_status_read(str test_bit(STATUS_INT_ENABLED, &priv->status)); pos +=scnprintf (buf + pos, bufsz - pos,"STATUS_RF_KILL_HW:\t %d\n" ,test_bit (STATUS_RF_KILL_HW , &priv->status)); - pos +=scnprintf (buf + pos, bufsz - pos,"STATUS_RF_KILL_SW:\t %d\n" , -test_bit (STATUS_RF_KILL_SW , &priv->status)); pos +=scnprintf (buf + pos, bufsz - pos,"STATUS_INIT:\t\t %d\n" ,test_bit (STATUS_INIT , &priv->status)); pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
drivers/net/wireless/iwlwifi/iwl-dev.h +0 -5
@@ -41,7 +41,6 @@#include "iwl-prph.h" #include "iwl-fh.h" #include "iwl-debug.h" -#include "iwl-rfkill.h" #include "iwl-4965-hw.h" #include "iwl-3945-hw.h" #include "iwl-3945-led.h"
@@ -930,9 +929,6 @@ struct iwl_priv {* 4965's initialize alive response contains some calibration data. */ struct iwl_init_alive_resp card_alive_init;struct iwl_alive_resp card_alive; -#if defined(CONFIG_IWLWIFI_RFKILL ) -struct rfkill *rfkill; -#endif #ifdef CONFIG_IWLWIFI_LEDS unsigned long last_blink_time;
@@ -1057,7 +1053,6 @@ struct iwl_priv {struct work_struct calibrated_work;struct work_struct scan_completed;struct work_struct rx_replenish; -struct work_struct rf_kill;struct work_struct abort_scan;struct work_struct update_link_led;struct work_struct auth_work;
drivers/net/wireless/iwlwifi/iwl3945-base.c +6 -35
112 lines not on this page · raw message
drivers/net/wireless/iwlwifi/iwl-rfkill.c deleted +0 -131
131 lines not on this page · raw message
drivers/net/wireless/iwlwifi/iwl-rfkill.h deleted +0 -48
48 lines not on this page · raw message
drivers/net/wireless/iwlwifi/Makefile +0 -1
@@ -4,7 +4,6 @@ iwlcore-objs += iwl-rx.o iwl-tx.o iwl- iwlcore-objs += iwl-scan.o iwlcore-$(CONFIG_IWLWIFI_DEBUGFS) += iwl-debugfs.o iwlcore-$(CONFIG_IWLWIFI_LEDS) += iwl-led.o -iwlcore-$(CONFIG_IWLWIFI_RFKILL) += iwl-rfkill.o iwlcore-$(CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT) += iwl-spectrum.o obj-$(CONFIG_IWLAGN) += iwlagn.o
Johannes Berg
maintainerPATCH v2 4/4 iwlwifi: port to cfg80211 rfkill
This ports the iwlwifi rfkill code to the new API offered by cfg80211 and thus removes a lot of useless stuff. The soft- rfkill is completely removed since that is now handled by setting the interfaces down.
--- drivers/net/wireless/iwlwifi/Kconfig | 4 drivers/net/wireless/iwlwifi/Makefile | 1 drivers/net/wireless/iwlwifi/iwl-3945.h | 1 drivers/net/wireless/iwlwifi/iwl-agn.c | 42 ++------ drivers/net/wireless/iwlwifi/iwl-core.c | 138 ---------------------------- drivers/net/wireless/iwlwifi/iwl-core.h | 16 --- drivers/net/wireless/iwlwifi/iwl-debugfs.c | 2 drivers/net/wireless/iwlwifi/iwl-dev.h | 5 - drivers/net/wireless/iwlwifi/iwl-rfkill.c | 131 -------------------------- drivers/net/wireless/iwlwifi/iwl-rfkill.h | 48 --------- drivers/net/wireless/iwlwifi/iwl3945-base.c | 41 +------- 11 files changed, 19 insertions(+), 410 deletions(-)
drivers/net/wireless/iwlwifi/Kconfig +0 -4
@@ -10,10 +10,6 @@ config IWLWIFI_LEDS bool "Enable LED support in iwlagn and iwl3945 drivers" depends on IWLWIFI -config IWLWIFI_RFKILL - def_bool y - depends on IWLWIFI && RFKILL - config IWLWIFI_SPECTRUM_MEASUREMENT bool "Enable Spectrum Measurement in iwlagn driver" depends on IWLWIFI
drivers/net/wireless/iwlwifi/iwl-3945.h +0 -1
@@ -154,7 +154,6 @@ struct iwl3945_frame {#define STATUS_HCMD_SYNC_ACTIVE 1/* sync host command in progress */ #define STATUS_INT_ENABLED 2#define STATUS_RF_KILL_HW 3 -#define STATUS_RF_KILL_SW 4#define STATUS_INIT 5#define STATUS_ALIVE 6#define STATUS_READY 7
drivers/net/wireless/iwlwifi/iwl-agn.c +12 -30
118 lines not on this page · raw message
drivers/net/wireless/iwlwifi/iwl-core.c +0 -138
156 lines not on this page · raw message
drivers/net/wireless/iwlwifi/iwl-core.h +1 -15
@@ -358,14 +358,6 @@ int iwl_txq_check_empty(struct iwl_priv****************************************************/ int iwl_set_tx_power (struct iwl_priv *priv,s8 tx_power,bool force); -/***************************************************** -* RF -Kill - here and not in iwl-rfkill.h to be available when -* RF-kill subsystem is not compiled. -****************************************************/ -void iwl_bg_rf_kill (struct work_struct *work); -void iwl_radio_kill_sw_disable_radio (struct iwl_priv *priv); -int iwl_radio_kill_sw_enable_radio (struct iwl_priv *priv); -/******************************************************************************* * Rate ******************************************************************************/
@@ -508,7 +500,6 @@ void iwlcore_free_geos(struct iwl_priv *#define STATUS_HCMD_SYNC_ACTIVE 1/* sync host command in progress */ #define STATUS_INT_ENABLED 2#define STATUS_RF_KILL_HW 3 -#define STATUS_RF_KILL_SW 4#define STATUS_INIT 5#define STATUS_ALIVE 6#define STATUS_READY 7
@@ -543,11 +534,6 @@ static inline int iwl_is_init(struct iwlreturn test_bit (STATUS_INIT , &priv->status); } -static inline int iwl_is_rfkill_sw (struct iwl_priv *priv) -{ -return test_bit (STATUS_RF_KILL_SW , &priv->status); -} -static inline int iwl_is_rfkill_hw (struct iwl_priv *priv) {return test_bit (STATUS_RF_KILL_HW , &priv->status);
@@ -555,7 +541,7 @@ static inline int iwl_is_rfkill_hw(strucstatic inline int iwl_is_rfkill (struct iwl_priv *priv) { -return iwl_is_rfkill_hw (priv) ||iwl_is_rfkill_sw (priv); +return iwl_is_rfkill_hw (priv); }static inline int iwl_is_ready_rf (struct iwl_priv *priv)
drivers/net/wireless/iwlwifi/iwl-debugfs.c +0 -2
@@ -449,8 +449,6 @@ static ssize_t iwl_dbgfs_status_read(str test_bit(STATUS_INT_ENABLED, &priv->status)); pos +=scnprintf (buf + pos, bufsz - pos,"STATUS_RF_KILL_HW:\t %d\n" ,test_bit (STATUS_RF_KILL_HW , &priv->status)); - pos +=scnprintf (buf + pos, bufsz - pos,"STATUS_RF_KILL_SW:\t %d\n" , -test_bit (STATUS_RF_KILL_SW , &priv->status)); pos +=scnprintf (buf + pos, bufsz - pos,"STATUS_INIT:\t\t %d\n" ,test_bit (STATUS_INIT , &priv->status)); pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
drivers/net/wireless/iwlwifi/iwl-dev.h +0 -5
@@ -41,7 +41,6 @@#include "iwl-prph.h" #include "iwl-fh.h" #include "iwl-debug.h" -#include "iwl-rfkill.h" #include "iwl-4965-hw.h" #include "iwl-3945-hw.h" #include "iwl-3945-led.h"
@@ -937,9 +936,6 @@ struct iwl_priv {* 4965's initialize alive response contains some calibration data. */ struct iwl_init_alive_resp card_alive_init;struct iwl_alive_resp card_alive; -#if defined(CONFIG_IWLWIFI_RFKILL ) -struct rfkill *rfkill; -#endif #ifdef CONFIG_IWLWIFI_LEDS unsigned long last_blink_time;
@@ -1074,7 +1070,6 @@ struct iwl_priv {struct work_struct calibrated_work;struct work_struct scan_completed;struct work_struct rx_replenish; -struct work_struct rf_kill;struct work_struct abort_scan;struct work_struct update_link_led;struct work_struct auth_work;
drivers/net/wireless/iwlwifi/iwl3945-base.c +6 -35
112 lines not on this page · raw message
drivers/net/wireless/iwlwifi/iwl-rfkill.c deleted +0 -131
131 lines not on this page · raw message
drivers/net/wireless/iwlwifi/iwl-rfkill.h deleted +0 -48
48 lines not on this page · raw message
drivers/net/wireless/iwlwifi/Makefile +0 -1
@@ -4,7 +4,6 @@ iwlcore-objs += iwl-rx.o iwl-tx.o iwl- iwlcore-objs += iwl-scan.o iwlcore-$(CONFIG_IWLWIFI_DEBUGFS) += iwl-debugfs.o iwlcore-$(CONFIG_IWLWIFI_LEDS) += iwl-led.o -iwlcore-$(CONFIG_IWLWIFI_RFKILL) += iwl-rfkill.o iwlcore-$(CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT) += iwl-spectrum.o obj-$(CONFIG_IWLAGN) += iwlagn.o
Johannes Berg
maintainer[RFT 5/4] iwm: port to new cfg80211 rfkill
In reply to Johannes BergWhich means removing all rfkill code since it only does soft-kill which cfg80211 will now handle in exactly the same way the driver did.
--- drivers/net/wireless/iwmc3200wifi/Makefile | 2 drivers/net/wireless/iwmc3200wifi/iwm.h | 4 - drivers/net/wireless/iwmc3200wifi/netdev.c | 10 --- drivers/net/wireless/iwmc3200wifi/rfkill.c | 83 ----------------------------- 4 files changed, 1 insertion(+), 98 deletions(-)
drivers/net/wireless/iwmc3200wifi/Makefile +1 -1
@@ -1,5 +1,5 @@ obj-$(CONFIG_IWM) := iwmc3200wifi.o iwmc3200wifi-objs += main.o netdev.o rx.o tx.o sdio.o hal.o fw.o -iwmc3200wifi-objs += commands.o wext.o cfg80211.o eeprom.o rfkill.o +iwmc3200wifi-objs += commands.o wext.o cfg80211.o eeprom.o iwmc3200wifi-$(CONFIG_IWM_DEBUG) += debugfs.o
drivers/net/wireless/iwmc3200wifi/rfkill.c deleted +0 -83
83 lines not on this page · raw message
drivers/net/wireless/iwmc3200wifi/iwm.h +0 -4
@@ -343,8 +343,4 @@ int iwm_rx_handle_resp(struct iwm_priv * struct iwm_wifi_cmd *cmd);void iwm_rx_free (struct iwm_priv *iwm); -/* RF Kill API */ -int iwm_rfkill_init (struct iwm_priv *iwm); -void iwm_rfkill_exit (struct iwm_priv *iwm); -#endif
drivers/net/wireless/iwmc3200wifi/netdev.c +0 -10
@@ -136,17 +136,8 @@ void *iwm_if_alloc(int sizeof_bus, struc wdev->netdev = ndev; - ret =iwm_rfkill_init (iwm); -if (ret) { -dev_err (dev,"Failed to init rfkill\n" ); - goto out_rfkill; - } -return iwm; - out_rfkill: -unregister_netdev (ndev); - out_ndev:free_netdev (ndev);
@@ -162,7 +153,6 @@ void iwm_if_free(struct iwm_priv *iwm)if (!iwm_to_ndev (iwm))return ; -iwm_rfkill_exit (iwm);unregister_netdev (iwm_to_ndev (iwm));free_netdev (iwm_to_ndev (iwm));iwm_wdev_free (iwm);
Johannes Berg
maintainerPATCH v2 3/4 cfg80211: add rfkill support
In reply to Johannes BergTo be easier on drivers and users, have cfg80211 register an rfkill structure that drivers can access. When soft-killed, simply take down all interfaces; when hard-killed the driver needs to notify us and we will take down the interfaces after the fact. While rfkilled, interfaces cannot be set UP.
--- include/net/cfg80211.h | 21 +++++++++-- include/net/mac80211.h | 20 +++++++++-- net/mac80211/cfg.c | 20 ++++------- net/mac80211/driver-ops.h | 7 +++ net/mac80211/iface.c | 4 +- net/mac80211/util.c | 2 - net/wireless/Kconfig | 3 + net/wireless/core.c | 81 +++++++++++++++++++++++++++++++++++++++++++-- net/wireless/core.h | 7 +++ net/wireless/wext-compat.c | 11 +++--- 10 files changed, 146 insertions(+), 30 deletions(-)
net/wireless/core.c +78 -3
@@ -12,6 +12,7 @@#include <linux/debugfs.h> #include <linux/notifier.h> #include <linux/device.h> +#include <linux/rtnetlink.h> #include <net/genetlink.h> #include <net/cfg80211.h> #include "nl80211.h"
@@ -227,6 +228,41 @@ int cfg80211_dev_rename(struct cfg80211_return 0 ; } +static void cfg80211_rfkill_poll (struct rfkill *rfkill,void *data) +{ +struct cfg80211_registered_device *drv = data; + + drv->ops->rfkill_poll (&drv->wiphy); +} + +static int cfg80211_rfkill_set_block (void *data,bool blocked) +{ +struct cfg80211_registered_device *drv = data; +struct wireless_dev *wdev; + +if (!blocked) +return 0 ; + +rtnl_lock (); +mutex_lock (&drv->devlist_mtx); + +list_for_each_entry (wdev, &drv->netdev_list, list) +dev_close (wdev->netdev); + +mutex_unlock (&drv->devlist_mtx); +rtnl_unlock (); + +return 0 ; +} + +void cfg80211_rfkill_sync_work (struct work_struct *work) +{ +struct cfg80211_registered_device *drv; + + drv = container_of(work, struct cfg80211_registered_device, rfkill_sync); +cfg80211_rfkill_set_block (drv,rfkill_blocked (drv->rfkill)); +} +/* exported functions */ struct wiphy *wiphy_new (const struct cfg80211_ops *ops,int sizeof_priv)
@@ -274,6 +310,18 @@ struct wiphy *wiphy_new(const struct cfg drv->wiphy.dev.class = &ieee80211_class; drv->wiphy.dev.platform_data = drv; + drv->rfkill_ops.set_block = cfg80211_rfkill_set_block; + drv->rfkill =rfkill_alloc (dev_name (&drv->wiphy.dev), + &drv->wiphy.dev,RFKILL_TYPE_WLAN , + &drv->rfkill_ops, drv); + +if (!drv->rfkill) { +kfree (drv); +return NULL ; + } + +INIT_WORK (&drv->rfkill_sync, cfg80211_rfkill_sync_work); +/* * Initialize wiphy parameters to IEEE 802.11 MIB default values. * Fragmentation and RTS threshold are disabled by default with the
@@ -356,6 +404,13 @@ int wiphy_register(struct wiphy *wiphy)if (res) goto out_unlock; +if (wiphy->rfkill_poll && drv->ops->rfkill_poll) + drv->rfkill_ops.poll = cfg80211_rfkill_poll; + + res =rfkill_register (drv->rfkill); +if (res) + goto out_rm_dev; +list_add (&drv->list, &cfg80211_drv_list);/* add to debugfs */
@@ -379,7 +434,11 @@ int wiphy_register(struct wiphy *wiphy)cfg80211_debugfs_drv_add (drv); res =0 ; -out_unlock: + goto out_unlock; + + out_rm_dev: +device_del (&drv->wiphy.dev); + out_unlock:mutex_unlock (&cfg80211_mutex);return res; }
@@ -389,6 +448,8 @@ void wiphy_unregister(struct wiphy *wiph {struct cfg80211_registered_device *drv =wiphy_to_dev (wiphy); +rfkill_unregister (drv->rfkill); +/* protect the device list */ mutex_lock (&cfg80211_mutex);
@@ -425,6 +486,7 @@ EXPORT_SYMBOL(wiphy_unregister);void cfg80211_dev_free (struct cfg80211_registered_device *drv) {struct cfg80211_internal_bss *scan, *tmp; +rfkill_destroy (drv->rfkill);mutex_destroy (&drv->mtx);mutex_destroy (&drv->devlist_mtx);list_for_each_entry_safe (scan, tmp, &drv->bss_list, list)
@@ -438,6 +500,15 @@ void wiphy_free(struct wiphy *wiphy) }EXPORT_SYMBOL (wiphy_free); +void wiphy_rfkill_set_hw_state (struct wiphy *wiphy,bool blocked) +{ +struct cfg80211_registered_device *drv =wiphy_to_dev (wiphy); + +if (rfkill_set_hw_state (drv->rfkill, blocked)) +schedule_work (&drv->rfkill_sync); +} +EXPORT_SYMBOL (wiphy_rfkill_set_hw_state); +static int cfg80211_netdev_notifier_call (struct notifier_block * nb,unsigned long state,void *ndev)
@@ -446,7 +517,7 @@ static int cfg80211_netdev_notifier_callstruct cfg80211_registered_device *rdev;if (!dev->ieee80211_ptr) -return 0 ; +return NOTIFY_DONE ; rdev =wiphy_to_dev (dev->ieee80211_ptr->wiphy);
@@ -492,9 +563,13 @@ static int cfg80211_netdev_notifier_call }mutex_unlock (&rdev->devlist_mtx);break ; +case NETDEV_PRE_UP : +if (rfkill_blocked (rdev->rfkill)) +return notifier_from_errno (-EINVAL ); +break ; } -return 0 ; +return NOTIFY_DONE ; }static struct notifier_block cfg80211_netdev_notifier = {
net/wireless/core.h +7 -0
@@ -11,6 +11,8 @@#include <linux/kref.h> #include <linux/rbtree.h> #include <linux/debugfs.h> +#include <linux/rfkill.h> +#include <linux/workqueue.h> #include <net/genetlink.h> #include <net/cfg80211.h> #include "reg.h"
@@ -24,6 +26,11 @@ struct cfg80211_registered_device {* any call is in progress */ struct mutex mtx; +/* rfkill support */ +struct rfkill_ops rfkill_ops; +struct rfkill *rfkill; +struct work_struct rfkill_sync; +/* ISO / IEC 3166 alpha2 for which this device is receiving * country IEs on, this can help disregard country IEs from APs * on the same alpha2 quickly. The alpha2 may differ from
include/net/cfg80211.h +17 -4
@@ -757,13 +757,11 @@ enum wiphy_params_flags {* @TX_POWER_AUTOMATIC: the dbm parameter is ignored * @TX_POWER_LIMITED: limit TX power by the dbm parameter * @TX_POWER_FIXED: fix TX power to the dbm parameter -* @TX_POWER_OFF: turn off completely (will go away) */ enum tx_power_setting {TX_POWER_AUTOMATIC ,TX_POWER_LIMITED ,TX_POWER_FIXED , -TX_POWER_OFF , };/**
@@ -855,8 +853,10 @@ enum tx_power_setting {* * @set_tx_power: set the transmit power according to the parameters * @get_tx_power: store the current TX power into the dbm variable; -* return 0 if successful; or -ENETDOWN if successful but power -* is disabled (this will go away) +* return 0 if successful +* +* @rfkill_poll: polls the hw rfkill line, use cfg80211 reporting +* functions to adjust rfkill hw state */ struct cfg80211_ops {int (*suspend)(struct wiphy *wiphy);
@@ -952,6 +952,8 @@ struct cfg80211_ops {int (*set_tx_power)(struct wiphy *wiphy,enum tx_power_setting type,int dbm);int (*get_tx_power)(struct wiphy *wiphy,int *dbm); + +void (*rfkill_poll)(struct wiphy *wiphy); };/*
@@ -990,6 +992,8 @@ struct cfg80211_ops {* @frag_threshold: Fragmentation threshold (dot11FragmentationThreshold); * -1 = fragmentation disabled, only odd values >= 256 used * @rts_threshold: RTS threshold (dot11RTSThreshold); -1 = RTS/CTS disabled +* +* @rfkill_poll: poll rfkill via rfkill_poll method, if present */ struct wiphy {/* assign these fields before you register the wiphy */
@@ -1003,6 +1007,8 @@ struct wiphy {bool custom_regulatory;bool strict_regulatory; +bool rfkill_poll; +enum cfg80211_signal_type signal_type;int bss_priv_size;
@@ -1666,4 +1672,11 @@ void cfg80211_michael_mic_failure(struct*/ void cfg80211_ibss_joined (struct net_device *dev,const u8 *bssid,gfp_t gfp); +/** +* wiphy_rfkill_set_hw_state - notify cfg80211 about hw block state +* @wiphy: the wiphy +* @blocked: block status +*/ +void wiphy_rfkill_set_hw_state (struct wiphy *wiphy,bool blocked); +#endif /* __NET_CFG80211_H */
net/wireless/Kconfig +2 -1
@@ -1,5 +1,6 @@ config CFG80211 - tristate "Improved wireless configuration API" + tristate "Improved wireless configuration API" + depends on RFKILL || !RFKILL config CFG80211_REG_DEBUG bool "cfg80211 regulatory debugging"
net/wireless/wext-compat.c +7 -4
@@ -764,6 +764,8 @@ int cfg80211_wext_siwtxpower(struct net_/* only change when not disabling */ if (!data->txpower.disabled) { +rfkill_set_sw_state (rdev->rfkill, false); +if (data->txpower.fixed) {/* * wext doesn't support negative values, see
@@ -787,7 +789,9 @@ int cfg80211_wext_siwtxpower(struct net_ } } }else { - type =TX_POWER_OFF ; +rfkill_set_sw_state (rdev->rfkill, true); +schedule_work (&rdev->rfkill_sync); +return 0 ; }return rdev->ops->set_tx_power (wdev->wiphy, type, dbm);;
@@ -811,13 +815,12 @@ int cfg80211_wext_giwtxpower(struct net_return -EOPNOTSUPP ; err = rdev->ops->get_tx_power (wdev->wiphy, &val); -/* HACK!!! */ -if (err && err != -ENETDOWN ) +if (err)return err;/* well... oh well */ data->txpower.fixed =1 ; - data->txpower.disabled = err == -ENETDOWN ; + data->txpower.disabled =rfkill_blocked (rdev->rfkill); data->txpower.value = val; data->txpower.flags =IW_TXPOW_DBM ;
net/mac80211/cfg.c +8 -12
@@ -1339,7 +1339,6 @@ static int ieee80211_set_tx_power(structstruct ieee80211_local *local =wiphy_priv (wiphy);struct ieee80211_channel *chan = local->hw.conf.channel;u32 changes =0 ; -bool radio_enabled = true;switch (type) {case TX_POWER_AUTOMATIC :
@@ -1358,14 +1357,6 @@ static int ieee80211_set_tx_power(structreturn -EINVAL ; local->user_power_level = dbm;break ; -case TX_POWER_OFF : - radio_enabled = false; -break ; - } - -if (radio_enabled != local->hw.conf.radio_enabled) { - changes |=IEEE80211_CONF_CHANGE_RADIO_ENABLED ; - local->hw.conf.radio_enabled = radio_enabled; }ieee80211_hw_config (local, changes);
@@ -1379,12 +1370,16 @@ static int ieee80211_get_tx_power(struct *dbm = local->hw.conf.power_level; -if (!local->hw.conf.radio_enabled) -return -ENETDOWN ; -return 0 ; } +static void ieee80211_rfkill_poll (struct wiphy *wiphy) +{ +struct ieee80211_local *local =wiphy_priv (wiphy); + +drv_rfkill_poll (local); +} +struct cfg80211_ops mac80211_config_ops = { .add_virtual_intf = ieee80211_add_iface, .del_virtual_intf = ieee80211_del_iface,
@@ -1426,4 +1421,5 @@ struct cfg80211_ops mac80211_config_ops .set_wiphy_params = ieee80211_set_wiphy_params, .set_tx_power = ieee80211_set_tx_power, .get_tx_power = ieee80211_get_tx_power, + .rfkill_poll = ieee80211_rfkill_poll, };
net/mac80211/iface.c +2 -2
@@ -170,7 +170,7 @@ static int ieee80211_open(struct net_dev goto err_del_bss;/* we're brought up, everything changes */ hw_reconf_flags = ~0 ; -ieee80211_led_radio (local, local->hw.conf.radio_enabled); +ieee80211_led_radio (local, true); }/*
@@ -560,7 +560,7 @@ static int ieee80211_stop(struct net_devdrv_stop (local); -ieee80211_led_radio (local,0 ); +ieee80211_led_radio (local, false);flush_workqueue (local->hw.workqueue);
net/mac80211/util.c +1 -1
@@ -1019,7 +1019,7 @@ int ieee80211_reconfig(struct ieee80211_if (local->open_count) { res =drv_start (local); -ieee80211_led_radio (local, hw->conf.radio_enabled); +ieee80211_led_radio (local, true); }/* add interfaces */
include/net/mac80211.h +17 -3
@@ -529,7 +529,7 @@ enum ieee80211_conf_flags {/** * enum ieee80211_conf_changed - denotes which configuration changed * -* @IEEE80211_CONF_CHANGE_RADIO_ENABLED: the value of radio_enabled changed +* @_IEEE80211_CONF_CHANGE_RADIO_ENABLED: DEPRECATED * @IEEE80211_CONF_CHANGE_LISTEN_INTERVAL: the listen interval changed * @IEEE80211_CONF_CHANGE_RADIOTAP: the radiotap flag changed * @IEEE80211_CONF_CHANGE_PS: the PS flag or dynamic PS timeout changed
@@ -539,7 +539,7 @@ enum ieee80211_conf_flags {* @IEEE80211_CONF_CHANGE_IDLE: Idle flag changed */ enum ieee80211_conf_changed { -IEEE80211_CONF_CHANGE_RADIO_ENABLED =BIT (0 ), + _IEEE80211_CONF_CHANGE_RADIO_ENABLED =BIT (0 ),IEEE80211_CONF_CHANGE_LISTEN_INTERVAL =BIT (2 ),IEEE80211_CONF_CHANGE_RADIOTAP =BIT (3 ),IEEE80211_CONF_CHANGE_PS =BIT (4 ),
@@ -549,6 +549,14 @@ enum ieee80211_conf_changed { IEEE80211_CONF_CHANGE_IDLE = BIT(8), }; +static inline __deprecated enum ieee80211_conf_changed +__IEEE80211_CONF_CHANGE_RADIO_ENABLED (void ) +{ +return _IEEE80211_CONF_CHANGE_RADIO_ENABLED; +} +#define IEEE80211_CONF_CHANGE_RADIO_ENABLED \ + __IEEE80211_CONF_CHANGE_RADIO_ENABLED() +/** * struct ieee80211_conf - configuration of the device *
@@ -588,7 +596,7 @@ struct ieee80211_conf {int max_sleep_period;u16 listen_interval; -bool radio_enabled; +bool __deprecated radio_enabled;u8 long_frame_max_tx_count, short_frame_max_tx_count;
@@ -1399,6 +1407,10 @@ enum ieee80211_ampdu_mlme_action {* is the first frame we expect to perform the action on. Notice * that TX/RX_STOP can pass NULL for this parameter. * Returns a negative error code on failure. +* +* @rfkill_poll: Poll rfkill hardware state. If you need this, you also +* need to set wiphy->rfkill_poll to %true before registration, +* and need to call wiphy_rfkill_set_hw_state() in the callback. */ struct ieee80211_ops {int (*tx)(struct ieee80211_hw *hw,struct sk_buff *skb);
@@ -1447,6 +1459,8 @@ struct ieee80211_ops {int (*ampdu_action)(struct ieee80211_hw *hw,enum ieee80211_ampdu_mlme_action action,struct ieee80211_sta *sta,u16 tid,u16 *ssn); + +void (*rfkill_poll)(struct ieee80211_hw *hw); };/**
net/mac80211/driver-ops.h +7 -0
@@ -181,4 +181,11 @@ static inline int drv_ampdu_action(struc sta, tid, ssn); return -EOPNOTSUPP; } + + +static inline void drv_rfkill_poll (struct ieee80211_local *local) +{ +if (local->ops->rfkill_poll) + local->ops->rfkill_poll (&local->hw); +}#endif /* __MAC80211_DRIVER_OPS */
Re: [RFT 3/4] cfg80211: add rfkill support
In reply to Johannes BergQuoted 6 lines · Johannes Berg
plain text document attachment (015-cfg80211-rfkill.patch) To be easier on drivers and users, have cfg80211 register an rfkill structure that drivers can access. When soft-killed, simply take down all interfaces; when hard-killed the driver needs to notify us and we will take down the interfaces after the fact. While rfkilled, interfaces cannot be set UP.
Any chance we could get something other than EINVAL returned from the PRE_UP notifier when the device is rfkilled? It's useful to get some indication of *why* the device can't be brought up. For example, if the device requires firmware but that firmware isn't present, the driver will usually return ENOENT because that's what request_firmware() returns when it can't find what it needs. Thus userspace can do something intelligent with the error.
So maybe EL2HLT could be (ab)used here? I guess technically it's an L1 halt since the PHY is powered down, but whatever. The only other stuff that seems to use this are the USB 'gadget' drivers. Either that, or lets make an EL1OFF or ERFKILL maybe.
Dan
Quoted 460 lines
Signed-off-by Johannes Berg <[email protected]>--- include/net/cfg80211.h | 21 +++++++++-- include/net/mac80211.h | 18 ++++++++-- net/mac80211/cfg.c | 20 ++++------- net/mac80211/driver-ops.h | 7 +++ net/mac80211/iface.c | 4 +- net/mac80211/util.c | 2 - net/wireless/Kconfig | 3 + net/wireless/core.c | 81 +++++++++++++++++++++++++++++++++++++++++++-- net/wireless/core.h | 7 +++ net/wireless/wext-compat.c | 11 +++--- 10 files changed, 145 insertions(+), 29 deletions(-)net/wireless/core.c +78
-3@@ -12,6 +12,7 @@#include <linux/debugfs.h> #include <linux/notifier.h> #include <linux/device.h> +#include <linux/rtnetlink.h> #include <net/genetlink.h> #include <net/cfg80211.h> #include "nl80211.h" @@ -227,6 +228,41 @@ int cfg80211_dev_rename(struct cfg80211_return 0 ; } +static void cfg80211_rfkill_poll (struct rfkill *rfkill,void *data) +{ +struct cfg80211_registered_device *drv = data; + + drv->ops->rfkill_poll (&drv->wiphy); +} + +static int cfg80211_rfkill_set_block (void *data,bool blocked) +{ +struct cfg80211_registered_device *drv = data; +struct wireless_dev *wdev; + +if (!blocked) +return 0 ; + +rtnl_lock (); +mutex_lock (&drv->devlist_mtx); + +list_for_each_entry (wdev, &drv->netdev_list, list) +dev_close (wdev->netdev); + +mutex_unlock (&drv->devlist_mtx); +rtnl_unlock (); + +return 0 ; +} + +void cfg80211_rfkill_sync_work (struct work_struct *work) +{ +struct cfg80211_registered_device *drv; + + drv = container_of(work, struct cfg80211_registered_device, rfkill_sync); +cfg80211_rfkill_set_block (drv,rfkill_blocked (drv->rfkill)); +} +/* exported functions */ struct wiphy *wiphy_new (const struct cfg80211_ops *ops,int sizeof_priv)@@ -274,6 +310,18 @@ struct wiphy *wiphy_new(const struct cfg drv->wiphy.dev.class = &ieee80211_class; drv->wiphy.dev.platform_data = drv; + drv->rfkill_ops.set_block = cfg80211_rfkill_set_block; + drv->rfkill =rfkill_alloc (dev_name (&drv->wiphy.dev), + &drv->wiphy.dev,RFKILL_TYPE_WLAN , + &drv->rfkill_ops, drv); + +if (!drv->rfkill) { +kfree (drv); +return NULL ; + } + +INIT_WORK (&drv->rfkill_sync, cfg80211_rfkill_sync_work); +/* * Initialize wiphy parameters to IEEE 802.11 MIB default values. * Fragmentation and RTS threshold are disabled by default with the @@ -356,6 +404,13 @@ int wiphy_register(struct wiphy *wiphy)if (res) goto out_unlock; +if (wiphy->rfkill_poll && drv->ops->rfkill_poll) + drv->rfkill_ops.poll = cfg80211_rfkill_poll; + + res =rfkill_register (drv->rfkill); +if (res) + goto out_rm_dev; +list_add (&drv->list, &cfg80211_drv_list);/* add to debugfs */ @@ -379,7 +434,11 @@ int wiphy_register(struct wiphy *wiphy)cfg80211_debugfs_drv_add (drv); res =0 ; -out_unlock: + goto out_unlock; + + out_rm_dev: +device_del (&drv->wiphy.dev); + out_unlock:mutex_unlock (&cfg80211_mutex);return res; }@@ -389,6 +448,8 @@ void wiphy_unregister(struct wiphy *wiph {struct cfg80211_registered_device *drv =wiphy_to_dev (wiphy); +rfkill_unregister (drv->rfkill); +/* protect the device list */ mutex_lock (&cfg80211_mutex);@@ -425,6 +486,7 @@ EXPORT_SYMBOL(wiphy_unregister);void cfg80211_dev_free (struct cfg80211_registered_device *drv) {struct cfg80211_internal_bss *scan, *tmp; +rfkill_destroy (drv->rfkill);mutex_destroy (&drv->mtx);mutex_destroy (&drv->devlist_mtx);list_for_each_entry_safe (scan, tmp, &drv->bss_list, list)@@ -438,6 +500,15 @@ void wiphy_free(struct wiphy *wiphy) }EXPORT_SYMBOL (wiphy_free); +void wiphy_rfkill_set_hw_state (struct wiphy *wiphy,bool blocked) +{ +struct cfg80211_registered_device *drv =wiphy_to_dev (wiphy); + +if (rfkill_set_hw_state (drv->rfkill, blocked)) +schedule_work (&drv->rfkill_sync); +} +EXPORT_SYMBOL (wiphy_rfkill_set_hw_state); +static int cfg80211_netdev_notifier_call (struct notifier_block * nb,unsigned long state,void *ndev)@@ -446,7 +517,7 @@ static int cfg80211_netdev_notifier_callstruct cfg80211_registered_device *rdev;if (!dev->ieee80211_ptr) -return 0 ; +return NOTIFY_DONE ; rdev =wiphy_to_dev (dev->ieee80211_ptr->wiphy);@@ -492,9 +563,13 @@ static int cfg80211_netdev_notifier_call }mutex_unlock (&rdev->devlist_mtx);break ; +case NETDEV_PRE_UP : +if (rfkill_blocked (rdev->rfkill)) +return notifier_from_errno (-EINVAL ); +break ; } -return 0 ; +return NOTIFY_DONE ; }static struct notifier_block cfg80211_netdev_notifier = {net/wireless/core.h +7
-0@@ -11,6 +11,8 @@#include <linux/kref.h> #include <linux/rbtree.h> #include <linux/debugfs.h> +#include <linux/rfkill.h> +#include <linux/workqueue.h> #include <net/genetlink.h> #include <net/cfg80211.h> #include "reg.h" @@ -24,6 +26,11 @@ struct cfg80211_registered_device {* any call is in progress */ struct mutex mtx; +/* rfkill support */ +struct rfkill_ops rfkill_ops; +struct rfkill *rfkill; +struct work_struct rfkill_sync; +/* ISO / IEC 3166 alpha2 for which this device is receiving * country IEs on, this can help disregard country IEs from APs * on the same alpha2 quickly. The alpha2 may differ from include/net/cfg80211.h +17
-4@@ -757,13 +757,11 @@ enum wiphy_params_flags {* @TX_POWER_AUTOMATIC: the dbm parameter is ignored * @TX_POWER_LIMITED: limit TX power by the dbm parameter * @TX_POWER_FIXED: fix TX power to the dbm parameter -* @TX_POWER_OFF: turn off completely (will go away) */ enum tx_power_setting {TX_POWER_AUTOMATIC ,TX_POWER_LIMITED ,TX_POWER_FIXED , -TX_POWER_OFF , };/** @@ -855,8 +853,10 @@ enum tx_power_setting {* * @set_tx_power: set the transmit power according to the parameters * @get_tx_power: store the current TX power into the dbm variable; -* return 0 if successful; or -ENETDOWN if successful but power -* is disabled (this will go away) +* return 0 if successful +* +* @rfkill_poll: polls the hw rfkill line, use cfg80211 reporting +* functions to adjust rfkill hw state */ struct cfg80211_ops {int (*suspend)(struct wiphy *wiphy);@@ -952,6 +952,8 @@ struct cfg80211_ops {int (*set_tx_power)(struct wiphy *wiphy,enum tx_power_setting type,int dbm);int (*get_tx_power)(struct wiphy *wiphy,int *dbm); + +void (*rfkill_poll)(struct wiphy *wiphy); };/* @@ -990,6 +992,8 @@ struct cfg80211_ops {* @frag_threshold: Fragmentation threshold (dot11FragmentationThreshold); * -1 = fragmentation disabled, only odd values >= 256 used * @rts_threshold: RTS threshold (dot11RTSThreshold); -1 = RTS/CTS disabled +* +* @rfkill_poll: poll rfkill via rfkill_poll method, if present */ struct wiphy {/* assign these fields before you register the wiphy */ @@ -1003,6 +1007,8 @@ struct wiphy {bool custom_regulatory;bool strict_regulatory; +bool rfkill_poll; +enum cfg80211_signal_type signal_type;int bss_priv_size;@@ -1619,4 +1625,11 @@ void cfg80211_michael_mic_failure(struct*/ void cfg80211_ibss_joined (struct net_device *dev,const u8 *bssid,gfp_t gfp); +/** +* wiphy_rfkill_set_hw_state - notify cfg80211 about hw block state +* @wiphy: the wiphy +* @blocked: block status +*/ +void wiphy_rfkill_set_hw_state (struct wiphy *wiphy,bool blocked); +#endif /* __NET_CFG80211_H */ net/wireless/Kconfig +2
-1@@ -1,5 +1,6 @@ config CFG80211 - tristate "Improved wireless configuration API" + tristate "Improved wireless configuration API" + depends on RFKILL || !RFKILL config CFG80211_REG_DEBUG bool "cfg80211 regulatory debugging"net/wireless/wext-compat.c +7
-4@@ -764,6 +764,8 @@ int cfg80211_wext_siwtxpower(struct net_/* only change when not disabling */ if (!data->txpower.disabled) { +rfkill_set_sw_state (rdev->rfkill, false); +if (data->txpower.fixed) {/* * wext doesn't support negative values, see @@ -787,7 +789,9 @@ int cfg80211_wext_siwtxpower(struct net_ } } }else { - type =TX_POWER_OFF ; +rfkill_set_sw_state (rdev->rfkill, true); +schedule_work (&rdev->rfkill_sync); +return 0 ; }return rdev->ops->set_tx_power (wdev->wiphy, type, dbm);;@@ -811,13 +815,12 @@ int cfg80211_wext_giwtxpower(struct net_return -EOPNOTSUPP ; err = rdev->ops->get_tx_power (wdev->wiphy, &val); -/* HACK!!! */ -if (err && err != -ENETDOWN ) +if (err)return err;/* well... oh well */ data->txpower.fixed =1 ; - data->txpower.disabled = err == -ENETDOWN ; + data->txpower.disabled =rfkill_blocked (rdev->rfkill); data->txpower.value = val; data->txpower.flags =IW_TXPOW_DBM ;net/mac80211/cfg.c +8
-12@@ -1339,7 +1339,6 @@ static int ieee80211_set_tx_power(structstruct ieee80211_local *local =wiphy_priv (wiphy);struct ieee80211_channel *chan = local->hw.conf.channel;u32 changes =0 ; -bool radio_enabled = true;switch (type) {case TX_POWER_AUTOMATIC :@@ -1358,14 +1357,6 @@ static int ieee80211_set_tx_power(structreturn -EINVAL ; local->user_power_level = dbm;break ; -case TX_POWER_OFF : - radio_enabled = false; -break ; - } - -if (radio_enabled != local->hw.conf.radio_enabled) { - changes |=IEEE80211_CONF_CHANGE_RADIO_ENABLED ; - local->hw.conf.radio_enabled = radio_enabled; }ieee80211_hw_config (local, changes);@@ -1379,12 +1370,16 @@ static int ieee80211_get_tx_power(struct *dbm = local->hw.conf.power_level; -if (!local->hw.conf.radio_enabled) -return -ENETDOWN ; -return 0 ; } +static void ieee80211_rfkill_poll (struct wiphy *wiphy) +{ +struct ieee80211_local *local =wiphy_priv (wiphy); + +drv_rfkill_poll (local); +} +struct cfg80211_ops mac80211_config_ops = { .add_virtual_intf = ieee80211_add_iface, .del_virtual_intf = ieee80211_del_iface,@@ -1426,4 +1421,5 @@ struct cfg80211_ops mac80211_config_ops .set_wiphy_params = ieee80211_set_wiphy_params, .set_tx_power = ieee80211_set_tx_power, .get_tx_power = ieee80211_get_tx_power, + .rfkill_poll = ieee80211_rfkill_poll, };net/mac80211/iface.c +2
-2@@ -170,7 +170,7 @@ static int ieee80211_open(struct net_dev goto err_del_bss;/* we're brought up, everything changes */ hw_reconf_flags = ~0 ; -ieee80211_led_radio (local, local->hw.conf.radio_enabled); +ieee80211_led_radio (local, true); }/* @@ -560,7 +560,7 @@ static int ieee80211_stop(struct net_devdrv_stop (local); -ieee80211_led_radio (local,0 ); +ieee80211_led_radio (local, false);flush_workqueue (local->hw.workqueue);net/mac80211/util.c +1
-1@@ -1092,7 +1092,7 @@ int ieee80211_reconfig(struct ieee80211_if (local->open_count) { res =drv_start (local); -ieee80211_led_radio (local, hw->conf.radio_enabled); +ieee80211_led_radio (local, true); }/* add interfaces */ include/net/mac80211.h +16
-2@@ -529,7 +529,7 @@ enum ieee80211_conf_flags {/** * enum ieee80211_conf_changed - denotes which configuration changed * -* @IEEE80211_CONF_CHANGE_RADIO_ENABLED: the value of radio_enabled changed +* @_IEEE80211_CONF_CHANGE_RADIO_ENABLED: DEPRECATED * @_IEEE80211_CONF_CHANGE_BEACON_INTERVAL: DEPRECATED * @IEEE80211_CONF_CHANGE_LISTEN_INTERVAL: the listen interval changed * @IEEE80211_CONF_CHANGE_RADIOTAP: the radiotap flag changed @@ -540,7 +540,7 @@ enum ieee80211_conf_flags {* @IEEE80211_CONF_CHANGE_IDLE: Idle flag changed */ enum ieee80211_conf_changed { -IEEE80211_CONF_CHANGE_RADIO_ENABLED =BIT (0 ), + _IEEE80211_CONF_CHANGE_RADIO_ENABLED =BIT (0 ), _IEEE80211_CONF_CHANGE_BEACON_INTERVAL =BIT (1 ),IEEE80211_CONF_CHANGE_LISTEN_INTERVAL =BIT (2 ),IEEE80211_CONF_CHANGE_RADIOTAP =BIT (3 ),@@ -559,6 +559,14 @@ __IEEE80211_CONF_CHANGE_BEACON_INTERVAL(#define IEEE80211_CONF_CHANGE_BEACON_INTERVAL \ __IEEE80211_CONF_CHANGE_BEACON_INTERVAL() +static inline __deprecated enum ieee80211_conf_changed +__IEEE80211_CONF_CHANGE_RADIO_ENABLED (void ) +{ +return _IEEE80211_CONF_CHANGE_RADIO_ENABLED; +} +#define IEEE80211_CONF_CHANGE_RADIO_ENABLED \ + __IEEE80211_CONF_CHANGE_RADIO_ENABLED() +/** * struct ieee80211_conf - configuration of the device * @@ -1419,6 +1427,10 @@ enum ieee80211_ampdu_mlme_action {* is the first frame we expect to perform the action on. Notice * that TX/RX_STOP can pass NULL for this parameter. * Returns a negative error code on failure. +* +* @rfkill_poll: Poll rfkill hardware state. If you need this, you also +* need to set wiphy->rfkill_poll to %true before registration, +* and need to call wiphy_rfkill_set_hw_state() in the callback. */ struct ieee80211_ops {int (*tx)(struct ieee80211_hw *hw,struct sk_buff *skb);@@ -1467,6 +1479,8 @@ struct ieee80211_ops {int (*ampdu_action)(struct ieee80211_hw *hw,enum ieee80211_ampdu_mlme_action action,struct ieee80211_sta *sta,u16 tid,u16 *ssn); + +void (*rfkill_poll)(struct ieee80211_hw *hw); };/** net/mac80211/driver-ops.h +7
-0@@ -181,4 +181,11 @@ static inline int drv_ampdu_action(struc sta, tid, ssn); return -EOPNOTSUPP; } + + +static inline void drv_rfkill_poll (struct ieee80211_local *local) +{ +if (local->ops->rfkill_poll) + local->ops->rfkill_poll (&local->hw); +}#endif /* __MAC80211_DRIVER_OPS */
Johannes Berg
maintainerRe: [RFT 3/4] cfg80211: add rfkill support
Quoted 16 lines · Dan Williams
Quoted 6 lines · Johannes Berg
plain text document attachment (015-cfg80211-rfkill.patch) To be easier on drivers and users, have cfg80211 register an rfkill structure that drivers can access. When soft-killed, simply take down all interfaces; when hard-killed the driver needs to notify us and we will take down the interfaces after the fact. While rfkilled, interfaces cannot be set UP.
Any chance we could get something other than EINVAL returned from the
PRE_UPnotifier when the device is rfkilled? It's useful to get some indication of *why* the device can't be brought up. For example, if the device requires firmware but that firmware isn't present, the driver will usually return ENOENT because that's whatrequest_firmware()returns when it can't find what it needs. Thus userspace can do something intelligent with the error.
Quoted 4 lines
So maybe EL2HLT could be (ab)used here? I guess technically it's an L1 halt since the PHY is powered down, but whatever. The only other stuff that seems to use this are the USB 'gadget' drivers. Either that, or lets make an EL1OFF or ERFKILL maybe.
Sure, we can do whatever we want, I just quickly put EINVAL in.
johannes
Re: [RFT 5/4] iwm: port to new cfg80211 rfkill
In reply to Johannes BergQuoted 5 lines · Johannes Berg
Which means removing all rfkill code since it only does soft-kill which cfg80211 will now handle in exactly the same way the driver did.
Signed-off-by Johannes Berg <[email protected]>
Looks good to me. I think we can remove the "select RFKILL" in Kconfig also.
Thanks,
-yi
Quoted 143 lines
--- drivers/net/wireless/iwmc3200wifi/Makefile | 2 drivers/net/wireless/iwmc3200wifi/iwm.h | 4 - drivers/net/wireless/iwmc3200wifi/netdev.c | 10 --- drivers/net/wireless/iwmc3200wifi/rfkill.c | 83 ----------------------------- 4 files changed, 1 insertion(+), 98 deletions(-)drivers/net/wireless/iwmc3200wifi/Makefile +1
-1@@ -1,5 +1,5 @@ obj-$(CONFIG_IWM) := iwmc3200wifi.o iwmc3200wifi-objs += main.o netdev.o rx.o tx.o sdio.o hal.o fw.o -iwmc3200wifi-objs += commands.o wext.o cfg80211.o eeprom.o rfkill.o +iwmc3200wifi-objs += commands.o wext.o cfg80211.o eeprom.o iwmc3200wifi-$(CONFIG_IWM_DEBUG) += debugfs.odrivers/net/wireless/iwmc3200wifi/rfkill.c deleted +0
-83@@ -1,83 +0,0 @@ -/* -* Intel Wireless Multicomm 3200 WiFi driver -* -* Copyright (C) 2009 Intel Corporation <[email protected]> -* Samuel Ortiz <[email protected]> -* Zhu Yi <[email protected]> -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License version -* 2 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-1301, USA. -* -*/ - -#include <linux/rfkill.h> - -#include "iwm.h" - -static int iwm_rfkill_set_block (void *data,bool blocked) -{ -struct iwm_priv *iwm = data; - -if (!blocked) { -if (test_bit (IWM_RADIO_RFKILL_HW , &iwm->radio)) -return -EBUSY ; - -if (test_and_clear_bit (IWM_RADIO_RFKILL_SW , &iwm->radio) && - (iwm_to_ndev (iwm)->flags &IFF_UP )) -return iwm_up (iwm); - }else { -if (!test_and_set_bit (IWM_RADIO_RFKILL_SW , &iwm->radio)) -return iwm_down (iwm); - } - -return 0 ; -} - -static const struct rfkill_ops iwm_rfkill_ops = { - .set_block = iwm_rfkill_set_block, -}; - -int iwm_rfkill_init (struct iwm_priv *iwm) -{ -int ret; - - iwm->rfkill =rfkill_alloc (KBUILD_MODNAME , -iwm_to_dev (iwm), -RFKILL_TYPE_WLAN , - &iwm_rfkill_ops, iwm); -if (!iwm->rfkill) { -IWM_ERR (iwm,"Unable to allocate rfkill device\n" ); -return -ENOMEM ; - } - - ret =rfkill_register (iwm->rfkill); -if (ret) { -IWM_ERR (iwm,"Failed to register rfkill device\n" ); - goto fail; - } - -return 0 ; - fail: -rfkill_destroy (iwm->rfkill); -return ret; -} - -void iwm_rfkill_exit (struct iwm_priv *iwm) -{ -if (iwm->rfkill) { -rfkill_unregister (iwm->rfkill); -rfkill_destroy (iwm->rfkill); - } - iwm->rfkill =NULL ; -}drivers/net/wireless/iwmc3200wifi/iwm.h +0
-4@@ -343,8 +343,4 @@ int iwm_rx_handle_resp(struct iwm_priv * struct iwm_wifi_cmd *cmd);void iwm_rx_free (struct iwm_priv *iwm); -/* RF Kill API */ -int iwm_rfkill_init (struct iwm_priv *iwm); -void iwm_rfkill_exit (struct iwm_priv *iwm); -#endif drivers/net/wireless/iwmc3200wifi/netdev.c +0
-10@@ -136,17 +136,8 @@ void *iwm_if_alloc(int sizeof_bus, struc wdev->netdev = ndev; - ret =iwm_rfkill_init (iwm); -if (ret) { -dev_err (dev,"Failed to init rfkill\n" ); - goto out_rfkill; - } -return iwm; - out_rfkill: -unregister_netdev (ndev); - out_ndev:free_netdev (ndev);@@ -162,7 +153,6 @@ void iwm_if_free(struct iwm_priv *iwm)if (!iwm_to_ndev (iwm))return ; -iwm_rfkill_exit (iwm);unregister_netdev (iwm_to_ndev (iwm));free_netdev (iwm_to_ndev (iwm));iwm_wdev_free (iwm);
Johannes Berg
maintainerRe: [RFT 5/4] iwm: port to new cfg80211 rfkill
Quoted 9 lines · Zhu Yi
Quoted 5 lines · Johannes Berg
Which means removing all rfkill code since it only does soft-kill which cfg80211 will now handle in exactly the same way the driver did.
Signed-off-by Johannes Berg <[email protected]>Looks good to me. I think we can remove the "select RFKILL" in
Kconfigalso.
Indeed, thanks.
johannes
Re: [RFT 3/4] cfg80211: add rfkill support
In reply to Dan WilliamsHi Dan,
Quoted 15 lines
Quoted 6 lines
plain text document attachment (015-cfg80211-rfkill.patch) To be easier on drivers and users, have cfg80211 register an rfkill structure that drivers can access. When soft-killed, simply take down all interfaces; when hard-killed the driver needs to notify us and we will take down the interfaces after the fact. While rfkilled, interfaces cannot be set UP.
Any chance we could get something other than EINVAL returned from the
PRE_UPnotifier when the device is rfkilled? It's useful to get some indication of *why* the device can't be brought up. For example, if the device requires firmware but that firmware isn't present, the driver will usually return ENOENT because that's whatrequest_firmware()returns when it can't find what it needs. Thus userspace can do something intelligent with the error.
Quoted 4 lines
So maybe EL2HLT could be (ab)used here? I guess technically it's an L1 halt since the PHY is powered down, but whatever. The only other stuff that seems to use this are the USB 'gadget' drivers. Either that, or lets make an EL1OFF or ERFKILL maybe.
I think that creating ERFKILL is a really good idea. We should do that.
Regards
Marcel