Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014-2016 The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 5 | * |
| 6 | * |
| 7 | * Permission to use, copy, modify, and/or distribute this software for |
| 8 | * any purpose with or without fee is hereby granted, provided that the |
| 9 | * above copyright notice and this permission notice appear in all |
| 10 | * copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 13 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 15 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 16 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 17 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 18 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 19 | * PERFORMANCE OF THIS SOFTWARE. |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * This file was originally distributed by Qualcomm Atheros, Inc. |
| 24 | * under proprietary terms before Copyright ownership was assigned |
| 25 | * to the Linux Foundation. |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * DOC: wlan_hdd_regulatory.c |
| 30 | * |
| 31 | * hdd regulatory implementation |
| 32 | */ |
| 33 | |
| 34 | #include "qdf_types.h" |
Amar Singhal | 5f99786 | 2016-08-24 13:17:50 -0700 | [diff] [blame] | 35 | #include "qdf_trace.h" |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 36 | #include "cds_reg_service.h" |
Amar Singhal | 604ba6cf | 2016-07-27 15:29:51 -0700 | [diff] [blame] | 37 | #include "cds_regdomain.h" |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 38 | #include "sme_api.h" |
| 39 | #include "wlan_hdd_main.h" |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 40 | #include "wlan_hdd_regulatory.h" |
| 41 | |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 42 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS) |
| 43 | #define IEEE80211_CHAN_PASSIVE_SCAN IEEE80211_CHAN_NO_IR |
| 44 | #define IEEE80211_CHAN_NO_IBSS IEEE80211_CHAN_NO_IR |
| 45 | #endif |
| 46 | |
| 47 | #define REG_RULE_2412_2462 REG_RULE(2412-10, 2462+10, 40, 0, 20, 0) |
| 48 | |
| 49 | #define REG_RULE_2467_2472 REG_RULE(2467-10, 2472+10, 40, 0, 20, \ |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 50 | NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS) |
| 51 | |
Amar Singhal | 1c94492 | 2016-03-23 18:46:49 -0700 | [diff] [blame] | 52 | #define REG_RULE_2484 REG_RULE(2484-10, 2484+10, 20, 0, 20, \ |
| 53 | NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS | \ |
| 54 | NL80211_RRF_NO_OFDM) |
| 55 | |
| 56 | #define REG_RULE_5180_5320 REG_RULE(5180-10, 5320+10, 160, 0, 20, \ |
| 57 | NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS) |
| 58 | |
| 59 | #define REG_RULE_5500_5720 REG_RULE(5500-10, 5720+10, 160, 0, 20, \ |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 60 | NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS) |
| 61 | |
| 62 | #define REG_RULE_5745_5925 REG_RULE(5745-10, 5925+10, 80, 0, 20, \ |
| 63 | NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS) |
| 64 | |
| 65 | static bool init_by_driver; |
| 66 | static bool init_by_reg_core; |
| 67 | |
| 68 | static const struct ieee80211_regdomain |
| 69 | hdd_world_regrules_60_61_62 = { |
| 70 | .n_reg_rules = 6, |
| 71 | .alpha2 = "00", |
| 72 | .reg_rules = { |
| 73 | REG_RULE_2412_2462, |
| 74 | REG_RULE_2467_2472, |
| 75 | REG_RULE_2484, |
| 76 | REG_RULE_5180_5320, |
| 77 | REG_RULE_5500_5720, |
| 78 | REG_RULE_5745_5925, |
| 79 | } |
| 80 | }; |
| 81 | |
| 82 | static const struct ieee80211_regdomain |
| 83 | hdd_world_regrules_63_65 = { |
| 84 | .n_reg_rules = 4, |
| 85 | .alpha2 = "00", |
| 86 | .reg_rules = { |
| 87 | REG_RULE_2412_2462, |
| 88 | REG_RULE_2467_2472, |
| 89 | REG_RULE_5180_5320, |
| 90 | REG_RULE_5745_5925, |
| 91 | } |
| 92 | }; |
| 93 | |
| 94 | static const struct ieee80211_regdomain |
| 95 | hdd_world_regrules_64 = { |
| 96 | .n_reg_rules = 3, |
| 97 | .alpha2 = "00", |
| 98 | .reg_rules = { |
| 99 | REG_RULE_2412_2462, |
| 100 | REG_RULE_5180_5320, |
| 101 | REG_RULE_5745_5925, |
| 102 | } |
| 103 | }; |
| 104 | |
| 105 | static const struct ieee80211_regdomain |
| 106 | hdd_world_regrules_66_69 = { |
| 107 | .n_reg_rules = 4, |
| 108 | .alpha2 = "00", |
| 109 | .reg_rules = { |
| 110 | REG_RULE_2412_2462, |
| 111 | REG_RULE_5180_5320, |
| 112 | REG_RULE_5500_5720, |
| 113 | REG_RULE_5745_5925, |
| 114 | } |
| 115 | }; |
| 116 | |
| 117 | static const struct ieee80211_regdomain |
| 118 | hdd_world_regrules_67_68_6A_6C = { |
| 119 | .n_reg_rules = 5, |
| 120 | .alpha2 = "00", |
| 121 | .reg_rules = { |
| 122 | REG_RULE_2412_2462, |
| 123 | REG_RULE_2467_2472, |
| 124 | REG_RULE_5180_5320, |
| 125 | REG_RULE_5500_5720, |
| 126 | REG_RULE_5745_5925, |
| 127 | } |
| 128 | }; |
| 129 | |
| 130 | /** |
| 131 | * hdd_get_world_regrules() - get the appropriate world regrules |
| 132 | * @reg: regulatory data |
| 133 | * |
| 134 | * Return: regulatory rules ptr |
| 135 | */ |
| 136 | static const struct ieee80211_regdomain *hdd_get_world_regrules( |
| 137 | struct regulatory *reg) |
| 138 | { |
Amar Singhal | 2299511 | 2016-01-22 10:42:33 -0800 | [diff] [blame] | 139 | struct reg_dmn_pair *regpair = |
| 140 | (struct reg_dmn_pair *)reg->regpair; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 141 | |
Amar Singhal | a7bb01b | 2016-01-27 11:31:59 -0800 | [diff] [blame] | 142 | switch (regpair->reg_dmn_pair) { |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 143 | case 0x60: |
| 144 | case 0x61: |
| 145 | case 0x62: |
| 146 | return &hdd_world_regrules_60_61_62; |
| 147 | case 0x63: |
| 148 | case 0x65: |
| 149 | return &hdd_world_regrules_63_65; |
| 150 | case 0x64: |
| 151 | return &hdd_world_regrules_64; |
| 152 | case 0x66: |
| 153 | case 0x69: |
| 154 | return &hdd_world_regrules_66_69; |
| 155 | case 0x67: |
| 156 | case 0x68: |
| 157 | case 0x6A: |
| 158 | case 0x6C: |
| 159 | return &hdd_world_regrules_67_68_6A_6C; |
| 160 | default: |
| 161 | hdd_warn("invalid world mode in BDF"); |
| 162 | return &hdd_world_regrules_60_61_62; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * hdd_is_world_regdomain() - whether world regdomain |
| 168 | * @reg_domain: integer regulatory domain |
| 169 | * |
| 170 | * Return: bool |
| 171 | */ |
Jeff Johnson | 87a2425 | 2016-10-05 16:20:52 -0700 | [diff] [blame] | 172 | static bool hdd_is_world_regdomain(uint32_t reg_domain) |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 173 | { |
Amar Singhal | 5f99786 | 2016-08-24 13:17:50 -0700 | [diff] [blame] | 174 | uint32_t temp_regd = reg_domain & ~WORLD_ROAMING_FLAG; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 175 | |
Amar Singhal | 5f99786 | 2016-08-24 13:17:50 -0700 | [diff] [blame] | 176 | return ((temp_regd & CTRY_FLAG) != CTRY_FLAG) && |
| 177 | ((temp_regd & WORLD_ROAMING_MASK) == |
| 178 | WORLD_ROAMING_PREFIX); |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | |
| 182 | /** |
| 183 | * hdd_update_regulatory_info() - update regulatory info |
| 184 | * @hdd_ctx: hdd context |
| 185 | * |
| 186 | * Return: void |
| 187 | */ |
| 188 | static void hdd_update_regulatory_info(hdd_context_t *hdd_ctx) |
| 189 | { |
| 190 | uint32_t country_code; |
| 191 | |
| 192 | country_code = cds_get_country_from_alpha2(hdd_ctx->reg.alpha2); |
| 193 | |
Amar Singhal | 5f99786 | 2016-08-24 13:17:50 -0700 | [diff] [blame] | 194 | hdd_ctx->reg.reg_domain = CTRY_FLAG; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 195 | hdd_ctx->reg.reg_domain |= country_code; |
| 196 | |
| 197 | cds_fill_some_regulatory_info(&hdd_ctx->reg); |
| 198 | |
| 199 | } |
| 200 | |
| 201 | /** |
Abhishek Singh | 3e6172f | 2016-05-04 16:56:48 +0530 | [diff] [blame] | 202 | * hdd_reset_global_reg_params - Reset global static reg params |
| 203 | * |
| 204 | * This function is helpful in static driver to reset |
| 205 | * the global params. |
| 206 | * |
| 207 | * Return: void |
| 208 | */ |
| 209 | void hdd_reset_global_reg_params(void) |
| 210 | { |
| 211 | init_by_driver = false; |
| 212 | init_by_reg_core = false; |
| 213 | } |
| 214 | |
| 215 | /** |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 216 | * hdd_regulatory_wiphy_init() - regulatory wiphy init |
| 217 | * @hdd_ctx: hdd context |
| 218 | * @reg: regulatory data |
| 219 | * @wiphy: wiphy structure |
| 220 | * |
| 221 | * Return: void |
| 222 | */ |
| 223 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS) |
| 224 | static void hdd_regulatory_wiphy_init(hdd_context_t *hdd_ctx, |
| 225 | struct regulatory *reg, |
| 226 | struct wiphy *wiphy) |
| 227 | { |
| 228 | const struct ieee80211_regdomain *reg_rules; |
Amar Singhal | b7fe261 | 2016-10-19 10:49:58 -0700 | [diff] [blame] | 229 | int chan_num; |
| 230 | struct ieee80211_channel chan; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 231 | |
| 232 | if (hdd_is_world_regdomain(reg->reg_domain)) { |
| 233 | reg_rules = hdd_get_world_regrules(reg); |
| 234 | wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG; |
| 235 | } else if (hdd_ctx->config->fRegChangeDefCountry) { |
| 236 | wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG; |
| 237 | reg_rules = &hdd_world_regrules_60_61_62; |
| 238 | } else { |
| 239 | wiphy->regulatory_flags |= REGULATORY_STRICT_REG; |
| 240 | reg_rules = &hdd_world_regrules_60_61_62; |
| 241 | } |
| 242 | |
| 243 | /* |
| 244 | * save the original driver regulatory flags |
| 245 | */ |
| 246 | hdd_ctx->reg.reg_flags = wiphy->regulatory_flags; |
| 247 | wiphy_apply_custom_regulatory(wiphy, reg_rules); |
| 248 | |
| 249 | /* |
Amar Singhal | b7fe261 | 2016-10-19 10:49:58 -0700 | [diff] [blame] | 250 | * disable 2.4 Ghz channels that dont have 20 mhz bw |
| 251 | */ |
| 252 | for (chan_num = 0; |
| 253 | chan_num < wiphy->bands[IEEE80211_BAND_2GHZ]->n_channels; |
| 254 | chan_num++) { |
| 255 | chan = wiphy->bands[IEEE80211_BAND_2GHZ]->channels[chan_num]; |
| 256 | if (chan.flags & IEEE80211_CHAN_NO_20MHZ) |
| 257 | chan.flags |= IEEE80211_CHAN_DISABLED; |
| 258 | } |
| 259 | |
| 260 | /* |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 261 | * restore the driver regulatory flags since |
| 262 | * wiphy_apply_custom_regulatory may have |
| 263 | * changed them |
| 264 | */ |
| 265 | wiphy->regulatory_flags = hdd_ctx->reg.reg_flags; |
| 266 | |
| 267 | } |
| 268 | #else |
| 269 | static void hdd_regulatory_wiphy_init(hdd_context_t *hdd_ctx, |
| 270 | struct regulatory *reg, |
| 271 | struct wiphy *wiphy) |
| 272 | { |
| 273 | const struct ieee80211_regdomain *reg_rules; |
| 274 | |
| 275 | if (hdd_is_world_regdomain(reg->reg_domain)) { |
| 276 | reg_rules = hdd_get_world_regrules(reg); |
| 277 | wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY; |
| 278 | } else if (hdd_ctx->config->fRegChangeDefCountry) { |
| 279 | wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY; |
| 280 | reg_rules = &hdd_world_regrules_60_61_62; |
| 281 | } else { |
| 282 | wiphy->flags |= WIPHY_FLAG_STRICT_REGULATORY; |
| 283 | reg_rules = &hdd_world_regrules_60_61_62; |
| 284 | } |
| 285 | |
| 286 | /* |
| 287 | * save the original driver regulatory flags |
| 288 | */ |
| 289 | hdd_ctx->reg.reg_flags = wiphy->flags; |
| 290 | wiphy_apply_custom_regulatory(wiphy, reg_rules); |
| 291 | |
| 292 | /* |
| 293 | * restore the driver regulatory flags since |
| 294 | * wiphy_apply_custom_regulatory may have |
| 295 | * changed them |
| 296 | */ |
| 297 | wiphy->flags = hdd_ctx->reg.reg_flags; |
| 298 | |
| 299 | } |
| 300 | #endif |
| 301 | |
| 302 | /** |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 303 | * is_wiphy_custom_regulatory() - is custom regulatory defined |
| 304 | * @wiphy: wiphy |
| 305 | * |
| 306 | * Return: int |
| 307 | */ |
| 308 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS) |
| 309 | static int is_wiphy_custom_regulatory(struct wiphy *wiphy) |
| 310 | { |
| 311 | |
| 312 | return wiphy->regulatory_flags & REGULATORY_CUSTOM_REG; |
| 313 | } |
| 314 | #else |
| 315 | static int is_wiphy_custom_regulatory(struct wiphy *wiphy) |
| 316 | { |
| 317 | return wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY; |
| 318 | } |
| 319 | #endif |
| 320 | |
| 321 | |
| 322 | /** |
| 323 | * hdd_modify_wiphy() - modify wiphy |
| 324 | * @wiphy: wiphy |
| 325 | * @chan: channel structure |
| 326 | * |
| 327 | * Return: void |
| 328 | */ |
| 329 | static void hdd_modify_wiphy(struct wiphy *wiphy, |
| 330 | struct ieee80211_channel *chan) |
| 331 | { |
| 332 | const struct ieee80211_reg_rule *reg_rule; |
| 333 | |
| 334 | if (is_wiphy_custom_regulatory(wiphy)) { |
| 335 | reg_rule = freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq)); |
| 336 | if (!IS_ERR(reg_rule)) { |
| 337 | chan->flags &= ~IEEE80211_CHAN_DISABLED; |
| 338 | |
| 339 | if (!(reg_rule->flags & NL80211_RRF_DFS)) { |
Abhishek Singh | 23edd1c | 2016-05-05 11:56:06 +0530 | [diff] [blame] | 340 | hdd_info("Remove dfs restriction for %u", |
| 341 | chan->center_freq); |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 342 | chan->flags &= ~IEEE80211_CHAN_RADAR; |
| 343 | } |
| 344 | |
| 345 | if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN)) { |
Abhishek Singh | 23edd1c | 2016-05-05 11:56:06 +0530 | [diff] [blame] | 346 | hdd_info("Remove passive restriction for %u", |
| 347 | chan->center_freq); |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 348 | chan->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN; |
| 349 | } |
| 350 | |
| 351 | if (!(reg_rule->flags & NL80211_RRF_NO_IBSS)) { |
Abhishek Singh | 23edd1c | 2016-05-05 11:56:06 +0530 | [diff] [blame] | 352 | hdd_info("Remove no ibss restriction for %u", |
| 353 | chan->center_freq); |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 354 | chan->flags &= ~IEEE80211_CHAN_NO_IBSS; |
| 355 | } |
| 356 | |
| 357 | chan->max_power = |
| 358 | MBM_TO_DBM(reg_rule->power_rule.max_eirp); |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * hdd_process_regulatory_data() - process regulatory data |
| 365 | * @hdd_ctx: hdd context |
| 366 | * @wiphy: wiphy |
| 367 | * @reset: whether to reset channel data |
| 368 | * |
| 369 | * Return: void |
| 370 | */ |
| 371 | static void hdd_process_regulatory_data(hdd_context_t *hdd_ctx, |
| 372 | struct wiphy *wiphy, |
| 373 | bool reset) |
| 374 | { |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 375 | int band_num; |
| 376 | int chan_num; |
Amar Singhal | b2cb300 | 2016-08-11 16:10:36 -0700 | [diff] [blame] | 377 | enum channel_enum chan_enum = CHAN_ENUM_1; |
| 378 | struct ieee80211_channel *wiphy_chan, *wiphy_chan_144 = NULL; |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 379 | struct regulatory_channel *cds_chan; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 380 | uint8_t band_capability; |
| 381 | |
| 382 | band_capability = hdd_ctx->config->nBandCapability; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 383 | |
Dustin Brown | a30892e | 2016-10-12 17:28:36 -0700 | [diff] [blame] | 384 | for (band_num = 0; band_num < NUM_NL80211_BANDS; band_num++) { |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 385 | |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 386 | if (wiphy->bands[band_num] == NULL) |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 387 | continue; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 388 | |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 389 | for (chan_num = 0; |
| 390 | chan_num < wiphy->bands[band_num]->n_channels; |
| 391 | chan_num++) { |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 392 | |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 393 | wiphy_chan = |
| 394 | &(wiphy->bands[band_num]->channels[chan_num]); |
| 395 | cds_chan = &(reg_channels[chan_enum]); |
Amar Singhal | b2cb300 | 2016-08-11 16:10:36 -0700 | [diff] [blame] | 396 | if (CHAN_ENUM_144 == chan_enum) |
| 397 | wiphy_chan_144 = wiphy_chan; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 398 | |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 399 | chan_enum++; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 400 | |
| 401 | if (!reset) |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 402 | hdd_modify_wiphy(wiphy, wiphy_chan); |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 403 | |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 404 | if (wiphy_chan->flags & IEEE80211_CHAN_DISABLED) { |
| 405 | cds_chan->state = CHANNEL_STATE_DISABLE; |
Amar Singhal | 1851788 | 2016-08-08 12:26:20 -0700 | [diff] [blame] | 406 | } else if ((wiphy_chan->flags & |
| 407 | (IEEE80211_CHAN_RADAR | |
| 408 | IEEE80211_CHAN_PASSIVE_SCAN)) || |
| 409 | ((hdd_ctx->config->indoor_channel_support |
| 410 | == false) && |
| 411 | (wiphy_chan->flags & |
| 412 | IEEE80211_CHAN_INDOOR_ONLY))) { |
| 413 | if ((wiphy_chan->flags & |
| 414 | IEEE80211_CHAN_INDOOR_ONLY) && |
| 415 | (false == |
| 416 | hdd_ctx->config->indoor_channel_support)) |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 417 | wiphy_chan->flags |= |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 418 | IEEE80211_CHAN_PASSIVE_SCAN; |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 419 | cds_chan->state = CHANNEL_STATE_DFS; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 420 | } else { |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 421 | cds_chan->state = CHANNEL_STATE_ENABLE; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 422 | } |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 423 | cds_chan->pwr_limit = wiphy_chan->max_power; |
| 424 | cds_chan->flags = wiphy_chan->flags; |
Amar Singhal | 1c94492 | 2016-03-23 18:46:49 -0700 | [diff] [blame] | 425 | |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | |
| 429 | if (0 == (hdd_ctx->reg.eeprom_rd_ext & |
| 430 | (1 << WHAL_REG_EXT_FCC_CH_144))) { |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 431 | cds_chan = &(reg_channels[CHAN_ENUM_144]); |
| 432 | cds_chan->state = CHANNEL_STATE_DISABLE; |
Amar Singhal | b2cb300 | 2016-08-11 16:10:36 -0700 | [diff] [blame] | 433 | if (NULL != wiphy_chan_144) |
| 434 | wiphy_chan_144->flags |= IEEE80211_CHAN_DISABLED; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 435 | } |
Amar Singhal | 6842e8f | 2016-02-23 16:30:32 -0800 | [diff] [blame] | 436 | |
| 437 | wlan_hdd_cfg80211_update_band(wiphy, band_capability); |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Amar Singhal | 604ba6cf | 2016-07-27 15:29:51 -0700 | [diff] [blame] | 440 | /** |
| 441 | * hdd_set_dfs_region() - set the dfs_region |
| 442 | * @dfs_region: the dfs_region to set |
| 443 | * |
| 444 | * Return: void |
| 445 | */ |
| 446 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS) |
| 447 | static void hdd_set_dfs_region(hdd_context_t *hdd_ctx, |
| 448 | enum dfs_region dfs_reg) |
| 449 | { |
| 450 | cds_put_dfs_region(dfs_reg); |
| 451 | } |
| 452 | #else |
| 453 | static void hdd_set_dfs_region(hdd_context_t *hdd_ctx, |
| 454 | enum dfs_region dfs_reg) |
| 455 | { |
| 456 | |
| 457 | /* remap the ctl code to dfs region code */ |
| 458 | switch (hdd_ctx->reg.ctl_5g) { |
| 459 | case FCC: |
| 460 | cds_put_dfs_region(DFS_FCC_REGION); |
| 461 | break; |
| 462 | case ETSI: |
| 463 | cds_put_dfs_region(DFS_ETSI_REGION); |
| 464 | break; |
| 465 | case MKK: |
| 466 | cds_put_dfs_region(DFS_MKK_REGION); |
| 467 | break; |
| 468 | default: |
| 469 | /* set default dfs_region to FCC */ |
| 470 | cds_put_dfs_region(DFS_FCC_REGION); |
| 471 | break; |
| 472 | } |
| 473 | |
| 474 | } |
| 475 | #endif |
| 476 | |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 477 | |
| 478 | /** |
| 479 | * hdd_regulatory_init() - regulatory_init |
| 480 | * @hdd_ctx: hdd context |
| 481 | * @wiphy: wiphy |
| 482 | * |
| 483 | * Return: int |
| 484 | */ |
| 485 | int hdd_regulatory_init(hdd_context_t *hdd_ctx, struct wiphy *wiphy) |
| 486 | { |
| 487 | int ret_val; |
| 488 | struct regulatory *reg_info; |
Amar Singhal | 604ba6cf | 2016-07-27 15:29:51 -0700 | [diff] [blame] | 489 | enum dfs_region dfs_reg; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 490 | |
| 491 | reg_info = &hdd_ctx->reg; |
| 492 | |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 493 | ret_val = cds_fill_some_regulatory_info(reg_info); |
| 494 | if (ret_val) { |
| 495 | hdd_err("incorrect BDF regulatory data"); |
| 496 | return ret_val; |
| 497 | } |
| 498 | |
Dustin Brown | 38f2b55 | 2016-10-04 13:57:46 -0700 | [diff] [blame] | 499 | hdd_regulatory_wiphy_init(hdd_ctx, reg_info, wiphy); |
| 500 | |
| 501 | hdd_process_regulatory_data(hdd_ctx, wiphy, true); |
| 502 | |
| 503 | reg_info->cc_src = SOURCE_DRIVER; |
| 504 | |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 505 | cds_put_default_country(reg_info->alpha2); |
| 506 | |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 507 | cds_fill_and_send_ctl_to_fw(reg_info); |
| 508 | |
Amar Singhal | 604ba6cf | 2016-07-27 15:29:51 -0700 | [diff] [blame] | 509 | hdd_set_dfs_region(hdd_ctx, DFS_FCC_REGION); |
| 510 | cds_get_dfs_region(&dfs_reg); |
| 511 | cds_set_wma_dfs_region(dfs_reg); |
| 512 | |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 513 | return 0; |
| 514 | } |
| 515 | |
| 516 | /** |
| 517 | * hdd_program_country_code() - process channel information from country code |
| 518 | * @hdd_ctx: hddc context |
| 519 | * |
| 520 | * Return: void |
| 521 | */ |
| 522 | void hdd_program_country_code(hdd_context_t *hdd_ctx) |
| 523 | { |
| 524 | struct wiphy *wiphy = hdd_ctx->wiphy; |
| 525 | uint8_t *country_alpha2 = hdd_ctx->reg.alpha2; |
| 526 | |
| 527 | if (false == init_by_reg_core) { |
| 528 | init_by_driver = true; |
| 529 | if (('0' != country_alpha2[0]) || |
Amar Singhal | 38c5eeb | 2016-08-22 16:50:01 -0700 | [diff] [blame] | 530 | ('0' != country_alpha2[1])) |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 531 | regulatory_hint(wiphy, country_alpha2); |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 532 | } |
| 533 | } |
| 534 | |
| 535 | |
| 536 | /** |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 537 | * hdd_restore_custom_reg_settings() - restore custom reg settings |
| 538 | * @wiphy: wiphy structure |
| 539 | * @country_alpha2: alpha2 of the country |
| 540 | * @reset: whether wiphy is reset |
| 541 | * |
| 542 | * Return: void |
| 543 | */ |
| 544 | #if (LINUX_VERSION_CODE > KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS) |
| 545 | static void hdd_restore_custom_reg_settings(struct wiphy *wiphy, |
| 546 | uint8_t *country_alpha2, |
| 547 | bool *reset) |
| 548 | { |
| 549 | } |
| 550 | #else |
| 551 | static void hdd_restore_custom_reg_settings(struct wiphy *wiphy, |
| 552 | uint8_t *country_alpha2, |
| 553 | bool *reset) |
| 554 | { |
| 555 | struct ieee80211_supported_band *sband; |
Dustin Brown | a30892e | 2016-10-12 17:28:36 -0700 | [diff] [blame] | 556 | enum nl80211_band band; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 557 | struct ieee80211_channel *chan; |
| 558 | int i; |
| 559 | |
| 560 | if ((country_alpha2[0] == '0') && |
| 561 | (country_alpha2[1] == '0') && |
| 562 | (wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY)) { |
| 563 | |
Dustin Brown | a30892e | 2016-10-12 17:28:36 -0700 | [diff] [blame] | 564 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 565 | sband = wiphy->bands[band]; |
| 566 | if (!sband) |
| 567 | continue; |
| 568 | for (i = 0; i < sband->n_channels; i++) { |
| 569 | chan = &sband->channels[i]; |
| 570 | chan->flags = chan->orig_flags; |
| 571 | chan->max_antenna_gain = chan->orig_mag; |
| 572 | chan->max_power = chan->orig_mpwr; |
| 573 | } |
| 574 | } |
| 575 | *reset = true; |
| 576 | } |
| 577 | } |
| 578 | #endif |
| 579 | |
| 580 | |
| 581 | /** |
| 582 | * hdd_restore_reg_flags() - restore regulatory flags |
| 583 | * @flags: regulatory flags |
| 584 | * |
| 585 | * Return: void |
| 586 | */ |
| 587 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS) |
| 588 | static void hdd_restore_reg_flags(struct wiphy *wiphy, uint32_t flags) |
| 589 | { |
| 590 | wiphy->regulatory_flags = flags; |
| 591 | } |
| 592 | #else |
| 593 | static void hdd_restore_reg_flags(struct wiphy *wiphy, uint32_t flags) |
| 594 | { |
| 595 | wiphy->flags = flags; |
| 596 | } |
| 597 | #endif |
| 598 | |
| 599 | |
| 600 | /** |
| 601 | * hdd_reg_notifier() - regulatory notifier |
| 602 | * @wiphy: wiphy |
| 603 | * @request: regulatory request |
| 604 | * |
| 605 | * Return: void |
| 606 | */ |
| 607 | void hdd_reg_notifier(struct wiphy *wiphy, |
| 608 | struct regulatory_request *request) |
| 609 | { |
| 610 | hdd_context_t *hdd_ctx = wiphy_priv(wiphy); |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 611 | bool reset = false; |
Amar Singhal | 604ba6cf | 2016-07-27 15:29:51 -0700 | [diff] [blame] | 612 | enum dfs_region dfs_reg; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 613 | |
| 614 | hdd_info("country: %c%c, initiator %d, dfs_region: %d", |
| 615 | request->alpha2[0], |
| 616 | request->alpha2[1], |
| 617 | request->initiator, |
| 618 | request->dfs_region); |
| 619 | |
| 620 | if (NULL == hdd_ctx) { |
| 621 | hdd_err("invalid hdd_ctx pointer"); |
| 622 | return; |
| 623 | } |
| 624 | |
| 625 | if (cds_is_driver_unloading() || cds_is_driver_recovering()) { |
| 626 | hdd_err("%s: unloading or ssr in progress, ignore", |
| 627 | __func__); |
| 628 | return; |
| 629 | } |
| 630 | |
Amar Singhal | 604ba6cf | 2016-07-27 15:29:51 -0700 | [diff] [blame] | 631 | if (('K' == request->alpha2[0]) && |
| 632 | ('R' == request->alpha2[1])) |
| 633 | request->dfs_region = DFS_KR_REGION; |
| 634 | |
| 635 | if (('C' == request->alpha2[0]) && |
| 636 | ('N' == request->alpha2[1])) |
| 637 | request->dfs_region = DFS_CN_REGION; |
| 638 | |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 639 | /* first check if this callback is in response to the driver callback */ |
| 640 | |
| 641 | switch (request->initiator) { |
| 642 | case NL80211_REGDOM_SET_BY_DRIVER: |
| 643 | case NL80211_REGDOM_SET_BY_CORE: |
| 644 | case NL80211_REGDOM_SET_BY_USER: |
| 645 | |
| 646 | if ((false == init_by_driver) && |
| 647 | (false == init_by_reg_core)) { |
| 648 | |
| 649 | if (NL80211_REGDOM_SET_BY_CORE == request->initiator) |
| 650 | return; |
| 651 | init_by_reg_core = true; |
| 652 | } |
| 653 | |
| 654 | if ((NL80211_REGDOM_SET_BY_DRIVER == request->initiator) && |
| 655 | (true == init_by_driver)) { |
| 656 | |
| 657 | /* |
| 658 | * restore the driver regulatory flags since |
| 659 | * regulatory_hint may have |
| 660 | * changed them |
| 661 | */ |
| 662 | hdd_restore_reg_flags(wiphy, hdd_ctx->reg.reg_flags); |
| 663 | } |
| 664 | |
| 665 | if (NL80211_REGDOM_SET_BY_CORE == request->initiator) { |
| 666 | hdd_ctx->reg.cc_src = SOURCE_CORE; |
| 667 | if (is_wiphy_custom_regulatory(wiphy)) |
| 668 | reset = true; |
| 669 | } else if (NL80211_REGDOM_SET_BY_DRIVER == request->initiator) |
| 670 | hdd_ctx->reg.cc_src = SOURCE_DRIVER; |
| 671 | else { |
| 672 | hdd_ctx->reg.cc_src = SOURCE_USERSPACE; |
| 673 | hdd_restore_custom_reg_settings(wiphy, |
| 674 | request->alpha2, |
| 675 | &reset); |
| 676 | } |
| 677 | |
| 678 | hdd_ctx->reg.alpha2[0] = request->alpha2[0]; |
| 679 | hdd_ctx->reg.alpha2[1] = request->alpha2[1]; |
| 680 | |
| 681 | hdd_update_regulatory_info(hdd_ctx); |
| 682 | |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 683 | hdd_process_regulatory_data(hdd_ctx, wiphy, reset); |
| 684 | |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 685 | sme_generic_change_country_code(hdd_ctx->hHal, |
| 686 | hdd_ctx->reg.alpha2); |
| 687 | |
| 688 | cds_fill_and_send_ctl_to_fw(&hdd_ctx->reg); |
| 689 | |
| 690 | hdd_set_dfs_region(hdd_ctx, request->dfs_region); |
| 691 | |
| 692 | cds_get_dfs_region(&dfs_reg); |
| 693 | cds_set_wma_dfs_region(dfs_reg); |
| 694 | break; |
| 695 | |
| 696 | default: |
| 697 | break; |
| 698 | } |
| 699 | } |