xref: /wlan-dirver/qca-wifi-host-cmn/umac/regulatory/dispatcher/inc/wlan_reg_services_api.h (revision 0626a4da6c07f30da06dd6747e8cc290a60371d8)
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_get_5g_bonded_channel_state() - Get 5G bonded channel state
108  * @pdev: The physical dev to program country code or regdomain
109  * @ch: channel number.
110  * @bw: channel band width
111  *
112  * Return: channel state
113  */
114 enum channel_state wlan_reg_get_5g_bonded_channel_state(
115 		struct wlan_objmgr_pdev *pdev, uint8_t ch,
116 		enum phy_ch_width bw);
117 
118 /**
119  * wlan_reg_get_2g_bonded_channel_state() - Get 2G bonded channel state
120  * @pdev: The physical dev to program country code or regdomain
121  * @ch: channel number.
122  * @sec_ch: Secondary channel.
123  * @bw: channel band width
124  *
125  * Return: channel state
126  */
127 enum channel_state wlan_reg_get_2g_bonded_channel_state(
128 		struct wlan_objmgr_pdev *pdev, uint8_t ch,
129 		uint8_t sec_ch, enum phy_ch_width bw);
130 
131 /**
132  * wlan_reg_set_channel_params () - Sets channel parameteres for given bandwidth
133  * @pdev: The physical dev to program country code or regdomain
134  * @ch: channel number.
135  * @sec_ch_2g: Secondary channel.
136  * @ch_params: pointer to the channel parameters.
137  *
138  * Return: None
139  */
140 void wlan_reg_set_channel_params(struct wlan_objmgr_pdev *pdev, uint8_t ch,
141 				 uint8_t sec_ch_2g,
142 				 struct ch_params *ch_params);
143 
144 /**
145  * wlan_reg_get_dfs_region () - Get the current dfs region
146  * @dfs_reg: pointer to dfs region
147  *
148  * Return: Status
149  */
150 QDF_STATUS wlan_reg_get_dfs_region(struct wlan_objmgr_pdev *pdev,
151 			     enum dfs_reg *dfs_reg);
152 
153 /**
154  * wlan_reg_get_channel_reg_power() - Provide the channel regulatory power
155  * @chan_num: chennal number
156  *
157  * Return: int
158  */
159 uint32_t wlan_reg_get_channel_reg_power(struct wlan_objmgr_pdev *pdev,
160 					uint32_t chan_num);
161 
162 /**
163  * wlan_reg_get_channel_freq() - provide the channel center freq
164  * @chan_num: chennal number
165  *
166  * Return: int
167  */
168 uint32_t wlan_reg_get_channel_freq(struct wlan_objmgr_pdev *pdev,
169 				   uint32_t chan_num);
170 
171 /**
172  * wlan_reg_get_current_chan_list() - provide the pdev current channel list
173  * @pdev: pdev pointer
174  * @chan_list: channel list pointer
175  *
176  * Return: QDF_STATUS
177  */
178 QDF_STATUS wlan_reg_get_current_chan_list(struct wlan_objmgr_pdev *pdev,
179 		struct regulatory_channel *chan_list);
180 /**
181  * wlan_reg_get_bonded_channel_state() - get bonded channel state
182  * @pdev: pdev ptr
183  * @ch: chennal number
184  * @bw: chennal number
185  * @sec_ch: secondary channel
186  *
187  * Return: enum channel_state
188  */
189 enum channel_state wlan_reg_get_bonded_channel_state(
190 	struct wlan_objmgr_pdev *pdev, uint8_t ch,
191 	enum phy_ch_width bw, uint8_t sec_ch);
192 
193 /**
194  * wlan_reg_set_dfs_region() - set the dfs region
195  * @pdev: pdev ptr
196  * @dfs_reg: dfs region
197  *
198  * Return: void
199  */
200 void wlan_reg_set_dfs_region(struct wlan_objmgr_pdev *pdev,
201 			     enum dfs_reg dfs_reg);
202 
203 /**
204  * wlan_reg_get_bw_value() - provide the channel center freq
205  * @chan_num: chennal number
206  *
207  * Return: int
208  */
209 uint16_t wlan_reg_get_bw_value(enum phy_ch_width bw);
210 
211 /**
212  * wlan_reg_get_domain_from_country_code() - provide the channel center freq
213  * @reg_domain_ptr: regulatory domain ptr
214  * @country_alpha2: country alpha2
215  * @source: alpha2 source
216  *
217  * Return: int
218  */
219 QDF_STATUS wlan_reg_get_domain_from_country_code(v_REGDOMAIN_t *reg_domain_ptr,
220 						 const uint8_t *country_alpha2,
221 						 enum country_src source);
222 
223 /**
224  * wlan_reg_dmn_get_opclass_from_channel() - provide the channel center freq
225  * @country: country alpha2
226  * @channel: channel number
227  * @offset: offset
228  *
229  * Return: int
230  */
231 uint16_t wlan_reg_dmn_get_opclass_from_channel(uint8_t *country,
232 					       uint8_t channel,
233 					       uint8_t offset);
234 
235 /**
236  * wlan_reg_dmn_get_chanwidth_from_opclass() - get channel width from
237  *                                             operating class
238  * @country: country alpha2
239  * @channel: channel number
240  * @opclass: operating class
241  *
242  * Return: int
243  */
244 uint16_t wlan_reg_dmn_get_chanwidth_from_opclass(uint8_t *country,
245 						 uint8_t channel,
246 						 uint8_t opclass);
247 /**
248  * wlan_reg_dmn_set_curr_opclasses() - set operating class
249  * @num_classes: number of classes
250  * @class: operating class
251  *
252  * Return: int
253  */
254 uint16_t wlan_reg_dmn_set_curr_opclasses(uint8_t num_classes,
255 					 uint8_t *class);
256 
257 /**
258  * wlan_reg_dmn_get_curr_opclasses() - get current oper classes
259  * @num_classes: number of classes
260  * @class: operating class
261  *
262  * Return: int
263  */
264 uint16_t wlan_reg_dmn_get_curr_opclasses(uint8_t *num_classes,
265 					 uint8_t *class);
266 
267 
268 /**
269  * wlan_regulatory_init() - init regulatory component
270  *
271  * Return: Success or Failure
272  */
273 QDF_STATUS wlan_regulatory_init(void);
274 
275 /**
276  * wlan_regulatory_deinit() - deinit regulatory component
277  *
278  * Return: Success or Failure
279  */
280 QDF_STATUS wlan_regulatory_deinit(void);
281 
282 /**
283  * regulatory_psoc_open() - open regulatory component
284  *
285  * Return: Success or Failure
286  */
287 QDF_STATUS regulatory_psoc_open(struct wlan_objmgr_psoc *psoc);
288 
289 
290 /**
291  * regulatory_psoc_close() - close regulatory component
292  *
293  * Return: Success or Failure
294  */
295 QDF_STATUS regulatory_psoc_close(struct wlan_objmgr_psoc *psoc);
296 
297 /**
298  * regulatory_pdev_open() - Open regulatory component
299  * @pdev: Pointer to pdev structure.
300  *
301  * Return: Success or Failure
302  */
303 QDF_STATUS regulatory_pdev_open(struct wlan_objmgr_pdev *pdev);
304 
305 /**
306  * regulatory_pdev_close() - Close regulatory component
307  * @pdev: Pointer to pdev structure.
308  *
309  * Return: Success or Failure
310  */
311 QDF_STATUS regulatory_pdev_close(struct wlan_objmgr_pdev *pdev);
312 
313 /**
314  * wlan_reg_update_nol_ch () - set nol channel
315  * @pdev: pdev ptr
316  * @ch_list: channel list to be returned
317  * @num_ch: number of channels
318  * @nol_ch: nol flag
319  *
320  * Return: void
321  */
322 void wlan_reg_update_nol_ch(struct wlan_objmgr_pdev *pdev,
323 			    uint8_t *ch_list,
324 			    uint8_t num_ch,
325 			    bool nol_ch);
326 
327 /**
328  * wlan_reg_is_dfs_ch () - Checks the channel state for DFS
329  * @pdev: pdev ptr
330  * @chan: channel
331  *
332  * Return: true or false
333  */
334 bool wlan_reg_is_dfs_ch(struct wlan_objmgr_pdev *pdev, uint32_t chan);
335 
336 /**
337  * wlan_reg_is_dsrc_chan () - Checks if the channel is dsrc channel or not
338  * @pdev: pdev ptr
339  * @chan_num: channel
340  *
341  * Return: true or false
342  */
343 bool wlan_reg_is_dsrc_chan(struct wlan_objmgr_pdev *pdev, uint8_t chan_num);
344 
345 /**
346  * wlan_reg_is_etsi13_srd_chan () - Checks if the ch is ETSI13 srd ch or not
347  * @pdev: pdev ptr
348  * @chan_num: channel
349  *
350  * Return: true or false
351  */
352 bool wlan_reg_is_etsi13_srd_chan(struct wlan_objmgr_pdev *pdev,
353 				 uint8_t chan_num);
354 
355 /**
356  * wlan_reg_is_etsi13_regdmn() - Checks if current reg domain is ETSI13 or not
357  * @pdev: pdev ptr
358  *
359  * Return: true or false
360  */
361 bool wlan_reg_is_etsi13_regdmn(struct wlan_objmgr_pdev *pdev);
362 
363 /**
364  * wlan_reg_is_etsi13_srd_chan_allowed_master_mode() - Checks if regdmn is
365  * ETSI13 and SRD channels are allowed in master mode or not.
366  *
367  * @pdev: pdev ptr
368  *
369  * Return: true or false
370  */
371 bool wlan_reg_is_etsi13_srd_chan_allowed_master_mode(struct wlan_objmgr_pdev
372 						     *pdev);
373 
374 /**
375  * wlan_reg_is_passive_or_disable_ch () - Checks chan state for passive
376  * and disabled
377  * @pdev: pdev ptr
378  * @chan: channel
379  *
380  * Return: true or false
381  */
382 bool wlan_reg_is_passive_or_disable_ch(struct wlan_objmgr_pdev *pdev,
383 				       uint32_t chan);
384 
385 /**
386  * wlan_reg_is_disable_ch () - Checks chan state for disabled
387  * @pdev: pdev ptr
388  * @chan: channel
389  *
390  * Return: true or false
391  */
392 bool wlan_reg_is_disable_ch(struct wlan_objmgr_pdev *pdev, uint32_t chan);
393 
394 /**
395  * wlan_reg_freq_to_chan () - convert channel freq to channel number
396  * @pdev: The physical dev to set current country for
397  * @freq: frequency
398  *
399  * Return: true or false
400  */
401 uint32_t wlan_reg_freq_to_chan(struct wlan_objmgr_pdev *pdev,
402 			       uint32_t freq);
403 
404 /**
405  * wlan_reg_chan_to_freq () - convert channel number to frequency
406  * @chan: channel number
407  *
408  * Return: true or false
409  */
410 uint32_t wlan_reg_chan_to_freq(struct wlan_objmgr_pdev *pdev,
411 			       uint32_t chan);
412 /**
413  * wlan_reg_is_world() - reg is world mode
414  * @country: The country information
415  *
416  * Return: true or false
417  */
418 bool wlan_reg_is_world(uint8_t *country);
419 
420 /**
421  * wlan_reg_is_us() - reg is us country
422  * @country: The country information
423  *
424  * Return: true or false
425  */
426 bool wlan_reg_is_us(uint8_t *country);
427 
428 /**
429  * wlan_reg_chan_is_49ghz() - Check if the input channel number is 4.9GHz
430  * @pdev: Pdev pointer
431  * @chan_num: Input channel number
432  *
433  * Return: true if the channel is 4.9GHz else false.
434  */
435 
436 bool wlan_reg_chan_is_49ghz(struct wlan_objmgr_pdev *pdev,
437 		uint8_t chan_num);
438 
439 /**
440  * wlan_reg_set_country() - Set the current regulatory country
441  * @pdev: The physical dev to set current country for
442  * @country: The country information to configure
443  *
444  * Return: QDF_STATUS
445  */
446 QDF_STATUS wlan_reg_set_country(struct wlan_objmgr_pdev *pdev,
447 				uint8_t *country);
448 
449 /**
450  * wlan_reg_set_11d_country() - Set the 11d regulatory country
451  * @pdev: The physical dev to set current country for
452  * @country: The country information to configure
453  *
454  * Return: QDF_STATUS
455  */
456 QDF_STATUS wlan_reg_set_11d_country(struct wlan_objmgr_pdev *pdev,
457 				    uint8_t *country);
458 
459 /**
460  * wlan_reg_register_chan_change_callback () - add chan change cbk
461  * @psoc: psoc ptr
462  * @cbk: callback
463  * @arg: argument
464  *
465  * Return: true or false
466  */
467 void wlan_reg_register_chan_change_callback(struct wlan_objmgr_psoc *psoc,
468 					    reg_chan_change_callback cbk,
469 					    void *arg);
470 
471 /**
472  * wlan_reg_unregister_chan_change_callback () - remove chan change cbk
473  * @psoc: psoc ptr
474  * @cbk:callback
475  *
476  * Return: true or false
477  */
478 void wlan_reg_unregister_chan_change_callback(struct wlan_objmgr_psoc *psoc,
479 					      reg_chan_change_callback cbk);
480 
481 /**
482  * wlan_reg_is_11d_offloaded() - 11d offloaded supported
483  * @psoc: psoc ptr
484  *
485  * Return: bool
486  */
487 bool wlan_reg_is_11d_offloaded(struct wlan_objmgr_psoc *psoc);
488 
489 /**
490  * wlan_reg_11d_enabled_on_host() - 11d enabled don host
491  * @psoc: psoc ptr
492  *
493  * Return: bool
494  */
495 bool wlan_reg_11d_enabled_on_host(struct wlan_objmgr_psoc *psoc);
496 
497 /**
498  * wlan_reg_get_chip_mode() - get supported chip mode
499  * @pdev: pdev pointer
500  * @chip_mode: chip mode
501  *
502  * Return: QDF STATUS
503  */
504 QDF_STATUS wlan_reg_get_chip_mode(struct wlan_objmgr_pdev *pdev,
505 		uint32_t *chip_mode);
506 
507 /**
508  * wlan_reg_is_11d_scan_inprogress() - checks 11d scan status
509  * @psoc: psoc ptr
510  *
511  * Return: bool
512  */
513 bool wlan_reg_is_11d_scan_inprogress(struct wlan_objmgr_psoc *psoc);
514 /**
515  * wlan_reg_get_freq_range() - Get 2GHz and 5GHz frequency range
516  * @pdev: pdev pointer
517  * @low_2g: low 2GHz frequency range
518  * @high_2g: high 2GHz frequency range
519  * @low_5g: low 5GHz frequency range
520  * @high_5g: high 5GHz frequency range
521  *
522  * Return: QDF status
523  */
524 QDF_STATUS wlan_reg_get_freq_range(struct wlan_objmgr_pdev *pdev,
525 		uint32_t *low_2g,
526 		uint32_t *high_2g,
527 		uint32_t *low_5g,
528 		uint32_t *high_5g);
529 /**
530  * wlan_reg_get_tx_ops () - get regulatory tx ops
531  * @psoc: psoc ptr
532  *
533  */
534 struct wlan_lmac_if_reg_tx_ops *
535 wlan_reg_get_tx_ops(struct wlan_objmgr_psoc *psoc);
536 
537 /**
538  * wlan_reg_get_curr_regdomain() - Get current regdomain in use
539  * @pdev: pdev pointer
540  * @cur_regdmn: Current regdomain info
541  *
542  * Return: QDF status
543  */
544 QDF_STATUS wlan_reg_get_curr_regdomain(struct wlan_objmgr_pdev *pdev,
545 		struct cur_regdmn_info *cur_regdmn);
546 #endif
547