Commit a110a3b7 authored by Johannes Berg's avatar Johannes Berg

wifi: cfg80211: optionally support monitor on disabled channels

If the hardware supports a disabled channel, it may in
some cases be possible to use monitor mode (without any
transmit) on it when it's otherwise disabled. Add a new
channel flag IEEE80211_CHAN_CAN_MONITOR that makes it
possible for a driver to indicate such a thing.

Make it per channel so drivers could have a choice with
it, perhaps it's only possible on some channels, perhaps
some channels are not supported at all, but still there
and marked disabled.

In _nl80211_parse_chandef() simplify the code and check
only for an unknown channel, _cfg80211_chandef_usable()
will later check for IEEE80211_CHAN_DISABLED anyway.
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
Signed-off-by: default avatarMiri Korenblit <miriam.rachel.korenblit@intel.com>
Link: https://msgid.link/20240206164849.87fad3a21a09.I9116b2fdc2e2c9fd59a9273a64db7fcb41fc0328@changeidSigned-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent 7b5e25b8
...@@ -122,6 +122,9 @@ struct wiphy; ...@@ -122,6 +122,9 @@ struct wiphy;
* not permitted using this channel * not permitted using this channel
* @IEEE80211_CHAN_NO_6GHZ_AFC_CLIENT: Client connection with AFC AP * @IEEE80211_CHAN_NO_6GHZ_AFC_CLIENT: Client connection with AFC AP
* not permitted using this channel * not permitted using this channel
* @IEEE80211_CHAN_CAN_MONITOR: This channel can be used for monitor
* mode even in the presence of other (regulatory) restrictions,
* even if it is otherwise disabled.
*/ */
enum ieee80211_channel_flags { enum ieee80211_channel_flags {
IEEE80211_CHAN_DISABLED = 1<<0, IEEE80211_CHAN_DISABLED = 1<<0,
...@@ -148,6 +151,7 @@ enum ieee80211_channel_flags { ...@@ -148,6 +151,7 @@ enum ieee80211_channel_flags {
IEEE80211_CHAN_DFS_CONCURRENT = 1<<21, IEEE80211_CHAN_DFS_CONCURRENT = 1<<21,
IEEE80211_CHAN_NO_6GHZ_VLP_CLIENT = 1<<22, IEEE80211_CHAN_NO_6GHZ_VLP_CLIENT = 1<<22,
IEEE80211_CHAN_NO_6GHZ_AFC_CLIENT = 1<<23, IEEE80211_CHAN_NO_6GHZ_AFC_CLIENT = 1<<23,
IEEE80211_CHAN_CAN_MONITOR = 1<<24,
}; };
#define IEEE80211_CHAN_NO_HT40 \ #define IEEE80211_CHAN_NO_HT40 \
......
...@@ -4273,6 +4273,9 @@ enum nl80211_wmm_rule { ...@@ -4273,6 +4273,9 @@ enum nl80211_wmm_rule {
* not allowed using this channel * not allowed using this channel
* @NL80211_FREQUENCY_ATTR_NO_6GHZ_AFC_CLIENT: Client connection to AFC AP * @NL80211_FREQUENCY_ATTR_NO_6GHZ_AFC_CLIENT: Client connection to AFC AP
* not allowed using this channel * not allowed using this channel
* @NL80211_FREQUENCY_ATTR_CAN_MONITOR: This channel can be used in monitor
* mode despite other (regulatory) restrictions, even if the channel is
* otherwise completely disabled.
* @NL80211_FREQUENCY_ATTR_MAX: highest frequency attribute number * @NL80211_FREQUENCY_ATTR_MAX: highest frequency attribute number
* currently defined * currently defined
* @__NL80211_FREQUENCY_ATTR_AFTER_LAST: internal use * @__NL80211_FREQUENCY_ATTR_AFTER_LAST: internal use
...@@ -4315,6 +4318,7 @@ enum nl80211_frequency_attr { ...@@ -4315,6 +4318,7 @@ enum nl80211_frequency_attr {
NL80211_FREQUENCY_ATTR_DFS_CONCURRENT, NL80211_FREQUENCY_ATTR_DFS_CONCURRENT,
NL80211_FREQUENCY_ATTR_NO_6GHZ_VLP_CLIENT, NL80211_FREQUENCY_ATTR_NO_6GHZ_VLP_CLIENT,
NL80211_FREQUENCY_ATTR_NO_6GHZ_AFC_CLIENT, NL80211_FREQUENCY_ATTR_NO_6GHZ_AFC_CLIENT,
NL80211_FREQUENCY_ATTR_CAN_MONITOR,
/* keep last */ /* keep last */
__NL80211_FREQUENCY_ATTR_AFTER_LAST, __NL80211_FREQUENCY_ATTR_AFTER_LAST,
......
...@@ -1145,7 +1145,7 @@ EXPORT_SYMBOL(cfg80211_chandef_dfs_cac_time); ...@@ -1145,7 +1145,7 @@ EXPORT_SYMBOL(cfg80211_chandef_dfs_cac_time);
static bool cfg80211_secondary_chans_ok(struct wiphy *wiphy, static bool cfg80211_secondary_chans_ok(struct wiphy *wiphy,
u32 center_freq, u32 bandwidth, u32 center_freq, u32 bandwidth,
u32 prohibited_flags) u32 prohibited_flags, bool monitor)
{ {
struct ieee80211_channel *c; struct ieee80211_channel *c;
u32 freq, start_freq, end_freq; u32 freq, start_freq, end_freq;
...@@ -1155,7 +1155,11 @@ static bool cfg80211_secondary_chans_ok(struct wiphy *wiphy, ...@@ -1155,7 +1155,11 @@ static bool cfg80211_secondary_chans_ok(struct wiphy *wiphy,
for (freq = start_freq; freq <= end_freq; freq += MHZ_TO_KHZ(20)) { for (freq = start_freq; freq <= end_freq; freq += MHZ_TO_KHZ(20)) {
c = ieee80211_get_channel_khz(wiphy, freq); c = ieee80211_get_channel_khz(wiphy, freq);
if (!c || c->flags & prohibited_flags) if (!c)
return false;
if (monitor && c->flags & IEEE80211_CHAN_CAN_MONITOR)
continue;
if (c->flags & prohibited_flags)
return false; return false;
} }
...@@ -1215,9 +1219,9 @@ static bool cfg80211_edmg_usable(struct wiphy *wiphy, u8 edmg_channels, ...@@ -1215,9 +1219,9 @@ static bool cfg80211_edmg_usable(struct wiphy *wiphy, u8 edmg_channels,
return true; return true;
} }
bool cfg80211_chandef_usable(struct wiphy *wiphy, bool _cfg80211_chandef_usable(struct wiphy *wiphy,
const struct cfg80211_chan_def *chandef, const struct cfg80211_chan_def *chandef,
u32 prohibited_flags) u32 prohibited_flags, bool monitor)
{ {
struct ieee80211_sta_ht_cap *ht_cap; struct ieee80211_sta_ht_cap *ht_cap;
struct ieee80211_sta_vht_cap *vht_cap; struct ieee80211_sta_vht_cap *vht_cap;
...@@ -1379,14 +1383,22 @@ bool cfg80211_chandef_usable(struct wiphy *wiphy, ...@@ -1379,14 +1383,22 @@ bool cfg80211_chandef_usable(struct wiphy *wiphy,
if (!cfg80211_secondary_chans_ok(wiphy, if (!cfg80211_secondary_chans_ok(wiphy,
ieee80211_chandef_to_khz(chandef), ieee80211_chandef_to_khz(chandef),
width, prohibited_flags)) width, prohibited_flags, monitor))
return false; return false;
if (!chandef->center_freq2) if (!chandef->center_freq2)
return true; return true;
return cfg80211_secondary_chans_ok(wiphy, return cfg80211_secondary_chans_ok(wiphy,
MHZ_TO_KHZ(chandef->center_freq2), MHZ_TO_KHZ(chandef->center_freq2),
width, prohibited_flags); width, prohibited_flags, monitor);
}
bool cfg80211_chandef_usable(struct wiphy *wiphy,
const struct cfg80211_chan_def *chandef,
u32 prohibited_flags)
{
return _cfg80211_chandef_usable(wiphy, chandef, prohibited_flags,
false);
} }
EXPORT_SYMBOL(cfg80211_chandef_usable); EXPORT_SYMBOL(cfg80211_chandef_usable);
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* Wireless configuration interface internals. * Wireless configuration interface internals.
* *
* Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
* Copyright (C) 2018-2023 Intel Corporation * Copyright (C) 2018-2024 Intel Corporation
*/ */
#ifndef __NET_WIRELESS_CORE_H #ifndef __NET_WIRELESS_CORE_H
#define __NET_WIRELESS_CORE_H #define __NET_WIRELESS_CORE_H
...@@ -492,6 +492,9 @@ bool cfg80211_is_sub_chan(struct cfg80211_chan_def *chandef, ...@@ -492,6 +492,9 @@ bool cfg80211_is_sub_chan(struct cfg80211_chan_def *chandef,
bool cfg80211_wdev_on_sub_chan(struct wireless_dev *wdev, bool cfg80211_wdev_on_sub_chan(struct wireless_dev *wdev,
struct ieee80211_channel *chan, struct ieee80211_channel *chan,
bool primary_only); bool primary_only);
bool _cfg80211_chandef_usable(struct wiphy *wiphy,
const struct cfg80211_chan_def *chandef,
u32 prohibited_flags, bool monitor);
static inline unsigned int elapsed_jiffies_msecs(unsigned long start) static inline unsigned int elapsed_jiffies_msecs(unsigned long start)
{ {
......
...@@ -3218,8 +3218,8 @@ static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) ...@@ -3218,8 +3218,8 @@ static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
wdev->iftype == NL80211_IFTYPE_P2P_GO; wdev->iftype == NL80211_IFTYPE_P2P_GO;
} }
int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, static int _nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
struct genl_info *info, struct genl_info *info, bool monitor,
struct cfg80211_chan_def *chandef) struct cfg80211_chan_def *chandef)
{ {
struct netlink_ext_ack *extack = info->extack; struct netlink_ext_ack *extack = info->extack;
...@@ -3245,10 +3245,9 @@ int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, ...@@ -3245,10 +3245,9 @@ int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
chandef->freq1_offset = control_freq % 1000; chandef->freq1_offset = control_freq % 1000;
chandef->center_freq2 = 0; chandef->center_freq2 = 0;
/* Primary channel not allowed */ if (!chandef->chan) {
if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) {
NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ], NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ],
"Channel is disabled"); "Unknown channel");
return -EINVAL; return -EINVAL;
} }
...@@ -3343,8 +3342,9 @@ int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, ...@@ -3343,8 +3342,9 @@ int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
return -EINVAL; return -EINVAL;
} }
if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, if (!_cfg80211_chandef_usable(&rdev->wiphy, chandef,
IEEE80211_CHAN_DISABLED)) { IEEE80211_CHAN_DISABLED,
monitor)) {
NL_SET_ERR_MSG(extack, "(extension) channel is disabled"); NL_SET_ERR_MSG(extack, "(extension) channel is disabled");
return -EINVAL; return -EINVAL;
} }
...@@ -3359,6 +3359,13 @@ int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, ...@@ -3359,6 +3359,13 @@ int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
return 0; return 0;
} }
int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
struct genl_info *info,
struct cfg80211_chan_def *chandef)
{
return _nl80211_parse_chandef(rdev, info, false, chandef);
}
static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
struct net_device *dev, struct net_device *dev,
struct genl_info *info, struct genl_info *info,
...@@ -3383,7 +3390,9 @@ static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, ...@@ -3383,7 +3390,9 @@ static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
link_id = 0; link_id = 0;
} }
result = nl80211_parse_chandef(rdev, info, &chandef); result = _nl80211_parse_chandef(rdev, info,
iftype == NL80211_IFTYPE_MONITOR,
&chandef);
if (result) if (result)
return result; return result;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment