xref: /wlan-dirver/qca-wifi-host-cmn/umac/regulatory/core/src/reg_opclass.h (revision eb134979c1cacbd1eb12caa116020b86fad96e1c)
1 /*
2  * Copyright (c) 2017-2020 The Linux Foundation. All rights reserved.
3  *
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /**
21  * DOC: reg_opclass.h
22  * This file provides prototypes of the regulatory opclass functions
23  */
24 
25 #ifndef __REG_OPCLASS_H__
26 #define __REG_OPCLASS_H__
27 
28 #ifdef HOST_OPCLASS
29 /**
30  * reg_dmn_get_chanwidth_from_opclass() - Get channel width from opclass.
31  * @country: Country code
32  * @channel: Channel number
33  * @opclass: Operating class
34  *
35  * Return: Channel width
36  */
37 uint16_t reg_dmn_get_chanwidth_from_opclass(uint8_t *country, uint8_t channel,
38 					    uint8_t opclass);
39 
40 /**
41  * reg_dmn_get_opclass_from_channel() - Get operating class from channel.
42  * @country: Country code.
43  * @channel: Channel number.
44  * @offset: Operating class offset.
45  *
46  * Return: Error code.
47  */
48 uint16_t reg_dmn_get_opclass_from_channel(uint8_t *country, uint8_t channel,
49 					  uint8_t offset);
50 
51 /**
52  * reg_dmn_get_opclass_from_freq_width() - Get operating class from frequency
53  * @country: Country code.
54  * @freq: Channel center frequency.
55  * @ch_width: Channel width.
56  * @behav_limit: Behaviour limit.
57  *
58  * Return: Error code.
59  */
60 uint8_t reg_dmn_get_opclass_from_freq_width(uint8_t *country,
61 					    qdf_freq_t freq,
62 					    uint8_t ch_width,
63 					    uint16_t behav_limit);
64 
65 /**
66  * reg_get_band_cap_from_op_class() - Return band capability bitmap
67  * @country: Pointer to Country code.
68  * @num_of_opclass: Number of Operating class.
69  * @opclass: Pointer to opclass.
70  *
71  * Return supported band bitmap based on the input operating class list
72  * provided.
73  *
74  * Return: Return supported band capability
75  */
76 uint8_t reg_get_band_cap_from_op_class(const uint8_t *country,
77 				       uint8_t num_of_opclass,
78 				       const uint8_t *opclass);
79 
80 /**
81  * reg_dmn_get_opclass_from_channe() - Print channels in op class.
82  * @country: Country code.
83  * @opclass: opclass.
84  *
85  * Return: Void.
86  */
87 void reg_dmn_print_channels_in_opclass(uint8_t *country, uint8_t op_class);
88 
89 /**
90  * reg_dmn_set_curr_opclasses() - Set current operating class
91  * @num_classes: Number of classes
92  * @class: Pointer to operating class.
93  *
94  * Return: Error code.
95  */
96 uint16_t reg_dmn_set_curr_opclasses(uint8_t num_classes, uint8_t *class);
97 
98 /**
99  * reg_dmn_get_curr_opclasses() - Get current supported operating classes.
100  * @num_classes: Number of classes.
101  * @class: Pointer to operating class.
102  *
103  * Return: Error code.
104  */
105 uint16_t reg_dmn_get_curr_opclasses(uint8_t *num_classes, uint8_t *class);
106 
107 /**
108  * reg_get_opclass_details() - Get details about the current opclass table.
109  * @pdev: Pointer to pdev.
110  * @reg_ap_cap: Pointer to reg_ap_cap.
111  * @n_opclasses: Pointer to number of opclasses.
112  * @max_supp_op_class: Maximum number of operating classes supported.
113  * @global_tbl_lookup: Whether to lookup global op class table.
114  *
115  * Return: QDF_STATUS_SUCCESS if success, else return QDF_STATUS_FAILURE.
116  */
117 QDF_STATUS reg_get_opclass_details(struct wlan_objmgr_pdev *pdev,
118 				   struct regdmn_ap_cap_opclass_t *reg_ap_cap,
119 				   uint8_t *n_opclasses,
120 				   uint8_t max_supp_op_class,
121 				   bool global_tbl_lookup);
122 
123 /**
124  * reg_is_5ghz_op_class() - Check if the input opclass is a 5GHz opclass.
125  * @country: Country code.
126  * @op_class: Operating class.
127  *
128  * Return: Return true if input the opclass is a 5GHz opclass,
129  * else return false.
130  */
131 bool reg_is_5ghz_op_class(const uint8_t *country, uint8_t op_class);
132 
133 /**
134  * reg_is_2ghz_op_class() - Check if the input opclass is a 2.4GHz opclass.
135  * @country: Country code.
136  * @op_class: Operating class.
137  *
138  * Return: Return true if input the opclass is a 2.4GHz opclass,
139  * else return false.
140  */
141 bool reg_is_2ghz_op_class(const uint8_t *country, uint8_t op_class);
142 
143 #ifdef CONFIG_CHAN_FREQ_API
144 
145 /**
146  * reg_freq_width_to_chan_op_class() - convert frequency to oper class,
147  *                                     channel
148  * @pdev: pdev pointer
149  * @freq: channel frequency in mhz
150  * @chan_width: channel width
151  * @global_tbl_lookup: whether to lookup global op class tbl
152  * @behav_limit: behavior limit
153  * @op_class: operating class
154  * @chan_num: channel number
155  *
156  * Return: Void.
157  */
158 void reg_freq_width_to_chan_op_class(struct wlan_objmgr_pdev *pdev,
159 				     qdf_freq_t freq,
160 				     uint16_t chan_width,
161 				     bool global_tbl_lookup,
162 				     uint16_t behav_limit,
163 				     uint8_t *op_class,
164 				     uint8_t *chan_num);
165 
166 /**
167  * reg_freq_width_to_chan_op_class_auto() - convert frequency to operating
168  * class,channel after fixing up the global_tbl_lookup and behav_limit
169  * for 6G frequencies.
170  * @pdev: pdev pointer
171  * @freq: channel frequency in mhz
172  * @chan_width: channel width
173  * @global_tbl_lookup: whether to lookup global op class tbl
174  * @behav_limit: behavior limit
175  * @op_class: operating class
176  * @chan_num: channel number
177  *
178  * Return: Void.
179  */
180 void reg_freq_width_to_chan_op_class_auto(struct wlan_objmgr_pdev *pdev,
181 					  qdf_freq_t freq,
182 					  uint16_t chan_width,
183 					  bool global_tbl_lookup,
184 					  uint16_t behav_limit,
185 					  uint8_t *op_class,
186 					  uint8_t *chan_num);
187 
188 /**
189  * reg_freq_to_chan_op_class() - convert frequency to oper class,
190  *                                   channel
191  * @pdev: pdev pointer
192  * @freq: channel frequency in mhz
193  * @global_tbl_lookup: whether to lookup global op class tbl
194  * @behav_limit: behavior limit
195  * @op_class: operating class
196  * @chan_num: channel number
197  *
198  * Return: Void.
199  */
200 void reg_freq_to_chan_op_class(struct wlan_objmgr_pdev *pdev,
201 			       qdf_freq_t freq,
202 			       bool global_tbl_lookup,
203 			       uint16_t behav_limit,
204 			       uint8_t *op_class,
205 			       uint8_t *chan_num);
206 
207 /**
208  * reg_is_freq_in_country_opclass() - check for frequency in (tbl, oper class)
209  *
210  * @pdev: pdev pointer
211  * @country: country from country IE
212  * @op_class: operating class
213  * @chan_freq: channel frequency in mhz
214  *
215  * Return: bool
216  */
217 bool reg_is_freq_in_country_opclass(struct wlan_objmgr_pdev *pdev,
218 				    const uint8_t country[3],
219 				    uint8_t op_class,
220 				    qdf_freq_t chan_freq);
221 #endif
222 
223 /**
224  * reg_get_op_class_width() - get oper class width
225  *
226  * @pdev: pdev pointer
227  * @global_tbl_lookup: whether to lookup global op class tbl
228  * @op_class: operating class
229  * Return: uint16
230  */
231 uint16_t reg_get_op_class_width(struct wlan_objmgr_pdev *pdev,
232 				uint8_t op_class,
233 				bool global_tbl_lookup);
234 
235 #ifdef HOST_OPCLASS_EXT
236 /**
237  * reg_country_chan_opclass_to_freq() - Convert channel number to frequency
238  * based on country code and op class
239  * @pdev: pdev object.
240  * @country: country code.
241  * @chan: IEEE Channel Number.
242  * @op_class: Opclass.
243  * @strict: flag to find channel from matched operating class code.
244  *
245  * Look up (channel, operating class) pair in country operating class tables
246  * and return the channel frequency.
247  * If not found and "strict" flag is false, try to get frequency (Mhz) by
248  * channel number only.
249  *
250  * Return: Channel center frequency else return 0.
251  */
252 qdf_freq_t reg_country_chan_opclass_to_freq(struct wlan_objmgr_pdev *pdev,
253 					    const uint8_t country[3],
254 					    uint8_t chan, uint8_t op_class,
255 					    bool strict);
256 #endif
257 
258 /**
259  * reg_chan_opclass_to_freq() - Convert channel number and opclass to frequency
260  * @chan: IEEE Channel Number.
261  * @op_class: Opclass.
262  * @global_tbl_lookup: Global table lookup.
263  *
264  * Return: Channel center frequency else return 0.
265  */
266 uint16_t reg_chan_opclass_to_freq(uint8_t chan,
267 				  uint8_t op_class,
268 				  bool global_tbl_lookup);
269 
270 /**
271  * reg_chan_opclass_to_freq_auto() - Convert channel number and opclass to
272  * frequency after fixing global_tbl_lookup
273  * @chan: IEEE Channel Number.
274  * @op_class: Opclass.
275  * @global_tbl_lookup: Global table lookup.
276  *
277  * Return: Channel center frequency else return 0.
278  */
279 qdf_freq_t reg_chan_opclass_to_freq_auto(uint8_t chan, uint8_t op_class,
280 					 bool global_tbl_lookup);
281 
282 #else
283 
284 static inline uint16_t reg_dmn_get_chanwidth_from_opclass(
285 		uint8_t *country, uint8_t channel, uint8_t opclass)
286 {
287 	return 0;
288 }
289 
290 static inline uint16_t reg_dmn_set_curr_opclasses(
291 		uint8_t num_classes, uint8_t *class)
292 {
293 	return 0;
294 }
295 
296 static inline uint16_t reg_dmn_get_curr_opclasses(
297 		uint8_t *num_classes, uint8_t *class)
298 {
299 	return 0;
300 }
301 
302 static inline uint16_t reg_dmn_get_opclass_from_channel(
303 		uint8_t *country, uint8_t channel, uint8_t offset)
304 {
305 	return 0;
306 }
307 
308 static inline
309 uint8_t reg_dmn_get_opclass_from_freq_width(uint8_t *country,
310 					    qdf_freq_t freq,
311 					    uint8_t ch_width,
312 					    uint16_t behav_limit)
313 {
314 	return 0;
315 }
316 
317 static inline
318 uint8_t reg_get_band_cap_from_op_class(const uint8_t *country,
319 				       uint8_t num_of_opclass,
320 				       const uint8_t *opclass)
321 {
322 	return 0;
323 }
324 
325 static inline void reg_dmn_print_channels_in_opclass(uint8_t *country,
326 						     uint8_t op_class)
327 {
328 }
329 
330 static inline
331 QDF_STATUS reg_get_opclass_details(struct wlan_objmgr_pdev *pdev,
332 				   struct regdmn_ap_cap_opclass_t *reg_ap_cap,
333 				   uint8_t *n_opclasses,
334 				   uint8_t max_supp_op_class,
335 				   bool global_tbl_lookup)
336 {
337 	return QDF_STATUS_E_FAILURE;
338 }
339 
340 static inline
341 bool reg_is_5ghz_op_class(const uint8_t *country, uint8_t op_class)
342 {
343 	return false;
344 }
345 
346 static inline
347 bool reg_is_2ghz_op_class(const uint8_t *country, uint8_t op_class)
348 {
349 	return false;
350 }
351 
352 #ifdef CONFIG_CHAN_FREQ_API
353 
354 static inline void
355 reg_freq_width_to_chan_op_class(struct wlan_objmgr_pdev *pdev,
356 				qdf_freq_t freq,
357 				uint16_t chan_width,
358 				bool global_tbl_lookup,
359 				uint16_t behav_limit,
360 				uint8_t *op_class,
361 				uint8_t *chan_num)
362 {
363 }
364 
365 static inline void
366 reg_freq_width_to_chan_op_class_auto(struct wlan_objmgr_pdev *pdev,
367 				     qdf_freq_t freq,
368 				     uint16_t chan_width,
369 				     bool global_tbl_lookup,
370 				     uint16_t behav_limit,
371 				     uint8_t *op_class,
372 				     uint8_t *chan_num)
373 {
374 }
375 
376 static inline void
377 reg_freq_to_chan_op_class(struct wlan_objmgr_pdev *pdev,
378 			  qdf_freq_t freq,
379 			  bool global_tbl_lookup,
380 			  uint16_t behav_limit,
381 			  uint8_t *op_class,
382 			  uint8_t *chan_num)
383 {
384 }
385 
386 static inline bool
387 reg_is_freq_in_country_opclass(struct wlan_objmgr_pdev *pdev,
388 			       const uint8_t country[3],
389 			       uint8_t op_class,
390 			       uint16_t chan_freq)
391 {
392 	return false;
393 }
394 
395 #endif
396 
397 static inline uint16_t reg_get_op_class_width(struct wlan_objmgr_pdev *pdev,
398 					      uint8_t op_class,
399 					      bool global_tbl_lookup)
400 {
401 	return 0;
402 }
403 
404 #ifdef HOST_OPCLASS_EXT
405 static inline
406 qdf_freq_t reg_country_chan_opclass_to_freq(struct wlan_objmgr_pdev *pdev,
407 					    const uint8_t country[3],
408 					    uint8_t chan, uint8_t op_class,
409 					    bool strict)
410 {
411 	return 0;
412 }
413 #endif
414 
415 static inline uint16_t
416 reg_chan_opclass_to_freq(uint8_t chan,
417 			 uint8_t op_class,
418 			 bool global_tbl_lookup)
419 {
420 	return 0;
421 }
422 
423 static inline qdf_freq_t
424 reg_chan_opclass_to_freq_auto(uint8_t chan, uint8_t op_class,
425 			      bool global_tbl_lookup)
426 {
427 	return 0;
428 }
429 #endif
430 
431 /**
432  * reg_dmn_get_chanwidth_from_opclass_auto()- Get channel width for the
433  * given channel and opclass. If not found then search it in the global
434  * op class.
435  * @country - Country
436  * @channel - Channel for which channel spacing is required
437  * @opclass - Opclass to search from.
438  *
439  * Return: valid channel spacing if found. If not found then
440  * return 0.
441  */
442 uint16_t reg_dmn_get_chanwidth_from_opclass_auto(uint8_t *country,
443 						 uint8_t channel,
444 						 uint8_t opclass);
445 #endif
446