xref: /wlan-dirver/qca-wifi-host-cmn/umac/regulatory/core/src/reg_utils.h (revision d0c05845839e5f2ba5a8dcebe0cd3e4cd4e8dfcf)
1 /*
2  * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  *
6  * Permission to use, copy, modify, and/or distribute this software for
7  * any purpose with or without fee is hereby granted, provided that the
8  * above copyright notice and this permission notice appear in all
9  * copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
12  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
13  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
14  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
15  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
16  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
17  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18  * PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 /**
22  * DOC: reg_utils.h
23  * This file provides prototypes for setting and getting regulatory variables.
24  */
25 
26 #ifndef __REG_UTILS_H_
27 #define __REG_UTILS_H_
28 
29 #include <wlan_lmac_if_def.h>
30 
31 #ifdef WLAN_FEATURE_DSRC
32 #define REG_DSRC_START_FREQ channel_map[MIN_DSRC_CHANNEL].center_freq
33 #define REG_DSRC_END_FREQ   channel_map[MAX_DSRC_CHANNEL].center_freq
34 #endif
35 
36 #define REG_ETSI13_SRD_START_FREQ 5745
37 #define REG_ETSI13_SRD_END_FREQ   5865
38 
39 /**
40  * reg_is_world_ctry_code() - Check if the given country code is WORLD regdomain
41  * @ctry_code: Country code value.
42  *
43  * Return: If country code is WORLD regdomain return true else false
44  */
45 bool reg_is_world_ctry_code(uint16_t ctry_code);
46 
47 #if defined(CONFIG_REG_CLIENT) && defined(CONFIG_CHAN_FREQ_API)
48 /**
49  * reg_chan_has_dfs_attribute_for_freq() - check channel frequency has dfs
50  * attribue or not
51  * @freq: channel frequency.
52  *
53  * This API gets initial dfs attribute flag of the channel frequency from
54  * regdomain
55  *
56  * Return: true if channel frequency is dfs, otherwise false
57  */
58 bool reg_chan_has_dfs_attribute_for_freq(struct wlan_objmgr_pdev *pdev,
59 					 qdf_freq_t freq);
60 /**
61  * reg_is_passive_or_disable_for_freq() - Check if the given channel is
62  * passive or disabled.
63  * @pdev: Pointer to physical dev
64  * @chan: Channel frequency
65  *
66  * Return: true if channel frequency is passive or disabled, else false.
67  */
68 bool reg_is_passive_or_disable_for_freq(struct wlan_objmgr_pdev *pdev,
69 					qdf_freq_t freq);
70 #else
71 static inline bool
72 reg_chan_has_dfs_attribute_for_freq(struct wlan_objmgr_pdev *pdev,
73 				    qdf_freq_t freq)
74 {
75 	return false;
76 }
77 
78 static inline bool
79 reg_is_passive_or_disable_for_freq(struct wlan_objmgr_pdev *pdev,
80 				   qdf_freq_t freq)
81 {
82 	return false;
83 }
84 #endif /* defined(CONFIG_REG_CLIENT) && defined(CONFIG_CHAN_FREQ_API) */
85 
86 #ifdef DISABLE_CHANNEL_LIST
87 /**
88  * reg_disable_cached_channels() - Disable cached channels
89  * @pdev: The physical dev to cache the channels for
90  */
91 QDF_STATUS reg_disable_cached_channels(struct wlan_objmgr_pdev *pdev);
92 /**
93  * reg_restore_cached_channels() - Restore disabled cached channels
94  * @pdev: The physical dev to cache the channels for
95  */
96 QDF_STATUS reg_restore_cached_channels(struct wlan_objmgr_pdev *pdev);
97 #else
98 static inline
99 QDF_STATUS reg_restore_cached_channels(struct wlan_objmgr_pdev *pdev)
100 {
101 	return QDF_STATUS_SUCCESS;
102 }
103 
104 static inline
105 QDF_STATUS reg_disable_cached_channels(struct wlan_objmgr_pdev *pdev)
106 {
107 	return QDF_STATUS_SUCCESS;
108 }
109 #endif /* DISABLE_CHANNEL_LIST */
110 
111 #if defined(DISABLE_CHANNEL_LIST) && defined(CONFIG_CHAN_FREQ_API)
112 /**
113  * reg_cache_channel_freq_state() - Cache the current state of the channels
114  * based on the channel center frequency
115  * @pdev: The physical dev to cache the channels for
116  * @channel_list: List of the channels for which states needs to be cached
117  * @num_channels: Number of channels in the list
118  *
119  */
120 QDF_STATUS reg_cache_channel_freq_state(struct wlan_objmgr_pdev *pdev,
121 					uint32_t *channel_list,
122 					uint32_t num_channels);
123 #else
124 static inline
125 QDF_STATUS reg_cache_channel_freq_state(struct wlan_objmgr_pdev *pdev,
126 					uint32_t *channel_list,
127 					uint32_t num_channels)
128 {
129 	return QDF_STATUS_SUCCESS;
130 }
131 #endif /* defined(DISABLE_CHANNEL_LIST) && defined(CONFIG_CHAN_FREQ_API) */
132 
133 #ifdef CONFIG_REG_CLIENT
134 /**
135  * reg_set_band() - Sets the band information for the PDEV
136  * @pdev: The physical dev to set the band for
137  * @band_bitmap: The set band parameters to configure for the physical device
138  *
139  * Return: QDF_STATUS
140  */
141 QDF_STATUS reg_set_band(struct wlan_objmgr_pdev *pdev, uint32_t band_bitmap);
142 
143 /**
144  * reg_get_band() - Get the band information for the PDEV
145  * @pdev: The physical dev to get the band for
146  * @band_bitmap: The band parameters of the physical device
147  *
148  * Return: QDF_STATUS
149  */
150 QDF_STATUS reg_get_band(struct wlan_objmgr_pdev *pdev, uint32_t *band_bitmap);
151 
152 /**
153  * reg_set_fcc_constraint() - Apply fcc constraints on channels 12/13
154  * @pdev: The physical dev to set the band for
155  *
156  * This function reduces the transmit power on channels 12 and 13, to comply
157  * with FCC regulations in the USA.
158  *
159  * Return: QDF_STATUS
160  */
161 QDF_STATUS reg_set_fcc_constraint(struct wlan_objmgr_pdev *pdev,
162 				  bool fcc_constraint);
163 
164 /**
165  * reg_get_fcc_constraint() - Check FCC constraint on given frequency
166  * @pdev: physical dev to get
167  * @freq: frequency to be checked
168  *
169  * Return: If FCC constraint is applied on given frequency return true
170  *	   else return false.
171  */
172 bool reg_get_fcc_constraint(struct wlan_objmgr_pdev *pdev, uint32_t freq);
173 
174 /**
175  * reg_read_current_country() - Get the current regulatory country
176  * @psoc: The physical SoC to get current country from
177  * @country_code: the buffer to populate the country code into
178  *
179  * Return: QDF_STATUS
180  */
181 QDF_STATUS reg_read_current_country(struct wlan_objmgr_psoc *psoc,
182 				    uint8_t *country_code);
183 
184 /**
185  * reg_set_default_country() - Set the default regulatory country
186  * @psoc: The physical SoC to set default country for
187  * @req: The country information to configure
188  *
189  * Return: QDF_STATUS
190  */
191 QDF_STATUS reg_set_default_country(struct wlan_objmgr_psoc *psoc,
192 				   uint8_t *country);
193 
194 /**
195  * reg_is_world_alpha2 - is reg world mode
196  * @alpha2: country code pointer
197  *
198  * Return: true or false
199  */
200 bool reg_is_world_alpha2(uint8_t *alpha2);
201 
202 /**
203  * reg_is_us_alpha2 - is US country code
204  * @alpha2: country code pointer
205  *
206  * Return: true or false
207  */
208 bool reg_is_us_alpha2(uint8_t *alpha2);
209 
210 /**
211  * reg_is_etsi_alpha2 - is country code in EU
212  * @alpha2: country code pointer
213  *
214  * Return: true or false
215  */
216 bool reg_is_etsi_alpha2(uint8_t *alpha2);
217 
218 /**
219  * reg_ctry_support_vlp - Does country code supports VLP
220  * @alpha2: country code pointer
221  *
222  * Return: true or false
223  */
224 bool reg_ctry_support_vlp(uint8_t *alpha2);
225 
226 /**
227  * reg_set_country() - Set the current regulatory country
228  * @pdev: pdev device for country information
229  * @country: country value
230  *
231  * Return: QDF_STATUS
232  */
233 QDF_STATUS reg_set_country(struct wlan_objmgr_pdev *pdev, uint8_t *country);
234 
235 /**
236  * reg_reset_country() - Reset the regulatory country to default
237  * @psoc: The physical SoC to reset country for
238  *
239  * Return: QDF_STATUS
240  */
241 QDF_STATUS reg_reset_country(struct wlan_objmgr_psoc *psoc);
242 
243 /**
244  * reg_get_domain_from_country_code() - Get regdomain from country code
245  * @reg_domain_ptr: Pointer to save regdomain
246  * @country_alpha2: country string
247  * @source: Country code source
248  *
249  * Return: QDF_STATUS
250  */
251 QDF_STATUS reg_get_domain_from_country_code(v_REGDOMAIN_t *reg_domain_ptr,
252 					    const uint8_t *country_alpha2,
253 					    enum country_src source);
254 
255 #ifdef CONFIG_REG_CLIENT
256 /**
257  * reg_get_6g_power_type_for_ctry() - Return power type for 6G based on cntry IE
258  * @ap_ctry: ptr to country string in country IE
259  * @sta_ctry: ptr to sta programmed country
260  * @pwr_type_6g: ptr to 6G power type
261  * @ctry_code_match: Check for country IE and sta country code match
262  * @ap_pwr_type: AP's power type as advertised in HE ops IE
263  * Return: QDF_STATUS
264  */
265 QDF_STATUS
266 reg_get_6g_power_type_for_ctry(struct wlan_objmgr_psoc *psoc,
267 			       uint8_t *ap_ctry, uint8_t *sta_ctry,
268 			       enum reg_6g_ap_type *pwr_type_6g,
269 			       bool *ctry_code_match,
270 			       enum reg_6g_ap_type ap_pwr_type);
271 #endif
272 
273 /**
274  * reg_set_config_vars () - set configration variables
275  * @psoc: psoc ptr
276  * @config_vars: configuration struct
277  *
278  * Return: QDF_STATUS
279  */
280 QDF_STATUS reg_set_config_vars(struct wlan_objmgr_psoc *psoc,
281 			       struct reg_config_vars config_vars);
282 
283 /**
284  * reg_program_mas_chan_list() - Program the master channel list
285  * @psoc: Pointer to psoc structure
286  * @reg_channels: Pointer to reg channels
287  * @alpha2: country string
288  * @dfs_region: DFS region
289  */
290 void reg_program_mas_chan_list(struct wlan_objmgr_psoc *psoc,
291 			       struct regulatory_channel *reg_channels,
292 			       uint8_t *alpha2, enum dfs_reg dfs_region);
293 
294 /**
295  * reg_get_cc_and_src() - Get country string and country source
296  * @psoc: Pointer to psoc
297  * @alpha2: Pointer to save country string
298  *
299  * Return: country_src
300  */
301 enum country_src reg_get_cc_and_src(struct wlan_objmgr_psoc *psoc,
302 				    uint8_t *alpha2);
303 
304 /**
305  * reg_reset_ctry_pending_hints() - Reset all country pending hints
306  * @soc_reg: regulatory private object
307  *
308  * Return: None
309  */
310 void
311 reg_reset_ctry_pending_hints(struct wlan_regulatory_psoc_priv_obj *soc_reg);
312 
313 /**
314  * reg_set_curr_country() - Set current country update
315  * @soc_reg: regulatory private object
316  * @regulat_info: regulatory info from firmware
317  * @tx_ops: send operations for regulatory component
318  *
319  * During SSR or restart of wlan modules after interface change timer phase,
320  * this function is used to send the recent user/11d country code to firmware.
321  *
322  * Return: QDF_STATUS_SUCCESS if correct country is configured
323  * else return failure
324  * error code.
325  */
326 QDF_STATUS reg_set_curr_country(
327 		struct wlan_regulatory_psoc_priv_obj *soc_reg,
328 		struct cur_regulatory_info *regulat_info,
329 		struct wlan_lmac_if_reg_tx_ops *tx_ops);
330 
331 /**
332  * reg_ignore_default_country() - Ignore default country update
333  * @soc_reg: regulatory private object
334  * @regulat_info: regulatory info from firmware
335  *
336  * During SSR or restart of wlan modules after interface change timer phase,
337  * this function is used to ignore default country code from firmware.
338  *
339  * Return: If default country needs to be ignored return true else false.
340  */
341 bool reg_ignore_default_country(struct wlan_regulatory_psoc_priv_obj *soc_reg,
342 				struct cur_regulatory_info *regulat_info);
343 
344 #ifdef CONFIG_BAND_6GHZ
345 /**
346  * reg_decide_6g_ap_pwr_type() - Decide which power mode AP should operate in
347  *
348  * @pdev: pdev ptr
349  *
350  * Return: AP power type
351  */
352 enum reg_6g_ap_type reg_decide_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev);
353 #else
354 static inline enum reg_6g_ap_type
355 reg_decide_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev)
356 {
357 	return REG_CURRENT_MAX_AP_TYPE;
358 }
359 #endif /* CONFIG_BAND_6GHZ */
360 #else
361 static inline QDF_STATUS reg_read_current_country(struct wlan_objmgr_psoc *psoc,
362 						  uint8_t *country_code)
363 {
364 	return QDF_STATUS_SUCCESS;
365 }
366 
367 static inline bool reg_is_world_alpha2(uint8_t *alpha2)
368 {
369 	return false;
370 }
371 
372 static inline bool reg_ctry_support_vlp(uint8_t *alpha2)
373 {
374 	return false;
375 }
376 
377 static inline bool reg_is_us_alpha2(uint8_t *alpha2)
378 {
379 	return false;
380 }
381 
382 static inline bool reg_is_etsi_alpha2(uint8_t *alpha2)
383 {
384 	return false;
385 }
386 
387 static inline QDF_STATUS reg_set_country(struct wlan_objmgr_pdev *pdev,
388 					 uint8_t *country)
389 {
390 	return QDF_STATUS_SUCCESS;
391 }
392 
393 static inline QDF_STATUS reg_reset_country(struct wlan_objmgr_psoc *psoc)
394 {
395 	return QDF_STATUS_SUCCESS;
396 }
397 
398 static inline QDF_STATUS reg_get_domain_from_country_code(
399 	v_REGDOMAIN_t *reg_domain_ptr, const uint8_t *country_alpha2,
400 	enum country_src source)
401 {
402 	return QDF_STATUS_SUCCESS;
403 }
404 
405 static inline QDF_STATUS reg_set_config_vars(struct wlan_objmgr_psoc *psoc,
406 					     struct reg_config_vars config_vars)
407 {
408 	return QDF_STATUS_SUCCESS;
409 }
410 
411 static inline void reg_program_mas_chan_list(
412 	struct wlan_objmgr_psoc *psoc,
413 	struct regulatory_channel *reg_channels,
414 	uint8_t *alpha2, enum dfs_reg dfs_region)
415 {
416 }
417 
418 static inline enum country_src reg_get_cc_and_src(struct wlan_objmgr_psoc *psoc,
419 						  uint8_t *alpha2)
420 {
421 		return SOURCE_UNKNOWN;
422 }
423 
424 static inline void
425 reg_reset_ctry_pending_hints(struct wlan_regulatory_psoc_priv_obj *soc_reg)
426 {
427 }
428 
429 static inline QDF_STATUS reg_set_curr_country(
430 		struct wlan_regulatory_psoc_priv_obj *soc_reg,
431 		struct cur_regulatory_info *regulat_info,
432 		struct wlan_lmac_if_reg_tx_ops *tx_ops)
433 {
434 	return QDF_STATUS_SUCCESS;
435 }
436 
437 static inline
438 bool reg_ignore_default_country(struct wlan_regulatory_psoc_priv_obj *soc_reg,
439 				struct cur_regulatory_info *regulat_info)
440 {
441 	return false;
442 }
443 
444 static inline
445 QDF_STATUS reg_set_fcc_constraint(struct wlan_objmgr_pdev *pdev,
446 				  bool fcc_constraint)
447 {
448 	return QDF_STATUS_SUCCESS;
449 }
450 
451 static inline
452 bool reg_get_fcc_constraint(struct wlan_objmgr_pdev *pdev, uint32_t freq)
453 {
454 	return false;
455 }
456 
457 static inline enum reg_6g_ap_type
458 reg_decide_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev)
459 {
460 	return REG_CURRENT_MAX_AP_TYPE;
461 }
462 #endif /* CONFIG_REG_CLIENT */
463 
464 #if defined(WLAN_FEATURE_DSRC) && defined(CONFIG_REG_CLIENT)
465 /**
466  * reg_is_dsrc_freq () - Checks the channel frequency is DSRC or not
467  * @freq: Channel center frequency
468  * @pdev: pdev ptr
469  *
470  * Return: true or false
471  */
472 #ifdef CONFIG_CHAN_FREQ_API
473 bool reg_is_dsrc_freq(qdf_freq_t freq);
474 #endif /* CONFIG_CHAN_FREQ_API*/
475 
476 static inline bool reg_is_etsi13_regdmn(struct wlan_objmgr_pdev *pdev)
477 {
478 	return false;
479 }
480 
481 /**
482  * reg_is_etsi13_srd_chan_for_freq() - Checks the channel for ETSI13 srd ch
483  * frequency or not
484  * @freq: Channel center frequency
485  * @pdev: pdev ptr
486  *
487  * Return: true or false
488  */
489 static inline bool
490 reg_is_etsi13_srd_chan_for_freq(struct wlan_objmgr_pdev *pdev, uint16_t freq)
491 {
492 	return false;
493 }
494 
495 static inline bool
496 reg_is_etsi13_srd_chan_allowed_master_mode(struct wlan_objmgr_pdev *pdev)
497 {
498 	return true;
499 }
500 #elif defined(CONFIG_REG_CLIENT)
501 static inline bool reg_is_dsrc_freq(qdf_freq_t freq)
502 {
503 	return false;
504 }
505 
506 #ifdef CONFIG_CHAN_FREQ_API
507 bool reg_is_etsi13_srd_chan_for_freq(struct wlan_objmgr_pdev
508 				     *pdev, uint16_t freq);
509 #endif /*CONFIG_CHAN_FREQ_API */
510 
511 /**
512  * reg_is_etsi13_regdmn () - Checks if the current reg domain is ETSI13 or not
513  * @pdev: pdev ptr
514  *
515  * Return: true or false
516  */
517 bool reg_is_etsi13_regdmn(struct wlan_objmgr_pdev *pdev);
518 
519 /**
520  * reg_is_etsi13_srd_chan_allowed_master_mode() - Checks if regdmn is ETSI13
521  * and SRD channels are allowed in master mode or not.
522  *
523  * @pdev: pdev ptr
524  *
525  * Return: true or false
526  */
527 bool reg_is_etsi13_srd_chan_allowed_master_mode(struct wlan_objmgr_pdev *pdev);
528 #else
529 static inline bool reg_is_dsrc_freq(qdf_freq_t freq)
530 {
531 	return false;
532 }
533 
534 static inline
535 bool reg_is_etsi13_srd_chan_for_freq(struct wlan_objmgr_pdev *pdev,
536 				     uint16_t freq)
537 {
538 	return false;
539 }
540 
541 static inline bool reg_is_etsi13_regdmn(struct wlan_objmgr_pdev *pdev)
542 {
543 	return false;
544 }
545 
546 static inline bool
547 reg_is_etsi13_srd_chan_allowed_master_mode(struct wlan_objmgr_pdev *pdev)
548 {
549 	return false;
550 }
551 
552 #endif
553 
554 #endif
555