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: 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, enum band_info band); 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: The band parameters of the physical device 201 * 202 * Return: QDF_STATUS 203 */ 204 QDF_STATUS reg_get_band(struct wlan_objmgr_pdev *pdev, enum band_info *band); 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_is_regdb_offloaded() - is regdb offloaded 305 * @psoc: Pointer to psoc object 306 * 307 * Return: true if regdb is offloaded, else false 308 */ 309 bool reg_is_regdb_offloaded(struct wlan_objmgr_psoc *psoc); 310 311 /** 312 * reg_program_mas_chan_list() - Program the master channel list 313 * @psoc: Pointer to psoc structure 314 * @reg_channels: Pointer to reg channels 315 * @alpha2: country string 316 * @dfs_region: DFS region 317 */ 318 void reg_program_mas_chan_list(struct wlan_objmgr_psoc *psoc, 319 struct regulatory_channel *reg_channels, 320 uint8_t *alpha2, enum dfs_reg dfs_region); 321 322 /** 323 * reg_get_regd_rules() - provides the reg domain rules info 324 * @pdev: pdev pointer 325 * @reg_rules: regulatory rules 326 * 327 * Return: QDF_STATUS 328 */ 329 QDF_STATUS reg_get_regd_rules(struct wlan_objmgr_pdev *pdev, 330 struct reg_rule_info *reg_rules); 331 332 /** 333 * reg_get_cc_and_src() - Get country string and country source 334 * @psoc: Pointer to psoc 335 * @alpha2: Pointer to save country string 336 * 337 * Return: country_src 338 */ 339 enum country_src reg_get_cc_and_src(struct wlan_objmgr_psoc *psoc, 340 uint8_t *alpha2); 341 342 /** 343 * reg_reset_ctry_pending_hints() - Reset all country pending hints 344 * @soc_reg: regulatory private object 345 * 346 * Return: None 347 */ 348 void 349 reg_reset_ctry_pending_hints(struct wlan_regulatory_psoc_priv_obj *soc_reg); 350 351 /** 352 * reg_set_curr_country() - Set current country update 353 * @soc_reg: regulatory private object 354 * @regulat_info: regulatory info from firmware 355 * @tx_ops: send operations for regulatory component 356 * 357 * During SSR or restart of wlan modules after interface change timer phase, 358 * this function is used to send the recent user/11d country code to firmware. 359 * 360 * Return: QDF_STATUS_SUCCESS if correct country is configured 361 * else return failure 362 * error code. 363 */ 364 QDF_STATUS reg_set_curr_country( 365 struct wlan_regulatory_psoc_priv_obj *soc_reg, 366 struct cur_regulatory_info *regulat_info, 367 struct wlan_lmac_if_reg_tx_ops *tx_ops); 368 369 /** 370 * reg_ignore_default_country() - Ignore default country update 371 * @soc_reg: regulatory private object 372 * @regulat_info: regulatory info from firmware 373 * 374 * During SSR or restart of wlan modules after interface change timer phase, 375 * this function is used to ignore default country code from firmware. 376 * 377 * Return: If default country needs to be ignored return true else false. 378 */ 379 bool reg_ignore_default_country(struct wlan_regulatory_psoc_priv_obj *soc_reg, 380 struct cur_regulatory_info *regulat_info); 381 382 #else 383 static inline QDF_STATUS reg_read_current_country(struct wlan_objmgr_psoc *psoc, 384 uint8_t *country_code) 385 { 386 return QDF_STATUS_SUCCESS; 387 } 388 389 static inline bool reg_is_world_alpha2(uint8_t *alpha2) 390 { 391 return false; 392 } 393 394 static inline bool reg_is_us_alpha2(uint8_t *alpha2) 395 { 396 return false; 397 } 398 399 static inline QDF_STATUS reg_set_country(struct wlan_objmgr_pdev *pdev, 400 uint8_t *country) 401 { 402 return QDF_STATUS_SUCCESS; 403 } 404 405 static inline QDF_STATUS reg_reset_country(struct wlan_objmgr_psoc *psoc) 406 { 407 return QDF_STATUS_SUCCESS; 408 } 409 410 static inline QDF_STATUS reg_get_domain_from_country_code( 411 v_REGDOMAIN_t *reg_domain_ptr, const uint8_t *country_alpha2, 412 enum country_src source) 413 { 414 return QDF_STATUS_SUCCESS; 415 } 416 417 static inline QDF_STATUS reg_set_config_vars(struct wlan_objmgr_psoc *psoc, 418 struct reg_config_vars config_vars) 419 { 420 return QDF_STATUS_SUCCESS; 421 } 422 423 static inline bool reg_is_regdb_offloaded(struct wlan_objmgr_psoc *psoc) 424 { 425 return false; 426 } 427 428 static inline void reg_program_mas_chan_list( 429 struct wlan_objmgr_psoc *psoc, 430 struct regulatory_channel *reg_channels, 431 uint8_t *alpha2, enum dfs_reg dfs_region) 432 { 433 } 434 435 static inline QDF_STATUS reg_get_regd_rules(struct wlan_objmgr_pdev *pdev, 436 struct reg_rule_info *reg_rules) 437 { 438 return QDF_STATUS_SUCCESS; 439 } 440 441 static inline enum country_src reg_get_cc_and_src(struct wlan_objmgr_psoc *psoc, 442 uint8_t *alpha2) 443 { 444 return SOURCE_UNKNOWN; 445 } 446 447 static inline void 448 reg_reset_ctry_pending_hints(struct wlan_regulatory_psoc_priv_obj *soc_reg) 449 { 450 } 451 452 static inline QDF_STATUS reg_set_curr_country( 453 struct wlan_regulatory_psoc_priv_obj *soc_reg, 454 struct cur_regulatory_info *regulat_info, 455 struct wlan_lmac_if_reg_tx_ops *tx_ops) 456 { 457 return QDF_STATUS_SUCCESS; 458 } 459 460 static inline 461 bool reg_ignore_default_country(struct wlan_regulatory_psoc_priv_obj *soc_reg, 462 struct cur_regulatory_info *regulat_info) 463 { 464 return false; 465 } 466 467 static inline 468 QDF_STATUS reg_set_fcc_constraint(struct wlan_objmgr_pdev *pdev, 469 bool fcc_constraint) 470 { 471 return QDF_STATUS_SUCCESS; 472 } 473 474 static inline 475 bool reg_get_fcc_constraint(struct wlan_objmgr_pdev *pdev, uint32_t freq) 476 { 477 return false; 478 } 479 480 #endif 481 482 #if defined(WLAN_FEATURE_DSRC) && defined(CONFIG_REG_CLIENT) 483 /** 484 * reg_is_dsrc_freq () - Checks the channel frequency is DSRC or not 485 * @freq: Channel center frequency 486 * @pdev: pdev ptr 487 * 488 * Return: true or false 489 */ 490 #ifdef CONFIG_CHAN_FREQ_API 491 bool reg_is_dsrc_freq(qdf_freq_t freq); 492 #endif /* CONFIG_CHAN_FREQ_API*/ 493 494 #ifdef CONFIG_CHAN_NUM_API 495 /** 496 * reg_is_dsrc_chan () - Checks the channel for DSRC or not 497 * @chan: channel 498 * @pdev: pdev ptr 499 * 500 * Return: true or false 501 */ 502 bool reg_is_dsrc_chan(struct wlan_objmgr_pdev *pdev, uint8_t chan); 503 #endif /* CONFIG_CHAN_NUM_API */ 504 505 static inline bool reg_is_etsi13_srd_chan(struct wlan_objmgr_pdev *pdev, 506 uint8_t chan) 507 { 508 return false; 509 } 510 511 static inline bool reg_is_etsi13_regdmn(struct wlan_objmgr_pdev *pdev) 512 { 513 return false; 514 } 515 516 /** 517 * reg_is_etsi13_srd_chan_for_freq() - Checks the channel for ETSI13 srd ch 518 * frequency or not 519 * @freq: Channel center frequency 520 * @pdev: pdev ptr 521 * 522 * Return: true or false 523 */ 524 static inline bool 525 reg_is_etsi13_srd_chan_for_freq(struct wlan_objmgr_pdev *pdev, uint16_t freq) 526 { 527 return false; 528 } 529 530 static inline bool 531 reg_is_etsi13_srd_chan_allowed_master_mode(struct wlan_objmgr_pdev *pdev) 532 { 533 return true; 534 } 535 #elif defined(CONFIG_REG_CLIENT) 536 static inline bool reg_is_dsrc_chan(struct wlan_objmgr_pdev *pdev, 537 uint8_t chan) 538 { 539 return false; 540 } 541 542 static inline bool reg_is_dsrc_freq(qdf_freq_t freq) 543 { 544 return false; 545 } 546 547 #ifdef CONFIG_CHAN_FREQ_API 548 bool reg_is_etsi13_srd_chan_for_freq(struct wlan_objmgr_pdev 549 *pdev, uint16_t freq); 550 #endif /*CONFIG_CHAN_FREQ_API */ 551 552 /** 553 * reg_is_etsi13_regdmn () - Checks if the current reg domain is ETSI13 or not 554 * @pdev: pdev ptr 555 * 556 * Return: true or false 557 */ 558 bool reg_is_etsi13_regdmn(struct wlan_objmgr_pdev *pdev); 559 560 #ifdef CONFIG_CHAN_NUM_API 561 /** 562 * reg_is_etsi13_srd_chan () - Checks the channel for ETSI13 srd ch or not 563 * @chan: channel 564 * @pdev: pdev ptr 565 * 566 * Return: true or false 567 */ 568 bool reg_is_etsi13_srd_chan(struct wlan_objmgr_pdev *pdev, uint8_t chan); 569 #endif /* CONFIG_CHAN_NUM_API */ 570 571 /** 572 * reg_is_etsi13_srd_chan_allowed_master_mode() - Checks if regdmn is ETSI13 573 * and SRD channels are allowed in master mode or not. 574 * 575 * @pdev: pdev ptr 576 * 577 * Return: true or false 578 */ 579 bool reg_is_etsi13_srd_chan_allowed_master_mode(struct wlan_objmgr_pdev *pdev); 580 #else 581 static inline bool reg_is_dsrc_chan(struct wlan_objmgr_pdev *pdev, 582 uint8_t chan) 583 { 584 return false; 585 } 586 587 static inline bool reg_is_dsrc_freq(qdf_freq_t freq) 588 { 589 return false; 590 } 591 592 static inline 593 bool reg_is_etsi13_srd_chan_for_freq(struct wlan_objmgr_pdev *pdev, 594 uint16_t freq) 595 { 596 return false; 597 } 598 599 static inline bool reg_is_etsi13_regdmn(struct wlan_objmgr_pdev *pdev) 600 { 601 return false; 602 } 603 604 static inline bool 605 reg_is_etsi13_srd_chan_allowed_master_mode(struct wlan_objmgr_pdev *pdev) 606 { 607 return false; 608 } 609 610 static inline bool reg_is_etsi13_srd_chan(struct wlan_objmgr_pdev *pdev, 611 uint8_t chan) 612 { 613 return false; 614 } 615 #endif 616 617 #if defined(DISABLE_CHANNEL_LIST) && defined(CONFIG_REG_CLIENT) 618 /** 619 * set_disable_channel_state() - Set disable channel state flag 620 * @pdev_priv_obj: Pointer to pdev object 621 */ 622 void set_disable_channel_state( 623 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj); 624 #else 625 static inline void set_disable_channel_state( 626 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj) 627 { 628 } 629 #endif 630 #endif 631