1 /* 2 * Copyright (c) 2017-2021 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 /** 39 * reg_is_world_ctry_code() - Check if the given country code is WORLD regdomain 40 * @ctry_code: Country code value. 41 * 42 * Return: If country code is WORLD regdomain return true else false 43 */ 44 bool reg_is_world_ctry_code(uint16_t ctry_code); 45 46 #if defined(CONFIG_REG_CLIENT) && defined(CONFIG_CHAN_FREQ_API) 47 /** 48 * reg_chan_has_dfs_attribute_for_freq() - check channel frequency has dfs 49 * attribue or not 50 * @freq: channel frequency. 51 * 52 * This API gets initial dfs attribute flag of the channel frequency from 53 * regdomain 54 * 55 * Return: true if channel frequency is dfs, otherwise false 56 */ 57 bool reg_chan_has_dfs_attribute_for_freq(struct wlan_objmgr_pdev *pdev, 58 qdf_freq_t freq); 59 /** 60 * reg_is_passive_or_disable_for_freq() - Check if the given channel is 61 * passive or disabled. 62 * @pdev: Pointer to physical dev 63 * @chan: Channel frequency 64 * 65 * Return: true if channel frequency is passive or disabled, else false. 66 */ 67 bool reg_is_passive_or_disable_for_freq(struct wlan_objmgr_pdev *pdev, 68 qdf_freq_t freq); 69 #else 70 static inline bool 71 reg_chan_has_dfs_attribute_for_freq(struct wlan_objmgr_pdev *pdev, 72 qdf_freq_t freq) 73 { 74 return false; 75 } 76 77 static inline bool 78 reg_is_passive_or_disable_for_freq(struct wlan_objmgr_pdev *pdev, 79 qdf_freq_t freq) 80 { 81 return false; 82 } 83 #endif /* defined(CONFIG_REG_CLIENT) && defined(CONFIG_CHAN_FREQ_API) */ 84 85 #ifdef DISABLE_CHANNEL_LIST 86 /** 87 * reg_disable_cached_channels() - Disable cached channels 88 * @pdev: The physical dev to cache the channels for 89 */ 90 QDF_STATUS reg_disable_cached_channels(struct wlan_objmgr_pdev *pdev); 91 /** 92 * reg_restore_cached_channels() - Restore disabled cached channels 93 * @pdev: The physical dev to cache the channels for 94 */ 95 QDF_STATUS reg_restore_cached_channels(struct wlan_objmgr_pdev *pdev); 96 #else 97 static inline 98 QDF_STATUS reg_restore_cached_channels(struct wlan_objmgr_pdev *pdev) 99 { 100 return QDF_STATUS_SUCCESS; 101 } 102 103 static inline 104 QDF_STATUS reg_disable_cached_channels(struct wlan_objmgr_pdev *pdev) 105 { 106 return QDF_STATUS_SUCCESS; 107 } 108 #endif /* DISABLE_CHANNEL_LIST */ 109 110 #if defined(DISABLE_CHANNEL_LIST) && defined(CONFIG_CHAN_FREQ_API) 111 /** 112 * reg_cache_channel_freq_state() - Cache the current state of the channels 113 * based on the channel center frequency 114 * @pdev: The physical dev to cache the channels for 115 * @channel_list: List of the channels for which states needs to be cached 116 * @num_channels: Number of channels in the list 117 * 118 */ 119 QDF_STATUS reg_cache_channel_freq_state(struct wlan_objmgr_pdev *pdev, 120 uint32_t *channel_list, 121 uint32_t num_channels); 122 #else 123 static inline 124 QDF_STATUS reg_cache_channel_freq_state(struct wlan_objmgr_pdev *pdev, 125 uint32_t *channel_list, 126 uint32_t num_channels) 127 { 128 return QDF_STATUS_SUCCESS; 129 } 130 #endif /* defined(DISABLE_CHANNEL_LIST) && defined(CONFIG_CHAN_FREQ_API) */ 131 132 #ifdef CONFIG_REG_CLIENT 133 /** 134 * reg_set_band() - Sets the band information for the PDEV 135 * @pdev: The physical dev to set the band for 136 * @band_bitmap: The set band parameters to configure for the physical device 137 * 138 * Return: QDF_STATUS 139 */ 140 QDF_STATUS reg_set_band(struct wlan_objmgr_pdev *pdev, uint32_t band_bitmap); 141 142 /** 143 * reg_get_band() - Get the band information for the PDEV 144 * @pdev: The physical dev to get the band for 145 * @band_bitmap: The band parameters of the physical device 146 * 147 * Return: QDF_STATUS 148 */ 149 QDF_STATUS reg_get_band(struct wlan_objmgr_pdev *pdev, uint32_t *band_bitmap); 150 151 /** 152 * reg_set_fcc_constraint() - Apply fcc constraints on channels 12/13 153 * @pdev: The physical dev to set the band for 154 * 155 * This function reduces the transmit power on channels 12 and 13, to comply 156 * with FCC regulations in the USA. 157 * 158 * Return: QDF_STATUS 159 */ 160 QDF_STATUS reg_set_fcc_constraint(struct wlan_objmgr_pdev *pdev, 161 bool fcc_constraint); 162 163 /** 164 * reg_get_fcc_constraint() - Check FCC constraint on given frequency 165 * @pdev: physical dev to get 166 * @freq: frequency to be checked 167 * 168 * Return: If FCC constraint is applied on given frequency return true 169 * else return false. 170 */ 171 bool reg_get_fcc_constraint(struct wlan_objmgr_pdev *pdev, uint32_t freq); 172 173 /** 174 * reg_read_current_country() - Get the current regulatory country 175 * @psoc: The physical SoC to get current country from 176 * @country_code: the buffer to populate the country code into 177 * 178 * Return: QDF_STATUS 179 */ 180 QDF_STATUS reg_read_current_country(struct wlan_objmgr_psoc *psoc, 181 uint8_t *country_code); 182 183 /** 184 * reg_set_default_country() - Set the default regulatory country 185 * @psoc: The physical SoC to set default country for 186 * @req: The country information to configure 187 * 188 * Return: QDF_STATUS 189 */ 190 QDF_STATUS reg_set_default_country(struct wlan_objmgr_psoc *psoc, 191 uint8_t *country); 192 193 /** 194 * reg_is_world_alpha2 - is reg world mode 195 * @alpha2: country code pointer 196 * 197 * Return: true or false 198 */ 199 bool reg_is_world_alpha2(uint8_t *alpha2); 200 201 /** 202 * reg_is_us_alpha2 - is US country code 203 * @alpha2: country code pointer 204 * 205 * Return: true or false 206 */ 207 bool reg_is_us_alpha2(uint8_t *alpha2); 208 209 /** 210 * reg_is_etsi_alpha2 - is country code in EU 211 * @alpha2: country code pointer 212 * 213 * Return: true or false 214 */ 215 bool reg_is_etsi_alpha2(uint8_t *alpha2); 216 217 /** 218 * reg_set_country() - Set the current regulatory country 219 * @pdev: pdev device for country information 220 * @country: country value 221 * 222 * Return: QDF_STATUS 223 */ 224 QDF_STATUS reg_set_country(struct wlan_objmgr_pdev *pdev, uint8_t *country); 225 226 /** 227 * reg_reset_country() - Reset the regulatory country to default 228 * @psoc: The physical SoC to reset country for 229 * 230 * Return: QDF_STATUS 231 */ 232 QDF_STATUS reg_reset_country(struct wlan_objmgr_psoc *psoc); 233 234 /** 235 * reg_get_domain_from_country_code() - Get regdomain from country code 236 * @reg_domain_ptr: Pointer to save regdomain 237 * @country_alpha2: country string 238 * @source: Country code source 239 * 240 * Return: QDF_STATUS 241 */ 242 QDF_STATUS reg_get_domain_from_country_code(v_REGDOMAIN_t *reg_domain_ptr, 243 const uint8_t *country_alpha2, 244 enum country_src source); 245 246 #ifdef CONFIG_REG_CLIENT 247 /** 248 * reg_get_6g_power_type_for_ctry() - Return power type for 6G based on cntry IE 249 * @ap_ctry: ptr to country string in country IE 250 * @sta_ctry: ptr to sta programmed country 251 * @pwr_type_6g: ptr to 6G power type 252 * @ctry_code_match: Check for country IE and sta country code match 253 * 254 * Return: QDF_STATUS 255 */ 256 QDF_STATUS 257 reg_get_6g_power_type_for_ctry(uint8_t *ap_ctry, uint8_t *sta_ctry, 258 enum reg_6g_ap_type *pwr_type_6g, 259 bool *ctry_code_match); 260 #endif 261 262 /** 263 * reg_set_config_vars () - set configration variables 264 * @psoc: psoc ptr 265 * @config_vars: configuration struct 266 * 267 * Return: QDF_STATUS 268 */ 269 QDF_STATUS reg_set_config_vars(struct wlan_objmgr_psoc *psoc, 270 struct reg_config_vars config_vars); 271 272 /** 273 * reg_program_mas_chan_list() - Program the master channel list 274 * @psoc: Pointer to psoc structure 275 * @reg_channels: Pointer to reg channels 276 * @alpha2: country string 277 * @dfs_region: DFS region 278 */ 279 void reg_program_mas_chan_list(struct wlan_objmgr_psoc *psoc, 280 struct regulatory_channel *reg_channels, 281 uint8_t *alpha2, enum dfs_reg dfs_region); 282 283 /** 284 * reg_get_regd_rules() - provides the reg domain rules info 285 * @pdev: pdev pointer 286 * @reg_rules: regulatory rules 287 * 288 * Return: QDF_STATUS 289 */ 290 QDF_STATUS reg_get_regd_rules(struct wlan_objmgr_pdev *pdev, 291 struct reg_rule_info *reg_rules); 292 293 /** 294 * reg_get_cc_and_src() - Get country string and country source 295 * @psoc: Pointer to psoc 296 * @alpha2: Pointer to save country string 297 * 298 * Return: country_src 299 */ 300 enum country_src reg_get_cc_and_src(struct wlan_objmgr_psoc *psoc, 301 uint8_t *alpha2); 302 303 /** 304 * reg_reset_ctry_pending_hints() - Reset all country pending hints 305 * @soc_reg: regulatory private object 306 * 307 * Return: None 308 */ 309 void 310 reg_reset_ctry_pending_hints(struct wlan_regulatory_psoc_priv_obj *soc_reg); 311 312 /** 313 * reg_set_curr_country() - Set current country update 314 * @soc_reg: regulatory private object 315 * @regulat_info: regulatory info from firmware 316 * @tx_ops: send operations for regulatory component 317 * 318 * During SSR or restart of wlan modules after interface change timer phase, 319 * this function is used to send the recent user/11d country code to firmware. 320 * 321 * Return: QDF_STATUS_SUCCESS if correct country is configured 322 * else return failure 323 * error code. 324 */ 325 QDF_STATUS reg_set_curr_country( 326 struct wlan_regulatory_psoc_priv_obj *soc_reg, 327 struct cur_regulatory_info *regulat_info, 328 struct wlan_lmac_if_reg_tx_ops *tx_ops); 329 330 /** 331 * reg_ignore_default_country() - Ignore default country update 332 * @soc_reg: regulatory private object 333 * @regulat_info: regulatory info from firmware 334 * 335 * During SSR or restart of wlan modules after interface change timer phase, 336 * this function is used to ignore default country code from firmware. 337 * 338 * Return: If default country needs to be ignored return true else false. 339 */ 340 bool reg_ignore_default_country(struct wlan_regulatory_psoc_priv_obj *soc_reg, 341 struct cur_regulatory_info *regulat_info); 342 343 #ifdef CONFIG_BAND_6GHZ 344 /** 345 * reg_decide_6g_ap_pwr_type() - Decide which power mode AP should operate in 346 * 347 * @pdev: pdev ptr 348 * 349 * Return: AP power type 350 */ 351 enum reg_6g_ap_type reg_decide_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev); 352 #else 353 static inline enum reg_6g_ap_type 354 reg_decide_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev) 355 { 356 return REG_CURRENT_MAX_AP_TYPE; 357 } 358 #endif /* CONFIG_BAND_6GHZ */ 359 #else 360 static inline QDF_STATUS reg_read_current_country(struct wlan_objmgr_psoc *psoc, 361 uint8_t *country_code) 362 { 363 return QDF_STATUS_SUCCESS; 364 } 365 366 static inline bool reg_is_world_alpha2(uint8_t *alpha2) 367 { 368 return false; 369 } 370 371 static inline bool reg_is_us_alpha2(uint8_t *alpha2) 372 { 373 return false; 374 } 375 376 static inline bool reg_is_etsi_alpha2(uint8_t *alpha2) 377 { 378 return false; 379 } 380 381 static inline QDF_STATUS reg_set_country(struct wlan_objmgr_pdev *pdev, 382 uint8_t *country) 383 { 384 return QDF_STATUS_SUCCESS; 385 } 386 387 static inline QDF_STATUS reg_reset_country(struct wlan_objmgr_psoc *psoc) 388 { 389 return QDF_STATUS_SUCCESS; 390 } 391 392 static inline QDF_STATUS reg_get_domain_from_country_code( 393 v_REGDOMAIN_t *reg_domain_ptr, const uint8_t *country_alpha2, 394 enum country_src source) 395 { 396 return QDF_STATUS_SUCCESS; 397 } 398 399 static inline QDF_STATUS reg_set_config_vars(struct wlan_objmgr_psoc *psoc, 400 struct reg_config_vars config_vars) 401 { 402 return QDF_STATUS_SUCCESS; 403 } 404 405 static inline void reg_program_mas_chan_list( 406 struct wlan_objmgr_psoc *psoc, 407 struct regulatory_channel *reg_channels, 408 uint8_t *alpha2, enum dfs_reg dfs_region) 409 { 410 } 411 412 static inline QDF_STATUS reg_get_regd_rules(struct wlan_objmgr_pdev *pdev, 413 struct reg_rule_info *reg_rules) 414 { 415 return QDF_STATUS_SUCCESS; 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