Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1 | /* |
Sujith | cee075a | 2009-03-13 09:07:23 +0530 | [diff] [blame] | 2 | * Copyright (c) 2008-2009 Atheros Communications Inc. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/slab.h> |
Bob Copeland | fc2ada3 | 2009-03-30 22:30:27 -0400 | [diff] [blame] | 19 | #include <net/wireless.h> |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 20 | #include "ath9k.h" |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 21 | #include "regd_common.h" |
| 22 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 23 | /* |
| 24 | * This is a set of common rules used by our world regulatory domains. |
| 25 | * We have 12 world regulatory domains. To save space we consolidate |
| 26 | * the regulatory domains in 5 structures by frequency and change |
| 27 | * the flags on our reg_notifier() on a case by case basis. |
| 28 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 29 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 30 | /* Only these channels all allow active scan on all world regulatory domains */ |
| 31 | #define ATH9K_2GHZ_CH01_11 REG_RULE(2412-10, 2462+10, 40, 0, 20, 0) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 32 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 33 | /* We enable active scan on these a case by case basis by regulatory domain */ |
| 34 | #define ATH9K_2GHZ_CH12_13 REG_RULE(2467-10, 2472+10, 40, 0, 20,\ |
| 35 | NL80211_RRF_PASSIVE_SCAN) |
| 36 | #define ATH9K_2GHZ_CH14 REG_RULE(2484-10, 2484+10, 40, 0, 20,\ |
| 37 | NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_OFDM) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 38 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 39 | /* We allow IBSS on these on a case by case basis by regulatory domain */ |
| 40 | #define ATH9K_5GHZ_5150_5350 REG_RULE(5150-10, 5350+10, 40, 0, 30,\ |
| 41 | NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS) |
| 42 | #define ATH9K_5GHZ_5470_5850 REG_RULE(5470-10, 5850+10, 40, 0, 30,\ |
| 43 | NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS) |
| 44 | #define ATH9K_5GHZ_5725_5850 REG_RULE(5725-10, 5850+10, 40, 0, 30,\ |
| 45 | NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS) |
| 46 | |
| 47 | #define ATH9K_2GHZ_ALL ATH9K_2GHZ_CH01_11, \ |
| 48 | ATH9K_2GHZ_CH12_13, \ |
| 49 | ATH9K_2GHZ_CH14 |
| 50 | |
| 51 | #define ATH9K_5GHZ_ALL ATH9K_5GHZ_5150_5350, \ |
| 52 | ATH9K_5GHZ_5470_5850 |
| 53 | /* This one skips what we call "mid band" */ |
| 54 | #define ATH9K_5GHZ_NO_MIDBAND ATH9K_5GHZ_5150_5350, \ |
| 55 | ATH9K_5GHZ_5725_5850 |
| 56 | |
| 57 | /* Can be used for: |
| 58 | * 0x60, 0x61, 0x62 */ |
| 59 | static const struct ieee80211_regdomain ath9k_world_regdom_60_61_62 = { |
| 60 | .n_reg_rules = 5, |
| 61 | .alpha2 = "99", |
| 62 | .reg_rules = { |
| 63 | ATH9K_2GHZ_ALL, |
| 64 | ATH9K_5GHZ_ALL, |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | /* Can be used by 0x63 and 0x65 */ |
| 69 | static const struct ieee80211_regdomain ath9k_world_regdom_63_65 = { |
| 70 | .n_reg_rules = 4, |
| 71 | .alpha2 = "99", |
| 72 | .reg_rules = { |
| 73 | ATH9K_2GHZ_CH01_11, |
| 74 | ATH9K_2GHZ_CH12_13, |
| 75 | ATH9K_5GHZ_NO_MIDBAND, |
| 76 | } |
| 77 | }; |
| 78 | |
| 79 | /* Can be used by 0x64 only */ |
| 80 | static const struct ieee80211_regdomain ath9k_world_regdom_64 = { |
| 81 | .n_reg_rules = 3, |
| 82 | .alpha2 = "99", |
| 83 | .reg_rules = { |
| 84 | ATH9K_2GHZ_CH01_11, |
| 85 | ATH9K_5GHZ_NO_MIDBAND, |
| 86 | } |
| 87 | }; |
| 88 | |
| 89 | /* Can be used by 0x66 and 0x69 */ |
| 90 | static const struct ieee80211_regdomain ath9k_world_regdom_66_69 = { |
| 91 | .n_reg_rules = 3, |
| 92 | .alpha2 = "99", |
| 93 | .reg_rules = { |
| 94 | ATH9K_2GHZ_CH01_11, |
| 95 | ATH9K_5GHZ_ALL, |
| 96 | } |
| 97 | }; |
| 98 | |
| 99 | /* Can be used by 0x67, 0x6A and 0x68 */ |
| 100 | static const struct ieee80211_regdomain ath9k_world_regdom_67_68_6A = { |
| 101 | .n_reg_rules = 4, |
| 102 | .alpha2 = "99", |
| 103 | .reg_rules = { |
| 104 | ATH9K_2GHZ_CH01_11, |
| 105 | ATH9K_2GHZ_CH12_13, |
| 106 | ATH9K_5GHZ_ALL, |
| 107 | } |
| 108 | }; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 109 | |
Bob Copeland | d0f48f9 | 2009-02-12 13:38:55 -0500 | [diff] [blame] | 110 | static inline bool is_wwr_sku(u16 regd) |
| 111 | { |
| 112 | return ((regd & WORLD_SKU_MASK) == WORLD_SKU_PREFIX) || |
| 113 | (regd == WORLD); |
| 114 | } |
| 115 | |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 116 | static u16 ath9k_regd_get_eepromRD(struct ath9k_regulatory *reg) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 117 | { |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 118 | return reg->current_rd & ~WORLDWIDE_ROAMING_FLAG; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 121 | bool ath9k_is_world_regd(struct ath9k_regulatory *reg) |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 122 | { |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 123 | return is_wwr_sku(ath9k_regd_get_eepromRD(reg)); |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | const struct ieee80211_regdomain *ath9k_default_world_regdomain(void) |
| 127 | { |
| 128 | /* this is the most restrictive */ |
| 129 | return &ath9k_world_regdom_64; |
| 130 | } |
| 131 | |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 132 | const struct |
| 133 | ieee80211_regdomain *ath9k_world_regdomain(struct ath9k_regulatory *reg) |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 134 | { |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 135 | switch (reg->regpair->regDmnEnum) { |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 136 | case 0x60: |
| 137 | case 0x61: |
| 138 | case 0x62: |
| 139 | return &ath9k_world_regdom_60_61_62; |
| 140 | case 0x63: |
| 141 | case 0x65: |
| 142 | return &ath9k_world_regdom_63_65; |
| 143 | case 0x64: |
| 144 | return &ath9k_world_regdom_64; |
| 145 | case 0x66: |
| 146 | case 0x69: |
| 147 | return &ath9k_world_regdom_66_69; |
| 148 | case 0x67: |
| 149 | case 0x68: |
| 150 | case 0x6A: |
| 151 | return &ath9k_world_regdom_67_68_6A; |
| 152 | default: |
| 153 | WARN_ON(1); |
| 154 | return ath9k_default_world_regdomain(); |
| 155 | } |
| 156 | } |
| 157 | |
Luis R. Rodriguez | 547e4c2 | 2009-01-28 12:17:48 -0800 | [diff] [blame] | 158 | /* Frequency is one where radar detection is required */ |
| 159 | static bool ath9k_is_radar_freq(u16 center_freq) |
| 160 | { |
| 161 | return (center_freq >= 5260 && center_freq <= 5700); |
| 162 | } |
| 163 | |
Luis R. Rodriguez | 7519a8f | 2009-01-28 12:17:49 -0800 | [diff] [blame] | 164 | /* |
Luis R. Rodriguez | 8454086 | 2009-02-21 00:20:40 -0500 | [diff] [blame] | 165 | * N.B: These exception rules do not apply radar freqs. |
| 166 | * |
| 167 | * - We enable adhoc (or beaconing) if allowed by 11d |
| 168 | * - We enable active scan if the channel is allowed by 11d |
| 169 | * - If no country IE has been processed and a we determine we have |
| 170 | * received a beacon on a channel we can enable active scan and |
| 171 | * adhoc (or beaconing). |
Luis R. Rodriguez | 7519a8f | 2009-01-28 12:17:49 -0800 | [diff] [blame] | 172 | */ |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 173 | static void ath9k_reg_apply_beaconing_flags( |
| 174 | struct wiphy *wiphy, |
| 175 | enum nl80211_reg_initiator initiator) |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 176 | { |
Luis R. Rodriguez | 8454086 | 2009-02-21 00:20:40 -0500 | [diff] [blame] | 177 | enum ieee80211_band band; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 178 | struct ieee80211_supported_band *sband; |
| 179 | const struct ieee80211_reg_rule *reg_rule; |
| 180 | struct ieee80211_channel *ch; |
| 181 | unsigned int i; |
| 182 | u32 bandwidth = 0; |
| 183 | int r; |
| 184 | |
Luis R. Rodriguez | 8454086 | 2009-02-21 00:20:40 -0500 | [diff] [blame] | 185 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 186 | |
Luis R. Rodriguez | 8454086 | 2009-02-21 00:20:40 -0500 | [diff] [blame] | 187 | if (!wiphy->bands[band]) |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 188 | continue; |
Luis R. Rodriguez | 8454086 | 2009-02-21 00:20:40 -0500 | [diff] [blame] | 189 | |
| 190 | sband = wiphy->bands[band]; |
| 191 | |
| 192 | for (i = 0; i < sband->n_channels; i++) { |
| 193 | |
| 194 | ch = &sband->channels[i]; |
| 195 | |
| 196 | if (ath9k_is_radar_freq(ch->center_freq) || |
| 197 | (ch->flags & IEEE80211_CHAN_RADAR)) |
| 198 | continue; |
| 199 | |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 200 | if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) { |
Luis R. Rodriguez | 8454086 | 2009-02-21 00:20:40 -0500 | [diff] [blame] | 201 | r = freq_reg_info(wiphy, ch->center_freq, |
| 202 | &bandwidth, ®_rule); |
| 203 | if (r) |
| 204 | continue; |
| 205 | /* |
| 206 | * If 11d had a rule for this channel ensure |
| 207 | * we enable adhoc/beaconing if it allows us to |
| 208 | * use it. Note that we would have disabled it |
| 209 | * by applying our static world regdomain by |
| 210 | * default during init, prior to calling our |
| 211 | * regulatory_hint(). |
| 212 | */ |
| 213 | if (!(reg_rule->flags & |
| 214 | NL80211_RRF_NO_IBSS)) |
| 215 | ch->flags &= |
| 216 | ~IEEE80211_CHAN_NO_IBSS; |
| 217 | if (!(reg_rule->flags & |
| 218 | NL80211_RRF_PASSIVE_SCAN)) |
| 219 | ch->flags &= |
| 220 | ~IEEE80211_CHAN_PASSIVE_SCAN; |
| 221 | } else { |
| 222 | if (ch->beacon_found) |
| 223 | ch->flags &= ~(IEEE80211_CHAN_NO_IBSS | |
| 224 | IEEE80211_CHAN_PASSIVE_SCAN); |
| 225 | } |
| 226 | } |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 227 | } |
Luis R. Rodriguez | 8454086 | 2009-02-21 00:20:40 -0500 | [diff] [blame] | 228 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | /* Allows active scan scan on Ch 12 and 13 */ |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 232 | static void ath9k_reg_apply_active_scan_flags( |
| 233 | struct wiphy *wiphy, |
| 234 | enum nl80211_reg_initiator initiator) |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 235 | { |
| 236 | struct ieee80211_supported_band *sband; |
| 237 | struct ieee80211_channel *ch; |
| 238 | const struct ieee80211_reg_rule *reg_rule; |
| 239 | u32 bandwidth = 0; |
| 240 | int r; |
| 241 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 242 | sband = wiphy->bands[IEEE80211_BAND_2GHZ]; |
| 243 | |
Luis R. Rodriguez | 8454086 | 2009-02-21 00:20:40 -0500 | [diff] [blame] | 244 | /* |
| 245 | * If no country IE has been received always enable active scan |
| 246 | * on these channels. This is only done for specific regulatory SKUs |
| 247 | */ |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 248 | if (initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) { |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 249 | ch = &sband->channels[11]; /* CH 12 */ |
| 250 | if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 251 | ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN; |
| 252 | ch = &sband->channels[12]; /* CH 13 */ |
| 253 | if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 254 | ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN; |
| 255 | return; |
| 256 | } |
| 257 | |
Luis R. Rodriguez | 8454086 | 2009-02-21 00:20:40 -0500 | [diff] [blame] | 258 | /* |
| 259 | * If a country IE has been recieved check its rule for this |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 260 | * channel first before enabling active scan. The passive scan |
Luis R. Rodriguez | 8454086 | 2009-02-21 00:20:40 -0500 | [diff] [blame] | 261 | * would have been enforced by the initial processing of our |
| 262 | * custom regulatory domain. |
| 263 | */ |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 264 | |
| 265 | ch = &sband->channels[11]; /* CH 12 */ |
| 266 | r = freq_reg_info(wiphy, ch->center_freq, &bandwidth, ®_rule); |
| 267 | if (!r) { |
| 268 | if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN)) |
| 269 | if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 270 | ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN; |
| 271 | } |
| 272 | |
| 273 | ch = &sband->channels[12]; /* CH 13 */ |
| 274 | r = freq_reg_info(wiphy, ch->center_freq, &bandwidth, ®_rule); |
| 275 | if (!r) { |
| 276 | if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN)) |
| 277 | if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 278 | ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | /* Always apply Radar/DFS rules on freq range 5260 MHz - 5700 MHz */ |
| 283 | void ath9k_reg_apply_radar_flags(struct wiphy *wiphy) |
| 284 | { |
| 285 | struct ieee80211_supported_band *sband; |
| 286 | struct ieee80211_channel *ch; |
| 287 | unsigned int i; |
| 288 | |
| 289 | if (!wiphy->bands[IEEE80211_BAND_5GHZ]) |
| 290 | return; |
| 291 | |
| 292 | sband = wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 293 | |
| 294 | for (i = 0; i < sband->n_channels; i++) { |
| 295 | ch = &sband->channels[i]; |
Luis R. Rodriguez | 547e4c2 | 2009-01-28 12:17:48 -0800 | [diff] [blame] | 296 | if (!ath9k_is_radar_freq(ch->center_freq)) |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 297 | continue; |
| 298 | /* We always enable radar detection/DFS on this |
| 299 | * frequency range. Additionally we also apply on |
| 300 | * this frequency range: |
| 301 | * - If STA mode does not yet have DFS supports disable |
| 302 | * active scanning |
| 303 | * - If adhoc mode does not support DFS yet then |
| 304 | * disable adhoc in the frequency. |
| 305 | * - If AP mode does not yet support radar detection/DFS |
| 306 | * do not allow AP mode |
| 307 | */ |
| 308 | if (!(ch->flags & IEEE80211_CHAN_DISABLED)) |
| 309 | ch->flags |= IEEE80211_CHAN_RADAR | |
| 310 | IEEE80211_CHAN_NO_IBSS | |
| 311 | IEEE80211_CHAN_PASSIVE_SCAN; |
| 312 | } |
| 313 | } |
| 314 | |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 315 | void ath9k_reg_apply_world_flags(struct wiphy *wiphy, |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 316 | enum nl80211_reg_initiator initiator, |
| 317 | struct ath9k_regulatory *reg) |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 318 | { |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 319 | switch (reg->regpair->regDmnEnum) { |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 320 | case 0x60: |
| 321 | case 0x63: |
| 322 | case 0x66: |
| 323 | case 0x67: |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 324 | ath9k_reg_apply_beaconing_flags(wiphy, initiator); |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 325 | break; |
| 326 | case 0x68: |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 327 | ath9k_reg_apply_beaconing_flags(wiphy, initiator); |
| 328 | ath9k_reg_apply_active_scan_flags(wiphy, initiator); |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 329 | break; |
| 330 | } |
| 331 | return; |
| 332 | } |
| 333 | |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 334 | static int ath9k_reg_notifier_apply(struct wiphy *wiphy, |
| 335 | struct regulatory_request *request, struct ath9k_regulatory *reg) |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 336 | { |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 337 | /* We always apply this */ |
| 338 | ath9k_reg_apply_radar_flags(wiphy); |
| 339 | |
| 340 | switch (request->initiator) { |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 341 | case NL80211_REGDOM_SET_BY_DRIVER: |
| 342 | case NL80211_REGDOM_SET_BY_CORE: |
| 343 | case NL80211_REGDOM_SET_BY_USER: |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 344 | break; |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 345 | case NL80211_REGDOM_SET_BY_COUNTRY_IE: |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 346 | if (ath9k_is_world_regd(reg)) |
| 347 | ath9k_reg_apply_world_flags(wiphy, request->initiator, |
| 348 | reg); |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 349 | break; |
| 350 | } |
| 351 | |
| 352 | return 0; |
| 353 | } |
| 354 | |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 355 | int ath9k_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 356 | { |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 357 | struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); |
| 358 | struct ath_wiphy *aphy = hw->priv; |
| 359 | struct ath_softc *sc = aphy->sc; |
| 360 | struct ath9k_regulatory *reg = &sc->sc_ah->regulatory; |
| 361 | |
| 362 | return ath9k_reg_notifier_apply(wiphy, request, reg); |
| 363 | } |
| 364 | |
| 365 | bool ath9k_regd_is_eeprom_valid(struct ath9k_regulatory *reg) |
| 366 | { |
| 367 | u16 rd = ath9k_regd_get_eepromRD(reg); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 368 | int i; |
| 369 | |
| 370 | if (rd & COUNTRY_ERD_FLAG) { |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 371 | /* EEPROM value is a country code */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 372 | u16 cc = rd & ~COUNTRY_ERD_FLAG; |
| 373 | for (i = 0; i < ARRAY_SIZE(allCountries); i++) |
| 374 | if (allCountries[i].countryCode == cc) |
| 375 | return true; |
| 376 | } else { |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 377 | /* EEPROM value is a regpair value */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 378 | for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) |
| 379 | if (regDomainPairs[i].regDmnEnum == rd) |
| 380 | return true; |
| 381 | } |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 382 | printk(KERN_DEBUG |
| 383 | "ath9k: invalid regulatory domain/country code 0x%x\n", rd); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 384 | return false; |
| 385 | } |
| 386 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 387 | /* EEPROM country code to regpair mapping */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 388 | static struct country_code_to_enum_rd* |
| 389 | ath9k_regd_find_country(u16 countryCode) |
| 390 | { |
| 391 | int i; |
| 392 | |
| 393 | for (i = 0; i < ARRAY_SIZE(allCountries); i++) { |
| 394 | if (allCountries[i].countryCode == countryCode) |
| 395 | return &allCountries[i]; |
| 396 | } |
| 397 | return NULL; |
| 398 | } |
| 399 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 400 | /* EEPROM rd code to regpair mapping */ |
| 401 | static struct country_code_to_enum_rd* |
| 402 | ath9k_regd_find_country_by_rd(int regdmn) |
| 403 | { |
| 404 | int i; |
| 405 | |
| 406 | for (i = 0; i < ARRAY_SIZE(allCountries); i++) { |
| 407 | if (allCountries[i].regDmnEnum == regdmn) |
| 408 | return &allCountries[i]; |
| 409 | } |
| 410 | return NULL; |
| 411 | } |
| 412 | |
| 413 | /* Returns the map of the EEPROM set RD to a country code */ |
Bob Copeland | e775aaf | 2009-02-12 13:38:54 -0500 | [diff] [blame] | 414 | static u16 ath9k_regd_get_default_country(u16 rd) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 415 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 416 | if (rd & COUNTRY_ERD_FLAG) { |
| 417 | struct country_code_to_enum_rd *country = NULL; |
| 418 | u16 cc = rd & ~COUNTRY_ERD_FLAG; |
| 419 | |
| 420 | country = ath9k_regd_find_country(cc); |
| 421 | if (country != NULL) |
| 422 | return cc; |
| 423 | } |
| 424 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 425 | return CTRY_DEFAULT; |
| 426 | } |
| 427 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 428 | static struct reg_dmn_pair_mapping* |
| 429 | ath9k_get_regpair(int regdmn) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 430 | { |
| 431 | int i; |
| 432 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 433 | if (regdmn == NO_ENUMRD) |
| 434 | return NULL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 435 | for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) { |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 436 | if (regDomainPairs[i].regDmnEnum == regdmn) |
| 437 | return ®DomainPairs[i]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 438 | } |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 439 | return NULL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 442 | int ath9k_regd_init(struct ath9k_regulatory *reg) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 443 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 444 | struct country_code_to_enum_rd *country = NULL; |
Bob Copeland | e775aaf | 2009-02-12 13:38:54 -0500 | [diff] [blame] | 445 | u16 regdmn; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 446 | |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 447 | if (!ath9k_regd_is_eeprom_valid(reg)) { |
| 448 | printk(KERN_DEBUG "ath9k: Invalid EEPROM contents\n"); |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 449 | return -EINVAL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 452 | regdmn = ath9k_regd_get_eepromRD(reg); |
| 453 | reg->country_code = ath9k_regd_get_default_country(regdmn); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 454 | |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 455 | if (reg->country_code == CTRY_DEFAULT && |
Bob Copeland | e775aaf | 2009-02-12 13:38:54 -0500 | [diff] [blame] | 456 | regdmn == CTRY_DEFAULT) |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 457 | reg->country_code = CTRY_UNITED_STATES; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 458 | |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 459 | if (reg->country_code == CTRY_DEFAULT) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 460 | country = NULL; |
| 461 | } else { |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 462 | country = ath9k_regd_find_country(reg->country_code); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 463 | if (country == NULL) { |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 464 | printk(KERN_DEBUG |
| 465 | "ath9k: Country is NULL!!!!, cc= %d\n", |
| 466 | reg->country_code); |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 467 | return -EINVAL; |
| 468 | } else |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 469 | regdmn = country->regDmnEnum; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 470 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 471 | |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 472 | reg->regpair = ath9k_get_regpair(regdmn); |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 473 | |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 474 | if (!reg->regpair) { |
| 475 | printk(KERN_DEBUG "ath9k: " |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 476 | "No regulatory domain pair found, cannot continue\n"); |
| 477 | return -EINVAL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 480 | if (!country) |
| 481 | country = ath9k_regd_find_country_by_rd(regdmn); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 482 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 483 | if (country) { |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 484 | reg->alpha2[0] = country->isoName[0]; |
| 485 | reg->alpha2[1] = country->isoName[1]; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 486 | } else { |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 487 | reg->alpha2[0] = '0'; |
| 488 | reg->alpha2[1] = '0'; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 489 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 490 | |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 491 | printk(KERN_DEBUG "ath9k: Country alpha2 being used: %c%c\n", |
| 492 | reg->alpha2[0], reg->alpha2[1]); |
| 493 | printk(KERN_DEBUG "ath9k: Regpair detected: 0x%0x\n", |
| 494 | reg->regpair->regDmnEnum); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 495 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 496 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 497 | } |
| 498 | |
Bob Copeland | fc2ada3 | 2009-03-30 22:30:27 -0400 | [diff] [blame] | 499 | static |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 500 | u32 ath9k_regd_get_band_ctl(struct ath9k_regulatory *reg, |
| 501 | enum ieee80211_band band) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 502 | { |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 503 | if (!reg->regpair || |
| 504 | (reg->country_code == CTRY_DEFAULT && |
| 505 | is_wwr_sku(ath9k_regd_get_eepromRD(reg)))) { |
Bob Copeland | fc2ada3 | 2009-03-30 22:30:27 -0400 | [diff] [blame] | 506 | return SD_NO_CTL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 507 | } |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 508 | |
Bob Copeland | fc2ada3 | 2009-03-30 22:30:27 -0400 | [diff] [blame] | 509 | switch (band) { |
| 510 | case IEEE80211_BAND_2GHZ: |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 511 | return reg->regpair->reg_2ghz_ctl; |
Bob Copeland | fc2ada3 | 2009-03-30 22:30:27 -0400 | [diff] [blame] | 512 | case IEEE80211_BAND_5GHZ: |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 513 | return reg->regpair->reg_5ghz_ctl; |
Bob Copeland | fc2ada3 | 2009-03-30 22:30:27 -0400 | [diff] [blame] | 514 | default: |
| 515 | return NO_CTL; |
| 516 | } |
| 517 | |
| 518 | return NO_CTL; |
| 519 | } |
| 520 | |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 521 | u32 ath9k_regd_get_ctl(struct ath9k_regulatory *reg, struct ath9k_channel *chan) |
Bob Copeland | fc2ada3 | 2009-03-30 22:30:27 -0400 | [diff] [blame] | 522 | { |
Bob Copeland | c02cf37 | 2009-03-30 22:30:28 -0400 | [diff] [blame^] | 523 | u32 ctl = ath9k_regd_get_band_ctl(reg, chan->chan->band); |
Bob Copeland | fc2ada3 | 2009-03-30 22:30:27 -0400 | [diff] [blame] | 524 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 525 | if (IS_CHAN_B(chan)) |
Bob Copeland | fc2ada3 | 2009-03-30 22:30:27 -0400 | [diff] [blame] | 526 | ctl |= CTL_11B; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 527 | else if (IS_CHAN_G(chan)) |
Bob Copeland | fc2ada3 | 2009-03-30 22:30:27 -0400 | [diff] [blame] | 528 | ctl |= CTL_11G; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 529 | else |
Bob Copeland | fc2ada3 | 2009-03-30 22:30:27 -0400 | [diff] [blame] | 530 | ctl |= CTL_11A; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 531 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 532 | return ctl; |
| 533 | } |