blob: e32ba2ff37994b76c00dd79964f394b233c40626 [file] [log] [blame]
developer4e85d132023-09-06 16:30:15 +08001From 979c688e54a73cfedb8757881a95c4f6c795023a Mon Sep 17 00:00:00 2001
2From: Michael-CY Lee <michael-cy.lee@mediatek.com>
3Date: Mon, 14 Aug 2023 18:03:29 +0800
4Subject: mac80211: mtk: Add utilities for converting op_class
5
6These utilities include converting op_class to nl80211 channel width and
7center frequency.
8
9Signed-off-by: Michael-CY Lee <michael-cy.lee@mediatek.com>
10---
11 include/net/cfg80211.h | 25 ++++++++
12 net/wireless/util.c | 130 ++++++++++++++++++++++++++++++++++++++++-
13 2 files changed, 154 insertions(+), 1 deletion(-)
14
15diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
16index cfaa3d6..bea7d25 100644
17--- a/include/net/cfg80211.h
18+++ b/include/net/cfg80211.h
19@@ -8693,6 +8693,31 @@ void cfg80211_ch_switch_started_notify(struct net_device *dev,
20 bool ieee80211_operating_class_to_band(u8 operating_class,
21 enum nl80211_band *band);
22
23+/**
24+ * ieee80211_operating_class_to_center_freq - convert operating class to
25+ * center frequency
26+ *
27+ * @operating_class: the operating class to convert
28+ * @chan: the ieee80211_channel to convert
29+ * @center_freq1: cneter frequency 1 pointer to fill
30+ * @center_freq2: cneter frequency 2 pointer to fill
31+ *
32+ * Returns %true if the conversion was successful, %false otherwise.
33+ */
34+bool ieee80211_operating_class_to_center_freq(u8 operating_class,
35+ struct ieee80211_channel *chan,
36+ u32 *center_freq1,
37+ u32 *center_freq2);
38+
39+/**
40+ * ieee80211_operating_class_to_chan_width - convert operating class to
41+ * nl80211 channel width
42+ *
43+ * @operating_class: the operating class to convert
44+ */
45+enum nl80211_chan_width
46+ieee80211_operating_class_to_chan_width(u8 operating_class);
47+
48 /**
49 * ieee80211_chandef_to_operating_class - convert chandef to operation class
50 *
51diff --git a/net/wireless/util.c b/net/wireless/util.c
52index 1783ab9..13cb986 100644
53--- a/net/wireless/util.c
54+++ b/net/wireless/util.c
55@@ -1981,7 +1981,7 @@ bool ieee80211_operating_class_to_band(u8 operating_class,
56 case 128 ... 130:
57 *band = NL80211_BAND_5GHZ;
58 return true;
59- case 131 ... 135:
60+ case 131 ... 137:
61 *band = NL80211_BAND_6GHZ;
62 return true;
63 case 81:
64@@ -1999,6 +1999,134 @@ bool ieee80211_operating_class_to_band(u8 operating_class,
65 }
66 EXPORT_SYMBOL(ieee80211_operating_class_to_band);
67
68+bool ieee80211_operating_class_to_center_freq(u8 operating_class,
69+ struct ieee80211_channel *chan,
70+ u32 *center_freq1,
71+ u32 *center_freq2)
72+{
73+ u32 control_freq, offset;
74+ enum nl80211_band band;
75+
76+ control_freq = chan->center_freq;
77+ if (!ieee80211_operating_class_to_band(operating_class, &band))
78+ return false;
79+
80+ if (band != chan->band)
81+ return false;
82+
83+ if (control_freq >= 5955)
84+ offset = control_freq - 5955;
85+ else if (control_freq >= 5745)
86+ offset = control_freq - 5745;
87+ else if (control_freq >= 5180)
88+ offset = control_freq - 5180;
89+ offset /= 20;
90+
91+ *center_freq2 = 0;
92+ switch (operating_class) {
93+ case 81: /* 2 GHz band; 20 MHz; channels 1..13 */
94+ case 82: /* 2 GHz band; 20 MHz; channel 14 */
95+ case 115: /* 5 GHz band; 20 MHz; channels 36,40,44,48 */
96+ case 118: /* 5 GHz band; 20 MHz; channels 52,56,60,64 */
97+ case 121: /* 5 GHz band; 20 MHz; channels 100..144 */
98+ case 124: /* 5 GHz band; 20 MHz; channels 149,153,157,161 */
99+ case 125: /* 5 GHz band; 20 MHz; channels 149..177 */
100+ case 131: /* 6 GHz band; 20 MHz; channels 1..233*/
101+ case 136: /* 6 GHz band; 20 MHz; channel 2 */
102+ *center_freq1 = control_freq;
103+ return true;
104+ case 83: /* 2 GHz band; 40 MHz; channels 1..9 */
105+ case 116: /* 5 GHz band; 40 MHz; channels 36,44 */
106+ case 119: /* 5 GHz band; 40 MHz; channels 52,60 */
107+ case 122: /* 5 GHz band; 40 MHz; channels 100,108,116,124,132,140 */
108+ case 126: /* 5 GHz band; 40 MHz; channels 149,157,165,173 */
109+ *center_freq1 = control_freq + 10;
110+ return true;
111+ case 84: /* 2 GHz band; 40 MHz; channels 5..13 */
112+ case 117: /* 5 GHz band; 40 MHz; channels 40,48 */
113+ case 120: /* 5 GHz band; 40 MHz; channels 56,64 */
114+ case 123: /* 5 GHz band; 40 MHz; channels 104,112,120,128,136,144 */
115+ case 127: /* 5 GHz band; 40 MHz; channels 153,161,169,177 */
116+ *center_freq1 = control_freq - 10;
117+ return true;
118+ case 132: /* 6 GHz band; 40 MHz; channels 1,5,..,229*/
119+ *center_freq1 = control_freq + 10 - (offset & 1) * 20;
120+ return true;
121+ case 128: /* 5 GHz band; 80 MHz; channels 36..64,100..144,149..177 */
122+ *center_freq1 = control_freq + 30 - (offset & 3) * 20;
123+ return true;
124+ case 130: /* 5 GHz band; 80+80 MHz; channels 36..64,100..144,149..177 */
125+ /* TODO How to know the center_freq2 of 80+80 MHz?*/
126+ *center_freq1 = 0;
127+ return false;
128+ case 133: /* 6 GHz band; 80 MHz; channels 1,5,..,229 */
129+ *center_freq1 = control_freq + 30 - (offset & 3) * 20;
130+ return true;
131+ case 129: /* 5 GHz band; 160 MHz; channels 36..64,100..144,149..177 */
132+ *center_freq1 = control_freq + 70 - (offset & 7) * 20;
133+ return true;
134+ case 134: /* 6 GHz band; 160 MHz; channels 1,5,..,229 */
135+ *center_freq1 = control_freq + 70 - (offset & 7) * 20;
136+ return true;
137+ case 135: /* 6 GHz band; 80+80 MHz; channels 1,5,..,229 */
138+ /* TODO How to know the center_freq2 of 80+80 MHz?*/
139+ *center_freq1 = 0;
140+ return false;
141+ case 137: /* 6 GHz band; 320 MHz; channels 1,5,..,229 */
142+ /* TODO it's 320-1 or 320-2 channelization? */
143+ /* Currently convert to 320-1 */
144+ *center_freq1 = control_freq + 150 - (offset & 15) * 20;
145+ return true;
146+ default:
147+ return false;
148+ }
149+}
150+EXPORT_SYMBOL(ieee80211_operating_class_to_center_freq);
151+
152+enum nl80211_chan_width
153+ieee80211_operating_class_to_chan_width(u8 operating_class)
154+{
155+ switch (operating_class) {
156+ case 81: /* 2 GHz band; 20 MHz; channels 1..13 */
157+ case 82: /* 2 GHz band; 20 MHz; channel 14 */
158+ case 115: /* 5 GHz band; 20 MHz; channels 36,40,44,48 */
159+ case 118: /* 5 GHz band; 20 MHz; channels 52,56,60,64 */
160+ case 121: /* 5 GHz band; 20 MHz; channels 100..144 */
161+ case 124: /* 5 GHz band; 20 MHz; channels 149,153,157,161 */
162+ case 125: /* 5 GHz band; 20 MHz; channels 149..177 */
163+ case 131: /* 6 GHz band; 20 MHz; channels 1..233*/
164+ case 136: /* 6 GHz band; 20 MHz; channel 2 */
165+ return NL80211_CHAN_WIDTH_20;
166+ case 83: /* 2 GHz band; 40 MHz; channels 1..9 */
167+ case 84: /* 2 GHz band; 40 MHz; channels 5..13 */
168+ case 116: /* 5 GHz band; 40 MHz; channels 36,44 */
169+ case 117: /* 5 GHz band; 40 MHz; channels 40,48 */
170+ case 119: /* 5 GHz band; 40 MHz; channels 52,60 */
171+ case 120: /* 5 GHz band; 40 MHz; channels 56,64 */
172+ case 122: /* 5 GHz band; 40 MHz; channels 100,108,116,124,132,140 */
173+ case 123: /* 5 GHz band; 40 MHz; channels 104,112,120,128,136,144 */
174+ case 126: /* 5 GHz band; 40 MHz; channels 149,157,165,173 */
175+ case 127: /* 5 GHz band; 40 MHz; channels 153,161,169,177 */
176+ case 132: /* 6 GHz band; 40 MHz; channels 1,5,..,229*/
177+ return NL80211_CHAN_WIDTH_40;
178+ case 128: /* 5 GHz band; 80 MHz; channels 36..64,100..144,149..177 */
179+ case 133: /* 6 GHz band; 80 MHz; channels 1,5,..,229 */
180+ return NL80211_CHAN_WIDTH_80;
181+ case 130: /* 5 GHz band; 80+80 MHz; channels 36..64,100..144,149..177 */
182+ case 135: /* 6 GHz band; 80+80 MHz; channels 1,5,..,229 */
183+ return NL80211_CHAN_WIDTH_80P80;
184+ case 129: /* 5 GHz band; 160 MHz; channels 36..64,100..144,149..177 */
185+ case 134: /* 6 GHz band; 160 MHz; channels 1,5,..,229 */
186+ return NL80211_CHAN_WIDTH_160;
187+ case 137: /* 6 GHz band; 320 MHz; channels 1,5,..,229 */
188+ return NL80211_CHAN_WIDTH_320;
189+ default:
190+ WARN_ON(1);
191+ return NL80211_CHAN_WIDTH_20_NOHT;
192+ }
193+}
194+EXPORT_SYMBOL(ieee80211_operating_class_to_chan_width);
195+
196 bool ieee80211_chandef_to_operating_class(struct cfg80211_chan_def *chandef,
197 u8 *op_class)
198 {
199--
2002.25.1
201