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