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