wifi: cfg80211: Add utility for converting op_class into chandef
authorMichael-CY Lee <michael-cy.lee@mediatek.com>
Fri, 22 Dec 2023 01:09:13 +0000 (09:09 +0800)
committerJohannes Berg <johannes.berg@intel.com>
Thu, 8 Feb 2024 14:00:44 +0000 (15:00 +0100)
This utility is used in STA CSA handling. The op_class in the ECSA
Element can be converted into chandef.

Co-developed-by: Money Wang <money.wang@mediatek.com>
Signed-off-by: Michael-CY Lee <michael-cy.lee@mediatek.com>
Link: https://msgid.link/20231222010914.6521-2-michael-cy.lee@mediatek.com
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
include/net/cfg80211.h
net/wireless/util.c

index cb5e34d640cdef2bcc6123834c059a8cba9d76d2..e27ed2307cdbc80baf28e7d7e83fd4eed5038d8d 100644 (file)
@@ -8774,6 +8774,19 @@ void cfg80211_ch_switch_started_notify(struct net_device *dev,
 bool ieee80211_operating_class_to_band(u8 operating_class,
                                       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
  *
index d1ce3bee279735c5c9aa45cf5d0db68ecf8b9418..379f742fd74155a7de643d6a88fe26f93acedbe4 100644 (file)
@@ -2073,6 +2073,82 @@ bool ieee80211_operating_class_to_band(u8 operating_class,
 }
 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,
                                          u8 *op_class)
 {