add a KHz component to wireless channels
Subsystems (8)
cover add a KHz component to wireless channels
Hello,
This patchset prepares for adding 802.11ah (S1G) support.
S1G channels, at least in the US, may be centered on a sub-MHz frequency. The current channel structures and nl80211 APIs expect frequencies in units of MHz. To extend the existing functionality and APIs while reducing churn and breakage, we add a KHz offset where needed. This also has the advantage that the KHz offset can be ignored at will (legacy drivers).
Some cfg80211 and nl80211 internals have been converted to handle units of KHz, which is not unprecedented (net/wireless/reg.c), and the collateral damage is localized.
One thing which is still unclear is backward compatibility in nl80211. If a frequency offset is supplied to an older kernel, it'll just silently fail to do the right thing. Likewise, these patches will accept a frequency offset to eg. NL80211_CMD_JOIN_MESH, but not handle it in mac80211. For this case is it sufficient to return an error?
The hostap hwsim tests are still passing on par with HEAD. Before these become PATCH we'd like to add some tests exercising the new nl80211 attributes, but it seems difficult without pulling in the full S1G patchset. Maybe we'll hack up hwsim + regulatory to use the S1G band for regular wifi tests. Suggestions here are welcome.
Thanks for looking.
Thomas Pedersen (7):
ieee80211: share 802.11 unit conversion helpers
cfg80211: express channels with a KHz component
mac80211: handle channel frequency offset
mac80211: add freq_offset to RX status
cfg80211: report frequency in KHz for management RX
nl80211: add KHz frequency offset for most wifi commands
nl80211: accept scan frequencies in KHz
drivers/net/wireless/ath/ath6kl/wmi.c | 5 +- drivers/net/wireless/ath/wil6210/wmi.c | 3 +- .../broadcom/brcm80211/brcmfmac/p2p.c | 6 +- drivers/net/wireless/marvell/mwifiex/util.c | 3 +- drivers/staging/wilc1000/cfg80211.c | 2 +- include/linux/ieee80211.h | 11 +++ include/net/cfg80211.h | 70 ++++++++++++- include/net/mac80211.h | 10 +- include/net/regulatory.h | 7 -- include/uapi/linux/nl80211.h | 51 +++++++--- net/mac80211/chan.c | 1 + net/mac80211/main.c | 8 +- net/mac80211/mlme.c | 22 +++-- net/mac80211/rx.c | 7 +- net/mac80211/scan.c | 4 +- net/mac80211/trace.h | 41 ++++++-- net/wireless/chan.c | 68 +++++++------ net/wireless/nl80211.c | 97 ++++++++++++++----- net/wireless/reg.c | 40 ++++---- net/wireless/scan.c | 4 +- net/wireless/trace.h | 21 +++- net/wireless/util.c | 72 ++++++++++++-- 22 files changed, 406 insertions(+), 147 deletions(-)
Signature · 1 line
2.20.1
RFC 1/7 ieee80211: share 802.11 unit conversion helpers
MHZ_TO_KHZ, and KHZ_TO_MHZ are useful to drivers and elsewhere so export these in the common ieee80211 header. Move the power helpers also because we might as well.
--- include/linux/ieee80211.h | 11 +++++++++++ include/net/regulatory.h | 7 ------- 2 files changed, 11 insertions(+), 7 deletions(-)
include/linux/ieee80211.h +11 -0
@@ -3323,6 +3323,17 @@ static inline int ieee80211_get_tdls_action(struct sk_buff *skb, u32 hdr_size)#define TU_TO_JIFFIES (x) (usecs_to_jiffies((x) * 1024))#define TU_TO_EXP_TIME (x) (jiffies + TU_TO_JIFFIES(x)) +/* convert frequencies */ +#define MHZ_TO_KHZ (freq) ((freq) * 1000) +#define KHZ_TO_MHZ (freq) ((freq) / 1000) +#define HZ_TO_KHZ (freq) ((freq) / 1000) + +/* convert powers */ +#define DBI_TO_MBI (gain) ((gain) * 100) +#define MBI_TO_DBI (gain) ((gain) / 100) +#define DBM_TO_MBM (gain) ((gain) * 100) +#define MBM_TO_DBM (gain) ((gain) / 100) +/** * ieee80211_action_contains_tpc - checks if the frame contains TPC element * @skb: the skb containing the frame, length will be checked
include/net/regulatory.h +0 -7
@@ -231,13 +231,6 @@ struct ieee80211_regdomain {struct ieee80211_reg_rule reg_rules[]; }; -#define MHZ_TO_KHZ (freq) ((freq) * 1000) -#define KHZ_TO_MHZ (freq) ((freq) / 1000) -#define DBI_TO_MBI (gain) ((gain) * 100) -#define MBI_TO_DBI (gain) ((gain) / 100) -#define DBM_TO_MBM (gain) ((gain) * 100) -#define MBM_TO_DBM (gain) ((gain) / 100) -#define REG_RULE_EXT (start, end, bw, gain, eirp, dfs_cac, reg_flags) \ { \ .freq_range.start_freq_khz = MHZ_TO_KHZ(start), \
Signature · 1 line
2.20.1
RFC 2/7 cfg80211: express channels with a KHz component
In reply to Thomas PedersenSome bands (S1G) define channels centered on a non-integer MHz. Give ieee80211_channel and cfg80211_chan_def a freq_offset component where the final frequency can be expressed as:
MHZ_TO_KHZ(chan->center_freq) + chan->freq_offset;
Also provide some helper functions to do the frequency conversion and test for equality.
Retain the existing interface to frequency and channel conversion helpers, and expose new ones which handle frequencies in units of KHz.
Some internal functions (net/wireless/chan.c) pass around a frequency value. Convert these to units of KHz.
mesh, ibss, wext, etc. are currently ignored.
--- include/net/cfg80211.h | 66 ++++++++++++++++++++++++++++++++++++-- net/wireless/chan.c | 68 +++++++++++++++++++++------------------ net/wireless/reg.c | 40 ++++++++++++----------- net/wireless/scan.c | 4 +-- net/wireless/trace.h | 21 +++++++++--- net/wireless/util.c | 72 ++++++++++++++++++++++++++++++++++++------ 6 files changed, 202 insertions(+), 69 deletions(-)
include/net/cfg80211.h +63 -3
@@ -128,6 +128,7 @@ enum ieee80211_channel_flags {* with cfg80211. * * @center_freq: center frequency in MHz +* @freq_offset: offset from @center_freq, in KHz * @hw_value: hardware-specific value for the channel * @flags: channel flags from &enum ieee80211_channel_flags. * @orig_flags: channel flags at registration time, used by regulatory
@@ -149,6 +150,7 @@ enum ieee80211_channel_flags {struct ieee80211_channel {enum nl80211_band band;u32 center_freq; +u16 freq_offset;u16 hw_value;u32 flags;int max_antenna_gain;
@@ -617,6 +619,7 @@ struct key_params {* If edmg is requested (i.e. the .channels member is non-zero), * chan will define the primary channel and all other * parameters are ignored. +* @freq1_offset: offset from @center_freq1, in KHz */ struct cfg80211_chan_def {struct ieee80211_channel *chan;
@@ -624,6 +627,7 @@ struct cfg80211_chan_def {u32 center_freq1;u32 center_freq2;struct ieee80211_edmg edmg; +u16 freq1_offset; };/**
@@ -713,6 +717,7 @@ cfg80211_chandef_identical(const struct cfg80211_chan_def *chandef1,return (chandef1->chan == chandef2->chan && chandef1->width == chandef2->width && chandef1->center_freq1 == chandef2->center_freq1 && + chandef1->freq1_offset == chandef2->freq1_offset && chandef1->center_freq2 == chandef2->center_freq2); }
@@ -5145,6 +5150,28 @@ static inline void *wdev_priv(struct wireless_dev *wdev)* cfg80211 offers a number of utility functions that can be useful. */ +/** +* ieee80211_channel_equal - compare two struct ieee80211_channel +* +* @a: 1st struct ieee80211_channel +* @b: 2nd struct ieee80211_channel +* Return: true if center frequency of @a == @b +*/ +static inline bool +ieee80211_channel_equal (struct ieee80211_channel *a, +struct ieee80211_channel *b) +{ +return (a->center_freq == b->center_freq && + a->freq_offset == b->freq_offset); +} + +/** +* ieee80211_channel_to_khz - convert ieee80211_channel to frequency in KHz +* @chan: struct ieee80211_channel to convert +* Return: The corresponding frequency (in KHz) +*/ +u32 ieee80211_channel_to_khz (const struct ieee80211_channel *chan); +/** * ieee80211_channel_to_frequency - convert channel number to frequency * @chan: channel number
@@ -5153,23 +5180,47 @@ static inline void *wdev_priv(struct wireless_dev *wdev)*/ int ieee80211_channel_to_frequency (int chan,enum nl80211_band band); +/** +* ieee80211_channel_to_freq_khz - convert channel number to frequency +* @chan: channel number +* @band: band, necessary due to channel number overlap +* Return: The corresponding frequency (in KHz), or 0 if the conversion failed. +*/ +u32 ieee80211_channel_to_freq_khz (int chan,enum nl80211_band band); +/** * ieee80211_frequency_to_channel - convert frequency to channel number -* @freq: center frequency +* @freq: center frequency in MHz * Return: The corresponding channel, or 0 if the conversion failed. */ int ieee80211_frequency_to_channel (int freq); +/** +* ieee80211_freq_khz_to_channel - convert frequency to channel number +* @freq: center frequency in KHz +* Return: The corresponding channel, or 0 if the conversion failed. +*/ +int ieee80211_freq_khz_to_channel (u32 freq); +/** * ieee80211_get_channel - get channel struct from wiphy for specified frequency * * @wiphy: the struct wiphy to get the channel for -* @freq: the center frequency of the channel -* +* @freq: the center frequency (in MHz) of the channel * Return: The channel struct from @wiphy at @freq. */ struct ieee80211_channel *ieee80211_get_channel (struct wiphy *wiphy,int freq); +/** +* ieee80211_get_channel_khz - get channel struct from wiphy for specified +* frequency +* @wiphy: the struct wiphy to get the channel for +* @freq: the center frequency (in KHz) of the channel +* Return: The channel struct from @wiphy at @freq. +*/ +struct ieee80211_channel * +ieee80211_get_channel_khz (struct wiphy *wiphy,u32 freq); +/** * ieee80211_get_response_rate - get basic rate for a given rate *
@@ -7192,6 +7243,15 @@ bool ieee80211_operating_class_to_band(u8 operating_class,bool ieee80211_chandef_to_operating_class (struct cfg80211_chan_def *chandef,u8 *op_class); +/** +* ieee80211_chandef_to_khz - convert chandef to frequency in KHz +* +* @chandef: the chandef to convert +* +* Returns the center frequency of chandef (1st segment) in KHz. +*/ +u32 ieee80211_chandef_to_khz (const struct cfg80211_chan_def *chandef); +/* * cfg80211_tdls_oper_request - request userspace to perform TDLS operation * @dev: the device on which the operation is requested
net/wireless/chan.c +38 -30
185 lines not on this page · raw message
net/wireless/reg.c +21 -19
@@ -1658,22 +1658,23 @@ static uint32_t reg_rule_to_chan_bw_flags(const struct ieee80211_regdomain *regd const struct ieee80211_channel *chan) {const struct ieee80211_freq_range *freq_range =NULL ; -u32 max_bandwidth_khz, bw_flags =0 ; +u32 max_bandwidth_khz, center_freq_khz, bw_flags =0 ; freq_range = ®_rule->freq_range; max_bandwidth_khz = freq_range->max_bandwidth_khz; + center_freq_khz =ieee80211_channel_to_khz (chan);/* Check if auto calculation requested */ if (reg_rule->flags &NL80211_RRF_AUTO_BW ) max_bandwidth_khz =reg_get_max_bandwidth (regd, reg_rule);/* If we get a reg_rule we can assume that at least 5Mhz fit */ if (!cfg80211_does_bw_fit_range (freq_range, -MHZ_TO_KHZ (chan->center_freq), + center_freq_khz,MHZ_TO_KHZ (10 ))) bw_flags |=IEEE80211_CHAN_NO_10MHZ ;if (!cfg80211_does_bw_fit_range (freq_range, -MHZ_TO_KHZ (chan->center_freq), + center_freq_khz,MHZ_TO_KHZ (20 ))) bw_flags |=IEEE80211_CHAN_NO_20MHZ ;
@@ -1710,7 +1711,7 @@ static void handle_channel(struct wiphy *wiphy, flags = chan->orig_flags; - reg_rule =freq_reg_info (wiphy,MHZ_TO_KHZ (chan->center_freq)); + reg_rule =freq_reg_info (wiphy,ieee80211_channel_to_khz (chan));if (IS_ERR (reg_rule)) {/* * We will disable all channels that do not match our
@@ -1729,13 +1730,13 @@ static void handle_channel(struct wiphy *wiphy,if (lr->initiator ==NL80211_REGDOM_SET_BY_DRIVER && request_wiphy && request_wiphy == wiphy && request_wiphy->regulatory_flags ®ULATORY_STRICT_REG ) { -pr_debug ("Disabling freq %d MHz for good\n" , - chan->center_freq); +pr_debug ("Disabling freq %d.%03d MHz for good\n" , + chan->center_freq, chan->freq_offset); chan->orig_flags |=IEEE80211_CHAN_DISABLED ; chan->flags = chan->orig_flags; }else { -pr_debug ("Disabling freq %d MHz\n" , - chan->center_freq); +pr_debug ("Disabling freq %d.%03d MHz\n" , + chan->center_freq, chan->freq_offset); chan->flags |=IEEE80211_CHAN_DISABLED ; }return ;
@@ -1936,7 +1937,7 @@ static void handle_reg_beacon(struct wiphy *wiphy, unsigned int chan_idx, sband = wiphy->bands[reg_beacon->chan.band]; chan = &sband->channels[chan_idx]; -if (likely (chan->center_freq != reg_beacon->chan.center_freq)) +if (likely (!ieee80211_channel_equal (chan, ®_beacon->chan)))return ;if (chan->beacon_found)
@@ -2269,18 +2270,18 @@ static void handle_channel_custom(struct wiphy *wiphy,u32 bw_flags =0 ;const struct ieee80211_reg_rule *reg_rule =NULL ;const struct ieee80211_power_rule *power_rule =NULL ; -u32 bw; +u32 bw, center_freq_khz; + center_freq_khz =ieee80211_channel_to_khz (chan);for (bw =MHZ_TO_KHZ (20 ); bw >= min_bw; bw = bw /2 ) { - reg_rule =freq_reg_info_regd (MHZ_TO_KHZ (chan->center_freq), - regd, bw); + reg_rule =freq_reg_info_regd (center_freq_khz, regd, bw);if (!IS_ERR (reg_rule))break ; }if (IS_ERR_OR_NULL (reg_rule)) { -pr_debug ("Disabling freq %d MHz as custom regd has no rule that fits it\n" , - chan->center_freq); +pr_debug ("Disabling freq %d.%03d MHz as custom regd has no rule that fits it\n" , + chan->center_freq, chan->freq_offset);if (wiphy->regulatory_flags ®ULATORY_WIPHY_SELF_MANAGED ) { chan->flags |=IEEE80211_CHAN_DISABLED ; }else {
@@ -3337,8 +3338,8 @@ static bool pending_reg_beacon(struct ieee80211_channel *beacon_chan)struct reg_beacon *pending_beacon;list_for_each_entry (pending_beacon, ®_pending_beacons, list) -if (beacon_chan->center_freq == - pending_beacon->chan.center_freq) +if (ieee80211_channel_equal (beacon_chan, + &pending_beacon->chan))return true;return false; }
@@ -3367,9 +3368,10 @@ int regulatory_hint_found_beacon(struct wiphy *wiphy,if (!reg_beacon)return -ENOMEM ; -pr_debug ("Found new beacon on frequency: %d MHz (Ch %d) on %s\n" , - beacon_chan->center_freq, -ieee80211_frequency_to_channel (beacon_chan->center_freq), +pr_debug ("Found new beacon on frequency: %d.%03d MHz (Ch %d) on %s\n" , + beacon_chan->center_freq, beacon_chan->freq_offset, +ieee80211_freq_khz_to_channel ( +ieee80211_channel_to_khz (beacon_chan)),wiphy_name (wiphy)); memcpy(®_beacon->chan, beacon_chan,
net/wireless/scan.c +2 -2
@@ -1322,8 +1322,8 @@ cfg80211_get_bss_channel(struct wiphy *wiphy, const u8 *ie, size_t ielen,return channel; } - freq =ieee80211_channel_to_frequency (channel_number, channel->band); - alt_channel =ieee80211_get_channel (wiphy, freq); + freq =ieee80211_channel_to_freq_khz (channel_number, channel->band); + alt_channel =ieee80211_get_channel_khz (wiphy, freq);if (!alt_channel) {if (channel->band ==NL80211_BAND_2GHZ ) {/*
net/wireless/trace.h +16 -5
@@ -112,24 +112,29 @@ } while (0)#define CHAN_ENTRY __field(enum nl80211_band, band) \ - __field(u32, center_freq) + __field(u32, center_freq) \ + __field(u16, freq_offset)#define CHAN_ASSIGN (chan) \ do { \ if (chan) { \ __entry->band = chan->band; \ __entry->center_freq = chan->center_freq; \ + __entry->freq_offset = chan->freq_offset; \ } else { \ __entry->band = 0; \ __entry->center_freq = 0; \ + __entry->freq_offset = 0; \ } \ } while (0) -#define CHAN_PR_FMT "band: %d, freq: %u" -#define CHAN_PR_ARG __entry->band, __entry->center_freq +#define CHAN_PR_FMT "band: %d, freq: %u.%03u" +#define CHAN_PR_ARG __entry->band, __entry->center_freq, __entry->freq_offset#define CHAN_DEF_ENTRY __field(enum nl80211_band, band) \ __field(u32, control_freq) \ + __field(u32, freq_offset) \ __field(u32, width) \ __field(u32, center_freq1) \ + __field(u32, freq1_offset) \ __field(u32, center_freq2)#define CHAN_DEF_ASSIGN (chandef) \ do { \
@@ -137,21 +142,27 @@ __entry->band = (chandef)->chan->band; \ __entry->control_freq = \ (chandef)->chan->center_freq; \ + __entry->freq_offset = \ + (chandef)->chan->freq_offset; \ __entry->width = (chandef)->width; \ __entry->center_freq1 = (chandef)->center_freq1;\ + __entry->freq1_offset = (chandef)->freq1_offset;\ __entry->center_freq2 = (chandef)->center_freq2;\ }else { \ __entry->band =0 ; \ __entry->control_freq =0 ; \ + __entry->freq_offset =0 ; \ __entry->width =0 ; \ __entry->center_freq1 =0 ; \ + __entry->freq1_offset =0 ; \ __entry->center_freq2 =0 ; \ } \ } while (0)#define CHAN_DEF_PR_FMT \ - "band: %d, control freq: %u, width: %d, cf1: %u, cf2: %u" + "band: %d, control freq: %u.%03u, width: %d, cf1: %u.%03u, cf2: %u"#define CHAN_DEF_PR_ARG __entry->band, __entry->control_freq, \ - __entry->width, __entry->center_freq1, \ + __entry->freq_offset, __entry->width, \ + __entry->center_freq1, __entry->freq1_offset, \ __entry->center_freq2#define SINFO_ENTRY __field(int, generation) \
net/wireless/util.c +62 -10
129 lines not on this page · raw message
Signature · 1 line
2.20.1
Johannes Berg
maintainerRe: [RFC 2/7] cfg80211: express channels with a KHz component
Quoted 4 lines · Thomas Pedersen
+/**
+ *ieee80211_get_channel_khz- get channel struct from wiphy for specified
+ * frequency
You can't line-break there, but I think I learned a while back that you can do
/**
* ieee80211_get_channel_khz -
* get channel ...
or something like that. Maybe try?
include/net/cfg80211.h bool ieee80211_operating_class_to_band(u8 operating_class, · line 7253
Quoted 8 lines
include/net/cfg80211.h +8
-0+/** +* ieee80211_chandef_to_khz - convert chandef to frequency in KHz +* +* @chandef: the chandef to convert +* +* Returns the center frequency of chandef (1st segment) in KHz. +*/ +u32 ieee80211_chandef_to_khz (const struct cfg80211_chan_def *chandef);
Isn't this one trivial, and probably better inlined (mhz*1000 + khz)?
Quoted 8 lines
net/wireless/util.c +8
-0+u32 ieee80211_channel_to_freq_khz (int chan,enum nl80211_band band) +{ +return __ieee80211_channel_to_frequency (chan, band); +} +EXPORT_SYMBOL (ieee80211_channel_to_freq_khz); + +int ieee80211_channel_to_frequency (int chan,enum nl80211_band band) +{
net/wireless/util.c int ieee80211_channel_to_frequency(int chan, enum nl80211_band band) · line 125
Quoted 10 lines
net/wireless/util.c +7
-1+return KHZ_TO_MHZ (__ieee80211_channel_to_frequency (chan, band)); +}EXPORT_SYMBOL (ieee80211_channel_to_frequency); -int ieee80211_frequency_to_channel (int freq) +u32 ieee80211_channel_to_khz (const struct ieee80211_channel *chan) +{ +return MHZ_TO_KHZ (chan->center_freq) + chan->freq_offset; +} +EXPORT_SYMBOL (ieee80211_channel_to_khz);
Some of these should probably be inlines? Or maybe all of them, and
Quoted 1 line
+static int
__ieee80211_frequency_to_channel(u32 freq)
export the double-underscore helpers like this one instead? That'd still be less code overall, IMHO.
net/wireless/util.c int ieee80211_frequency_to_channel(int freq) · line 160
Quoted 11 lines
net/wireless/util.c +10
-0+int ieee80211_freq_khz_to_channel (u32 freq) +{ +return __ieee80211_frequency_to_channel (freq); +} +EXPORT_SYMBOL (ieee80211_freq_khz_to_channel); + +int ieee80211_frequency_to_channel (int freq) +{ +return __ieee80211_frequency_to_channel (MHZ_TO_KHZ (freq)); +}EXPORT_SYMBOL (ieee80211_frequency_to_channel);
similarly here, I guess.
net/wireless/util.c struct ieee80211_channel *ieee80211_get_channel(struct wiphy *wiphy, int freq) · line 197
Quoted 13 lines
net/wireless/util.c +12
-0+struct ieee80211_channel *ieee80211_get_channel_khz (struct wiphy *wiphy, +u32 freq) +{ +return __ieee80211_get_channel (wiphy, freq); +} +EXPORT_SYMBOL (ieee80211_get_channel_khz); + +struct ieee80211_channel *ieee80211_get_channel (struct wiphy *wiphy, +int freq) +{ +return __ieee80211_get_channel (wiphy,MHZ_TO_KHZ (freq)); +}EXPORT_SYMBOL (ieee80211_get_channel);
And maybe here? In fact, how is __ieee80211_get_channel() even different from ieee80211_get_channel_khz()?
net/wireless/util.c bool ieee80211_chandef_to_operating_class(struct cfg80211_chan_def *chandef, · line 1723
Quoted 9 lines
net/wireless/util.c +5
-0@@ -1670,6 +1716,12 @@ bool ieee80211_chandef_to_operating_class(struct cfg80211_chan_def *chandef, }EXPORT_SYMBOL (ieee80211_chandef_to_operating_class); +u32 ieee80211_chandef_to_khz (const struct cfg80211_chan_def *chandef) +{ +return MHZ_TO_KHZ (chandef->center_freq1) + chandef->freq1_offset; +} +EXPORT_SYMBOL (ieee80211_chandef_to_khz);
That's like I thought above.
I think that'd have less code overall, don't you think?
johannes
Re: [RFC 2/7] cfg80211: express channels with a KHz component
Quoted 6 lines · Johannes Berg
Quoted 4 lines · Thomas Pedersen
+/**
+ *ieee80211_get_channel_khz- get channel struct from wiphy for specified
+ * frequency
Quoted 8 lines
You can't line-break there, but I think I learned a while back that you can do
/**
*ieee80211_get_channel_khz-
* get channel ...or something like that. Maybe try?
Looks like it renders ok though:
---
.. c:function:: struct ieee80211_channel * ieee80211_get_channel (struct wiphy * wiphy, int freq)
get channel struct from wiphy for specified frequency
**Parameters**
``struct wiphy * wiphy``
the struct wiphy to get the channel for
``int freq``
the center frequency (in MHz) of the channel
---
Documentation/doc-guide/kernel-doc.rst says:
The brief description following the function name may span multiple lines, and ends with an argument description, a blank comment line, or the end of the comment block.
Quoted 10 lines
include/net/cfg80211.h bool ieee80211_operating_class_to_band(u8 operating_class, · line 7253
Quoted 8 lines
include/net/cfg80211.h +8
-0+/** +* ieee80211_chandef_to_khz - convert chandef to frequency in KHz +* +* @chandef: the chandef to convert +* +* Returns the center frequency of chandef (1st segment) in KHz. +*/ +u32 ieee80211_chandef_to_khz (const struct cfg80211_chan_def *chandef);Isn't this one trivial, and probably better inlined (mhz*1000 + khz)?
Do you mean open code the conversion? I would prefer not to. If you meant make it an inline function then yes probably.
Quoted 21 lines
Quoted 8 lines
net/wireless/util.c +8
-0+u32 ieee80211_channel_to_freq_khz (int chan,enum nl80211_band band) +{ +return __ieee80211_channel_to_frequency (chan, band); +} +EXPORT_SYMBOL (ieee80211_channel_to_freq_khz); + +int ieee80211_channel_to_frequency (int chan,enum nl80211_band band) +{net/wireless/util.c int ieee80211_channel_to_frequency(int chan, enum nl80211_band band) · line 125
Quoted 10 lines
net/wireless/util.c +7
-1+return KHZ_TO_MHZ (__ieee80211_channel_to_frequency (chan, band)); +}EXPORT_SYMBOL (ieee80211_channel_to_frequency); -int ieee80211_frequency_to_channel (int freq) +u32 ieee80211_channel_to_khz (const struct ieee80211_channel *chan) +{ +return MHZ_TO_KHZ (chan->center_freq) + chan->freq_offset; +} +EXPORT_SYMBOL (ieee80211_channel_to_khz);Some of these should probably be inlines? Or maybe all of them, and
Quoted 4 lines
Quoted 1 line
+static int
__ieee80211_frequency_to_channel(u32 freq)export the double-underscore helpers like this one instead? That'd still be less code overall, IMHO.
I didn't want to change the interface for ieee80211_frequency_to_channel(). It's a little confusing that one takes MHz, but the __ieee80211_frequency_to_channel() takes KHz? By giving the _khz() hint in the wrapper we were trying to make it explicit. Similar to below.
Quoted 14 lines
net/wireless/util.c int ieee80211_frequency_to_channel(int freq) · line 160
Quoted 11 lines
net/wireless/util.c +10
-0+int ieee80211_freq_khz_to_channel (u32 freq) +{ +return __ieee80211_frequency_to_channel (freq); +} +EXPORT_SYMBOL (ieee80211_freq_khz_to_channel); + +int ieee80211_frequency_to_channel (int freq) +{ +return __ieee80211_frequency_to_channel (MHZ_TO_KHZ (freq)); +}EXPORT_SYMBOL (ieee80211_frequency_to_channel);similarly here, I guess.
Quoted 16 lines
net/wireless/util.c struct ieee80211_channel *ieee80211_get_channel(struct wiphy *wiphy, int freq) · line 197
Quoted 13 lines
net/wireless/util.c +12
-0+struct ieee80211_channel *ieee80211_get_channel_khz (struct wiphy *wiphy, +u32 freq) +{ +return __ieee80211_get_channel (wiphy, freq); +} +EXPORT_SYMBOL (ieee80211_get_channel_khz); + +struct ieee80211_channel *ieee80211_get_channel (struct wiphy *wiphy, +int freq) +{ +return __ieee80211_get_channel (wiphy,MHZ_TO_KHZ (freq)); +}EXPORT_SYMBOL (ieee80211_get_channel);And maybe here? In fact, how is
__ieee80211_get_channel()even different fromieee80211_get_channel_khz()?
It's not. I thought the _khz() hint was helpful for the reader to keep the units straight.
Quoted 12 lines
net/wireless/util.c bool ieee80211_chandef_to_operating_class(struct cfg80211_chan_def *chandef, · line 1723
Quoted 9 lines
net/wireless/util.c +5
-0@@ -1670,6 +1716,12 @@ bool ieee80211_chandef_to_operating_class(struct cfg80211_chan_def *chandef, }EXPORT_SYMBOL (ieee80211_chandef_to_operating_class); +u32 ieee80211_chandef_to_khz (const struct cfg80211_chan_def *chandef) +{ +return MHZ_TO_KHZ (chandef->center_freq1) + chandef->freq1_offset; +} +EXPORT_SYMBOL (ieee80211_chandef_to_khz);That's like I thought above.
Quoted 1 line
I think that'd have less code overall, don't you think?
What do you think about keeping the interfaces in place, but otherwise converting them to inline functions (where it makes sense)?
I'd like to avoid open coding the conversions and otherwise keep the gory internals of the channel structures hidden from the caller.
Signature · 1 line
thomas
Johannes Berg
maintainerRe: [RFC 2/7] cfg80211: express channels with a KHz component
Quoted 15 lines · Thomas Pedersen
---
.. c:function:: structieee80211_channel*ieee80211_get_channel(struct wiphy * wiphy, int freq)get channel struct from wiphy for specified frequency
**Parameters**
``struct wiphy * wiphy``
the struct wiphy to get the channel for``int freq``
the center frequency (in MHz) of the channel
---
Quoted 5 lines
Documentation/doc-guide/kernel-doc.rstsays:The brief description following the function name may span multiple lines, and ends with an argument description, a blank comment line, or the end of the comment block.
Interesting. I guess they must've fixed this at some point - at least I _seem_ to remember getting wrong output with it. Thanks for the correction!
Quoted 11 lines
Quoted 10 lines
include/net/cfg80211.h bool ieee80211_operating_class_to_band(u8 operating_class, · line 7253
Quoted 8 lines
include/net/cfg80211.h +8
-0+/** +* ieee80211_chandef_to_khz - convert chandef to frequency in KHz +* +* @chandef: the chandef to convert +* +* Returns the center frequency of chandef (1st segment) in KHz. +*/ +u32 ieee80211_chandef_to_khz (const struct cfg80211_chan_def *chandef);Isn't this one trivial, and probably better inlined (mhz*1000 + khz)?
Quoted 2 lines
Do you mean open code the conversion? I would prefer not to. If you meant make it an inline function then yes probably.
Right, I meant making it an inline.
Quoted 10 lines
Quoted 4 lines
Quoted 1 line
+static int
__ieee80211_frequency_to_channel(u32 freq)export the double-underscore helpers like this one instead? That'd still be less code overall, IMHO.
I didn't want to change the interface for
ieee80211_frequency_to_channel(). It's a little confusing that one takes MHz, but the__ieee80211_frequency_to_channel()takes KHz? By giving the_khz()hint in the wrapper we were trying to make it explicit. Similar to below.
Right. I think that's fine. I was just wondering if / thinking that it may be better to just export ieee80211_freq_khz_to_channel(), and express the other ones as inline function in terms of that?
Quoted 5 lines
Quoted 2 lines
And maybe here? In fact, how is
__ieee80211_get_channel()even different fromieee80211_get_channel_khz()?It's not. I thought the
_khz()hint was helpful for the reader to keep the units straight.
Agree, but then you don't need the double-underscore version and can just express the old one in terms of the _khz one?
Quoted 2 lines
What do you think about keeping the interfaces in place, but otherwise converting them to inline functions (where it makes sense)?
Yes, I think that's what I had in mind.
Quoted 2 lines
I'd like to avoid open coding the conversions and otherwise keep the gory internals of the channel structures hidden from the caller.
Agree.
johannes
Re: [RFC 2/7] cfg80211: express channels with a KHz component
Quoted 22 lines · Johannes Berg
Quoted 10 lines · Thomas Pedersen
Quoted 4 lines
Quoted 1 line
+static int
__ieee80211_frequency_to_channel(u32 freq)export the double-underscore helpers like this one instead? That'd still be less code overall, IMHO.
I didn't want to change the interface for
ieee80211_frequency_to_channel(). It's a little confusing that one takes MHz, but the__ieee80211_frequency_to_channel()takes KHz? By giving the_khz()hint in the wrapper we were trying to make it explicit. Similar to below.Right. I think that's fine. I was just wondering if / thinking that it may be better to just export
ieee80211_freq_khz_to_channel(), and express the other ones as inline function in terms of that?Quoted 5 lines
Quoted 2 lines
And maybe here? In fact, how is
__ieee80211_get_channel()even different fromieee80211_get_channel_khz()?It's not. I thought the
_khz()hint was helpful for the reader to keep the units straight.
Quoted 7 lines
Agree, but then you don't need the double-underscore version and can just express the old one in terms of the
_khzone?Quoted 2 lines
What do you think about keeping the interfaces in place, but otherwise converting them to inline functions (where it makes sense)?
Yes, I think that's what I had in mind.
OK I get it. That is a lot cleaner.
Signature · 1 line
thomas
RFC 3/7 mac80211: handle channel frequency offset
In reply to Thomas Pedersencfg80211_chan_def and ieee80211_channel recently gained a frequency offset component. Handle this where it makes sense (potentially required by S1G channels), ie. ignore for mesh, ibss, HT/VHT specific stuff, TDLS, etc.
--- net/mac80211/chan.c | 1 + net/mac80211/main.c | 8 +++++--- net/mac80211/mlme.c | 16 ++++++++++++---- net/mac80211/scan.c | 1 + net/mac80211/trace.h | 41 +++++++++++++++++++++++++++++++++-------- 5 files changed, 52 insertions(+), 15 deletions(-)
net/mac80211/chan.c +1 -0
@@ -533,6 +533,7 @@ static void ieee80211_del_chanctx(struct ieee80211_local *local,struct cfg80211_chan_def *chandef = &local->_oper_chandef; chandef->width =NL80211_CHAN_WIDTH_20_NOHT ; chandef->center_freq1 = chandef->chan->center_freq; + chandef->freq1_offset = chandef->chan->freq_offset; chandef->center_freq2 =0 ;/* NOTE: Disabling radar is only valid here for
net/mac80211/main.c +5 -3
@@ -104,13 +104,15 @@ static u32 ieee80211_hw_conf_chan(struct ieee80211_local *local) chandef.chan = local->tmp_channel; chandef.width =NL80211_CHAN_WIDTH_20_NOHT ; chandef.center_freq1 = chandef.chan->center_freq; + chandef.freq1_offset = chandef.chan->freq_offset; }else chandef = local->_oper_chandef;WARN (!cfg80211_chandef_valid (&chandef), -"control:%d MHz width:%d center: %d/%d MHz" , - chandef.chan->center_freq, chandef.width, - chandef.center_freq1, chandef.center_freq2); +"control:%d.%03d MHz width:%d center: %d.%03d/%d MHz" , + chandef.chan->center_freq, chandef.chan->freq_offset, + chandef.width, chandef.center_freq1, chandef.freq1_offset, + chandef.center_freq2);if (!cfg80211_chandef_identical (&chandef, &local->_oper_chandef)) local->hw.conf.flags |=IEEE80211_CONF_OFFCHANNEL ;
net/mac80211/mlme.c +12 -4
@@ -162,6 +162,7 @@ ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata, chandef->chan = channel; chandef->width =NL80211_CHAN_WIDTH_20_NOHT ; chandef->center_freq1 = channel->center_freq; + chandef->freq1_offset = channel->freq_offset;if (!ht_oper || !sta_ht_cap.ht_supported) { ret = IEEE80211_STA_DISABLE_HT |
@@ -396,9 +397,12 @@ static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,return 0 ;sdata_info (sdata, -"AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n" , - ifmgd->bssid, chandef.chan->center_freq, chandef.width, - chandef.center_freq1, chandef.center_freq2); +"AP %pM changed bandwidth, new config is %d.%03d MHz, " +"width %d (%d.%03d/%d MHz)\n" , + ifmgd->bssid, chandef.chan->center_freq, + chandef.chan->freq_offset, chandef.width, + chandef.center_freq1, chandef.freq1_offset, + chandef.center_freq2); if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT |
@@ -1364,10 +1368,14 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,if (!cfg80211_chandef_usable (local->hw.wiphy, &csa_ie.chandef,IEEE80211_CHAN_DISABLED )) {sdata_info (sdata, -"AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n" , +"AP %pM switches to unsupported channel " +"(%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), " +"disconnecting\n" , ifmgd->associated->bssid, csa_ie.chandef.chan->center_freq, + csa_ie.chandef.chan->freq_offset, csa_ie.chandef.width, csa_ie.chandef.center_freq1, + csa_ie.chandef.freq1_offset, csa_ie.chandef.center_freq2);ieee80211_queue_work (&local->hw, &ifmgd->csa_connection_drop_work);
net/mac80211/scan.c +1 -0
@@ -896,6 +896,7 @@ static void ieee80211_scan_state_set_channel(struct ieee80211_local *local, local->scan_chandef.chan = chan; local->scan_chandef.center_freq1 = chan->center_freq; + local->scan_chandef.freq1_offset = chan->freq_offset; local->scan_chandef.center_freq2 =0 ;switch (scan_req->scan_width) {case NL80211_BSS_CHAN_WIDTH_5 :
net/mac80211/trace.h +33 -8
123 lines not on this page · raw message
Signature · 1 line
2.20.1
Johannes Berg
maintainerRe: [RFC 3/7] mac80211: handle channel frequency offset
Quoted 2 lines · Thomas Pedersen
ie. ignore
for mesh, ibss, HT/VHT specific stuff, TDLS, etc.
This makes sense, but I don't see that you prevent using mesh, ibss and perhaps TDLS on s1g channels?
Or do we not expect drivers/devices that support this, as well as S1G channels?
johannes
Re: [RFC 3/7] mac80211: handle channel frequency offset
Quoted 9 lines · Johannes Berg
Quoted 2 lines · Thomas Pedersen
ie. ignore
for mesh, ibss, HT/VHT specific stuff, TDLS, etc.This makes sense, but I don't see that you prevent using mesh, ibss and perhaps TDLS on s1g channels?
Or do we not expect
drivers/devicesthat support this, as well as S1G channels?
Well it's really orthogonal to S1G (maybe a new 2412.5Mhz channel opens up :)). We should probably return an error 'if (chan->freq_offset)' or so for features which have not yet been tested / implemented for frequency offset.
Signature · 1 line
thomas
Johannes Berg
maintainerRe: [RFC 3/7] mac80211: handle channel frequency offset
Quoted 8 lines · Thomas Pedersen
Quoted 7 lines · Johannes Berg
Quoted 2 lines · Thomas Pedersen
ie. ignore
for mesh, ibss, HT/VHT specific stuff, TDLS, etc.This makes sense, but I don't see that you prevent using mesh, ibss and perhaps TDLS on s1g channels?
Quoted 7 lines
Quoted 2 lines
Or do we not expect
drivers/devicesthat support this, as well as S1G channels?Well it's really orthogonal to S1G (maybe a new 2412.5Mhz channel opens up :)). We should probably return an error 'if (
chan->freq_offset)' or so for features which have not yet been tested / implemented for frequency offset.
OK, fair enough.
johannes
RFC 4/7 mac80211: add freq_offset to RX status
In reply to Thomas PedersenRX status needs a KHz component, so add freq_offset. We can make ampdu_reference u16 since it is probably sufficient to be able to distinguish 64k different A-MPDUs.
--- include/net/mac80211.h | 10 +++++++++- net/mac80211/mlme.c | 6 ++++-- net/mac80211/rx.c | 1 + net/mac80211/scan.c | 3 ++- 4 files changed, 16 insertions(+), 4 deletions(-)
include/net/mac80211.h +9 -1
@@ -1333,6 +1333,7 @@ enum mac80211_rx_encoding {* @freq: frequency the radio was tuned to when receiving this frame, in MHz * This field must be set for management frames, but isn't strictly needed * for data (other) frames - for those it only affects radiotap reporting. +* @freq_offset: positive KHz component of @freq. * @signal: signal strength when receiving this frame, either in dBm, in dB or * unspecified depending on the hardware capabilities flags * @IEEE80211_HW_SIGNAL_*
@@ -1361,9 +1362,10 @@ struct ieee80211_rx_status {u64 mactime;u64 boottime_ns;u32 device_timestamp; -u32 ampdu_reference;u32 flag; +u16 ampdu_reference;u16 freq; +u16 freq_offset;u8 enc_flags; u8 encoding:2, bw:3, he_ru:3; u8 he_gi:2, he_dcm:1;
@@ -1379,6 +1381,12 @@ struct ieee80211_rx_status {u8 zero_length_psdu_type; }; +static inline u32 +ieee80211_rx_status_to_khz (struct ieee80211_rx_status *rx_status) +{ +return MHZ_TO_KHZ (rx_status->freq) + rx_status->freq_offset; +} +/** * struct ieee80211_vendor_radiotap - vendor radiotap data information * @present: presence bitmap for this vendor namespace
net/mac80211/mlme.c +4 -2
@@ -3669,7 +3669,8 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,sdata_assert_lock (sdata); - channel =ieee80211_get_channel (local->hw.wiphy, rx_status->freq); + channel =ieee80211_get_channel_khz (local->hw.wiphy, +ieee80211_rx_status_to_khz (rx_status));if (!channel)return ;
@@ -3885,7 +3886,8 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,return ; } -if (rx_status->freq != chanctx_conf->def.chan->center_freq) { +if (rx_status->freq != chanctx_conf->def.chan->center_freq || + rx_status->freq_offset != chanctx_conf->def.chan->freq_offset) {rcu_read_unlock ();return ; }
net/mac80211/rx.c +1 -0
@@ -412,6 +412,7 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local, pos++;/* IEEE80211_RADIOTAP_CHANNEL */ +/* TODO: frequency offset in KHz */ put_unaligned_le16 (status->freq, pos); pos +=2 ;if (status->bw ==RATE_INFO_BW_10 )
net/mac80211/scan.c +2 -1
@@ -275,7 +275,8 @@ void ieee80211_scan_rx(struct ieee80211_local *local, struct sk_buff *skb)return ; } - channel =ieee80211_get_channel (local->hw.wiphy, rx_status->freq); + channel =ieee80211_get_channel_khz (local->hw.wiphy, +ieee80211_rx_status_to_khz (rx_status));if (!channel || channel->flags &IEEE80211_CHAN_DISABLED )return ;
Signature · 1 line
2.20.1
Johannes Berg
maintainerRe: [RFC 4/7] mac80211: add freq_offset to RX status
Quoted 4 lines · Thomas Pedersen
RX status needs a KHz component, so add
freq_offset. We can makeampdu_referenceu16 since it is probably sufficient to be able to distinguish 64k different A-MPDUs.
Is that necessary? Reads like we have 2 bytes free there?
And we only need 13 bits for the frequency (up to 8192 MHz, 60 GHz isn't supported), so we could take out a few fractional ones for the S1G part?
Dunno, I mean, we probably also don't need the A-MPDU reference, even radiotap doesn't make much representation on this, but it sort of implies that it should be unique in a capture file, for which 16 bits wouldn't be enough? (should probably clarify that though and say that you should look only "close by" or something?)
johannes
Re: [RFC 4/7] mac80211: add freq_offset to RX status
Quoted 7 lines · Johannes Berg
Quoted 4 lines · Thomas Pedersen
RX status needs a KHz component, so add
freq_offset. We can makeampdu_referenceu16 since it is probably sufficient to be able to distinguish 64k different A-MPDUs.Is that necessary? Reads like we have 2 bytes free there?
Indeed there is, maybe this wasn't the case on 4.9 where I originally wrote this patch.
Quoted 2 lines
And we only need 13 bits for the frequency (up to 8192 MHz, 60 GHz isn't supported), so we could take out a few fractional ones for the S1G part?
Makes sense, and yeah we really don't need 2 whole bytes to essentially express "+0.5 MHz". Will shorten the frequency and just use a single bit indicating offset or not.
Quoted 5 lines
Dunno, I mean, we probably also don't need the A-MPDU reference, even radiotap doesn't make much representation on this, but it sort of implies that it should be unique in a capture file, for which 16 bits wouldn't be enough? (should probably clarify that though and say that you should look only "close by" or something?)
Yeah. I'll drop this for now, but maybe the space will come in handy in the future.
Signature · 1 line
thomas
RFC 5/7 cfg80211: report frequency in KHz for management RX
In reply to Thomas PedersenExpect and convert drivers to report the RX frequency to cfg80211_rx_mgmt() and cfg80211_report_obss_beacon() in KHz
This doesn't actually change the nl80211 API yet.
--- drivers/net/wireless/ath/ath6kl/wmi.c | 5 +++-- drivers/net/wireless/ath/wil6210/wmi.c | 3 ++- drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c | 6 ++++-- drivers/net/wireless/marvell/mwifiex/util.c | 3 ++- drivers/staging/wilc1000/cfg80211.c | 2 +- include/net/cfg80211.h | 4 ++-- net/mac80211/rx.c | 6 ++++-- net/wireless/nl80211.c | 4 ++-- 8 files changed, 20 insertions(+), 13 deletions(-)
drivers/net/wireless/ath/ath6kl/wmi.c +3 -2
@@ -619,7 +619,8 @@ static int ath6kl_wmi_rx_probe_req_event_rx(struct wmi *wmi, u8 *datap, int len, dlen, freq, vif->probe_req_report);if (vif->probe_req_report || vif->nw_type ==AP_NETWORK ) -cfg80211_rx_mgmt (&vif->wdev, freq,0 , ev->data, dlen,0 ); +cfg80211_rx_mgmt (&vif->wdev,MHZ_TO_KHZ (freq),0 , ev->data, + dlen,0 );return 0 ; }
@@ -658,7 +659,7 @@ static int ath6kl_wmi_rx_action_event_rx(struct wmi *wmi, u8 *datap, int len,return -EINVAL ; }ath6kl_dbg (ATH6KL_DBG_WMI ,"rx_action: len=%u freq=%u\n" , dlen, freq); -cfg80211_rx_mgmt (&vif->wdev, freq,0 , ev->data, dlen,0 ); +cfg80211_rx_mgmt (&vif->wdev,MHZ_TO_KHZ (freq),0 , ev->data, dlen,0 );return 0 ; }
drivers/net/wireless/ath/wil6210/wmi.c +2 -1
@@ -905,7 +905,8 @@ static void wmi_evt_rx_mgmt(struct wil6210_vif *vif, int id, void *d, int len) } }else {mutex_lock (&wil->vif_mutex); -cfg80211_rx_mgmt (vif_to_radio_wdev (wil, vif), freq, signal, +cfg80211_rx_mgmt (vif_to_radio_wdev (wil, vif), +MHZ_TO_KHZ (freq), signal, (void *)rx_mgmt_frame, d_len,0 );mutex_unlock (&wil->vif_mutex); }
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +4 -2
@@ -1423,7 +1423,8 @@ int brcmf_p2p_notify_action_frame_rx(struct brcmf_if *ifp, NL80211_BAND_5GHZ); wdev = &ifp->vif->wdev; -cfg80211_rx_mgmt (wdev, freq,0 , (u8 *)mgmt_frame, mgmt_frame_len,0 ); +cfg80211_rx_mgmt (wdev,MHZ_TO_KHZ (freq),0 , (u8 *)mgmt_frame, + mgmt_frame_len,0 );kfree (mgmt_frame);return 0 ;
@@ -1908,7 +1909,8 @@ s32 brcmf_p2p_notify_rx_mgmt_p2p_probereq(struct brcmf_if *ifp, NL80211_BAND_2GHZ : NL80211_BAND_5GHZ); -cfg80211_rx_mgmt (&vif->wdev, freq,0 , mgmt_frame, mgmt_frame_len,0 ); +cfg80211_rx_mgmt (&vif->wdev,MHZ_TO_KHZ (freq),0 , mgmt_frame, + mgmt_frame_len,0 );brcmf_dbg (INFO ,"mgmt_frame_len (%d) , e->datalen (%d), chanspec (%04x), freq (%d)\n" , mgmt_frame_len, e->datalen, ch.chspec, freq);
drivers/net/wireless/marvell/mwifiex/util.c +2 -1
@@ -425,7 +425,8 @@ mwifiex_process_mgmt_packet(struct mwifiex_private *priv, pkt_len -=ETH_ALEN +sizeof (pkt_len); rx_pd->rx_pkt_length =cpu_to_le16 (pkt_len); -cfg80211_rx_mgmt (&priv->wdev, priv->roc_cfg.chan.center_freq, +cfg80211_rx_mgmt (&priv->wdev, +MHZ_TO_KHZ (priv->roc_cfg.chan.center_freq),CAL_RSSI (rx_pd->snr, rx_pd->nf), skb->data, pkt_len,0 );
drivers/staging/wilc1000/cfg80211.c +1 -1
@@ -1077,7 +1077,7 @@ void wilc_wfi_p2p_rx(struct wilc_vif *vif, u8 *buff, u32 size) } } -cfg80211_rx_mgmt (&priv->wdev, freq,0 , buff, size,0 ); +cfg80211_rx_mgmt (&priv->wdev,MHZ_TO_KHZ (freq),0 , buff, size,0 ); }static void wilc_wfi_mgmt_tx_complete (void *priv,int status)
include/net/cfg80211.h +2 -2
@@ -6937,7 +6937,7 @@ void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,/** * cfg80211_rx_mgmt - notification of received, unprocessed management frame * @wdev: wireless device receiving the frame -* @freq: Frequency on which the frame was received in MHz +* @freq: Frequency on which the frame was received in KHz * @sig_dbm: signal strength in dBm, or 0 if unknown * @buf: Management frame (header + body) * @len: length of the frame data
@@ -7155,7 +7155,7 @@ void cfg80211_probe_status(struct net_device *dev, const u8 *addr,* @wiphy: The wiphy that received the beacon * @frame: the frame * @len: length of the frame -* @freq: frequency the frame was received on +* @freq: frequency the frame was received on in KHz * @sig_dbm: signal strength in dBm, or 0 if unknown * * Use this function to report to userspace when a beacon was
net/mac80211/rx.c +4 -2
@@ -3085,7 +3085,8 @@ ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)cfg80211_report_obss_beacon (rx->local->hw.wiphy, rx->skb->data, rx->skb->len, - status->freq, sig); +ieee80211_rx_status_to_khz (status), + sig); rx->flags |=IEEE80211_RX_BEACON_REPORTED ; }
@@ -3431,7 +3432,8 @@ ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx) !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) sig = status->signal; -if (cfg80211_rx_mgmt (&rx->sdata->wdev, status->freq, sig, +if (cfg80211_rx_mgmt (&rx->sdata->wdev, +ieee80211_rx_status_to_khz (status), sig, rx->skb->data, rx->skb->len,0 )) {if (rx->sta) rx->sta->rx_stats.packets++;
net/wireless/nl80211.c +2 -2
@@ -16226,7 +16226,7 @@ int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, netdev->ifindex)) ||nla_put_u64_64bit (msg,NL80211_ATTR_WDEV ,wdev_id (wdev),NL80211_ATTR_PAD ) || -nla_put_u32 (msg,NL80211_ATTR_WIPHY_FREQ , freq) || +nla_put_u32 (msg,NL80211_ATTR_WIPHY_FREQ ,KHZ_TO_MHZ (freq)) || (sig_dbm &&nla_put_u32 (msg,NL80211_ATTR_RX_SIGNAL_DBM , sig_dbm)) || nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
@@ -16877,7 +16877,7 @@ void cfg80211_report_obss_beacon(struct wiphy *wiphy,if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || (freq && -nla_put_u32 (msg,NL80211_ATTR_WIPHY_FREQ , freq)) || +nla_put_u32 (msg,NL80211_ATTR_WIPHY_FREQ ,KHZ_TO_MHZ (freq))) || (sig_dbm &&nla_put_u32 (msg,NL80211_ATTR_RX_SIGNAL_DBM , sig_dbm)) ||nla_put (msg,NL80211_ATTR_FRAME , len, frame))
Signature · 1 line
2.20.1
RFC 6/7 nl80211: add KHz frequency offset for most wifi commands
In reply to Thomas Pedersencfg80211 recently gained the ability to understand a frequency offset component in KHz. Expose this in nl80211 through the new attributes NL80211_ATTR_WIPHY_FREQ_OFFSET, NL80211_FREQUENCY_ATTR_OFFSET, NL80211_ATTR_CENTER_FREQ1_OFFSET, and NL80211_BSS_FREQUENCY_OFFSET.
These add support to send and receive a KHz offset component with the following NL80211 commands:
- NL80211_CMD_FRAME
- NL80211_CMD_GET_SCAN
- NL80211_CMD_AUTHENTICATE
- NL80211_CMD_ASSOCIATE
- NL80211_CMD_CONNECT
Along with any other command which takes a chandef, ie:
TODO: several of these commands will eventually just ignore the _OFFSET component, like _JOIN_MESH, _CMD_RADAR_DETECT, etc. Should return an error to give user a hint things won't work as expected?
- NL80211_CMD_SET_CHANNEL
- NL80211_CMD_SET_WIPHY
- NL80211_CMD_START_AP
- NL80211_CMD_RADAR_DETECT
- NL80211_CMD_NOTIFY_RADAR
- NL80211_CMD_CHANNEL_SWITCH
- NL80211_JOIN_IBSS
- NL80211_CMD_REMAIN_ON_CHANNEL
- NL80211_CMD_JOIN_CB
- NL80211_CMD_JOIN_MESH
- NL80211_CMD_TDLS_CHANNEL_SWITCH
--- include/uapi/linux/nl80211.h | 49 ++++++++++++++++-------- net/wireless/nl80211.c | 72 +++++++++++++++++++++++++++--------- 2 files changed, 87 insertions(+), 34 deletions(-)
include/uapi/linux/nl80211.h +33 -16
@@ -296,13 +296,14 @@* to get a list of all present wiphys. * @NL80211_CMD_SET_WIPHY: set wiphy parameters, needs %NL80211_ATTR_WIPHY or * %NL80211_ATTR_IFINDEX; can be used to set %NL80211_ATTR_WIPHY_NAME, -* %NL80211_ATTR_WIPHY_TXQ_PARAMS, %NL80211_ATTR_WIPHY_FREQ (and the -* attributes determining the channel width; this is used for setting -* monitor mode channel), %NL80211_ATTR_WIPHY_RETRY_SHORT, -* %NL80211_ATTR_WIPHY_RETRY_LONG, %NL80211_ATTR_WIPHY_FRAG_THRESHOLD, -* and/or %NL80211_ATTR_WIPHY_RTS_THRESHOLD. -* However, for setting the channel, see %NL80211_CMD_SET_CHANNEL -* instead, the support here is for backward compatibility only. +* %NL80211_ATTR_WIPHY_TXQ_PARAMS, %NL80211_ATTR_WIPHY_FREQ, +* %NL80211_ATTR_WIPHY_FREQ_OFFSET (and the attributes determining the +* channel width; this is used for setting monitor mode channel), +* %NL80211_ATTR_WIPHY_RETRY_SHORT, %NL80211_ATTR_WIPHY_RETRY_LONG, +* %NL80211_ATTR_WIPHY_FRAG_THRESHOLD, and/or +* %NL80211_ATTR_WIPHY_RTS_THRESHOLD. However, for setting the channel, +* see %NL80211_CMD_SET_CHANNEL instead, the support here is for backward +* compatibility only. * @NL80211_CMD_NEW_WIPHY: Newly created wiphy, response to get request * or rename notification. Has attributes %NL80211_ATTR_WIPHY and * %NL80211_ATTR_WIPHY_NAME.
@@ -351,7 +352,8 @@* %NL80211_ATTR_AUTH_TYPE, %NL80211_ATTR_INACTIVITY_TIMEOUT, * %NL80211_ATTR_ACL_POLICY and %NL80211_ATTR_MAC_ADDRS. * The channel to use can be set on the interface or be given using the -* %NL80211_ATTR_WIPHY_FREQ and the attributes determining channel width. +* %NL80211_ATTR_WIPHY_FREQ and %NL80211_ATTR_WIPHY_FREQ_OFFSET, and the +* attributes determining channel width. * @NL80211_CMD_NEW_BEACON: old alias for %NL80211_CMD_START_AP * @NL80211_CMD_STOP_AP: Stop AP operation on the given interface * @NL80211_CMD_DEL_BEACON: old alias for %NL80211_CMD_STOP_AP
@@ -536,11 +538,12 @@* interface. %NL80211_ATTR_MAC is used to specify PeerSTAAddress (and * BSSID in case of station mode). %NL80211_ATTR_SSID is used to specify * the SSID (mainly for association, but is included in authentication -* request, too, to help BSS selection. %NL80211_ATTR_WIPHY_FREQ is used -* to specify the frequence of the channel in MHz. %NL80211_ATTR_AUTH_TYPE -* is used to specify the authentication type. %NL80211_ATTR_IE is used to -* define IEs (VendorSpecificInfo, but also including RSN IE and FT IEs) -* to be added to the frame. +* request, too, to help BSS selection. %NL80211_ATTR_WIPHY_FREQ + +* %NL80211_ATTR_WIPHY_FREQ_OFFSET is used to specify the frequence of the +* channel in MHz. %NL80211_ATTR_AUTH_TYPE is used to specify the +* authentication type. %NL80211_ATTR_IE is used to define IEs +* (VendorSpecificInfo, but also including RSN IE and FT IEs) to be added +* to the frame. * When used as an event, this reports reception of an Authentication * frame in station and IBSS modes when the local MLME processed the * frame, i.e., it was for the local STA and was received in correct
@@ -595,8 +598,9 @@* requests to connect to a specified network but without separating * auth and assoc steps. For this, you need to specify the SSID in a * %NL80211_ATTR_SSID attribute, and can optionally specify the association -* IEs in %NL80211_ATTR_IE, %NL80211_ATTR_AUTH_TYPE, %NL80211_ATTR_USE_MFP, -* %NL80211_ATTR_MAC, %NL80211_ATTR_WIPHY_FREQ, %NL80211_ATTR_CONTROL_PORT, +* IEs in %NL80211_ATTR_IE, %NL80211_ATTR_AUTH_TYPE, +* %NL80211_ATTR_USE_MFP, %NL80211_ATTR_MAC, %NL80211_ATTR_WIPHY_FREQ, +* %NL80211_ATTR_WIPHY_FREQ_OFFSET, %NL80211_ATTR_CONTROL_PORT, * %NL80211_ATTR_CONTROL_PORT_ETHERTYPE, * %NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT, * %NL80211_ATTR_CONTROL_PORT_OVER_NL80211, %NL80211_ATTR_MAC_HINT, and
@@ -1422,7 +1426,8 @@ enum nl80211_commands {* of &enum nl80211_chan_width, describing the channel width. See the * documentation of the enum for more information. * @NL80211_ATTR_CENTER_FREQ1: Center frequency of the first part of the -* channel, used for anything but 20 MHz bandwidth +* channel, used for anything but 20 MHz bandwidth. In S1G this is the +* operating channel center frequency. * @NL80211_ATTR_CENTER_FREQ2: Center frequency of the second part of the * channel, used only for 80+80 MHz bandwidth * @NL80211_ATTR_WIPHY_CHANNEL_TYPE: included with NL80211_ATTR_WIPHY_FREQ
@@ -2469,6 +2474,11 @@ enum nl80211_commands {* entry without having to force a disconnection after the PMK timeout. If * no roaming occurs between the reauth threshold and PMK expiration, * disassociation is still forced. +* @NL80211_ATTR_WIPHY_FREQ_OFFSET: offset of the associated +* %NL80211_ATTR_WIPHY_FREQ in positive KHz. Only valid when supplied with +* an %NL80211_ATTR_WIPHY_FREQ_OFFSET. +* @NL80211_ATTR_CENTER_FREQ1_OFFSET: Center frequency offset in KHz for the +* first channel segment specified in %NL80211_ATTR_CENTER_FREQ1. * * @NUM_NL80211_ATTR: total number of nl80211_attrs available * @NL80211_ATTR_MAX: highest attribute number currently defined
@@ -2945,6 +2955,9 @@ enum nl80211_attrs {NL80211_ATTR_PMK_LIFETIME ,NL80211_ATTR_PMK_REAUTH_THRESHOLD , +NL80211_ATTR_WIPHY_FREQ_OFFSET , +NL80211_ATTR_CENTER_FREQ1_OFFSET , +/* add attributes here, update the policy in nl80211.c */ __NL80211_ATTR_AFTER_LAST,
@@ -3666,6 +3679,7 @@ enum nl80211_wmm_rule {* (see &enum nl80211_wmm_rule) * @NL80211_FREQUENCY_ATTR_NO_HE: HE operation is not allowed on this channel * in current regulatory domain. +* @NL80211_FREQUENCY_ATTR_OFFSET: frequency offset in KHz * @NL80211_FREQUENCY_ATTR_MAX: highest frequency attribute number * currently defined * @__NL80211_FREQUENCY_ATTR_AFTER_LAST: internal use
@@ -3696,6 +3710,7 @@ enum nl80211_frequency_attr {NL80211_FREQUENCY_ATTR_NO_10MHZ ,NL80211_FREQUENCY_ATTR_WMM ,NL80211_FREQUENCY_ATTR_NO_HE , +NL80211_FREQUENCY_ATTR_OFFSET ,/* keep last */ __NL80211_FREQUENCY_ATTR_AFTER_LAST,
@@ -4466,6 +4481,7 @@ enum nl80211_bss_scan_width {* @NL80211_BSS_CHAIN_SIGNAL: per-chain signal strength of last BSS update. * Contains a nested array of signal strength attributes (u8, dBm), * using the nesting index as the antenna number. +* @NL80211_BSS_FREQUENCY_OFFSET: frequency offset in KHz * @__NL80211_BSS_AFTER_LAST: internal * @NL80211_BSS_MAX: highest BSS attribute */
@@ -4490,6 +4506,7 @@ enum nl80211_bss {NL80211_BSS_PARENT_TSF ,NL80211_BSS_PARENT_BSSID ,NL80211_BSS_CHAIN_SIGNAL , +NL80211_BSS_FREQUENCY_OFFSET ,/* keep last */ __NL80211_BSS_AFTER_LAST,
net/wireless/nl80211.c +54 -18
177 lines not on this page · raw message
Signature · 1 line
2.20.1
Johannes Berg
maintainerRe: [RFC 6/7] nl80211: add KHz frequency offset for most wifi commands
Quoted 5 lines · Thomas Pedersen
TODO: several of these commands will eventually just ignore the
_OFFSETcomponent, like_JOIN_MESH,_CMD_RADAR_DETECT, etc. Should return an error to give user a hint things won't work as expected?
Wouldn't most of them already require that a channel with the given frequency exists, and thus fail anyway?
johannes
Re: [RFC 6/7] nl80211: add KHz frequency offset for most wifi commands
Quoted 9 lines · Johannes Berg
Quoted 5 lines · Thomas Pedersen
TODO: several of these commands will eventually just ignore the
_OFFSETcomponent, like_JOIN_MESH,_CMD_RADAR_DETECT, etc. Should return an error to give user a hint things won't work as expected?Wouldn't most of them already require that a channel with the given frequency exists, and thus fail anyway?
Well I was thinking of the case where you have:
ch 2: 903MHz
ch 3: 903.5Mhz
userspace tries to eg. join a mesh on channel 3 by sending 903MHz + 500KHz, the (old) kernel interprets this as channel 2 and happily joins on the wrong channel. However this only applies on a new band which doesn't even exist yet, and if we return an error for commands which have not yet been tested with frequency offset nothing unexpected will happen.
Signature · 1 line
thomas
Johannes Berg
maintainerRe: [RFC 6/7] nl80211: add KHz frequency offset for most wifi commands
In reply to Thomas Pedersennet/wireless/nl80211.c const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { · line 368
Quoted 2 lines · Thomas Pedersen
net/wireless/nl80211.c +1
-0+ [NL80211_ATTR_CENTER_FREQ1_OFFSET] = { .type = NLA_U32 },
These should probably all be something like
NLA_POLICY_RANGE(NLA_U32, 0, 999)?
johannes
RFC 7/7 nl80211: accept scan frequencies in KHz
In reply to Thomas PedersenNL80211_ATTR_SCAN_FREQUENCIES_KHZ are optional in addition to the MHz frequencies specified in NL80211_ATTR_SCAN_FREQUENCIES.
--- include/uapi/linux/nl80211.h | 2 ++ net/wireless/nl80211.c | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-)
include/uapi/linux/nl80211.h +2 -0
@@ -2430,6 +2430,7 @@ enum nl80211_commands {* @NL80211_ATTR_WIPHY_EDMG_BW_CONFIG: Channel BW Configuration subfield encodes * the allowed channel bandwidth configurations. (u8 attribute) * Defined by IEEE P802.11ay/D4.0 section 9.4.2.251, Table 13. +* @NL80211_ATTR_SCAN_FREQUENCIES_KHZ: nested attribute with frequencies (in KHz) * * @NL80211_ATTR_VLAN_ID: VLAN ID (1..4094) for the station and VLAN group key * (u16).
@@ -2957,6 +2958,7 @@ enum nl80211_attrs {NL80211_ATTR_WIPHY_FREQ_OFFSET ,NL80211_ATTR_CENTER_FREQ1_OFFSET , + NL80211_ATTR_SCAN_FREQUENCIES_KHZ,/* add attributes here, update the policy in nl80211.c */
net/wireless/nl80211.c +17 -6
@@ -665,6 +665,7 @@ const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { [NL80211_ATTR_PMK_LIFETIME] = NLA_POLICY_MIN(NLA_U32, 1), [NL80211_ATTR_PMK_REAUTH_THRESHOLD] = NLA_POLICY_RANGE(NLA_U8, 1, 100), [NL80211_ATTR_WIPHY_FREQ_OFFSET] = { .type = NLA_U32 }, + [NL80211_ATTR_SCAN_FREQUENCIES_KHZ] = { .type = NLA_NESTED }, };/* policy for the key attributes */
@@ -7749,6 +7750,8 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)struct cfg80211_registered_device *rdev = info->user_ptr[0 ];struct wireless_dev *wdev = info->user_ptr[1 ];struct cfg80211_scan_request *request; +struct nlattr *scan_freqs =NULL ; +bool scan_freqs_khz = false;struct nlattr *attr;struct wiphy *wiphy;int err, tmp, n_ssids =0 , n_channels, i;
@@ -7767,9 +7770,14 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) goto unlock; } -if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES ]) { - n_channels =validate_scan_freqs ( - info->attrs[NL80211_ATTR_SCAN_FREQUENCIES ]); +if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES_KHZ ]) { + scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQUENCIES_KHZ ]; + scan_freqs_khz = true; + }else if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES ]) + scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQUENCIES ]; + +if (scan_freqs) { + n_channels =validate_scan_freqs (scan_freqs);if (!n_channels) { err = -EINVAL ; goto unlock;
@@ -7817,13 +7825,16 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) } i =0 ; -if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES ]) { +if (scan_freqs) {/* user specified, bail out if channel not found */ -nla_for_each_nested (attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES ], tmp) { +nla_for_each_nested (attr, scan_freqs, tmp) {struct ieee80211_channel *chan; +int freq =nla_get_u32 (attr); - chan =ieee80211_get_channel (wiphy,nla_get_u32 (attr)); +if (!scan_freqs_khz) + freq =MHZ_TO_KHZ (freq); + chan =ieee80211_get_channel_khz (wiphy, freq);if (!chan) { err = -EINVAL ; goto out_free;
Signature · 1 line
2.20.1
Johannes Berg
maintainerQuoted 3 lines · Thomas Pedersen
Some cfg80211 and nl80211 internals have been converted to handle units of KHz, which is not unprecedented (
net/wireless/reg.c), and the collateral damage is localized.
:)
Quoted 3 lines
One thing which is still unclear is backward compatibility in nl80211. If a frequency offset is supplied to an older kernel, it'll just silently fail to do the right thing.
But will it? It mostly requires to have a struct ieee80211_channel registered with the wiphy for a given frequency, and won't find that?
But speaking of which - I was expecting to see a new *band* here for S1G, so that you can actually register the channels properly in the wiphy struct? Or is that just not part of this patchset yet?
johannes
Quoted 6 lines · Johannes Berg
Quoted 3 lines · Thomas Pedersen
Some cfg80211 and nl80211 internals have been converted to handle units of KHz, which is not unprecedented (
net/wireless/reg.c), and the collateral damage is localized.
Quoted 8 lines
:)
Quoted 3 lines
One thing which is still unclear is backward compatibility in nl80211. If a frequency offset is supplied to an older kernel, it'll just silently fail to do the right thing.
But will it? It mostly requires to have a struct
ieee80211_channelregistered with the wiphy for a given frequency, and won't find that?
I was worried the wrong ("rounded down") channel would be found, but I think the point is mostly moot since that channel wouldn't exist either.
Quoted 3 lines
But speaking of which - I was expecting to see a new *band* here for S1G, so that you can actually register the channels properly in the wiphy struct? Or is that just not part of this patchset yet?
Yeah just trying to focus on the frequency offset stuff and keep S1G out of it for now. Do you think it would be helpful to cap it with the new S1G band definition?
Signature · 1 line
thomas