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