xref: /wlan-dirver/qca-wifi-host-cmn/umac/regulatory/dispatcher/inc/wlan_reg_services_api.h (revision dae10a5fbc53d54c53c4ba24fa018ad8b1e7c008)
1 /*
2  * Copyright (c) 2017-2018 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /**
20  * DOC: wlan_reg_services_api.h
21  * This file provides prototypes of the routines needed for the
22  * external components to utilize the services provided by the
23  * regulatory component.
24  */
25 
26 #ifndef __WLAN_REG_SERVICES_API_H
27 #define __WLAN_REG_SERVICES_API_H
28 
29 #include "../../core/src/reg_services.h"
30 #include <reg_services_public_struct.h>
31 
32 
33 #define WLAN_REG_MIN_24GHZ_CH_NUM REG_MIN_24GHZ_CH_NUM
34 #define WLAN_REG_MAX_24GHZ_CH_NUM REG_MAX_24GHZ_CH_NUM
35 #define WLAN_REG_MIN_5GHZ_CH_NUM REG_MIN_5GHZ_CH_NUM
36 #define WLAN_REG_MAX_5GHZ_CH_NUM REG_MAX_5GHZ_CH_NUM
37 
38 #define WLAN_REG_IS_24GHZ_CH(chan) REG_IS_24GHZ_CH(chan)
39 #define WLAN_REG_IS_5GHZ_CH(chan) REG_IS_5GHZ_CH(chan)
40 
41 #define WLAN_REG_IS_24GHZ_CH_FREQ(freq) REG_IS_24GHZ_CH_FREQ(freq)
42 
43 #ifndef CONFIG_LEGACY_CHAN_ENUM
44 #define WLAN_REG_IS_49GHZ_FREQ(freq) REG_IS_49GHZ_FREQ(freq)
45 #endif
46 
47 #define WLAN_REG_CH_NUM(ch_enum) REG_CH_NUM(ch_enum)
48 #define WLAN_REG_CH_TO_FREQ(ch_enum) REG_CH_TO_FREQ(ch_enum)
49 
50 #define WLAN_REG_IS_SAME_BAND_CHANNELS(chan_num1, chan_num2) \
51 	(chan_num1 && chan_num2 &&					\
52 	(WLAN_REG_IS_5GHZ_CH(chan_num1) == WLAN_REG_IS_5GHZ_CH(chan_num2)))
53 
54 
55 #define WLAN_REG_IS_CHANNEL_VALID_5G_SBS(curchan, newchan) \
56 	(curchan > newchan ?				   \
57 	 REG_CH_TO_FREQ(reg_get_chan_enum(curchan))	   \
58 	 - REG_CH_TO_FREQ(reg_get_chan_enum(newchan))	   \
59 	 > REG_SBS_SEPARATION_THRESHOLD :		   \
60 	 REG_CH_TO_FREQ(reg_get_chan_enum(newchan))	   \
61 	 - REG_CH_TO_FREQ(reg_get_chan_enum(curchan))	   \
62 	 > REG_SBS_SEPARATION_THRESHOLD)
63 
64 #define WLAN_REG_INVALID_CHANNEL_ID
65 #define WLAN_REG_GET_24_END_CHAN_NUM 14
66 
67 #define WLAN_REG_CHAN_TO_BAND(chan_num)  reg_chan_to_band(chan_num)
68 
69 /**
70  * wlan_reg_get_channel_list_with_power() - Provide the channel list with power
71  * @ch_list: pointer to the channel list.
72  *
73  * Return: QDF_STATUS
74  */
75 QDF_STATUS wlan_reg_get_channel_list_with_power(struct wlan_objmgr_pdev *pdev,
76 						struct channel_power *ch_list,
77 						uint8_t *num_chan);
78 
79 /**
80  * wlan_reg_read_default_country() - Read the default country for the regdomain
81  * @country: pointer to the country code.
82  *
83  * Return: QDF_STATUS
84  */
85 QDF_STATUS wlan_reg_read_default_country(struct wlan_objmgr_psoc *psoc,
86 				   uint8_t *country);
87 
88 /**
89  * wlan_reg_read_current_country() - Read the current country for the regdomain
90  * @country: pointer to the country code.
91  *
92  * Return: QDF_STATUS
93  */
94 QDF_STATUS wlan_reg_read_current_country(struct wlan_objmgr_psoc *psoc,
95 				   uint8_t *country);
96 
97 /**
98  * wlan_reg_get_channel_state() - Get channel state from regulatory
99  * @ch: channel number.
100  *
101  * Return: channel state
102  */
103 enum channel_state wlan_reg_get_channel_state(struct wlan_objmgr_pdev *pdev,
104 					      uint32_t ch);
105 
106 /**
107  * wlan_reg_chan_has_dfs_attribute() - check channel has dfs attribute flag
108  * @ch: channel number.
109  *
110  * This API get chan initial dfs attribute from regdomain
111  *
112  * Return: true if chan is dfs, otherwise false
113  */
114 bool
115 wlan_reg_chan_has_dfs_attribute(struct wlan_objmgr_pdev *pdev, uint32_t ch);
116 
117 /**
118  * wlan_reg_get_5g_bonded_channel_state() - Get 5G bonded channel state
119  * @pdev: The physical dev to program country code or regdomain
120  * @ch: channel number.
121  * @bw: channel band width
122  *
123  * Return: channel state
124  */
125 enum channel_state wlan_reg_get_5g_bonded_channel_state(
126 		struct wlan_objmgr_pdev *pdev, uint8_t ch,
127 		enum phy_ch_width bw);
128 
129 /**
130  * wlan_reg_get_2g_bonded_channel_state() - Get 2G bonded channel state
131  * @pdev: The physical dev to program country code or regdomain
132  * @ch: channel number.
133  * @sec_ch: Secondary channel.
134  * @bw: channel band width
135  *
136  * Return: channel state
137  */
138 enum channel_state wlan_reg_get_2g_bonded_channel_state(
139 		struct wlan_objmgr_pdev *pdev, uint8_t ch,
140 		uint8_t sec_ch, enum phy_ch_width bw);
141 
142 /**
143  * wlan_reg_set_channel_params () - Sets channel parameteres for given bandwidth
144  * @pdev: The physical dev to program country code or regdomain
145  * @ch: channel number.
146  * @sec_ch_2g: Secondary channel.
147  * @ch_params: pointer to the channel parameters.
148  *
149  * Return: None
150  */
151 void wlan_reg_set_channel_params(struct wlan_objmgr_pdev *pdev, uint8_t ch,
152 				 uint8_t sec_ch_2g,
153 				 struct ch_params *ch_params);
154 
155 /**
156  * wlan_reg_get_dfs_region () - Get the current dfs region
157  * @dfs_reg: pointer to dfs region
158  *
159  * Return: Status
160  */
161 QDF_STATUS wlan_reg_get_dfs_region(struct wlan_objmgr_pdev *pdev,
162 			     enum dfs_reg *dfs_reg);
163 
164 /**
165  * wlan_reg_get_channel_reg_power() - Provide the channel regulatory power
166  * @chan_num: chennal number
167  *
168  * Return: int
169  */
170 uint32_t wlan_reg_get_channel_reg_power(struct wlan_objmgr_pdev *pdev,
171 					uint32_t chan_num);
172 
173 /**
174  * wlan_reg_get_channel_freq() - provide the channel center freq
175  * @chan_num: chennal number
176  *
177  * Return: int
178  */
179 uint32_t wlan_reg_get_channel_freq(struct wlan_objmgr_pdev *pdev,
180 				   uint32_t chan_num);
181 
182 /**
183  * wlan_reg_get_current_chan_list() - provide the pdev current channel list
184  * @pdev: pdev pointer
185  * @chan_list: channel list pointer
186  *
187  * Return: QDF_STATUS
188  */
189 QDF_STATUS wlan_reg_get_current_chan_list(struct wlan_objmgr_pdev *pdev,
190 		struct regulatory_channel *chan_list);
191 /**
192  * wlan_reg_get_bonded_channel_state() - get bonded channel state
193  * @pdev: pdev ptr
194  * @ch: chennal number
195  * @bw: chennal number
196  * @sec_ch: secondary channel
197  *
198  * Return: enum channel_state
199  */
200 enum channel_state wlan_reg_get_bonded_channel_state(
201 	struct wlan_objmgr_pdev *pdev, uint8_t ch,
202 	enum phy_ch_width bw, uint8_t sec_ch);
203 
204 /**
205  * wlan_reg_set_dfs_region() - set the dfs region
206  * @pdev: pdev ptr
207  * @dfs_reg: dfs region
208  *
209  * Return: void
210  */
211 void wlan_reg_set_dfs_region(struct wlan_objmgr_pdev *pdev,
212 			     enum dfs_reg dfs_reg);
213 
214 /**
215  * wlan_reg_get_bw_value() - provide the channel center freq
216  * @chan_num: chennal number
217  *
218  * Return: int
219  */
220 uint16_t wlan_reg_get_bw_value(enum phy_ch_width bw);
221 
222 /**
223  * wlan_reg_get_domain_from_country_code() - provide the channel center freq
224  * @reg_domain_ptr: regulatory domain ptr
225  * @country_alpha2: country alpha2
226  * @source: alpha2 source
227  *
228  * Return: int
229  */
230 QDF_STATUS wlan_reg_get_domain_from_country_code(v_REGDOMAIN_t *reg_domain_ptr,
231 						 const uint8_t *country_alpha2,
232 						 enum country_src source);
233 
234 /**
235  * wlan_reg_dmn_get_opclass_from_channel() - provide the channel center freq
236  * @country: country alpha2
237  * @channel: channel number
238  * @offset: offset
239  *
240  * Return: int
241  */
242 uint16_t wlan_reg_dmn_get_opclass_from_channel(uint8_t *country,
243 					       uint8_t channel,
244 					       uint8_t offset);
245 
246 /**
247  * wlan_reg_dmn_get_chanwidth_from_opclass() - get channel width from
248  *                                             operating class
249  * @country: country alpha2
250  * @channel: channel number
251  * @opclass: operating class
252  *
253  * Return: int
254  */
255 uint16_t wlan_reg_dmn_get_chanwidth_from_opclass(uint8_t *country,
256 						 uint8_t channel,
257 						 uint8_t opclass);
258 /**
259  * wlan_reg_dmn_set_curr_opclasses() - set operating class
260  * @num_classes: number of classes
261  * @class: operating class
262  *
263  * Return: int
264  */
265 uint16_t wlan_reg_dmn_set_curr_opclasses(uint8_t num_classes,
266 					 uint8_t *class);
267 
268 /**
269  * wlan_reg_dmn_get_curr_opclasses() - get current oper classes
270  * @num_classes: number of classes
271  * @class: operating class
272  *
273  * Return: int
274  */
275 uint16_t wlan_reg_dmn_get_curr_opclasses(uint8_t *num_classes,
276 					 uint8_t *class);
277 
278 
279 /**
280  * wlan_regulatory_init() - init regulatory component
281  *
282  * Return: Success or Failure
283  */
284 QDF_STATUS wlan_regulatory_init(void);
285 
286 /**
287  * wlan_regulatory_deinit() - deinit regulatory component
288  *
289  * Return: Success or Failure
290  */
291 QDF_STATUS wlan_regulatory_deinit(void);
292 
293 /**
294  * regulatory_psoc_open() - open regulatory component
295  *
296  * Return: Success or Failure
297  */
298 QDF_STATUS regulatory_psoc_open(struct wlan_objmgr_psoc *psoc);
299 
300 
301 /**
302  * regulatory_psoc_close() - close regulatory component
303  *
304  * Return: Success or Failure
305  */
306 QDF_STATUS regulatory_psoc_close(struct wlan_objmgr_psoc *psoc);
307 
308 /**
309  * regulatory_pdev_open() - Open regulatory component
310  * @pdev: Pointer to pdev structure.
311  *
312  * Return: Success or Failure
313  */
314 QDF_STATUS regulatory_pdev_open(struct wlan_objmgr_pdev *pdev);
315 
316 /**
317  * regulatory_pdev_close() - Close regulatory component
318  * @pdev: Pointer to pdev structure.
319  *
320  * Return: Success or Failure
321  */
322 QDF_STATUS regulatory_pdev_close(struct wlan_objmgr_pdev *pdev);
323 
324 /**
325  * wlan_reg_update_nol_ch () - set nol channel
326  * @pdev: pdev ptr
327  * @ch_list: channel list to be returned
328  * @num_ch: number of channels
329  * @nol_ch: nol flag
330  *
331  * Return: void
332  */
333 void wlan_reg_update_nol_ch(struct wlan_objmgr_pdev *pdev,
334 			    uint8_t *ch_list,
335 			    uint8_t num_ch,
336 			    bool nol_ch);
337 
338 /**
339  * wlan_reg_is_dfs_ch () - Checks the channel state for DFS
340  * @pdev: pdev ptr
341  * @chan: channel
342  *
343  * Return: true or false
344  */
345 bool wlan_reg_is_dfs_ch(struct wlan_objmgr_pdev *pdev, uint32_t chan);
346 
347 /**
348  * wlan_reg_is_dsrc_chan () - Checks if the channel is dsrc channel or not
349  * @pdev: pdev ptr
350  * @chan_num: channel
351  *
352  * Return: true or false
353  */
354 bool wlan_reg_is_dsrc_chan(struct wlan_objmgr_pdev *pdev, uint8_t chan_num);
355 
356 /**
357  * wlan_reg_is_etsi13_srd_chan () - Checks if the ch is ETSI13 srd ch or not
358  * @pdev: pdev ptr
359  * @chan_num: channel
360  *
361  * Return: true or false
362  */
363 bool wlan_reg_is_etsi13_srd_chan(struct wlan_objmgr_pdev *pdev,
364 				 uint8_t chan_num);
365 
366 /**
367  * wlan_reg_is_etsi13_regdmn() - Checks if current reg domain is ETSI13 or not
368  * @pdev: pdev ptr
369  *
370  * Return: true or false
371  */
372 bool wlan_reg_is_etsi13_regdmn(struct wlan_objmgr_pdev *pdev);
373 
374 /**
375  * wlan_reg_is_etsi13_srd_chan_allowed_master_mode() - Checks if regdmn is
376  * ETSI13 and SRD channels are allowed in master mode or not.
377  *
378  * @pdev: pdev ptr
379  *
380  * Return: true or false
381  */
382 bool wlan_reg_is_etsi13_srd_chan_allowed_master_mode(struct wlan_objmgr_pdev
383 						     *pdev);
384 
385 /**
386  * wlan_reg_is_passive_or_disable_ch () - Checks chan state for passive
387  * and disabled
388  * @pdev: pdev ptr
389  * @chan: channel
390  *
391  * Return: true or false
392  */
393 bool wlan_reg_is_passive_or_disable_ch(struct wlan_objmgr_pdev *pdev,
394 				       uint32_t chan);
395 
396 /**
397  * wlan_reg_is_disable_ch () - Checks chan state for disabled
398  * @pdev: pdev ptr
399  * @chan: channel
400  *
401  * Return: true or false
402  */
403 bool wlan_reg_is_disable_ch(struct wlan_objmgr_pdev *pdev, uint32_t chan);
404 
405 /**
406  * wlan_reg_freq_to_chan () - convert channel freq to channel number
407  * @pdev: The physical dev to set current country for
408  * @freq: frequency
409  *
410  * Return: true or false
411  */
412 uint32_t wlan_reg_freq_to_chan(struct wlan_objmgr_pdev *pdev,
413 			       uint32_t freq);
414 
415 /**
416  * wlan_reg_chan_to_freq () - convert channel number to frequency
417  * @chan: channel number
418  *
419  * Return: true or false
420  */
421 uint32_t wlan_reg_chan_to_freq(struct wlan_objmgr_pdev *pdev,
422 			       uint32_t chan);
423 /**
424  * wlan_reg_is_world() - reg is world mode
425  * @country: The country information
426  *
427  * Return: true or false
428  */
429 bool wlan_reg_is_world(uint8_t *country);
430 
431 /**
432  * wlan_reg_is_us() - reg is us country
433  * @country: The country information
434  *
435  * Return: true or false
436  */
437 bool wlan_reg_is_us(uint8_t *country);
438 
439 /**
440  * wlan_reg_chan_is_49ghz() - Check if the input channel number is 4.9GHz
441  * @pdev: Pdev pointer
442  * @chan_num: Input channel number
443  *
444  * Return: true if the channel is 4.9GHz else false.
445  */
446 
447 bool wlan_reg_chan_is_49ghz(struct wlan_objmgr_pdev *pdev,
448 		uint8_t chan_num);
449 
450 /**
451  * wlan_reg_set_country() - Set the current regulatory country
452  * @pdev: The physical dev to set current country for
453  * @country: The country information to configure
454  *
455  * Return: QDF_STATUS
456  */
457 QDF_STATUS wlan_reg_set_country(struct wlan_objmgr_pdev *pdev,
458 				uint8_t *country);
459 
460 /**
461  * wlan_reg_set_11d_country() - Set the 11d regulatory country
462  * @pdev: The physical dev to set current country for
463  * @country: The country information to configure
464  *
465  * Return: QDF_STATUS
466  */
467 QDF_STATUS wlan_reg_set_11d_country(struct wlan_objmgr_pdev *pdev,
468 				    uint8_t *country);
469 
470 /**
471  * wlan_reg_register_chan_change_callback () - add chan change cbk
472  * @psoc: psoc ptr
473  * @cbk: callback
474  * @arg: argument
475  *
476  * Return: true or false
477  */
478 void wlan_reg_register_chan_change_callback(struct wlan_objmgr_psoc *psoc,
479 					    reg_chan_change_callback cbk,
480 					    void *arg);
481 
482 /**
483  * wlan_reg_unregister_chan_change_callback () - remove chan change cbk
484  * @psoc: psoc ptr
485  * @cbk:callback
486  *
487  * Return: true or false
488  */
489 void wlan_reg_unregister_chan_change_callback(struct wlan_objmgr_psoc *psoc,
490 					      reg_chan_change_callback cbk);
491 
492 /**
493  * wlan_reg_is_11d_offloaded() - 11d offloaded supported
494  * @psoc: psoc ptr
495  *
496  * Return: bool
497  */
498 bool wlan_reg_is_11d_offloaded(struct wlan_objmgr_psoc *psoc);
499 
500 /**
501  * wlan_reg_11d_enabled_on_host() - 11d enabled don host
502  * @psoc: psoc ptr
503  *
504  * Return: bool
505  */
506 bool wlan_reg_11d_enabled_on_host(struct wlan_objmgr_psoc *psoc);
507 
508 /**
509  * wlan_reg_get_chip_mode() - get supported chip mode
510  * @pdev: pdev pointer
511  * @chip_mode: chip mode
512  *
513  * Return: QDF STATUS
514  */
515 QDF_STATUS wlan_reg_get_chip_mode(struct wlan_objmgr_pdev *pdev,
516 		uint32_t *chip_mode);
517 
518 /**
519  * wlan_reg_is_11d_scan_inprogress() - checks 11d scan status
520  * @psoc: psoc ptr
521  *
522  * Return: bool
523  */
524 bool wlan_reg_is_11d_scan_inprogress(struct wlan_objmgr_psoc *psoc);
525 /**
526  * wlan_reg_get_freq_range() - Get 2GHz and 5GHz frequency range
527  * @pdev: pdev pointer
528  * @low_2g: low 2GHz frequency range
529  * @high_2g: high 2GHz frequency range
530  * @low_5g: low 5GHz frequency range
531  * @high_5g: high 5GHz frequency range
532  *
533  * Return: QDF status
534  */
535 QDF_STATUS wlan_reg_get_freq_range(struct wlan_objmgr_pdev *pdev,
536 		uint32_t *low_2g,
537 		uint32_t *high_2g,
538 		uint32_t *low_5g,
539 		uint32_t *high_5g);
540 /**
541  * wlan_reg_get_tx_ops () - get regulatory tx ops
542  * @psoc: psoc ptr
543  *
544  */
545 struct wlan_lmac_if_reg_tx_ops *
546 wlan_reg_get_tx_ops(struct wlan_objmgr_psoc *psoc);
547 
548 /**
549  * wlan_reg_get_curr_regdomain() - Get current regdomain in use
550  * @pdev: pdev pointer
551  * @cur_regdmn: Current regdomain info
552  *
553  * Return: QDF status
554  */
555 QDF_STATUS wlan_reg_get_curr_regdomain(struct wlan_objmgr_pdev *pdev,
556 		struct cur_regdmn_info *cur_regdmn);
557 #endif
558