Commit 68de1302 authored by Michael-CY Lee's avatar Michael-CY Lee Committed by Johannes Berg

wifi: cfg80211: Add utility for converting op_class into chandef

This utility is used in STA CSA handling. The op_class in the ECSA
Element can be converted into chandef.
Co-developed-by: default avatarMoney Wang <money.wang@mediatek.com>
Signed-off-by: default avatarMichael-CY Lee <michael-cy.lee@mediatek.com>
Link: https://msgid.link/20231222010914.6521-2-michael-cy.lee@mediatek.comSigned-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent f29a8be8
...@@ -8774,6 +8774,19 @@ void cfg80211_ch_switch_started_notify(struct net_device *dev, ...@@ -8774,6 +8774,19 @@ void cfg80211_ch_switch_started_notify(struct net_device *dev,
bool ieee80211_operating_class_to_band(u8 operating_class, bool ieee80211_operating_class_to_band(u8 operating_class,
enum nl80211_band *band); enum nl80211_band *band);
/**
* ieee80211_operating_class_to_chandef - convert operating class to chandef
*
* @operating_class: the operating class to convert
* @chan: the ieee80211_channel to convert
* @chandef: a pointer to the resulting chandef
*
* Returns %true if the conversion was successful, %false otherwise.
*/
bool ieee80211_operating_class_to_chandef(u8 operating_class,
struct ieee80211_channel *chan,
struct cfg80211_chan_def *chandef);
/** /**
* ieee80211_chandef_to_operating_class - convert chandef to operation class * ieee80211_chandef_to_operating_class - convert chandef to operation class
* *
......
...@@ -2073,6 +2073,82 @@ bool ieee80211_operating_class_to_band(u8 operating_class, ...@@ -2073,6 +2073,82 @@ bool ieee80211_operating_class_to_band(u8 operating_class,
} }
EXPORT_SYMBOL(ieee80211_operating_class_to_band); EXPORT_SYMBOL(ieee80211_operating_class_to_band);
bool ieee80211_operating_class_to_chandef(u8 operating_class,
struct ieee80211_channel *chan,
struct cfg80211_chan_def *chandef)
{
u32 control_freq, offset = 0;
enum nl80211_band band;
if (!ieee80211_operating_class_to_band(operating_class, &band) ||
!chan || band != chan->band)
return false;
control_freq = chan->center_freq;
chandef->chan = chan;
if (control_freq >= 5955)
offset = control_freq - 5955;
else if (control_freq >= 5745)
offset = control_freq - 5745;
else if (control_freq >= 5180)
offset = control_freq - 5180;
offset /= 20;
switch (operating_class) {
case 81: /* 2 GHz band; 20 MHz; channels 1..13 */
case 82: /* 2 GHz band; 20 MHz; channel 14 */
case 115: /* 5 GHz band; 20 MHz; channels 36,40,44,48 */
case 118: /* 5 GHz band; 20 MHz; channels 52,56,60,64 */
case 121: /* 5 GHz band; 20 MHz; channels 100..144 */
case 124: /* 5 GHz band; 20 MHz; channels 149,153,157,161 */
case 125: /* 5 GHz band; 20 MHz; channels 149..177 */
case 131: /* 6 GHz band; 20 MHz; channels 1..233*/
case 136: /* 6 GHz band; 20 MHz; channel 2 */
chandef->center_freq1 = control_freq;
chandef->width = NL80211_CHAN_WIDTH_20;
return true;
case 83: /* 2 GHz band; 40 MHz; channels 1..9 */
case 116: /* 5 GHz band; 40 MHz; channels 36,44 */
case 119: /* 5 GHz band; 40 MHz; channels 52,60 */
case 122: /* 5 GHz band; 40 MHz; channels 100,108,116,124,132,140 */
case 126: /* 5 GHz band; 40 MHz; channels 149,157,165,173 */
chandef->center_freq1 = control_freq + 10;
chandef->width = NL80211_CHAN_WIDTH_40;
return true;
case 84: /* 2 GHz band; 40 MHz; channels 5..13 */
case 117: /* 5 GHz band; 40 MHz; channels 40,48 */
case 120: /* 5 GHz band; 40 MHz; channels 56,64 */
case 123: /* 5 GHz band; 40 MHz; channels 104,112,120,128,136,144 */
case 127: /* 5 GHz band; 40 MHz; channels 153,161,169,177 */
chandef->center_freq1 = control_freq - 10;
chandef->width = NL80211_CHAN_WIDTH_40;
return true;
case 132: /* 6 GHz band; 40 MHz; channels 1,5,..,229*/
chandef->center_freq1 = control_freq + 10 - (offset & 1) * 20;
chandef->width = NL80211_CHAN_WIDTH_40;
return true;
case 128: /* 5 GHz band; 80 MHz; channels 36..64,100..144,149..177 */
case 133: /* 6 GHz band; 80 MHz; channels 1,5,..,229 */
chandef->center_freq1 = control_freq + 30 - (offset & 3) * 20;
chandef->width = NL80211_CHAN_WIDTH_80;
return true;
case 129: /* 5 GHz band; 160 MHz; channels 36..64,100..144,149..177 */
case 134: /* 6 GHz band; 160 MHz; channels 1,5,..,229 */
chandef->center_freq1 = control_freq + 70 - (offset & 7) * 20;
chandef->width = NL80211_CHAN_WIDTH_160;
return true;
case 130: /* 5 GHz band; 80+80 MHz; channels 36..64,100..144,149..177 */
case 135: /* 6 GHz band; 80+80 MHz; channels 1,5,..,229 */
/* The center_freq2 of 80+80 MHz is unknown */
case 137: /* 6 GHz band; 320 MHz; channels 1,5,..,229 */
/* 320-1 or 320-2 channelization is unknown */
default:
return false;
}
}
EXPORT_SYMBOL(ieee80211_operating_class_to_chandef);
bool ieee80211_chandef_to_operating_class(struct cfg80211_chan_def *chandef, bool ieee80211_chandef_to_operating_class(struct cfg80211_chan_def *chandef,
u8 *op_class) u8 *op_class)
{ {
......
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