xref: /wlan-dirver/qca-wifi-host-cmn/umac/regulatory/dispatcher/inc/wlan_reg_services_api.h (revision 3149adf58a329e17232a4c0e58d460d025edd55a)
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 #define WLAN_REG_MIN_11P_CH_NUM REG_MIN_11P_CH_NUM
38 #define WLAN_REG_MAX_11P_CH_NUM REG_MAX_11P_CH_NUM
39 
40 #define WLAN_REG_IS_24GHZ_CH(chan) REG_IS_24GHZ_CH(chan)
41 #define WLAN_REG_IS_5GHZ_CH(chan) REG_IS_5GHZ_CH(chan)
42 #define WLAN_REG_IS_11P_CH(chan) REG_IS_11P_CH(chan)
43 
44 #ifndef CONFIG_LEGACY_CHAN_ENUM
45 #define WLAN_REG_IS_49GHZ_FREQ(freq) REG_IS_49GHZ_FREQ(freq)
46 #endif
47 
48 #define WLAN_REG_CH_NUM(ch_enum) REG_CH_NUM(ch_enum)
49 #define WLAN_REG_CH_TO_FREQ(ch_enum) REG_CH_TO_FREQ(ch_enum)
50 
51 #define WLAN_REG_IS_SAME_BAND_CHANNELS(chan_num1, chan_num2) \
52 	(chan_num1 && chan_num2 &&					\
53 	(WLAN_REG_IS_5GHZ_CH(chan_num1) == WLAN_REG_IS_5GHZ_CH(chan_num2)))
54 
55 
56 #define WLAN_REG_IS_CHANNEL_VALID_5G_SBS(curchan, newchan) \
57 	(curchan > newchan ?				   \
58 	 REG_CH_TO_FREQ(reg_get_chan_enum(curchan))	   \
59 	 - REG_CH_TO_FREQ(reg_get_chan_enum(newchan))	   \
60 	 > REG_SBS_SEPARATION_THRESHOLD :		   \
61 	 REG_CH_TO_FREQ(reg_get_chan_enum(newchan))	   \
62 	 - REG_CH_TO_FREQ(reg_get_chan_enum(curchan))	   \
63 	 > REG_SBS_SEPARATION_THRESHOLD)
64 
65 #define WLAN_REG_INVALID_CHANNEL_ID
66 #define WLAN_REG_GET_24_END_CHAN_NUM 14
67 
68 #define WLAN_REG_CHAN_TO_BAND(chan_num)  reg_chan_to_band(chan_num)
69 
70 /**
71  * wlan_reg_get_channel_list_with_power() - Provide the channel list with power
72  * @ch_list: pointer to the channel list.
73  *
74  * Return: QDF_STATUS
75  */
76 QDF_STATUS wlan_reg_get_channel_list_with_power(struct wlan_objmgr_pdev *pdev,
77 						struct channel_power *ch_list,
78 						uint8_t *num_chan);
79 
80 /**
81  * wlan_reg_read_default_country() - Read the default country for the regdomain
82  * @country: pointer to the country code.
83  *
84  * Return: QDF_STATUS
85  */
86 QDF_STATUS wlan_reg_read_default_country(struct wlan_objmgr_psoc *psoc,
87 				   uint8_t *country);
88 
89 /**
90  * wlan_reg_read_current_country() - Read the current country for the regdomain
91  * @country: pointer to the country code.
92  *
93  * Return: QDF_STATUS
94  */
95 QDF_STATUS wlan_reg_read_current_country(struct wlan_objmgr_psoc *psoc,
96 				   uint8_t *country);
97 
98 /**
99  * wlan_reg_get_channel_state() - Get channel state from regulatory
100  * @ch: channel number.
101  *
102  * Return: channel state
103  */
104 enum channel_state wlan_reg_get_channel_state(struct wlan_objmgr_pdev *pdev,
105 					      uint32_t ch);
106 
107 /**
108  * wlan_reg_get_5g_bonded_channel_state() - Get 5G bonded channel state
109  * @pdev: The physical dev to program country code or regdomain
110  * @ch: channel number.
111  * @bw: channel band width
112  *
113  * Return: channel state
114  */
115 enum channel_state wlan_reg_get_5g_bonded_channel_state(
116 		struct wlan_objmgr_pdev *pdev, uint8_t ch,
117 		enum phy_ch_width bw);
118 
119 /**
120  * wlan_reg_get_2g_bonded_channel_state() - Get 2G bonded channel state
121  * @pdev: The physical dev to program country code or regdomain
122  * @ch: channel number.
123  * @sec_ch: Secondary channel.
124  * @bw: channel band width
125  *
126  * Return: channel state
127  */
128 enum channel_state wlan_reg_get_2g_bonded_channel_state(
129 		struct wlan_objmgr_pdev *pdev, uint8_t ch,
130 		uint8_t sec_ch, enum phy_ch_width bw);
131 
132 /**
133  * wlan_reg_set_channel_params () - Sets channel parameteres for given bandwidth
134  * @pdev: The physical dev to program country code or regdomain
135  * @ch: channel number.
136  * @sec_ch_2g: Secondary channel.
137  * @ch_params: pointer to the channel parameters.
138  *
139  * Return: None
140  */
141 void wlan_reg_set_channel_params(struct wlan_objmgr_pdev *pdev, uint8_t ch,
142 				 uint8_t sec_ch_2g,
143 				 struct ch_params *ch_params);
144 
145 /**
146  * wlan_reg_get_dfs_region () - Get the current dfs region
147  * @dfs_reg: pointer to dfs region
148  *
149  * Return: Status
150  */
151 QDF_STATUS wlan_reg_get_dfs_region(struct wlan_objmgr_pdev *pdev,
152 			     enum dfs_reg *dfs_reg);
153 
154 /**
155  * wlan_reg_get_channel_reg_power() - Provide the channel regulatory power
156  * @chan_num: chennal number
157  *
158  * Return: int
159  */
160 uint32_t wlan_reg_get_channel_reg_power(struct wlan_objmgr_pdev *pdev,
161 					uint32_t chan_num);
162 
163 /**
164  * wlan_reg_get_channel_freq() - provide the channel center freq
165  * @chan_num: chennal number
166  *
167  * Return: int
168  */
169 uint32_t wlan_reg_get_channel_freq(struct wlan_objmgr_pdev *pdev,
170 				   uint32_t chan_num);
171 
172 /**
173  * wlan_reg_get_current_chan_list() - provide the pdev current channel list
174  * @pdev: pdev pointer
175  * @chan_list: channel list pointer
176  *
177  * Return: QDF_STATUS
178  */
179 QDF_STATUS wlan_reg_get_current_chan_list(struct wlan_objmgr_pdev *pdev,
180 		struct regulatory_channel *chan_list);
181 /**
182  * wlan_reg_get_bonded_channel_state() - get bonded channel state
183  * @pdev: pdev ptr
184  * @ch: chennal number
185  * @bw: chennal number
186  * @sec_ch: secondary channel
187  *
188  * Return: enum channel_state
189  */
190 enum channel_state wlan_reg_get_bonded_channel_state(
191 	struct wlan_objmgr_pdev *pdev, uint8_t ch,
192 	enum phy_ch_width bw, uint8_t sec_ch);
193 
194 /**
195  * wlan_reg_set_dfs_region() - set the dfs region
196  * @pdev: pdev ptr
197  * @dfs_reg: dfs region
198  *
199  * Return: void
200  */
201 void wlan_reg_set_dfs_region(struct wlan_objmgr_pdev *pdev,
202 			     enum dfs_reg dfs_reg);
203 
204 /**
205  * wlan_reg_get_bw_value() - provide the channel center freq
206  * @chan_num: chennal number
207  *
208  * Return: int
209  */
210 uint16_t wlan_reg_get_bw_value(enum phy_ch_width bw);
211 
212 /**
213  * wlan_reg_get_domain_from_country_code() - provide the channel center freq
214  * @reg_domain_ptr: regulatory domain ptr
215  * @country_alpha2: country alpha2
216  * @source: alpha2 source
217  *
218  * Return: int
219  */
220 QDF_STATUS wlan_reg_get_domain_from_country_code(v_REGDOMAIN_t *reg_domain_ptr,
221 						 const uint8_t *country_alpha2,
222 						 enum country_src source);
223 
224 /**
225  * wlan_reg_dmn_get_opclass_from_channel() - provide the channel center freq
226  * @country: country alpha2
227  * @channel: channel number
228  * @offset: offset
229  *
230  * Return: int
231  */
232 uint16_t wlan_reg_dmn_get_opclass_from_channel(uint8_t *country,
233 					       uint8_t channel,
234 					       uint8_t offset);
235 
236 /**
237  * wlan_reg_dmn_get_chanwidth_from_opclass() - get channel width from
238  *                                             operating class
239  * @country: country alpha2
240  * @channel: channel number
241  * @opclass: operating class
242  *
243  * Return: int
244  */
245 uint16_t wlan_reg_dmn_get_chanwidth_from_opclass(uint8_t *country,
246 						 uint8_t channel,
247 						 uint8_t opclass);
248 /**
249  * wlan_reg_dmn_set_curr_opclasses() - set operating class
250  * @num_classes: number of classes
251  * @class: operating class
252  *
253  * Return: int
254  */
255 uint16_t wlan_reg_dmn_set_curr_opclasses(uint8_t num_classes,
256 					 uint8_t *class);
257 
258 /**
259  * wlan_reg_dmn_get_curr_opclasses() - get current oper classes
260  * @num_classes: number of classes
261  * @class: operating class
262  *
263  * Return: int
264  */
265 uint16_t wlan_reg_dmn_get_curr_opclasses(uint8_t *num_classes,
266 					 uint8_t *class);
267 
268 
269 /**
270  * wlan_regulatory_init() - init regulatory component
271  *
272  * Return: Success or Failure
273  */
274 QDF_STATUS wlan_regulatory_init(void);
275 
276 /**
277  * wlan_regulatory_deinit() - deinit regulatory component
278  *
279  * Return: Success or Failure
280  */
281 QDF_STATUS wlan_regulatory_deinit(void);
282 
283 /**
284  * regulatory_psoc_open() - open regulatory component
285  *
286  * Return: Success or Failure
287  */
288 QDF_STATUS regulatory_psoc_open(struct wlan_objmgr_psoc *psoc);
289 
290 
291 /**
292  * regulatory_psoc_close() - close regulatory component
293  *
294  * Return: Success or Failure
295  */
296 QDF_STATUS regulatory_psoc_close(struct wlan_objmgr_psoc *psoc);
297 
298 /**
299  * regulatory_pdev_open() - Open regulatory component
300  * @pdev: Pointer to pdev structure.
301  *
302  * Return: Success or Failure
303  */
304 QDF_STATUS regulatory_pdev_open(struct wlan_objmgr_pdev *pdev);
305 
306 /**
307  * regulatory_pdev_close() - Close regulatory component
308  * @pdev: Pointer to pdev structure.
309  *
310  * Return: Success or Failure
311  */
312 QDF_STATUS regulatory_pdev_close(struct wlan_objmgr_pdev *pdev);
313 
314 /**
315  * wlan_reg_update_nol_ch () - set nol channel
316  * @pdev: pdev ptr
317  * @ch_list: channel list to be returned
318  * @num_ch: number of channels
319  * @nol_ch: nol flag
320  *
321  * Return: void
322  */
323 void wlan_reg_update_nol_ch(struct wlan_objmgr_pdev *pdev,
324 			    uint8_t *ch_list,
325 			    uint8_t num_ch,
326 			    bool nol_ch);
327 
328 /**
329  * wlan_reg_is_dfs_ch () - Checks the channel state for DFS
330  * @pdev: pdev ptr
331  * @chan: channel
332  *
333  * Return: true or false
334  */
335 bool wlan_reg_is_dfs_ch(struct wlan_objmgr_pdev *pdev, uint32_t chan);
336 
337 /**
338  * wlan_reg_is_passive_or_disable_ch () - Checks chan state for passive
339  * and disabled
340  * @pdev: pdev ptr
341  * @chan: channel
342  *
343  * Return: true or false
344  */
345 bool wlan_reg_is_passive_or_disable_ch(struct wlan_objmgr_pdev *pdev,
346 				       uint32_t chan);
347 
348 /**
349  * wlan_reg_is_disable_ch () - Checks chan state for disabled
350  * @pdev: pdev ptr
351  * @chan: channel
352  *
353  * Return: true or false
354  */
355 bool wlan_reg_is_disable_ch(struct wlan_objmgr_pdev *pdev, uint32_t chan);
356 
357 /**
358  * wlan_reg_freq_to_chan () - convert channel freq to channel number
359  * @pdev: The physical dev to set current country for
360  * @freq: frequency
361  *
362  * Return: true or false
363  */
364 uint32_t wlan_reg_freq_to_chan(struct wlan_objmgr_pdev *pdev,
365 			       uint32_t freq);
366 
367 /**
368  * wlan_reg_chan_to_freq () - convert channel number to frequency
369  * @chan: channel number
370  *
371  * Return: true or false
372  */
373 uint32_t wlan_reg_chan_to_freq(struct wlan_objmgr_pdev *pdev,
374 			       uint32_t chan);
375 /**
376  * wlan_reg_is_world() - reg is world mode
377  * @country: The country information
378  *
379  * Return: true or false
380  */
381 bool wlan_reg_is_world(uint8_t *country);
382 
383 /**
384  * wlan_reg_is_us() - reg is us country
385  * @country: The country information
386  *
387  * Return: true or false
388  */
389 bool wlan_reg_is_us(uint8_t *country);
390 
391 /**
392  * wlan_reg_set_country() - Set the current regulatory country
393  * @pdev: The physical dev to set current country for
394  * @country: The country information to configure
395  *
396  * Return: QDF_STATUS
397  */
398 QDF_STATUS wlan_reg_set_country(struct wlan_objmgr_pdev *pdev,
399 				uint8_t *country);
400 
401 /**
402  * wlan_reg_set_11d_country() - Set the 11d regulatory country
403  * @pdev: The physical dev to set current country for
404  * @country: The country information to configure
405  *
406  * Return: QDF_STATUS
407  */
408 QDF_STATUS wlan_reg_set_11d_country(struct wlan_objmgr_pdev *pdev,
409 				    uint8_t *country);
410 
411 /**
412  * wlan_reg_register_chan_change_callback () - add chan change cbk
413  * @psoc: psoc ptr
414  * @cbk: callback
415  * @arg: argument
416  *
417  * Return: true or false
418  */
419 void wlan_reg_register_chan_change_callback(struct wlan_objmgr_psoc *psoc,
420 					    reg_chan_change_callback cbk,
421 					    void *arg);
422 
423 /**
424  * wlan_reg_unregister_chan_change_callback () - remove chan change cbk
425  * @psoc: psoc ptr
426  * @cbk:callback
427  *
428  * Return: true or false
429  */
430 void wlan_reg_unregister_chan_change_callback(struct wlan_objmgr_psoc *psoc,
431 					      reg_chan_change_callback cbk);
432 
433 /**
434  * wlan_reg_11d_original_enabled_on_host() - 11d original enabled don host
435  * @psoc: psoc ptr
436  *
437  * Return: bool
438  */
439 bool wlan_reg_11d_original_enabled_on_host(struct wlan_objmgr_psoc *psoc);
440 
441 /**
442  * wlan_reg_11d_enabled_on_host() - 11d enabled don host
443  * @psoc: psoc ptr
444  *
445  * Return: bool
446  */
447 bool wlan_reg_11d_enabled_on_host(struct wlan_objmgr_psoc *psoc);
448 
449 /**
450  * wlan_reg_get_chip_mode() - get supported chip mode
451  * @pdev: pdev pointer
452  * @chip_mode: chip mode
453  *
454  * Return: QDF STATUS
455  */
456 QDF_STATUS wlan_reg_get_chip_mode(struct wlan_objmgr_pdev *pdev,
457 		uint32_t *chip_mode);
458 
459 /**
460  * wlan_reg_is_11d_scan_inprogress() - checks 11d scan status
461  * @psoc: psoc ptr
462  *
463  * Return: bool
464  */
465 bool wlan_reg_is_11d_scan_inprogress(struct wlan_objmgr_psoc *psoc);
466 /**
467  * wlan_reg_get_freq_range() - Get 2GHz and 5GHz frequency range
468  * @pdev: pdev pointer
469  * @low_2g: low 2GHz frequency range
470  * @high_2g: high 2GHz frequency range
471  * @low_5g: low 5GHz frequency range
472  * @high_5g: high 5GHz frequency range
473  *
474  * Return: QDF status
475  */
476 QDF_STATUS wlan_reg_get_freq_range(struct wlan_objmgr_pdev *pdev,
477 		uint32_t *low_2g,
478 		uint32_t *high_2g,
479 		uint32_t *low_5g,
480 		uint32_t *high_5g);
481 /**
482  * wlan_reg_get_tx_ops () - get regulatory tx ops
483  * @psoc: psoc ptr
484  *
485  */
486 struct wlan_lmac_if_reg_tx_ops *
487 wlan_reg_get_tx_ops(struct wlan_objmgr_psoc *psoc);
488 
489 /**
490  * wlan_reg_get_curr_regdomain() - Get current regdomain in use
491  * @pdev: pdev pointer
492  * @cur_regdmn: Current regdomain info
493  *
494  * Return: QDF status
495  */
496 QDF_STATUS wlan_reg_get_curr_regdomain(struct wlan_objmgr_pdev *pdev,
497 		struct cur_regdmn_info *cur_regdmn);
498 #endif
499