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