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