blob: 979351540e69b0cfac3578c89e12beffed44c788 [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
2 * Copyright (c) 2008 Atheros Communications Inc.
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>
Sujith394cf0a2009-02-09 13:26:54 +053019#include "ath9k.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070020#include "regd_common.h"
21
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -080022/*
23 * This is a set of common rules used by our world regulatory domains.
24 * We have 12 world regulatory domains. To save space we consolidate
25 * the regulatory domains in 5 structures by frequency and change
26 * the flags on our reg_notifier() on a case by case basis.
27 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070028
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -080029/* Only these channels all allow active scan on all world regulatory domains */
30#define ATH9K_2GHZ_CH01_11 REG_RULE(2412-10, 2462+10, 40, 0, 20, 0)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070031
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -080032/* We enable active scan on these a case by case basis by regulatory domain */
33#define ATH9K_2GHZ_CH12_13 REG_RULE(2467-10, 2472+10, 40, 0, 20,\
34 NL80211_RRF_PASSIVE_SCAN)
35#define ATH9K_2GHZ_CH14 REG_RULE(2484-10, 2484+10, 40, 0, 20,\
36 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_OFDM)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070037
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -080038/* We allow IBSS on these on a case by case basis by regulatory domain */
39#define ATH9K_5GHZ_5150_5350 REG_RULE(5150-10, 5350+10, 40, 0, 30,\
40 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
41#define ATH9K_5GHZ_5470_5850 REG_RULE(5470-10, 5850+10, 40, 0, 30,\
42 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
43#define ATH9K_5GHZ_5725_5850 REG_RULE(5725-10, 5850+10, 40, 0, 30,\
44 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
45
46#define ATH9K_2GHZ_ALL ATH9K_2GHZ_CH01_11, \
47 ATH9K_2GHZ_CH12_13, \
48 ATH9K_2GHZ_CH14
49
50#define ATH9K_5GHZ_ALL ATH9K_5GHZ_5150_5350, \
51 ATH9K_5GHZ_5470_5850
52/* This one skips what we call "mid band" */
53#define ATH9K_5GHZ_NO_MIDBAND ATH9K_5GHZ_5150_5350, \
54 ATH9K_5GHZ_5725_5850
55
56/* Can be used for:
57 * 0x60, 0x61, 0x62 */
58static const struct ieee80211_regdomain ath9k_world_regdom_60_61_62 = {
59 .n_reg_rules = 5,
60 .alpha2 = "99",
61 .reg_rules = {
62 ATH9K_2GHZ_ALL,
63 ATH9K_5GHZ_ALL,
64 }
65};
66
67/* Can be used by 0x63 and 0x65 */
68static const struct ieee80211_regdomain ath9k_world_regdom_63_65 = {
69 .n_reg_rules = 4,
70 .alpha2 = "99",
71 .reg_rules = {
72 ATH9K_2GHZ_CH01_11,
73 ATH9K_2GHZ_CH12_13,
74 ATH9K_5GHZ_NO_MIDBAND,
75 }
76};
77
78/* Can be used by 0x64 only */
79static const struct ieee80211_regdomain ath9k_world_regdom_64 = {
80 .n_reg_rules = 3,
81 .alpha2 = "99",
82 .reg_rules = {
83 ATH9K_2GHZ_CH01_11,
84 ATH9K_5GHZ_NO_MIDBAND,
85 }
86};
87
88/* Can be used by 0x66 and 0x69 */
89static const struct ieee80211_regdomain ath9k_world_regdom_66_69 = {
90 .n_reg_rules = 3,
91 .alpha2 = "99",
92 .reg_rules = {
93 ATH9K_2GHZ_CH01_11,
94 ATH9K_5GHZ_ALL,
95 }
96};
97
98/* Can be used by 0x67, 0x6A and 0x68 */
99static const struct ieee80211_regdomain ath9k_world_regdom_67_68_6A = {
100 .n_reg_rules = 4,
101 .alpha2 = "99",
102 .reg_rules = {
103 ATH9K_2GHZ_CH01_11,
104 ATH9K_2GHZ_CH12_13,
105 ATH9K_5GHZ_ALL,
106 }
107};
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700108
Bob Copelandd0f48f92009-02-12 13:38:55 -0500109static inline bool is_wwr_sku(u16 regd)
110{
111 return ((regd & WORLD_SKU_MASK) == WORLD_SKU_PREFIX) ||
112 (regd == WORLD);
113}
114
Sujithcbe61d82009-02-09 13:27:12 +0530115static u16 ath9k_regd_get_eepromRD(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700116{
Sujithd6bad492009-02-09 13:27:08 +0530117 return ah->regulatory.current_rd & ~WORLDWIDE_ROAMING_FLAG;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700118}
119
Sujithcbe61d82009-02-09 13:27:12 +0530120u16 ath9k_regd_get_rd(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700121{
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800122 return ath9k_regd_get_eepromRD(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700123}
124
Sujithcbe61d82009-02-09 13:27:12 +0530125bool ath9k_is_world_regd(struct ath_hw *ah)
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800126{
Bob Copelandd0f48f92009-02-12 13:38:55 -0500127 return is_wwr_sku(ath9k_regd_get_eepromRD(ah));
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800128}
129
130const struct ieee80211_regdomain *ath9k_default_world_regdomain(void)
131{
132 /* this is the most restrictive */
133 return &ath9k_world_regdom_64;
134}
135
Sujithcbe61d82009-02-09 13:27:12 +0530136const struct ieee80211_regdomain *ath9k_world_regdomain(struct ath_hw *ah)
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800137{
Sujithd6bad492009-02-09 13:27:08 +0530138 switch (ah->regulatory.regpair->regDmnEnum) {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800139 case 0x60:
140 case 0x61:
141 case 0x62:
142 return &ath9k_world_regdom_60_61_62;
143 case 0x63:
144 case 0x65:
145 return &ath9k_world_regdom_63_65;
146 case 0x64:
147 return &ath9k_world_regdom_64;
148 case 0x66:
149 case 0x69:
150 return &ath9k_world_regdom_66_69;
151 case 0x67:
152 case 0x68:
153 case 0x6A:
154 return &ath9k_world_regdom_67_68_6A;
155 default:
156 WARN_ON(1);
157 return ath9k_default_world_regdomain();
158 }
159}
160
Luis R. Rodriguez547e4c22009-01-28 12:17:48 -0800161/* Frequency is one where radar detection is required */
162static bool ath9k_is_radar_freq(u16 center_freq)
163{
164 return (center_freq >= 5260 && center_freq <= 5700);
165}
166
Luis R. Rodriguez7519a8f2009-01-28 12:17:49 -0800167/*
168 * Enable adhoc on 5 GHz if allowed by 11d.
169 * Remove passive scan if channel is allowed by 11d,
170 * except when on radar frequencies.
171 */
172static void ath9k_reg_apply_5ghz_beaconing_flags(struct wiphy *wiphy,
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800173 enum reg_set_by setby)
174{
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800175 struct ieee80211_supported_band *sband;
176 const struct ieee80211_reg_rule *reg_rule;
177 struct ieee80211_channel *ch;
178 unsigned int i;
179 u32 bandwidth = 0;
180 int r;
181
182 if (setby != REGDOM_SET_BY_COUNTRY_IE)
183 return;
Luis R. Rodriguez8c63c462009-01-28 12:17:47 -0800184 if (!wiphy->bands[IEEE80211_BAND_5GHZ])
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800185 return;
186
187 sband = wiphy->bands[IEEE80211_BAND_5GHZ];
188 for (i = 0; i < sband->n_channels; i++) {
189 ch = &sband->channels[i];
190 r = freq_reg_info(wiphy, ch->center_freq,
191 &bandwidth, &reg_rule);
192 if (r)
193 continue;
194 /* If 11d had a rule for this channel ensure we enable adhoc
195 * if it allows us to use it. Note that we would have disabled
196 * it by applying our static world regdomain by default during
197 * probe */
198 if (!(reg_rule->flags & NL80211_RRF_NO_IBSS))
Luis R. Rodriguezde9f97e2009-02-02 20:35:05 -0800199 ch->flags &= ~IEEE80211_CHAN_NO_IBSS;
Luis R. Rodriguez7519a8f2009-01-28 12:17:49 -0800200 if (!ath9k_is_radar_freq(ch->center_freq))
201 continue;
202 if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN))
Luis R. Rodriguezde9f97e2009-02-02 20:35:05 -0800203 ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800204 }
205}
206
207/* Allows active scan scan on Ch 12 and 13 */
208static void ath9k_reg_apply_active_scan_flags(struct wiphy *wiphy,
209 enum reg_set_by setby)
210{
211 struct ieee80211_supported_band *sband;
212 struct ieee80211_channel *ch;
213 const struct ieee80211_reg_rule *reg_rule;
214 u32 bandwidth = 0;
215 int r;
216
217 /* Force passive scan on Channels 12-13 */
218 sband = wiphy->bands[IEEE80211_BAND_2GHZ];
219
220 /* If no country IE has been received always enable active scan
221 * on these channels */
222 if (setby != REGDOM_SET_BY_COUNTRY_IE) {
223 ch = &sband->channels[11]; /* CH 12 */
224 if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
225 ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
226 ch = &sband->channels[12]; /* CH 13 */
227 if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
228 ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
229 return;
230 }
231
232 /* If a country IE has been recieved check its rule for this
233 * channel first before enabling active scan. The passive scan
234 * would have been enforced by the initial probe processing on
235 * our custom regulatory domain. */
236
237 ch = &sband->channels[11]; /* CH 12 */
238 r = freq_reg_info(wiphy, ch->center_freq, &bandwidth, &reg_rule);
239 if (!r) {
240 if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN))
241 if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
242 ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
243 }
244
245 ch = &sband->channels[12]; /* CH 13 */
246 r = freq_reg_info(wiphy, ch->center_freq, &bandwidth, &reg_rule);
247 if (!r) {
248 if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN))
249 if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
250 ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
251 }
252}
253
254/* Always apply Radar/DFS rules on freq range 5260 MHz - 5700 MHz */
255void ath9k_reg_apply_radar_flags(struct wiphy *wiphy)
256{
257 struct ieee80211_supported_band *sband;
258 struct ieee80211_channel *ch;
259 unsigned int i;
260
261 if (!wiphy->bands[IEEE80211_BAND_5GHZ])
262 return;
263
264 sband = wiphy->bands[IEEE80211_BAND_5GHZ];
265
266 for (i = 0; i < sband->n_channels; i++) {
267 ch = &sband->channels[i];
Luis R. Rodriguez547e4c22009-01-28 12:17:48 -0800268 if (!ath9k_is_radar_freq(ch->center_freq))
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800269 continue;
270 /* We always enable radar detection/DFS on this
271 * frequency range. Additionally we also apply on
272 * this frequency range:
273 * - If STA mode does not yet have DFS supports disable
274 * active scanning
275 * - If adhoc mode does not support DFS yet then
276 * disable adhoc in the frequency.
277 * - If AP mode does not yet support radar detection/DFS
278 * do not allow AP mode
279 */
280 if (!(ch->flags & IEEE80211_CHAN_DISABLED))
281 ch->flags |= IEEE80211_CHAN_RADAR |
282 IEEE80211_CHAN_NO_IBSS |
283 IEEE80211_CHAN_PASSIVE_SCAN;
284 }
285}
286
287void ath9k_reg_apply_world_flags(struct wiphy *wiphy, enum reg_set_by setby)
288{
289 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
290 struct ath_softc *sc = hw->priv;
Sujithcbe61d82009-02-09 13:27:12 +0530291 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800292
Sujithd6bad492009-02-09 13:27:08 +0530293 switch (ah->regulatory.regpair->regDmnEnum) {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800294 case 0x60:
295 case 0x63:
296 case 0x66:
297 case 0x67:
Luis R. Rodriguez7519a8f2009-01-28 12:17:49 -0800298 ath9k_reg_apply_5ghz_beaconing_flags(wiphy, setby);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800299 break;
300 case 0x68:
Luis R. Rodriguez7519a8f2009-01-28 12:17:49 -0800301 ath9k_reg_apply_5ghz_beaconing_flags(wiphy, setby);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800302 ath9k_reg_apply_active_scan_flags(wiphy, setby);
303 break;
304 }
305 return;
306}
307
308int ath9k_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request)
309{
310 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
311 struct ath_softc *sc = hw->priv;
312
313 /* We always apply this */
314 ath9k_reg_apply_radar_flags(wiphy);
315
316 switch (request->initiator) {
317 case REGDOM_SET_BY_DRIVER:
318 case REGDOM_SET_BY_INIT:
319 case REGDOM_SET_BY_CORE:
320 case REGDOM_SET_BY_USER:
321 break;
322 case REGDOM_SET_BY_COUNTRY_IE:
323 if (ath9k_is_world_regd(sc->sc_ah))
324 ath9k_reg_apply_world_flags(wiphy, request->initiator);
325 break;
326 }
327
328 return 0;
329}
330
Sujithcbe61d82009-02-09 13:27:12 +0530331bool ath9k_regd_is_eeprom_valid(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700332{
333 u16 rd = ath9k_regd_get_eepromRD(ah);
334 int i;
335
336 if (rd & COUNTRY_ERD_FLAG) {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800337 /* EEPROM value is a country code */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700338 u16 cc = rd & ~COUNTRY_ERD_FLAG;
339 for (i = 0; i < ARRAY_SIZE(allCountries); i++)
340 if (allCountries[i].countryCode == cc)
341 return true;
342 } else {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800343 /* EEPROM value is a regpair value */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700344 for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++)
345 if (regDomainPairs[i].regDmnEnum == rd)
346 return true;
347 }
348 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY,
Sujith04bd4632008-11-28 22:18:05 +0530349 "invalid regulatory domain/country code 0x%x\n", rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700350 return false;
351}
352
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800353/* EEPROM country code to regpair mapping */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700354static struct country_code_to_enum_rd*
355ath9k_regd_find_country(u16 countryCode)
356{
357 int i;
358
359 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
360 if (allCountries[i].countryCode == countryCode)
361 return &allCountries[i];
362 }
363 return NULL;
364}
365
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800366/* EEPROM rd code to regpair mapping */
367static struct country_code_to_enum_rd*
368ath9k_regd_find_country_by_rd(int regdmn)
369{
370 int i;
371
372 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
373 if (allCountries[i].regDmnEnum == regdmn)
374 return &allCountries[i];
375 }
376 return NULL;
377}
378
379/* Returns the map of the EEPROM set RD to a country code */
Bob Copelande775aaf2009-02-12 13:38:54 -0500380static u16 ath9k_regd_get_default_country(u16 rd)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700381{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700382 if (rd & COUNTRY_ERD_FLAG) {
383 struct country_code_to_enum_rd *country = NULL;
384 u16 cc = rd & ~COUNTRY_ERD_FLAG;
385
386 country = ath9k_regd_find_country(cc);
387 if (country != NULL)
388 return cc;
389 }
390
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700391 return CTRY_DEFAULT;
392}
393
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800394static struct reg_dmn_pair_mapping*
395ath9k_get_regpair(int regdmn)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700396{
397 int i;
398
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800399 if (regdmn == NO_ENUMRD)
400 return NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700401 for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800402 if (regDomainPairs[i].regDmnEnum == regdmn)
403 return &regDomainPairs[i];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700404 }
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800405 return NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700406}
407
Sujithcbe61d82009-02-09 13:27:12 +0530408int ath9k_regd_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700409{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700410 struct country_code_to_enum_rd *country = NULL;
Bob Copelande775aaf2009-02-12 13:38:54 -0500411 u16 regdmn;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700412
413 if (!ath9k_regd_is_eeprom_valid(ah)) {
414 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY,
Sujith04bd4632008-11-28 22:18:05 +0530415 "Invalid EEPROM contents\n");
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800416 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700417 }
418
Bob Copelande775aaf2009-02-12 13:38:54 -0500419 regdmn = ath9k_regd_get_eepromRD(ah);
420 ah->regulatory.country_code = ath9k_regd_get_default_country(regdmn);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700421
Sujithd6bad492009-02-09 13:27:08 +0530422 if (ah->regulatory.country_code == CTRY_DEFAULT &&
Bob Copelande775aaf2009-02-12 13:38:54 -0500423 regdmn == CTRY_DEFAULT)
Sujithd6bad492009-02-09 13:27:08 +0530424 ah->regulatory.country_code = CTRY_UNITED_STATES;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700425
Sujithd6bad492009-02-09 13:27:08 +0530426 if (ah->regulatory.country_code == CTRY_DEFAULT) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700427 country = NULL;
428 } else {
Sujithd6bad492009-02-09 13:27:08 +0530429 country = ath9k_regd_find_country(ah->regulatory.country_code);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700430 if (country == NULL) {
431 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY,
432 "Country is NULL!!!!, cc= %d\n",
Sujithd6bad492009-02-09 13:27:08 +0530433 ah->regulatory.country_code);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800434 return -EINVAL;
435 } else
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700436 regdmn = country->regDmnEnum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700437 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700438
Sujithd6bad492009-02-09 13:27:08 +0530439 ah->regulatory.regpair = ath9k_get_regpair(regdmn);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800440
Sujithd6bad492009-02-09 13:27:08 +0530441 if (!ah->regulatory.regpair) {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800442 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
443 "No regulatory domain pair found, cannot continue\n");
444 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700445 }
446
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800447 if (!country)
448 country = ath9k_regd_find_country_by_rd(regdmn);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700449
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800450 if (country) {
Sujithd6bad492009-02-09 13:27:08 +0530451 ah->regulatory.alpha2[0] = country->isoName[0];
452 ah->regulatory.alpha2[1] = country->isoName[1];
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800453 } else {
Sujithd6bad492009-02-09 13:27:08 +0530454 ah->regulatory.alpha2[0] = '0';
455 ah->regulatory.alpha2[1] = '0';
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800456 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700457
458 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY,
Luis R. Rodriguez0c6666e2009-01-26 06:48:10 -0800459 "Country alpha2 being used: %c%c\n"
Sujithd6bad492009-02-09 13:27:08 +0530460 "Regulatory.Regpair detected: 0x%0x\n",
461 ah->regulatory.alpha2[0], ah->regulatory.alpha2[1],
462 ah->regulatory.regpair->regDmnEnum);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700463
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800464 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700465}
466
Sujithcbe61d82009-02-09 13:27:12 +0530467u32 ath9k_regd_get_ctl(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700468{
469 u32 ctl = NO_CTL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700470
Sujithd6bad492009-02-09 13:27:08 +0530471 if (!ah->regulatory.regpair ||
Bob Copelandd0f48f92009-02-12 13:38:55 -0500472 (ah->regulatory.country_code == CTRY_DEFAULT &&
473 is_wwr_sku(ath9k_regd_get_eepromRD(ah)))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700474 if (IS_CHAN_B(chan))
475 ctl = SD_NO_CTL | CTL_11B;
476 else if (IS_CHAN_G(chan))
477 ctl = SD_NO_CTL | CTL_11G;
478 else
479 ctl = SD_NO_CTL | CTL_11A;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800480 return ctl;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700481 }
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800482
483 if (IS_CHAN_B(chan))
Sujithd6bad492009-02-09 13:27:08 +0530484 ctl = ah->regulatory.regpair->reg_2ghz_ctl | CTL_11B;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800485 else if (IS_CHAN_G(chan))
Sujithd6bad492009-02-09 13:27:08 +0530486 ctl = ah->regulatory.regpair->reg_5ghz_ctl | CTL_11G;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800487 else
Sujithd6bad492009-02-09 13:27:08 +0530488 ctl = ah->regulatory.regpair->reg_5ghz_ctl | CTL_11A;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800489
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700490 return ctl;
491}