1 /* 2 * Copyright (c) 2017-2018 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 * @file wlan_reg_services_api.c 22 * @brief contains regulatory service functions 23 */ 24 25 26 #include <qdf_status.h> 27 #include <qdf_types.h> 28 #include <wlan_reg_services_api.h> 29 #include "../../core/src/reg_services.h" 30 #include "../../core/src/reg_priv.h" 31 #include "../../core/src/reg_db_parser.h" 32 33 /** 34 * wlan_reg_get_channel_list_with_power() - Provide the channel list with power 35 * @ch_list: pointer to the channel list. 36 * 37 * Return: QDF_STATUS 38 */ 39 QDF_STATUS wlan_reg_get_channel_list_with_power(struct wlan_objmgr_pdev *pdev, 40 struct channel_power *ch_list, 41 uint8_t *num_chan) 42 { 43 /* 44 * Update the channel list with channel information with power. 45 */ 46 return reg_get_channel_list_with_power(pdev, ch_list, num_chan); 47 } 48 49 /** 50 * wlan_reg_read_default_country() - Read the default country for the regdomain 51 * @country: pointer to the country code. 52 * 53 * Return: None 54 */ 55 QDF_STATUS wlan_reg_read_default_country(struct wlan_objmgr_psoc *psoc, 56 uint8_t *country) 57 { 58 /* 59 * Get the default country information 60 */ 61 return reg_read_default_country(psoc, country); 62 } 63 64 QDF_STATUS wlan_reg_read_current_country(struct wlan_objmgr_psoc *psoc, 65 uint8_t *country) 66 { 67 /* 68 * Get the current country information 69 */ 70 return reg_read_current_country(psoc, country); 71 } 72 73 /** 74 * wlan_reg_get_channel_state() - Get channel state from regulatory 75 * @ch: channel number. 76 * 77 * Return: channel state 78 */ 79 enum channel_state wlan_reg_get_channel_state(struct wlan_objmgr_pdev *pdev, 80 uint32_t ch) 81 { 82 /* 83 * Get channel state from regulatory 84 */ 85 return reg_get_channel_state(pdev, ch); 86 } 87 88 /** 89 * wlan_reg_get_5g_bonded_channel_state() - Get 5G bonded channel state 90 * @ch: channel number. 91 * @bw: channel band width 92 * 93 * Return: channel state 94 */ 95 enum channel_state wlan_reg_get_5g_bonded_channel_state( 96 struct wlan_objmgr_pdev *pdev, uint8_t ch, 97 enum phy_ch_width bw) 98 { 99 /* 100 * Get channel state from regulatory 101 */ 102 return reg_get_5g_bonded_channel_state(pdev, ch, bw); 103 } 104 105 /** 106 * wlan_reg_get_2g_bonded_channel_state() - Get 2G bonded channel state 107 * @ch: channel number. 108 * @bw: channel band width 109 * 110 * Return: channel state 111 */ 112 enum channel_state wlan_reg_get_2g_bonded_channel_state( 113 struct wlan_objmgr_pdev *pdev, uint8_t ch, 114 uint8_t sec_ch, enum phy_ch_width bw) 115 { 116 /* 117 * Get channel state from regulatory 118 */ 119 return reg_get_2g_bonded_channel_state(pdev, ch, sec_ch, bw); 120 } 121 122 /** 123 * wlan_reg_set_channel_params() - Sets channel parameteres for given bandwidth 124 * @ch: channel number. 125 * @ch_params: pointer to the channel parameters. 126 * 127 * Return: None 128 */ 129 void wlan_reg_set_channel_params(struct wlan_objmgr_pdev *pdev, uint8_t ch, 130 uint8_t sec_ch_2g, 131 struct ch_params *ch_params) 132 { 133 /* 134 * Set channel parameters like center frequency for a bonded channel 135 * state. Also return the maximum bandwidth supported by the channel. 136 */ 137 reg_set_channel_params(pdev, ch, sec_ch_2g, ch_params); 138 } 139 140 /** 141 * wlan_reg_get_dfs_region () - Get the current dfs region 142 * @dfs_reg: pointer to dfs region 143 * 144 * Return: Status 145 */ 146 QDF_STATUS wlan_reg_get_dfs_region(struct wlan_objmgr_pdev *pdev, 147 enum dfs_reg *dfs_reg) 148 { 149 /* 150 * Get the current dfs region 151 */ 152 reg_get_current_dfs_region(pdev, dfs_reg); 153 154 return QDF_STATUS_SUCCESS; 155 } 156 157 uint32_t wlan_reg_get_channel_reg_power(struct wlan_objmgr_pdev *pdev, 158 uint32_t chan_num) 159 { 160 return reg_get_channel_reg_power(pdev, chan_num); 161 } 162 163 /** 164 * wlan_reg_get_channel_freq() - get regulatory power for channel 165 * @chan_num: channel number 166 * 167 * Return: int 168 */ 169 uint32_t wlan_reg_get_channel_freq(struct wlan_objmgr_pdev *pdev, 170 uint32_t chan_num) 171 { 172 return reg_get_channel_freq(pdev, chan_num); 173 } 174 175 QDF_STATUS wlan_reg_get_current_chan_list(struct wlan_objmgr_pdev *pdev, 176 struct regulatory_channel *chan_list) 177 { 178 return reg_get_current_chan_list(pdev, chan_list); 179 } 180 181 /** 182 * wlan_reg_get_bw_value() - give bandwidth value 183 * bw: bandwidth enum 184 * 185 * Return: uint16_t 186 */ 187 uint16_t wlan_reg_get_bw_value(enum phy_ch_width bw) 188 { 189 return reg_get_bw_value(bw); 190 } 191 192 /** 193 * wlan_reg_get_bonded_channel_state() - Get 2G bonded channel state 194 * @ch: channel number. 195 * @bw: channel band width 196 * 197 * Return: channel state 198 */ 199 enum channel_state wlan_reg_get_bonded_channel_state( 200 struct wlan_objmgr_pdev *pdev, uint8_t ch, 201 enum phy_ch_width bw, uint8_t sec_ch) 202 { 203 if (WLAN_REG_IS_24GHZ_CH(ch)) 204 return reg_get_2g_bonded_channel_state(pdev, ch, 205 sec_ch, bw); 206 else 207 return reg_get_5g_bonded_channel_state(pdev, ch, 208 bw); 209 } 210 211 /** 212 * wlan_reg_set_dfs_region () - Get the current dfs region 213 * @dfs_reg: pointer to dfs region 214 * 215 * Return: None 216 */ 217 void wlan_reg_set_dfs_region(struct wlan_objmgr_pdev *pdev, 218 enum dfs_reg dfs_reg) 219 { 220 reg_set_dfs_region(pdev, dfs_reg); 221 } 222 223 QDF_STATUS wlan_reg_get_domain_from_country_code(v_REGDOMAIN_t *reg_domain_ptr, 224 const uint8_t *country_alpha2, enum country_src source) 225 { 226 227 return reg_get_domain_from_country_code(reg_domain_ptr, 228 country_alpha2, source); 229 } 230 231 232 uint16_t wlan_reg_dmn_get_opclass_from_channel(uint8_t *country, 233 uint8_t channel, 234 uint8_t offset) 235 { 236 return reg_dmn_get_opclass_from_channel(country, channel, 237 offset); 238 } 239 240 uint16_t wlan_reg_dmn_get_chanwidth_from_opclass(uint8_t *country, 241 uint8_t channel, 242 uint8_t opclass) 243 { 244 return reg_dmn_get_chanwidth_from_opclass(country, channel, 245 opclass); 246 } 247 248 uint16_t wlan_reg_dmn_set_curr_opclasses(uint8_t num_classes, 249 uint8_t *class) 250 { 251 return reg_dmn_set_curr_opclasses(num_classes, class); 252 } 253 254 uint16_t wlan_reg_dmn_get_curr_opclasses(uint8_t *num_classes, 255 uint8_t *class) 256 { 257 return reg_dmn_get_curr_opclasses(num_classes, class); 258 } 259 260 QDF_STATUS wlan_regulatory_init(void) 261 { 262 QDF_STATUS status; 263 264 status = wlan_objmgr_register_psoc_create_handler( 265 WLAN_UMAC_COMP_REGULATORY, 266 wlan_regulatory_psoc_obj_created_notification, NULL); 267 if (status != QDF_STATUS_SUCCESS) { 268 reg_err("failed to register reg psoc obj create handler"); 269 return status; 270 } 271 272 status = wlan_objmgr_register_psoc_destroy_handler( 273 WLAN_UMAC_COMP_REGULATORY, 274 wlan_regulatory_psoc_obj_destroyed_notification, NULL); 275 if (status != QDF_STATUS_SUCCESS) { 276 reg_err("failed to register reg psoc obj create handler"); 277 goto unreg_psoc_create; 278 } 279 280 status = wlan_objmgr_register_pdev_create_handler( 281 WLAN_UMAC_COMP_REGULATORY, 282 wlan_regulatory_pdev_obj_created_notification, NULL); 283 if (status != QDF_STATUS_SUCCESS) { 284 reg_err("failed to register reg psoc obj create handler"); 285 goto unreg_psoc_destroy; 286 } 287 288 status = wlan_objmgr_register_pdev_destroy_handler( 289 WLAN_UMAC_COMP_REGULATORY, 290 wlan_regulatory_pdev_obj_destroyed_notification, NULL); 291 if (status != QDF_STATUS_SUCCESS) { 292 reg_err("failed to register reg psoc obj create handler"); 293 goto unreg_pdev_create; 294 } 295 296 reg_debug("regulatory handlers registered with obj mgr"); 297 298 return status; 299 300 unreg_pdev_create: 301 status = wlan_objmgr_unregister_pdev_create_handler( 302 WLAN_UMAC_COMP_REGULATORY, 303 wlan_regulatory_pdev_obj_created_notification, 304 NULL); 305 306 unreg_psoc_destroy: 307 status = wlan_objmgr_unregister_psoc_destroy_handler( 308 WLAN_UMAC_COMP_REGULATORY, 309 wlan_regulatory_psoc_obj_destroyed_notification, 310 NULL); 311 312 unreg_psoc_create: 313 status = wlan_objmgr_unregister_psoc_create_handler( 314 WLAN_UMAC_COMP_REGULATORY, 315 wlan_regulatory_psoc_obj_created_notification, 316 NULL); 317 318 return QDF_STATUS_E_FAILURE; 319 } 320 321 QDF_STATUS wlan_regulatory_deinit(void) 322 { 323 QDF_STATUS status, ret_status = QDF_STATUS_SUCCESS; 324 325 status = wlan_objmgr_unregister_pdev_destroy_handler( 326 WLAN_UMAC_COMP_REGULATORY, 327 wlan_regulatory_pdev_obj_destroyed_notification, NULL); 328 if (status != QDF_STATUS_SUCCESS) { 329 reg_err("failed to unregister reg pdev obj destroy handler"); 330 ret_status = status; 331 } 332 333 status = wlan_objmgr_unregister_pdev_create_handler( 334 WLAN_UMAC_COMP_REGULATORY, 335 wlan_regulatory_pdev_obj_created_notification, NULL); 336 if (status != QDF_STATUS_SUCCESS) { 337 reg_err("failed to unregister reg pdev obj create handler"); 338 ret_status = status; 339 } 340 341 status = wlan_objmgr_unregister_psoc_destroy_handler( 342 WLAN_UMAC_COMP_REGULATORY, 343 wlan_regulatory_psoc_obj_destroyed_notification, NULL); 344 if (status != QDF_STATUS_SUCCESS) { 345 reg_err("failed to unregister reg psoc obj destroy handler"); 346 ret_status = status; 347 } 348 349 status = wlan_objmgr_unregister_psoc_create_handler( 350 WLAN_UMAC_COMP_REGULATORY, 351 wlan_regulatory_psoc_obj_created_notification, NULL); 352 if (status != QDF_STATUS_SUCCESS) { 353 reg_err("failed to unregister reg psoc obj create handler"); 354 ret_status = status; 355 } 356 357 reg_debug("deregistered callbacks with obj mgr"); 358 359 return ret_status; 360 } 361 362 QDF_STATUS regulatory_psoc_open(struct wlan_objmgr_psoc *psoc) 363 { 364 struct wlan_lmac_if_reg_tx_ops *tx_ops; 365 366 tx_ops = reg_get_psoc_tx_ops(psoc); 367 if (tx_ops->register_master_handler) 368 tx_ops->register_master_handler(psoc, NULL); 369 if (tx_ops->register_11d_new_cc_handler) 370 tx_ops->register_11d_new_cc_handler(psoc, NULL); 371 if (tx_ops->register_ch_avoid_event_handler) 372 tx_ops->register_ch_avoid_event_handler(psoc, NULL); 373 374 return QDF_STATUS_SUCCESS; 375 } 376 377 QDF_STATUS regulatory_psoc_close(struct wlan_objmgr_psoc *psoc) 378 { 379 struct wlan_lmac_if_reg_tx_ops *tx_ops; 380 struct wlan_regulatory_psoc_priv_obj *soc_reg; 381 uint8_t i; 382 383 tx_ops = reg_get_psoc_tx_ops(psoc); 384 if (tx_ops->unregister_11d_new_cc_handler) 385 tx_ops->unregister_11d_new_cc_handler(psoc, NULL); 386 if (tx_ops->unregister_master_handler) 387 tx_ops->unregister_master_handler(psoc, NULL); 388 if (tx_ops->unregister_ch_avoid_event_handler) 389 tx_ops->unregister_ch_avoid_event_handler(psoc, NULL); 390 391 soc_reg = reg_get_psoc_obj(psoc); 392 393 if (!soc_reg) { 394 reg_err("reg psoc private obj is NULL"); 395 return QDF_STATUS_E_FAULT; 396 } 397 for (i = 0; i < PSOC_MAX_PHY_REG_CAP; i++) 398 reg_reset_reg_rules(&soc_reg->mas_chan_params[i].reg_rules); 399 400 return QDF_STATUS_SUCCESS; 401 } 402 403 QDF_STATUS regulatory_pdev_open(struct wlan_objmgr_pdev *pdev) 404 { 405 struct wlan_objmgr_psoc *parent_psoc; 406 QDF_STATUS status; 407 408 parent_psoc = wlan_pdev_get_psoc(pdev); 409 410 status = reg_send_scheduler_msg_sb(parent_psoc, pdev); 411 412 if (QDF_IS_STATUS_ERROR(status)) 413 reg_err("scheduler send msg failed"); 414 415 return status; 416 } 417 418 QDF_STATUS regulatory_pdev_close(struct wlan_objmgr_pdev *pdev) 419 { 420 return QDF_STATUS_SUCCESS; 421 } 422 423 void wlan_reg_update_nol_ch(struct wlan_objmgr_pdev *pdev, uint8_t *ch_list, 424 uint8_t num_ch, bool nol_ch) 425 { 426 reg_update_nol_ch(pdev, ch_list, num_ch, nol_ch); 427 } 428 429 bool wlan_reg_is_dfs_ch(struct wlan_objmgr_pdev *pdev, 430 uint32_t chan) 431 { 432 return reg_is_dfs_ch(pdev, chan); 433 } 434 435 bool wlan_reg_is_passive_or_disable_ch(struct wlan_objmgr_pdev *pdev, 436 uint32_t chan) 437 { 438 return reg_is_passive_or_disable_ch(pdev, chan); 439 } 440 441 bool wlan_reg_is_disable_ch(struct wlan_objmgr_pdev *pdev, 442 uint32_t chan) 443 { 444 return reg_is_disable_ch(pdev, chan); 445 } 446 447 uint32_t wlan_reg_freq_to_chan(struct wlan_objmgr_pdev *pdev, 448 uint32_t freq) 449 { 450 return reg_freq_to_chan(pdev, freq); 451 } 452 453 uint32_t wlan_reg_chan_to_freq(struct wlan_objmgr_pdev *pdev, 454 uint32_t chan_num) 455 { 456 return reg_chan_to_freq(pdev, chan_num); 457 } 458 459 bool wlan_reg_chan_is_49ghz(struct wlan_objmgr_pdev *pdev, 460 uint8_t chan_num) 461 { 462 return reg_chan_is_49ghz(pdev, chan_num); 463 } 464 465 QDF_STATUS wlan_reg_set_country(struct wlan_objmgr_pdev *pdev, 466 uint8_t *country) 467 { 468 return reg_set_country(pdev, country); 469 } 470 471 QDF_STATUS wlan_reg_set_11d_country(struct wlan_objmgr_pdev *pdev, 472 uint8_t *country) 473 { 474 return reg_set_11d_country(pdev, country); 475 } 476 477 bool wlan_reg_is_world(uint8_t *country) 478 { 479 return reg_is_world_alpha2(country); 480 } 481 482 bool wlan_reg_is_us(uint8_t *country) 483 { 484 return reg_is_us_alpha2(country); 485 } 486 487 void wlan_reg_register_chan_change_callback(struct wlan_objmgr_psoc *psoc, 488 reg_chan_change_callback cbk, 489 void *arg) 490 { 491 reg_register_chan_change_callback(psoc, cbk, arg); 492 493 } 494 495 void wlan_reg_unregister_chan_change_callback(struct wlan_objmgr_psoc *psoc, 496 reg_chan_change_callback cbk) 497 { 498 reg_unregister_chan_change_callback(psoc, cbk); 499 } 500 501 bool wlan_reg_11d_original_enabled_on_host(struct wlan_objmgr_psoc *psoc) 502 { 503 return reg_11d_original_enabled_on_host(psoc); 504 } 505 506 bool wlan_reg_11d_enabled_on_host(struct wlan_objmgr_psoc *psoc) 507 { 508 return reg_11d_enabled_on_host(psoc); 509 } 510 511 bool wlan_reg_is_dsrc_chan(struct wlan_objmgr_pdev *pdev, uint8_t chan_num) 512 { 513 return reg_is_dsrc_chan(pdev, chan_num); 514 } 515 516 bool wlan_reg_is_etsi13_srd_chan(struct wlan_objmgr_pdev *pdev, 517 uint8_t chan_num) 518 { 519 return reg_is_etsi13_srd_chan(pdev, chan_num); 520 } 521 522 bool wlan_reg_is_etsi13_regdmn(struct wlan_objmgr_pdev *pdev) 523 { 524 return reg_is_etsi13_regdmn(pdev); 525 } 526 527 bool wlan_reg_is_etsi13_srd_chan_allowed_master_mode(struct wlan_objmgr_pdev 528 *pdev) 529 { 530 return reg_is_etsi13_srd_chan_allowed_master_mode(pdev); 531 } 532 533 QDF_STATUS wlan_reg_get_chip_mode(struct wlan_objmgr_pdev *pdev, 534 uint32_t *chip_mode) 535 { 536 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 537 538 pdev_priv_obj = wlan_objmgr_pdev_get_comp_private_obj(pdev, 539 WLAN_UMAC_COMP_REGULATORY); 540 541 if (NULL == pdev_priv_obj) { 542 reg_err("reg pdev private obj is NULL"); 543 return QDF_STATUS_E_FAULT; 544 } 545 546 *chip_mode = pdev_priv_obj->wireless_modes; 547 548 return QDF_STATUS_SUCCESS; 549 } 550 551 bool wlan_reg_is_11d_scan_inprogress(struct wlan_objmgr_psoc *psoc) 552 { 553 return reg_is_11d_scan_inprogress(psoc); 554 } 555 556 QDF_STATUS wlan_reg_get_freq_range(struct wlan_objmgr_pdev *pdev, 557 uint32_t *low_2g, 558 uint32_t *high_2g, 559 uint32_t *low_5g, 560 uint32_t *high_5g) 561 { 562 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj; 563 564 pdev_priv_obj = wlan_objmgr_pdev_get_comp_private_obj(pdev, 565 WLAN_UMAC_COMP_REGULATORY); 566 567 if (NULL == pdev_priv_obj) { 568 reg_err("reg pdev private obj is NULL"); 569 return QDF_STATUS_E_FAULT; 570 } 571 572 *low_2g = pdev_priv_obj->range_2g_low; 573 *high_2g = pdev_priv_obj->range_2g_high; 574 *low_5g = pdev_priv_obj->range_5g_low; 575 *high_5g = pdev_priv_obj->range_5g_high; 576 577 return QDF_STATUS_SUCCESS; 578 } 579 580 struct wlan_lmac_if_reg_tx_ops * 581 wlan_reg_get_tx_ops(struct wlan_objmgr_psoc *psoc) 582 { 583 return reg_get_psoc_tx_ops(psoc); 584 } 585 586 QDF_STATUS wlan_reg_get_curr_regdomain(struct wlan_objmgr_pdev *pdev, 587 struct cur_regdmn_info *cur_regdmn) 588 { 589 return reg_get_curr_regdomain(pdev, cur_regdmn); 590 } 591