cfg80211: expose the rfkill device to the low level driver
authorEmmanuel Grumbach <emmanuel.grumbach@intel.com>
Wed, 16 Jun 2021 20:28:26 +0000 (23:28 +0300)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 23 Jun 2021 09:29:13 +0000 (11:29 +0200)
This will allow the low level driver to query the rfkill
state.

Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
Link: https://lore.kernel.org/r/20210616202826.9833-1-emmanuel.grumbach@intel.com
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
include/net/cfg80211.h
net/wireless/core.c
net/wireless/core.h
net/wireless/nl80211.c
net/wireless/wext-compat.c

index 60325b62daae7afd81388be1f8046f1e550c83a6..b3bc58ec9098ff074a9cc6cd75ad9894a5c9d206 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/if_ether.h>
 #include <linux/ieee80211.h>
 #include <linux/net.h>
+#include <linux/rfkill.h>
 #include <net/regulatory.h>
 
 /**
@@ -4943,6 +4944,7 @@ struct wiphy_iftype_akm_suites {
  *     configuration through the %NL80211_TID_CONFIG_ATTR_RETRY_SHORT and
  *     %NL80211_TID_CONFIG_ATTR_RETRY_LONG attributes
  * @sar_capa: SAR control capabilities
+ * @rfkill: a pointer to the rfkill structure
  */
 struct wiphy {
        struct mutex mtx;
@@ -5085,6 +5087,8 @@ struct wiphy {
 
        const struct cfg80211_sar_capa *sar_capa;
 
+       struct rfkill *rfkill;
+
        char priv[] __aligned(NETDEV_ALIGN);
 };
 
@@ -6659,7 +6663,10 @@ void wiphy_rfkill_start_polling(struct wiphy *wiphy);
  * wiphy_rfkill_stop_polling - stop polling rfkill
  * @wiphy: the wiphy
  */
-void wiphy_rfkill_stop_polling(struct wiphy *wiphy);
+static inline void wiphy_rfkill_stop_polling(struct wiphy *wiphy)
+{
+       rfkill_pause_polling(wiphy->rfkill);
+}
 
 /**
  * DOC: Vendor commands
index 47f55130159231d5ddb706d22caee1c8b7a7e2fd..41c15cc7791fb040e1e344d3bc7dffbe7f3be1ee 100644 (file)
@@ -532,11 +532,11 @@ use_default_name:
        wiphy_net_set(&rdev->wiphy, &init_net);
 
        rdev->rfkill_ops.set_block = cfg80211_rfkill_set_block;
-       rdev->rfkill = rfkill_alloc(dev_name(&rdev->wiphy.dev),
-                                  &rdev->wiphy.dev, RFKILL_TYPE_WLAN,
-                                  &rdev->rfkill_ops, rdev);
+       rdev->wiphy.rfkill = rfkill_alloc(dev_name(&rdev->wiphy.dev),
+                                         &rdev->wiphy.dev, RFKILL_TYPE_WLAN,
+                                         &rdev->rfkill_ops, rdev);
 
-       if (!rdev->rfkill) {
+       if (!rdev->wiphy.rfkill) {
                wiphy_free(&rdev->wiphy);
                return NULL;
        }
@@ -985,10 +985,10 @@ int wiphy_register(struct wiphy *wiphy)
        rdev->wiphy.registered = true;
        rtnl_unlock();
 
-       res = rfkill_register(rdev->rfkill);
+       res = rfkill_register(rdev->wiphy.rfkill);
        if (res) {
-               rfkill_destroy(rdev->rfkill);
-               rdev->rfkill = NULL;
+               rfkill_destroy(rdev->wiphy.rfkill);
+               rdev->wiphy.rfkill = NULL;
                wiphy_unregister(&rdev->wiphy);
                return res;
        }
@@ -1004,18 +1004,10 @@ void wiphy_rfkill_start_polling(struct wiphy *wiphy)
        if (!rdev->ops->rfkill_poll)
                return;
        rdev->rfkill_ops.poll = cfg80211_rfkill_poll;
-       rfkill_resume_polling(rdev->rfkill);
+       rfkill_resume_polling(wiphy->rfkill);
 }
 EXPORT_SYMBOL(wiphy_rfkill_start_polling);
 
-void wiphy_rfkill_stop_polling(struct wiphy *wiphy)
-{
-       struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
-
-       rfkill_pause_polling(rdev->rfkill);
-}
-EXPORT_SYMBOL(wiphy_rfkill_stop_polling);
-
 void wiphy_unregister(struct wiphy *wiphy)
 {
        struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
@@ -1027,8 +1019,8 @@ void wiphy_unregister(struct wiphy *wiphy)
                wiphy_unlock(&rdev->wiphy);
                __count == 0; }));
 
-       if (rdev->rfkill)
-               rfkill_unregister(rdev->rfkill);
+       if (rdev->wiphy.rfkill)
+               rfkill_unregister(rdev->wiphy.rfkill);
 
        rtnl_lock();
        wiphy_lock(&rdev->wiphy);
@@ -1080,7 +1072,7 @@ void cfg80211_dev_free(struct cfg80211_registered_device *rdev)
 {
        struct cfg80211_internal_bss *scan, *tmp;
        struct cfg80211_beacon_registration *reg, *treg;
-       rfkill_destroy(rdev->rfkill);
+       rfkill_destroy(rdev->wiphy.rfkill);
        list_for_each_entry_safe(reg, treg, &rdev->beacon_registrations, list) {
                list_del(&reg->list);
                kfree(reg);
@@ -1102,7 +1094,7 @@ void wiphy_rfkill_set_hw_state_reason(struct wiphy *wiphy, bool blocked,
 {
        struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
 
-       if (rfkill_set_hw_state_reason(rdev->rfkill, blocked, reason))
+       if (rfkill_set_hw_state_reason(wiphy->rfkill, blocked, reason))
                schedule_work(&rdev->rfkill_block);
 }
 EXPORT_SYMBOL(wiphy_rfkill_set_hw_state_reason);
@@ -1495,7 +1487,7 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
                                             wdev->use_4addr, 0))
                        return notifier_from_errno(-EOPNOTSUPP);
 
-               if (rfkill_blocked(rdev->rfkill))
+               if (rfkill_blocked(rdev->wiphy.rfkill))
                        return notifier_from_errno(-ERFKILL);
                break;
        default:
index a7d19b4b40ac6339ce122258628f0ada822412cc..b35d0db12f1d5c2abd7911f2d1593f574b187372 100644 (file)
@@ -3,7 +3,7 @@
  * Wireless configuration interface internals.
  *
  * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
- * Copyright (C) 2018-2020 Intel Corporation
+ * Copyright (C) 2018-2021 Intel Corporation
  */
 #ifndef __NET_WIRELESS_CORE_H
 #define __NET_WIRELESS_CORE_H
@@ -27,7 +27,6 @@ struct cfg80211_registered_device {
 
        /* rfkill support */
        struct rfkill_ops rfkill_ops;
-       struct rfkill *rfkill;
        struct work_struct rfkill_block;
 
        /* ISO / IEC 3166 alpha2 for which this device is receiving
index 912977bf3ec80665dbe27ef525a5e52ec6a8408e..c62d61d8aa0292a3e87f0dd07c256565acf1cae7 100644 (file)
@@ -13041,7 +13041,7 @@ static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
        if (wdev_running(wdev))
                return 0;
 
-       if (rfkill_blocked(rdev->rfkill))
+       if (rfkill_blocked(rdev->wiphy.rfkill))
                return -ERFKILL;
 
        err = rdev_start_p2p_device(rdev, wdev);
@@ -13083,7 +13083,7 @@ static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
        if (wdev_running(wdev))
                return -EEXIST;
 
-       if (rfkill_blocked(rdev->rfkill))
+       if (rfkill_blocked(rdev->wiphy.rfkill))
                return -ERFKILL;
 
        if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
index 50a2330de2361c610130b56151a4ffdb01d06cde..a32065d600a1c584c67a711a43798f168f5aaeba 100644 (file)
@@ -902,7 +902,7 @@ static int cfg80211_wext_siwtxpower(struct net_device *dev,
 
        /* only change when not disabling */
        if (!data->txpower.disabled) {
-               rfkill_set_sw_state(rdev->rfkill, false);
+               rfkill_set_sw_state(rdev->wiphy.rfkill, false);
 
                if (data->txpower.fixed) {
                        /*
@@ -927,7 +927,7 @@ static int cfg80211_wext_siwtxpower(struct net_device *dev,
                        }
                }
        } else {
-               if (rfkill_set_sw_state(rdev->rfkill, true))
+               if (rfkill_set_sw_state(rdev->wiphy.rfkill, true))
                        schedule_work(&rdev->rfkill_block);
                return 0;
        }
@@ -963,7 +963,7 @@ static int cfg80211_wext_giwtxpower(struct net_device *dev,
 
        /* well... oh well */
        data->txpower.fixed = 1;
-       data->txpower.disabled = rfkill_blocked(rdev->rfkill);
+       data->txpower.disabled = rfkill_blocked(rdev->wiphy.rfkill);
        data->txpower.value = val;
        data->txpower.flags = IW_TXPOW_DBM;