xref: /wlan-dirver/qca-wifi-host-cmn/umac/regulatory/core/src/reg_opclass.h (revision d0c05845839e5f2ba5a8dcebe0cd3e4cd4e8dfcf)
1 /*
2  * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
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 CONFIG_AFC_SUPPORT
29 #include <wlan_reg_afc.h>
30 #endif
31 
32 #define OPCLS_132 132
33 
34 #ifdef HOST_OPCLASS
35 /**
36  * reg_dmn_get_chanwidth_from_opclass() - Get channel width from opclass.
37  * @country: Country code
38  * @channel: Channel number
39  * @opclass: Operating class
40  *
41  * Return: Channel width
42  */
43 uint16_t reg_dmn_get_chanwidth_from_opclass(uint8_t *country, uint8_t channel,
44 					    uint8_t opclass);
45 
46 /**
47  * reg_dmn_get_opclass_from_channel() - Get operating class from channel.
48  * @country: Country code.
49  * @channel: Channel number.
50  * @offset: Operating class offset.
51  *
52  * Return: Error code.
53  */
54 uint16_t reg_dmn_get_opclass_from_channel(uint8_t *country, uint8_t channel,
55 					  uint8_t offset);
56 
57 /**
58  * reg_dmn_get_opclass_from_freq_width() - Get operating class from frequency
59  * @country: Country code.
60  * @freq: Channel center frequency.
61  * @ch_width: Channel width.
62  * @behav_limit: Behaviour limit.
63  *
64  * Return: Error code.
65  */
66 uint8_t reg_dmn_get_opclass_from_freq_width(uint8_t *country,
67 					    qdf_freq_t freq,
68 					    uint16_t ch_width,
69 					    uint16_t behav_limit);
70 
71 /**
72  * reg_get_band_cap_from_op_class() - Return band capability bitmap
73  * @country: Pointer to Country code.
74  * @num_of_opclass: Number of Operating class.
75  * @opclass: Pointer to opclass.
76  *
77  * Return supported band bitmap based on the input operating class list
78  * provided.
79  *
80  * Return: Return supported band capability
81  */
82 uint8_t reg_get_band_cap_from_op_class(const uint8_t *country,
83 				       uint8_t num_of_opclass,
84 				       const uint8_t *opclass);
85 
86 /**
87  * reg_dmn_get_opclass_from_channe() - Print channels in op class.
88  * @country: Country code.
89  * @opclass: opclass.
90  *
91  * Return: Void.
92  */
93 void reg_dmn_print_channels_in_opclass(uint8_t *country, uint8_t op_class);
94 
95 /**
96  * reg_dmn_set_curr_opclasses() - Set current operating class
97  * @num_classes: Number of classes
98  * @class: Pointer to operating class.
99  *
100  * Return: Error code.
101  */
102 uint16_t reg_dmn_set_curr_opclasses(uint8_t num_classes, uint8_t *class);
103 
104 /**
105  * reg_dmn_get_curr_opclasses() - Get current supported operating classes.
106  * @num_classes: Number of classes.
107  * @class: Pointer to operating class.
108  *
109  * Return: Error code.
110  */
111 uint16_t reg_dmn_get_curr_opclasses(uint8_t *num_classes, uint8_t *class);
112 
113 /**
114  * reg_get_opclass_details() - Get details about the current opclass table.
115  * @pdev: Pointer to pdev.
116  * @reg_ap_cap: Pointer to reg_ap_cap.
117  * @n_opclasses: Pointer to number of opclasses.
118  * @max_supp_op_class: Maximum number of operating classes supported.
119  * @global_tbl_lookup: Whether to lookup global op class table.
120  *
121  * Return: QDF_STATUS_SUCCESS if success, else return QDF_STATUS_FAILURE.
122  */
123 QDF_STATUS reg_get_opclass_details(struct wlan_objmgr_pdev *pdev,
124 				   struct regdmn_ap_cap_opclass_t *reg_ap_cap,
125 				   uint8_t *n_opclasses,
126 				   uint8_t max_supp_op_class,
127 				   bool global_tbl_lookup);
128 
129 /**
130  * reg_get_opclass_for_cur_hwmode() - Get details about the opclasses for
131  * the current hwmode.
132  * @pdev: Pointer to pdev.
133  * @reg_ap_cap: Pointer to reg_ap_cap.
134  * @n_opclasses: Pointer to number of opclasses.
135  * @max_supp_op_class: Maximum number of operating classes supported.
136  * @global_tbl_lookup: Whether to lookup global op class table.
137  * @max_chwidth: Max channel width supported by cur hwmode
138  * @is_80p80_supp: Bool to indicate if 80p80 is supported
139  *
140  * Return: QDF_STATUS_SUCCESS if success, else return QDF_STATUS_FAILURE.
141  */
142 QDF_STATUS
143 reg_get_opclass_for_cur_hwmode(struct wlan_objmgr_pdev *pdev,
144 			       struct regdmn_ap_cap_opclass_t *reg_ap_cap,
145 			       uint8_t *n_opclasses,
146 			       uint8_t max_supp_op_class,
147 			       bool global_tbl_lookup,
148 			       enum phy_ch_width max_chwidth,
149 			       bool is_80p80_supp);
150 /**
151  * reg_is_5ghz_op_class() - Check if the input opclass is a 5GHz opclass.
152  * @country: Country code.
153  * @op_class: Operating class.
154  *
155  * Return: Return true if input the opclass is a 5GHz opclass,
156  * else return false.
157  */
158 bool reg_is_5ghz_op_class(const uint8_t *country, uint8_t op_class);
159 
160 /**
161  * reg_is_2ghz_op_class() - Check if the input opclass is a 2.4GHz opclass.
162  * @country: Country code.
163  * @op_class: Operating class.
164  *
165  * Return: Return true if input the opclass is a 2.4GHz opclass,
166  * else return false.
167  */
168 bool reg_is_2ghz_op_class(const uint8_t *country, uint8_t op_class);
169 
170 #ifdef CONFIG_CHAN_FREQ_API
171 
172 /**
173  * reg_freq_width_to_chan_op_class() - convert frequency to oper class,
174  *                                     channel
175  * @pdev: pdev pointer
176  * @freq: channel frequency in mhz
177  * @chan_width: channel width
178  * @global_tbl_lookup: whether to lookup global op class tbl
179  * @behav_limit: behavior limit
180  * @op_class: operating class
181  * @chan_num: channel number
182  *
183  * Return: Void.
184  */
185 void reg_freq_width_to_chan_op_class(struct wlan_objmgr_pdev *pdev,
186 				     qdf_freq_t freq,
187 				     uint16_t chan_width,
188 				     bool global_tbl_lookup,
189 				     uint16_t behav_limit,
190 				     uint8_t *op_class,
191 				     uint8_t *chan_num);
192 
193 /**
194  * reg_freq_width_to_chan_op_class_auto() - convert frequency to operating
195  * class,channel after fixing up the global_tbl_lookup and behav_limit
196  * for 6G frequencies.
197  * @pdev: pdev pointer
198  * @freq: channel frequency in mhz
199  * @chan_width: channel width
200  * @global_tbl_lookup: whether to lookup global op class tbl
201  * @behav_limit: behavior limit
202  * @op_class: operating class
203  * @chan_num: channel number
204  *
205  * Return: Void.
206  */
207 void reg_freq_width_to_chan_op_class_auto(struct wlan_objmgr_pdev *pdev,
208 					  qdf_freq_t freq,
209 					  uint16_t chan_width,
210 					  bool global_tbl_lookup,
211 					  uint16_t behav_limit,
212 					  uint8_t *op_class,
213 					  uint8_t *chan_num);
214 
215 /**
216  * reg_freq_to_chan_op_class() - convert frequency to oper class,
217  *                                   channel
218  * @pdev: pdev pointer
219  * @freq: channel frequency in mhz
220  * @global_tbl_lookup: whether to lookup global op class tbl
221  * @behav_limit: behavior limit
222  * @op_class: operating class
223  * @chan_num: channel number
224  *
225  * Return: Void.
226  */
227 void reg_freq_to_chan_op_class(struct wlan_objmgr_pdev *pdev,
228 			       qdf_freq_t freq,
229 			       bool global_tbl_lookup,
230 			       uint16_t behav_limit,
231 			       uint8_t *op_class,
232 			       uint8_t *chan_num);
233 
234 /**
235  * reg_is_freq_in_country_opclass() - check for frequency in (tbl, oper class)
236  *
237  * @pdev: pdev pointer
238  * @country: country from country IE
239  * @op_class: operating class
240  * @chan_freq: channel frequency in mhz
241  *
242  * Return: bool
243  */
244 bool reg_is_freq_in_country_opclass(struct wlan_objmgr_pdev *pdev,
245 				    const uint8_t country[3],
246 				    uint8_t op_class,
247 				    qdf_freq_t chan_freq);
248 #endif
249 
250 /**
251  * reg_get_op_class_width() - get oper class width
252  *
253  * @pdev: pdev pointer
254  * @global_tbl_lookup: whether to lookup global op class tbl
255  * @op_class: operating class
256  * Return: uint16
257  */
258 uint16_t reg_get_op_class_width(struct wlan_objmgr_pdev *pdev,
259 				uint8_t op_class,
260 				bool global_tbl_lookup);
261 
262 #ifdef HOST_OPCLASS_EXT
263 /**
264  * reg_country_chan_opclass_to_freq() - Convert channel number to frequency
265  * based on country code and op class
266  * @pdev: pdev object.
267  * @country: country code.
268  * @chan: IEEE Channel Number.
269  * @op_class: Opclass.
270  * @strict: flag to find channel from matched operating class code.
271  *
272  * Look up (channel, operating class) pair in country operating class tables
273  * and return the channel frequency.
274  * If not found and "strict" flag is false, try to get frequency (Mhz) by
275  * channel number only.
276  *
277  * Return: Channel center frequency else return 0.
278  */
279 qdf_freq_t reg_country_chan_opclass_to_freq(struct wlan_objmgr_pdev *pdev,
280 					    const uint8_t country[3],
281 					    uint8_t chan, uint8_t op_class,
282 					    bool strict);
283 #endif
284 
285 /**
286  * reg_chan_opclass_to_freq() - Convert channel number and opclass to frequency
287  * @chan: IEEE Channel Number.
288  * @op_class: Opclass.
289  * @global_tbl_lookup: Global table lookup.
290  *
291  * Return: Channel center frequency else return 0.
292  */
293 uint16_t reg_chan_opclass_to_freq(uint8_t chan,
294 				  uint8_t op_class,
295 				  bool global_tbl_lookup);
296 
297 /**
298  * reg_chan_opclass_to_freq_auto() - Convert channel number and opclass to
299  * frequency after fixing global_tbl_lookup
300  * @chan: IEEE Channel Number.
301  * @op_class: Opclass.
302  * @global_tbl_lookup: Global table lookup.
303  *
304  * Return: Channel center frequency else return 0.
305  */
306 qdf_freq_t reg_chan_opclass_to_freq_auto(uint8_t chan, uint8_t op_class,
307 					 bool global_tbl_lookup);
308 
309 #else
310 
311 static inline uint16_t reg_dmn_get_chanwidth_from_opclass(
312 		uint8_t *country, uint8_t channel, uint8_t opclass)
313 {
314 	return 0;
315 }
316 
317 static inline uint16_t reg_dmn_set_curr_opclasses(
318 		uint8_t num_classes, uint8_t *class)
319 {
320 	return 0;
321 }
322 
323 static inline uint16_t reg_dmn_get_curr_opclasses(
324 		uint8_t *num_classes, uint8_t *class)
325 {
326 	return 0;
327 }
328 
329 static inline uint16_t reg_dmn_get_opclass_from_channel(
330 		uint8_t *country, uint8_t channel, uint8_t offset)
331 {
332 	return 0;
333 }
334 
335 static inline
336 uint8_t reg_dmn_get_opclass_from_freq_width(uint8_t *country,
337 					    qdf_freq_t freq,
338 					    uint16_t ch_width,
339 					    uint16_t behav_limit)
340 {
341 	return 0;
342 }
343 
344 static inline
345 uint8_t reg_get_band_cap_from_op_class(const uint8_t *country,
346 				       uint8_t num_of_opclass,
347 				       const uint8_t *opclass)
348 {
349 	return 0;
350 }
351 
352 static inline void reg_dmn_print_channels_in_opclass(uint8_t *country,
353 						     uint8_t op_class)
354 {
355 }
356 
357 static inline
358 QDF_STATUS reg_get_opclass_details(struct wlan_objmgr_pdev *pdev,
359 				   struct regdmn_ap_cap_opclass_t *reg_ap_cap,
360 				   uint8_t *n_opclasses,
361 				   uint8_t max_supp_op_class,
362 				   bool global_tbl_lookup)
363 {
364 	return QDF_STATUS_E_FAILURE;
365 }
366 
367 static inline
368 bool reg_is_5ghz_op_class(const uint8_t *country, uint8_t op_class)
369 {
370 	return false;
371 }
372 
373 static inline
374 bool reg_is_2ghz_op_class(const uint8_t *country, uint8_t op_class)
375 {
376 	return false;
377 }
378 
379 static inline QDF_STATUS
380 reg_get_opclass_for_cur_hwmode(struct wlan_objmgr_pdev *pdev,
381 			       struct regdmn_ap_cap_opclass_t *reg_ap_cap,
382 			       uint8_t *n_opclasses,
383 			       uint8_t max_supp_op_class,
384 			       bool global_tbl_lookup,
385 			       enum phy_ch_width max_ch_width,
386 			       bool is_80p80_supp)
387 {
388 	return QDF_STATUS_E_FAILURE;
389 }
390 
391 #ifdef CONFIG_CHAN_FREQ_API
392 
393 static inline void
394 reg_freq_width_to_chan_op_class(struct wlan_objmgr_pdev *pdev,
395 				qdf_freq_t freq,
396 				uint16_t chan_width,
397 				bool global_tbl_lookup,
398 				uint16_t behav_limit,
399 				uint8_t *op_class,
400 				uint8_t *chan_num)
401 {
402 }
403 
404 static inline void
405 reg_freq_width_to_chan_op_class_auto(struct wlan_objmgr_pdev *pdev,
406 				     qdf_freq_t freq,
407 				     uint16_t chan_width,
408 				     bool global_tbl_lookup,
409 				     uint16_t behav_limit,
410 				     uint8_t *op_class,
411 				     uint8_t *chan_num)
412 {
413 }
414 
415 static inline void
416 reg_freq_to_chan_op_class(struct wlan_objmgr_pdev *pdev,
417 			  qdf_freq_t freq,
418 			  bool global_tbl_lookup,
419 			  uint16_t behav_limit,
420 			  uint8_t *op_class,
421 			  uint8_t *chan_num)
422 {
423 }
424 
425 static inline bool
426 reg_is_freq_in_country_opclass(struct wlan_objmgr_pdev *pdev,
427 			       const uint8_t country[3],
428 			       uint8_t op_class,
429 			       uint16_t chan_freq)
430 {
431 	return false;
432 }
433 
434 #endif
435 
436 static inline uint16_t reg_get_op_class_width(struct wlan_objmgr_pdev *pdev,
437 					      uint8_t op_class,
438 					      bool global_tbl_lookup)
439 {
440 	return 0;
441 }
442 
443 #ifdef HOST_OPCLASS_EXT
444 static inline
445 qdf_freq_t reg_country_chan_opclass_to_freq(struct wlan_objmgr_pdev *pdev,
446 					    const uint8_t country[3],
447 					    uint8_t chan, uint8_t op_class,
448 					    bool strict)
449 {
450 	return 0;
451 }
452 #endif
453 
454 static inline uint16_t
455 reg_chan_opclass_to_freq(uint8_t chan,
456 			 uint8_t op_class,
457 			 bool global_tbl_lookup)
458 {
459 	return 0;
460 }
461 
462 static inline qdf_freq_t
463 reg_chan_opclass_to_freq_auto(uint8_t chan, uint8_t op_class,
464 			      bool global_tbl_lookup)
465 {
466 	return 0;
467 }
468 #endif
469 
470 /**
471  * reg_dmn_get_chanwidth_from_opclass_auto()- Get channel width for the
472  * given channel and opclass. If not found then search it in the global
473  * op class.
474  * @country - Country
475  * @channel - Channel for which channel spacing is required
476  * @opclass - Opclass to search from.
477  *
478  * Return: valid channel spacing if found. If not found then
479  * return 0.
480  */
481 uint16_t reg_dmn_get_chanwidth_from_opclass_auto(uint8_t *country,
482 						 uint8_t channel,
483 						 uint8_t opclass);
484 
485 #ifdef CONFIG_AFC_SUPPORT
486 
487 /**
488  * reg_dmn_get_6g_opclasses_and_channels()- Get the following from the
489  * operating class table for 6Ghz band: number of operating classes, list of
490  * opclasses, list channel sizes, list of channel lists.
491  * @p_frange_lst: Pointer to frequencey range list (AFC)
492  * @pdev: Pointer to pdev.
493  * @num_opclasses: Pointer to number of operating classes. This is the number
494  * of elements in the list array arguments
495  * @opclas_lst: Pointer to pointer to memory of list of opclasses
496  * @chansize_lst: Pointer to pointer to memory of list of channel sizes
497  * @channel_lists: Array of pointers to pointer to memory of list of channels
498  *
499  * Return: QDF_STATUS
500  * NOTE:- All memory allocations done by this function should be freed by the
501  *        caller. The caller may use the function
502  *        'reg_dmn_free_6g_opclasses_and_channels' to free the allocations.
503  */
504 
505 QDF_STATUS reg_dmn_get_6g_opclasses_and_channels(struct wlan_objmgr_pdev *pdev,
506 						 struct wlan_afc_frange_list *p_frange_lst,
507 						 uint8_t *num_opclasses,
508 						 uint8_t **opclass_lst,
509 						 uint8_t **chansize_lst,
510 						 uint8_t **channel_lists[]);
511 
512 /**
513  * reg_dmn_free_6g_opclasses_and_channels()- Free the memory allocated by
514  * the pointers and arrays indicated by the arguments.
515  * @pdev: Pointer to pdev.
516  * @num_opclasses: Number of operating classes. This is the number of
517  * elements in the 'channel_lists' array.
518  * @opclas_lst: Pointer to memory of list of opclasses
519  * @chansize_lst: Pointer to memory of list of channel sizes
520  * @channel_lists: Array of pointers to memory of list of channels
521  *
522  * Return: void
523  */
524 void reg_dmn_free_6g_opclasses_and_channels(struct wlan_objmgr_pdev *pdev,
525 					    uint8_t num_opclasses,
526 					    uint8_t *opclass_lst,
527 					    uint8_t *chansize_lst,
528 					    uint8_t *channel_lists[]);
529 #endif
530 #endif
531