xref: /wlan-dirver/qca-wifi-host-cmn/umac/regulatory/core/src/reg_utils.h (revision 901120c066e139c7f8a2c8e4820561fdd83c67ef)
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  * 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  * @ap_ctry: ptr to country string in country IE
265  * @sta_ctry: ptr to sta programmed country
266  * @pwr_type_6g: ptr to 6G power type
267  * @ctry_code_match: Check for country IE and sta country code match
268  * @ap_pwr_type: AP's power type as advertised in HE ops IE
269  * Return: QDF_STATUS
270  */
271 QDF_STATUS
272 reg_get_6g_power_type_for_ctry(struct wlan_objmgr_psoc *psoc,
273 			       uint8_t *ap_ctry, uint8_t *sta_ctry,
274 			       enum reg_6g_ap_type *pwr_type_6g,
275 			       bool *ctry_code_match,
276 			       enum reg_6g_ap_type ap_pwr_type);
277 #endif
278 
279 /**
280  * reg_set_config_vars () - set configuration variables
281  * @psoc: psoc ptr
282  * @config_vars: configuration struct
283  *
284  * Return: QDF_STATUS
285  */
286 QDF_STATUS reg_set_config_vars(struct wlan_objmgr_psoc *psoc,
287 			       struct reg_config_vars config_vars);
288 
289 /**
290  * reg_program_mas_chan_list() - Program the master channel list
291  * @psoc: Pointer to psoc structure
292  * @reg_channels: Pointer to reg channels
293  * @alpha2: country string
294  * @dfs_region: DFS region
295  */
296 void reg_program_mas_chan_list(struct wlan_objmgr_psoc *psoc,
297 			       struct regulatory_channel *reg_channels,
298 			       uint8_t *alpha2, enum dfs_reg dfs_region);
299 
300 /**
301  * reg_get_cc_and_src() - Get country string and country source
302  * @psoc: Pointer to psoc
303  * @alpha2: Pointer to save country string
304  *
305  * Return: country_src
306  */
307 enum country_src reg_get_cc_and_src(struct wlan_objmgr_psoc *psoc,
308 				    uint8_t *alpha2);
309 
310 /**
311  * reg_reset_ctry_pending_hints() - Reset all country pending hints
312  * @soc_reg: regulatory private object
313  *
314  * Return: None
315  */
316 void
317 reg_reset_ctry_pending_hints(struct wlan_regulatory_psoc_priv_obj *soc_reg);
318 
319 /**
320  * reg_set_curr_country() - Set current country update
321  * @soc_reg: regulatory private object
322  * @regulat_info: regulatory info from firmware
323  * @tx_ops: send operations for regulatory component
324  *
325  * During SSR or restart of wlan modules after interface change timer phase,
326  * this function is used to send the recent user/11d country code to firmware.
327  *
328  * Return: QDF_STATUS_SUCCESS if correct country is configured
329  * else return failure
330  * error code.
331  */
332 QDF_STATUS reg_set_curr_country(
333 		struct wlan_regulatory_psoc_priv_obj *soc_reg,
334 		struct cur_regulatory_info *regulat_info,
335 		struct wlan_lmac_if_reg_tx_ops *tx_ops);
336 
337 /**
338  * reg_ignore_default_country() - Ignore default country update
339  * @soc_reg: regulatory private object
340  * @regulat_info: regulatory info from firmware
341  *
342  * During SSR or restart of wlan modules after interface change timer phase,
343  * this function is used to ignore default country code from firmware.
344  *
345  * Return: If default country needs to be ignored return true else false.
346  */
347 bool reg_ignore_default_country(struct wlan_regulatory_psoc_priv_obj *soc_reg,
348 				struct cur_regulatory_info *regulat_info);
349 
350 #ifdef CONFIG_BAND_6GHZ
351 /**
352  * reg_decide_6g_ap_pwr_type() - Decide which power mode AP should operate in
353  *
354  * @pdev: pdev ptr
355  *
356  * Return: AP power type
357  */
358 enum reg_6g_ap_type reg_decide_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev);
359 #else
360 static inline enum reg_6g_ap_type
361 reg_decide_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev)
362 {
363 	return REG_CURRENT_MAX_AP_TYPE;
364 }
365 #endif /* CONFIG_BAND_6GHZ */
366 #else
367 static inline QDF_STATUS reg_read_current_country(struct wlan_objmgr_psoc *psoc,
368 						  uint8_t *country_code)
369 {
370 	return QDF_STATUS_SUCCESS;
371 }
372 
373 static inline bool reg_is_world_alpha2(uint8_t *alpha2)
374 {
375 	return false;
376 }
377 
378 static inline bool reg_ctry_support_vlp(uint8_t *alpha2)
379 {
380 	return false;
381 }
382 
383 static inline bool reg_is_us_alpha2(uint8_t *alpha2)
384 {
385 	return false;
386 }
387 
388 static inline bool reg_is_etsi_alpha2(uint8_t *alpha2)
389 {
390 	return false;
391 }
392 
393 static inline QDF_STATUS reg_set_country(struct wlan_objmgr_pdev *pdev,
394 					 uint8_t *country)
395 {
396 	return QDF_STATUS_SUCCESS;
397 }
398 
399 static inline QDF_STATUS reg_reset_country(struct wlan_objmgr_psoc *psoc)
400 {
401 	return QDF_STATUS_SUCCESS;
402 }
403 
404 static inline QDF_STATUS reg_get_domain_from_country_code(
405 	v_REGDOMAIN_t *reg_domain_ptr, const uint8_t *country_alpha2,
406 	enum country_src source)
407 {
408 	return QDF_STATUS_SUCCESS;
409 }
410 
411 static inline QDF_STATUS reg_set_config_vars(struct wlan_objmgr_psoc *psoc,
412 					     struct reg_config_vars config_vars)
413 {
414 	return QDF_STATUS_SUCCESS;
415 }
416 
417 static inline void reg_program_mas_chan_list(
418 	struct wlan_objmgr_psoc *psoc,
419 	struct regulatory_channel *reg_channels,
420 	uint8_t *alpha2, enum dfs_reg dfs_region)
421 {
422 }
423 
424 static inline enum country_src reg_get_cc_and_src(struct wlan_objmgr_psoc *psoc,
425 						  uint8_t *alpha2)
426 {
427 		return SOURCE_UNKNOWN;
428 }
429 
430 static inline void
431 reg_reset_ctry_pending_hints(struct wlan_regulatory_psoc_priv_obj *soc_reg)
432 {
433 }
434 
435 static inline QDF_STATUS reg_set_curr_country(
436 		struct wlan_regulatory_psoc_priv_obj *soc_reg,
437 		struct cur_regulatory_info *regulat_info,
438 		struct wlan_lmac_if_reg_tx_ops *tx_ops)
439 {
440 	return QDF_STATUS_SUCCESS;
441 }
442 
443 static inline
444 bool reg_ignore_default_country(struct wlan_regulatory_psoc_priv_obj *soc_reg,
445 				struct cur_regulatory_info *regulat_info)
446 {
447 	return false;
448 }
449 
450 static inline
451 QDF_STATUS reg_set_fcc_constraint(struct wlan_objmgr_pdev *pdev,
452 				  bool fcc_constraint)
453 {
454 	return QDF_STATUS_SUCCESS;
455 }
456 
457 static inline
458 bool reg_get_fcc_constraint(struct wlan_objmgr_pdev *pdev, uint32_t freq)
459 {
460 	return false;
461 }
462 
463 static inline enum reg_6g_ap_type
464 reg_decide_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev)
465 {
466 	return REG_CURRENT_MAX_AP_TYPE;
467 }
468 #endif /* CONFIG_REG_CLIENT */
469 
470 #if defined(WLAN_FEATURE_DSRC) && defined(CONFIG_REG_CLIENT)
471 /**
472  * reg_is_dsrc_freq () - Checks the channel frequency is DSRC or not
473  * @freq: Channel center frequency
474  * @pdev: pdev ptr
475  *
476  * Return: true or false
477  */
478 #ifdef CONFIG_CHAN_FREQ_API
479 bool reg_is_dsrc_freq(qdf_freq_t freq);
480 #endif /* CONFIG_CHAN_FREQ_API*/
481 
482 static inline bool reg_is_etsi13_regdmn(struct wlan_objmgr_pdev *pdev)
483 {
484 	return false;
485 }
486 
487 /**
488  * reg_is_etsi13_srd_chan_for_freq() - Checks the channel for ETSI13 srd ch
489  * frequency or not
490  * @freq: Channel center frequency
491  * @pdev: pdev ptr
492  *
493  * Return: true or false
494  */
495 static inline bool
496 reg_is_etsi13_srd_chan_for_freq(struct wlan_objmgr_pdev *pdev, uint16_t freq)
497 {
498 	return false;
499 }
500 
501 static inline bool
502 reg_is_etsi13_srd_chan_allowed_master_mode(struct wlan_objmgr_pdev *pdev)
503 {
504 	return true;
505 }
506 #elif defined(CONFIG_REG_CLIENT)
507 static inline bool reg_is_dsrc_freq(qdf_freq_t freq)
508 {
509 	return false;
510 }
511 
512 #ifdef CONFIG_CHAN_FREQ_API
513 bool reg_is_etsi13_srd_chan_for_freq(struct wlan_objmgr_pdev
514 				     *pdev, uint16_t freq);
515 #endif /*CONFIG_CHAN_FREQ_API */
516 
517 /**
518  * reg_is_etsi13_regdmn () - Checks if the current reg domain is ETSI13 or not
519  * @pdev: pdev ptr
520  *
521  * Return: true or false
522  */
523 bool reg_is_etsi13_regdmn(struct wlan_objmgr_pdev *pdev);
524 
525 /**
526  * reg_is_etsi13_srd_chan_allowed_master_mode() - Checks if regdmn is ETSI13
527  * and SRD channels are allowed in master mode or not.
528  *
529  * @pdev: pdev ptr
530  *
531  * Return: true or false
532  */
533 bool reg_is_etsi13_srd_chan_allowed_master_mode(struct wlan_objmgr_pdev *pdev);
534 #else
535 static inline bool reg_is_dsrc_freq(qdf_freq_t freq)
536 {
537 	return false;
538 }
539 
540 static inline
541 bool reg_is_etsi13_srd_chan_for_freq(struct wlan_objmgr_pdev *pdev,
542 				     uint16_t freq)
543 {
544 	return false;
545 }
546 
547 static inline bool reg_is_etsi13_regdmn(struct wlan_objmgr_pdev *pdev)
548 {
549 	return false;
550 }
551 
552 static inline bool
553 reg_is_etsi13_srd_chan_allowed_master_mode(struct wlan_objmgr_pdev *pdev)
554 {
555 	return false;
556 }
557 
558 #endif
559 
560 #endif
561