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