Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 1 | /* |
Sandeep Puligilla | 985d1ee | 2017-01-04 16:41:39 -0800 | [diff] [blame] | 2 | * Copyright (c) 2014-2017 The Linux Foundation. All rights reserved. |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 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; |
Amar Singhal | 6fc6638 | 2016-11-09 13:33:33 -0800 | [diff] [blame] | 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; |
Dustin Brown | 67f1695 | 2017-02-03 15:37:53 -0800 | [diff] [blame] | 253 | chan_num < wiphy->bands[NL80211_BAND_2GHZ]->n_channels; |
Amar Singhal | b7fe261 | 2016-10-19 10:49:58 -0700 | [diff] [blame] | 254 | chan_num++) { |
Dustin Brown | 67f1695 | 2017-02-03 15:37:53 -0800 | [diff] [blame] | 255 | chan = &(wiphy->bands[NL80211_BAND_2GHZ]->channels[chan_num]); |
Amar Singhal | 6fc6638 | 2016-11-09 13:33:33 -0800 | [diff] [blame] | 256 | if (chan->flags & IEEE80211_CHAN_NO_20MHZ) |
| 257 | chan->flags |= IEEE80211_CHAN_DISABLED; |
Amar Singhal | b7fe261 | 2016-10-19 10:49:58 -0700 | [diff] [blame] | 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; |
Manjeet Singh | ec40206 | 2016-10-27 15:58:01 +0530 | [diff] [blame] | 390 | chan_num < wiphy->bands[band_num]->n_channels && |
| 391 | chan_enum < NUM_CHANNELS; |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 392 | chan_num++) { |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 393 | |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 394 | wiphy_chan = |
| 395 | &(wiphy->bands[band_num]->channels[chan_num]); |
| 396 | cds_chan = &(reg_channels[chan_enum]); |
Amar Singhal | b2cb300 | 2016-08-11 16:10:36 -0700 | [diff] [blame] | 397 | if (CHAN_ENUM_144 == chan_enum) |
| 398 | wiphy_chan_144 = wiphy_chan; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 399 | |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 400 | chan_enum++; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 401 | |
| 402 | if (!reset) |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 403 | hdd_modify_wiphy(wiphy, wiphy_chan); |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 404 | |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 405 | if (wiphy_chan->flags & IEEE80211_CHAN_DISABLED) { |
| 406 | cds_chan->state = CHANNEL_STATE_DISABLE; |
Amar Singhal | 1851788 | 2016-08-08 12:26:20 -0700 | [diff] [blame] | 407 | } else if ((wiphy_chan->flags & |
| 408 | (IEEE80211_CHAN_RADAR | |
| 409 | IEEE80211_CHAN_PASSIVE_SCAN)) || |
| 410 | ((hdd_ctx->config->indoor_channel_support |
| 411 | == false) && |
| 412 | (wiphy_chan->flags & |
| 413 | IEEE80211_CHAN_INDOOR_ONLY))) { |
| 414 | if ((wiphy_chan->flags & |
| 415 | IEEE80211_CHAN_INDOOR_ONLY) && |
| 416 | (false == |
| 417 | hdd_ctx->config->indoor_channel_support)) |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 418 | wiphy_chan->flags |= |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 419 | IEEE80211_CHAN_PASSIVE_SCAN; |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 420 | cds_chan->state = CHANNEL_STATE_DFS; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 421 | } else { |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 422 | cds_chan->state = CHANNEL_STATE_ENABLE; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 423 | } |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 424 | cds_chan->pwr_limit = wiphy_chan->max_power; |
| 425 | cds_chan->flags = wiphy_chan->flags; |
Amar Singhal | 1c94492 | 2016-03-23 18:46:49 -0700 | [diff] [blame] | 426 | |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
| 430 | if (0 == (hdd_ctx->reg.eeprom_rd_ext & |
Sandeep Puligilla | 985d1ee | 2017-01-04 16:41:39 -0800 | [diff] [blame] | 431 | (1 << WMI_REG_EXT_FCC_CH_144))) { |
Amar Singhal | 388b3f0 | 2016-02-10 13:37:18 -0800 | [diff] [blame] | 432 | cds_chan = &(reg_channels[CHAN_ENUM_144]); |
| 433 | cds_chan->state = CHANNEL_STATE_DISABLE; |
Amar Singhal | b2cb300 | 2016-08-11 16:10:36 -0700 | [diff] [blame] | 434 | if (NULL != wiphy_chan_144) |
| 435 | wiphy_chan_144->flags |= IEEE80211_CHAN_DISABLED; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 436 | } |
Amar Singhal | 6842e8f | 2016-02-23 16:30:32 -0800 | [diff] [blame] | 437 | |
| 438 | wlan_hdd_cfg80211_update_band(wiphy, band_capability); |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 439 | } |
| 440 | |
Amar Singhal | 604ba6cf | 2016-07-27 15:29:51 -0700 | [diff] [blame] | 441 | /** |
| 442 | * hdd_set_dfs_region() - set the dfs_region |
| 443 | * @dfs_region: the dfs_region to set |
| 444 | * |
| 445 | * Return: void |
| 446 | */ |
| 447 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS) |
| 448 | static void hdd_set_dfs_region(hdd_context_t *hdd_ctx, |
| 449 | enum dfs_region dfs_reg) |
| 450 | { |
| 451 | cds_put_dfs_region(dfs_reg); |
| 452 | } |
| 453 | #else |
| 454 | static void hdd_set_dfs_region(hdd_context_t *hdd_ctx, |
| 455 | enum dfs_region dfs_reg) |
| 456 | { |
| 457 | |
| 458 | /* remap the ctl code to dfs region code */ |
| 459 | switch (hdd_ctx->reg.ctl_5g) { |
| 460 | case FCC: |
| 461 | cds_put_dfs_region(DFS_FCC_REGION); |
| 462 | break; |
| 463 | case ETSI: |
| 464 | cds_put_dfs_region(DFS_ETSI_REGION); |
| 465 | break; |
| 466 | case MKK: |
| 467 | cds_put_dfs_region(DFS_MKK_REGION); |
| 468 | break; |
| 469 | default: |
| 470 | /* set default dfs_region to FCC */ |
| 471 | cds_put_dfs_region(DFS_FCC_REGION); |
| 472 | break; |
| 473 | } |
| 474 | |
| 475 | } |
| 476 | #endif |
| 477 | |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 478 | |
| 479 | /** |
| 480 | * hdd_regulatory_init() - regulatory_init |
| 481 | * @hdd_ctx: hdd context |
| 482 | * @wiphy: wiphy |
| 483 | * |
| 484 | * Return: int |
| 485 | */ |
| 486 | int hdd_regulatory_init(hdd_context_t *hdd_ctx, struct wiphy *wiphy) |
| 487 | { |
| 488 | int ret_val; |
| 489 | struct regulatory *reg_info; |
Amar Singhal | 604ba6cf | 2016-07-27 15:29:51 -0700 | [diff] [blame] | 490 | enum dfs_region dfs_reg; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 491 | |
| 492 | reg_info = &hdd_ctx->reg; |
| 493 | |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 494 | ret_val = cds_fill_some_regulatory_info(reg_info); |
| 495 | if (ret_val) { |
| 496 | hdd_err("incorrect BDF regulatory data"); |
| 497 | return ret_val; |
| 498 | } |
| 499 | |
Dustin Brown | 38f2b55 | 2016-10-04 13:57:46 -0700 | [diff] [blame] | 500 | hdd_regulatory_wiphy_init(hdd_ctx, reg_info, wiphy); |
| 501 | |
| 502 | hdd_process_regulatory_data(hdd_ctx, wiphy, true); |
| 503 | |
| 504 | reg_info->cc_src = SOURCE_DRIVER; |
| 505 | |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 506 | cds_put_default_country(reg_info->alpha2); |
| 507 | |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 508 | cds_fill_and_send_ctl_to_fw(reg_info); |
| 509 | |
Amar Singhal | 604ba6cf | 2016-07-27 15:29:51 -0700 | [diff] [blame] | 510 | hdd_set_dfs_region(hdd_ctx, DFS_FCC_REGION); |
| 511 | cds_get_dfs_region(&dfs_reg); |
| 512 | cds_set_wma_dfs_region(dfs_reg); |
| 513 | |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 514 | return 0; |
| 515 | } |
| 516 | |
| 517 | /** |
| 518 | * hdd_program_country_code() - process channel information from country code |
| 519 | * @hdd_ctx: hddc context |
| 520 | * |
| 521 | * Return: void |
| 522 | */ |
| 523 | void hdd_program_country_code(hdd_context_t *hdd_ctx) |
| 524 | { |
| 525 | struct wiphy *wiphy = hdd_ctx->wiphy; |
| 526 | uint8_t *country_alpha2 = hdd_ctx->reg.alpha2; |
| 527 | |
Abhishek Singh | 897b27a | 2017-03-17 11:56:46 +0530 | [diff] [blame] | 528 | if (!init_by_reg_core && !init_by_driver) { |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 529 | init_by_driver = true; |
| 530 | if (('0' != country_alpha2[0]) || |
Amar Singhal | 38c5eeb | 2016-08-22 16:50:01 -0700 | [diff] [blame] | 531 | ('0' != country_alpha2[1])) |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 532 | regulatory_hint(wiphy, country_alpha2); |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | |
| 536 | |
| 537 | /** |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 538 | * hdd_restore_custom_reg_settings() - restore custom reg settings |
| 539 | * @wiphy: wiphy structure |
| 540 | * @country_alpha2: alpha2 of the country |
| 541 | * @reset: whether wiphy is reset |
| 542 | * |
| 543 | * Return: void |
| 544 | */ |
| 545 | #if (LINUX_VERSION_CODE > KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS) |
| 546 | static void hdd_restore_custom_reg_settings(struct wiphy *wiphy, |
| 547 | uint8_t *country_alpha2, |
| 548 | bool *reset) |
| 549 | { |
| 550 | } |
| 551 | #else |
| 552 | static void hdd_restore_custom_reg_settings(struct wiphy *wiphy, |
| 553 | uint8_t *country_alpha2, |
| 554 | bool *reset) |
| 555 | { |
| 556 | struct ieee80211_supported_band *sband; |
Dustin Brown | a30892e | 2016-10-12 17:28:36 -0700 | [diff] [blame] | 557 | enum nl80211_band band; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 558 | struct ieee80211_channel *chan; |
| 559 | int i; |
| 560 | |
| 561 | if ((country_alpha2[0] == '0') && |
| 562 | (country_alpha2[1] == '0') && |
| 563 | (wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY)) { |
| 564 | |
Dustin Brown | a30892e | 2016-10-12 17:28:36 -0700 | [diff] [blame] | 565 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 566 | sband = wiphy->bands[band]; |
| 567 | if (!sband) |
| 568 | continue; |
| 569 | for (i = 0; i < sband->n_channels; i++) { |
| 570 | chan = &sband->channels[i]; |
| 571 | chan->flags = chan->orig_flags; |
| 572 | chan->max_antenna_gain = chan->orig_mag; |
| 573 | chan->max_power = chan->orig_mpwr; |
| 574 | } |
| 575 | } |
| 576 | *reset = true; |
| 577 | } |
| 578 | } |
| 579 | #endif |
| 580 | |
| 581 | |
| 582 | /** |
| 583 | * hdd_restore_reg_flags() - restore regulatory flags |
| 584 | * @flags: regulatory flags |
| 585 | * |
| 586 | * Return: void |
| 587 | */ |
| 588 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS) |
| 589 | static void hdd_restore_reg_flags(struct wiphy *wiphy, uint32_t flags) |
| 590 | { |
| 591 | wiphy->regulatory_flags = flags; |
| 592 | } |
| 593 | #else |
| 594 | static void hdd_restore_reg_flags(struct wiphy *wiphy, uint32_t flags) |
| 595 | { |
| 596 | wiphy->flags = flags; |
| 597 | } |
| 598 | #endif |
| 599 | |
| 600 | |
| 601 | /** |
| 602 | * hdd_reg_notifier() - regulatory notifier |
| 603 | * @wiphy: wiphy |
| 604 | * @request: regulatory request |
| 605 | * |
| 606 | * Return: void |
| 607 | */ |
| 608 | void hdd_reg_notifier(struct wiphy *wiphy, |
| 609 | struct regulatory_request *request) |
| 610 | { |
| 611 | hdd_context_t *hdd_ctx = wiphy_priv(wiphy); |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 612 | bool reset = false; |
Amar Singhal | 604ba6cf | 2016-07-27 15:29:51 -0700 | [diff] [blame] | 613 | enum dfs_region dfs_reg; |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 614 | |
| 615 | hdd_info("country: %c%c, initiator %d, dfs_region: %d", |
| 616 | request->alpha2[0], |
| 617 | request->alpha2[1], |
| 618 | request->initiator, |
| 619 | request->dfs_region); |
| 620 | |
| 621 | if (NULL == hdd_ctx) { |
| 622 | hdd_err("invalid hdd_ctx pointer"); |
| 623 | return; |
| 624 | } |
| 625 | |
| 626 | if (cds_is_driver_unloading() || cds_is_driver_recovering()) { |
| 627 | hdd_err("%s: unloading or ssr in progress, ignore", |
| 628 | __func__); |
| 629 | return; |
| 630 | } |
| 631 | |
Dustin Brown | c0ad1ec | 2017-01-26 12:01:32 -0800 | [diff] [blame] | 632 | if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) { |
| 633 | hdd_err("Driver module is closed; dropping request"); |
| 634 | return; |
| 635 | } |
| 636 | |
Mukul Sharma | 0c854a0 | 2016-10-20 15:36:20 +0530 | [diff] [blame] | 637 | if (hdd_ctx->isWiphySuspended == true) { |
| 638 | hdd_err("%s: system/cfg80211 is already suspend", __func__); |
| 639 | return; |
| 640 | } |
| 641 | |
Amar Singhal | 604ba6cf | 2016-07-27 15:29:51 -0700 | [diff] [blame] | 642 | if (('K' == request->alpha2[0]) && |
| 643 | ('R' == request->alpha2[1])) |
| 644 | request->dfs_region = DFS_KR_REGION; |
| 645 | |
| 646 | if (('C' == request->alpha2[0]) && |
| 647 | ('N' == request->alpha2[1])) |
| 648 | request->dfs_region = DFS_CN_REGION; |
| 649 | |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 650 | /* first check if this callback is in response to the driver callback */ |
| 651 | |
| 652 | switch (request->initiator) { |
| 653 | case NL80211_REGDOM_SET_BY_DRIVER: |
| 654 | case NL80211_REGDOM_SET_BY_CORE: |
| 655 | case NL80211_REGDOM_SET_BY_USER: |
| 656 | |
| 657 | if ((false == init_by_driver) && |
| 658 | (false == init_by_reg_core)) { |
| 659 | |
| 660 | if (NL80211_REGDOM_SET_BY_CORE == request->initiator) |
| 661 | return; |
| 662 | init_by_reg_core = true; |
| 663 | } |
| 664 | |
| 665 | if ((NL80211_REGDOM_SET_BY_DRIVER == request->initiator) && |
| 666 | (true == init_by_driver)) { |
| 667 | |
| 668 | /* |
| 669 | * restore the driver regulatory flags since |
| 670 | * regulatory_hint may have |
| 671 | * changed them |
| 672 | */ |
| 673 | hdd_restore_reg_flags(wiphy, hdd_ctx->reg.reg_flags); |
| 674 | } |
| 675 | |
| 676 | if (NL80211_REGDOM_SET_BY_CORE == request->initiator) { |
| 677 | hdd_ctx->reg.cc_src = SOURCE_CORE; |
| 678 | if (is_wiphy_custom_regulatory(wiphy)) |
| 679 | reset = true; |
Amar Singhal | 6edf973 | 2016-11-20 21:43:40 -0800 | [diff] [blame] | 680 | } else if (NL80211_REGDOM_SET_BY_DRIVER == request->initiator) { |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 681 | hdd_ctx->reg.cc_src = SOURCE_DRIVER; |
Amar Singhal | 6edf973 | 2016-11-20 21:43:40 -0800 | [diff] [blame] | 682 | sme_set_cc_src(hdd_ctx->hHal, SOURCE_DRIVER); |
| 683 | } else { |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 684 | hdd_ctx->reg.cc_src = SOURCE_USERSPACE; |
| 685 | hdd_restore_custom_reg_settings(wiphy, |
| 686 | request->alpha2, |
| 687 | &reset); |
| 688 | } |
| 689 | |
| 690 | hdd_ctx->reg.alpha2[0] = request->alpha2[0]; |
| 691 | hdd_ctx->reg.alpha2[1] = request->alpha2[1]; |
| 692 | |
| 693 | hdd_update_regulatory_info(hdd_ctx); |
| 694 | |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 695 | hdd_process_regulatory_data(hdd_ctx, wiphy, reset); |
| 696 | |
Amar Singhal | e4f28ee | 2015-10-21 14:36:56 -0700 | [diff] [blame] | 697 | sme_generic_change_country_code(hdd_ctx->hHal, |
| 698 | hdd_ctx->reg.alpha2); |
| 699 | |
| 700 | cds_fill_and_send_ctl_to_fw(&hdd_ctx->reg); |
| 701 | |
| 702 | hdd_set_dfs_region(hdd_ctx, request->dfs_region); |
| 703 | |
| 704 | cds_get_dfs_region(&dfs_reg); |
| 705 | cds_set_wma_dfs_region(dfs_reg); |
| 706 | break; |
| 707 | |
| 708 | default: |
| 709 | break; |
| 710 | } |
| 711 | } |