blob: 43ed35ba95cf7516693bb68d094a86cbf82e1543 [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 Atheros Communications Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003 *
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 Copelandfc2ada32009-03-30 22:30:27 -040019#include <net/wireless.h>
Sujith394cf0a2009-02-09 13:26:54 +053020#include "ath9k.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070021#include "regd_common.h"
22
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -080023/*
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. Rodriguezf078f202008-08-04 00:16:41 -070029
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -080030/* 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. Rodriguezf078f202008-08-04 00:16:41 -070032
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -080033/* 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. Rodriguezf078f202008-08-04 00:16:41 -070038
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -080039/* 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 */
59static 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 */
69static 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 */
80static 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 */
90static 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 */
100static 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. Rodriguezf078f202008-08-04 00:16:41 -0700109
Bob Copelandd0f48f92009-02-12 13:38:55 -0500110static inline bool is_wwr_sku(u16 regd)
111{
112 return ((regd & WORLD_SKU_MASK) == WORLD_SKU_PREFIX) ||
113 (regd == WORLD);
114}
115
Sujithcbe61d82009-02-09 13:27:12 +0530116static u16 ath9k_regd_get_eepromRD(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700117{
Sujithd6bad492009-02-09 13:27:08 +0530118 return ah->regulatory.current_rd & ~WORLDWIDE_ROAMING_FLAG;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700119}
120
Sujithcbe61d82009-02-09 13:27:12 +0530121bool ath9k_is_world_regd(struct ath_hw *ah)
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800122{
Bob Copelandd0f48f92009-02-12 13:38:55 -0500123 return is_wwr_sku(ath9k_regd_get_eepromRD(ah));
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800124}
125
126const struct ieee80211_regdomain *ath9k_default_world_regdomain(void)
127{
128 /* this is the most restrictive */
129 return &ath9k_world_regdom_64;
130}
131
Sujithcbe61d82009-02-09 13:27:12 +0530132const struct ieee80211_regdomain *ath9k_world_regdomain(struct ath_hw *ah)
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800133{
Sujithd6bad492009-02-09 13:27:08 +0530134 switch (ah->regulatory.regpair->regDmnEnum) {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800135 case 0x60:
136 case 0x61:
137 case 0x62:
138 return &ath9k_world_regdom_60_61_62;
139 case 0x63:
140 case 0x65:
141 return &ath9k_world_regdom_63_65;
142 case 0x64:
143 return &ath9k_world_regdom_64;
144 case 0x66:
145 case 0x69:
146 return &ath9k_world_regdom_66_69;
147 case 0x67:
148 case 0x68:
149 case 0x6A:
150 return &ath9k_world_regdom_67_68_6A;
151 default:
152 WARN_ON(1);
153 return ath9k_default_world_regdomain();
154 }
155}
156
Luis R. Rodriguez547e4c22009-01-28 12:17:48 -0800157/* Frequency is one where radar detection is required */
158static bool ath9k_is_radar_freq(u16 center_freq)
159{
160 return (center_freq >= 5260 && center_freq <= 5700);
161}
162
Luis R. Rodriguez7519a8f2009-01-28 12:17:49 -0800163/*
Luis R. Rodriguez84540862009-02-21 00:20:40 -0500164 * N.B: These exception rules do not apply radar freqs.
165 *
166 * - We enable adhoc (or beaconing) if allowed by 11d
167 * - We enable active scan if the channel is allowed by 11d
168 * - If no country IE has been processed and a we determine we have
169 * received a beacon on a channel we can enable active scan and
170 * adhoc (or beaconing).
Luis R. Rodriguez7519a8f2009-01-28 12:17:49 -0800171 */
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -0400172static void ath9k_reg_apply_beaconing_flags(
173 struct wiphy *wiphy,
174 enum nl80211_reg_initiator initiator)
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800175{
Luis R. Rodriguez84540862009-02-21 00:20:40 -0500176 enum ieee80211_band band;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800177 struct ieee80211_supported_band *sband;
178 const struct ieee80211_reg_rule *reg_rule;
179 struct ieee80211_channel *ch;
180 unsigned int i;
181 u32 bandwidth = 0;
182 int r;
183
Luis R. Rodriguez84540862009-02-21 00:20:40 -0500184 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800185
Luis R. Rodriguez84540862009-02-21 00:20:40 -0500186 if (!wiphy->bands[band])
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800187 continue;
Luis R. Rodriguez84540862009-02-21 00:20:40 -0500188
189 sband = wiphy->bands[band];
190
191 for (i = 0; i < sband->n_channels; i++) {
192
193 ch = &sband->channels[i];
194
195 if (ath9k_is_radar_freq(ch->center_freq) ||
196 (ch->flags & IEEE80211_CHAN_RADAR))
197 continue;
198
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -0400199 if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) {
Luis R. Rodriguez84540862009-02-21 00:20:40 -0500200 r = freq_reg_info(wiphy, ch->center_freq,
201 &bandwidth, &reg_rule);
202 if (r)
203 continue;
204 /*
205 * If 11d had a rule for this channel ensure
206 * we enable adhoc/beaconing if it allows us to
207 * use it. Note that we would have disabled it
208 * by applying our static world regdomain by
209 * default during init, prior to calling our
210 * regulatory_hint().
211 */
212 if (!(reg_rule->flags &
213 NL80211_RRF_NO_IBSS))
214 ch->flags &=
215 ~IEEE80211_CHAN_NO_IBSS;
216 if (!(reg_rule->flags &
217 NL80211_RRF_PASSIVE_SCAN))
218 ch->flags &=
219 ~IEEE80211_CHAN_PASSIVE_SCAN;
220 } else {
221 if (ch->beacon_found)
222 ch->flags &= ~(IEEE80211_CHAN_NO_IBSS |
223 IEEE80211_CHAN_PASSIVE_SCAN);
224 }
225 }
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800226 }
Luis R. Rodriguez84540862009-02-21 00:20:40 -0500227
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800228}
229
230/* Allows active scan scan on Ch 12 and 13 */
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -0400231static void ath9k_reg_apply_active_scan_flags(
232 struct wiphy *wiphy,
233 enum nl80211_reg_initiator initiator)
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800234{
235 struct ieee80211_supported_band *sband;
236 struct ieee80211_channel *ch;
237 const struct ieee80211_reg_rule *reg_rule;
238 u32 bandwidth = 0;
239 int r;
240
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800241 sband = wiphy->bands[IEEE80211_BAND_2GHZ];
242
Luis R. Rodriguez84540862009-02-21 00:20:40 -0500243 /*
244 * If no country IE has been received always enable active scan
245 * on these channels. This is only done for specific regulatory SKUs
246 */
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -0400247 if (initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800248 ch = &sband->channels[11]; /* CH 12 */
249 if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
250 ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
251 ch = &sband->channels[12]; /* CH 13 */
252 if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
253 ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
254 return;
255 }
256
Luis R. Rodriguez84540862009-02-21 00:20:40 -0500257 /*
258 * If a country IE has been recieved check its rule for this
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800259 * channel first before enabling active scan. The passive scan
Luis R. Rodriguez84540862009-02-21 00:20:40 -0500260 * would have been enforced by the initial processing of our
261 * custom regulatory domain.
262 */
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800263
264 ch = &sband->channels[11]; /* CH 12 */
265 r = freq_reg_info(wiphy, ch->center_freq, &bandwidth, &reg_rule);
266 if (!r) {
267 if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN))
268 if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
269 ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
270 }
271
272 ch = &sband->channels[12]; /* CH 13 */
273 r = freq_reg_info(wiphy, ch->center_freq, &bandwidth, &reg_rule);
274 if (!r) {
275 if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN))
276 if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
277 ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
278 }
279}
280
281/* Always apply Radar/DFS rules on freq range 5260 MHz - 5700 MHz */
282void ath9k_reg_apply_radar_flags(struct wiphy *wiphy)
283{
284 struct ieee80211_supported_band *sband;
285 struct ieee80211_channel *ch;
286 unsigned int i;
287
288 if (!wiphy->bands[IEEE80211_BAND_5GHZ])
289 return;
290
291 sband = wiphy->bands[IEEE80211_BAND_5GHZ];
292
293 for (i = 0; i < sband->n_channels; i++) {
294 ch = &sband->channels[i];
Luis R. Rodriguez547e4c22009-01-28 12:17:48 -0800295 if (!ath9k_is_radar_freq(ch->center_freq))
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800296 continue;
297 /* We always enable radar detection/DFS on this
298 * frequency range. Additionally we also apply on
299 * this frequency range:
300 * - If STA mode does not yet have DFS supports disable
301 * active scanning
302 * - If adhoc mode does not support DFS yet then
303 * disable adhoc in the frequency.
304 * - If AP mode does not yet support radar detection/DFS
305 * do not allow AP mode
306 */
307 if (!(ch->flags & IEEE80211_CHAN_DISABLED))
308 ch->flags |= IEEE80211_CHAN_RADAR |
309 IEEE80211_CHAN_NO_IBSS |
310 IEEE80211_CHAN_PASSIVE_SCAN;
311 }
312}
313
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -0400314void ath9k_reg_apply_world_flags(struct wiphy *wiphy,
315 enum nl80211_reg_initiator initiator)
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800316{
317 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
Jouni Malinenbce048d2009-03-03 19:23:28 +0200318 struct ath_wiphy *aphy = hw->priv;
319 struct ath_softc *sc = aphy->sc;
Sujithcbe61d82009-02-09 13:27:12 +0530320 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800321
Sujithd6bad492009-02-09 13:27:08 +0530322 switch (ah->regulatory.regpair->regDmnEnum) {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800323 case 0x60:
324 case 0x63:
325 case 0x66:
326 case 0x67:
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -0400327 ath9k_reg_apply_beaconing_flags(wiphy, initiator);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800328 break;
329 case 0x68:
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -0400330 ath9k_reg_apply_beaconing_flags(wiphy, initiator);
331 ath9k_reg_apply_active_scan_flags(wiphy, initiator);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800332 break;
333 }
334 return;
335}
336
337int ath9k_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request)
338{
339 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
Jouni Malinenbce048d2009-03-03 19:23:28 +0200340 struct ath_wiphy *aphy = hw->priv;
341 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800342
343 /* We always apply this */
344 ath9k_reg_apply_radar_flags(wiphy);
345
346 switch (request->initiator) {
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -0400347 case NL80211_REGDOM_SET_BY_DRIVER:
348 case NL80211_REGDOM_SET_BY_CORE:
349 case NL80211_REGDOM_SET_BY_USER:
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800350 break;
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -0400351 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800352 if (ath9k_is_world_regd(sc->sc_ah))
353 ath9k_reg_apply_world_flags(wiphy, request->initiator);
354 break;
355 }
356
357 return 0;
358}
359
Sujithcbe61d82009-02-09 13:27:12 +0530360bool ath9k_regd_is_eeprom_valid(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700361{
362 u16 rd = ath9k_regd_get_eepromRD(ah);
363 int i;
364
365 if (rd & COUNTRY_ERD_FLAG) {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800366 /* EEPROM value is a country code */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700367 u16 cc = rd & ~COUNTRY_ERD_FLAG;
368 for (i = 0; i < ARRAY_SIZE(allCountries); i++)
369 if (allCountries[i].countryCode == cc)
370 return true;
371 } else {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800372 /* EEPROM value is a regpair value */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700373 for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++)
374 if (regDomainPairs[i].regDmnEnum == rd)
375 return true;
376 }
377 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY,
Sujith04bd4632008-11-28 22:18:05 +0530378 "invalid regulatory domain/country code 0x%x\n", rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700379 return false;
380}
381
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800382/* EEPROM country code to regpair mapping */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700383static struct country_code_to_enum_rd*
384ath9k_regd_find_country(u16 countryCode)
385{
386 int i;
387
388 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
389 if (allCountries[i].countryCode == countryCode)
390 return &allCountries[i];
391 }
392 return NULL;
393}
394
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800395/* EEPROM rd code to regpair mapping */
396static struct country_code_to_enum_rd*
397ath9k_regd_find_country_by_rd(int regdmn)
398{
399 int i;
400
401 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
402 if (allCountries[i].regDmnEnum == regdmn)
403 return &allCountries[i];
404 }
405 return NULL;
406}
407
408/* Returns the map of the EEPROM set RD to a country code */
Bob Copelande775aaf2009-02-12 13:38:54 -0500409static u16 ath9k_regd_get_default_country(u16 rd)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700410{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700411 if (rd & COUNTRY_ERD_FLAG) {
412 struct country_code_to_enum_rd *country = NULL;
413 u16 cc = rd & ~COUNTRY_ERD_FLAG;
414
415 country = ath9k_regd_find_country(cc);
416 if (country != NULL)
417 return cc;
418 }
419
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700420 return CTRY_DEFAULT;
421}
422
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800423static struct reg_dmn_pair_mapping*
424ath9k_get_regpair(int regdmn)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700425{
426 int i;
427
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800428 if (regdmn == NO_ENUMRD)
429 return NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700430 for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800431 if (regDomainPairs[i].regDmnEnum == regdmn)
432 return &regDomainPairs[i];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700433 }
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800434 return NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700435}
436
Sujithcbe61d82009-02-09 13:27:12 +0530437int ath9k_regd_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700438{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700439 struct country_code_to_enum_rd *country = NULL;
Bob Copelande775aaf2009-02-12 13:38:54 -0500440 u16 regdmn;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700441
442 if (!ath9k_regd_is_eeprom_valid(ah)) {
443 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY,
Sujith04bd4632008-11-28 22:18:05 +0530444 "Invalid EEPROM contents\n");
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800445 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700446 }
447
Bob Copelande775aaf2009-02-12 13:38:54 -0500448 regdmn = ath9k_regd_get_eepromRD(ah);
449 ah->regulatory.country_code = ath9k_regd_get_default_country(regdmn);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700450
Sujithd6bad492009-02-09 13:27:08 +0530451 if (ah->regulatory.country_code == CTRY_DEFAULT &&
Bob Copelande775aaf2009-02-12 13:38:54 -0500452 regdmn == CTRY_DEFAULT)
Sujithd6bad492009-02-09 13:27:08 +0530453 ah->regulatory.country_code = CTRY_UNITED_STATES;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700454
Sujithd6bad492009-02-09 13:27:08 +0530455 if (ah->regulatory.country_code == CTRY_DEFAULT) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700456 country = NULL;
457 } else {
Sujithd6bad492009-02-09 13:27:08 +0530458 country = ath9k_regd_find_country(ah->regulatory.country_code);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700459 if (country == NULL) {
460 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY,
461 "Country is NULL!!!!, cc= %d\n",
Sujithd6bad492009-02-09 13:27:08 +0530462 ah->regulatory.country_code);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800463 return -EINVAL;
464 } else
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700465 regdmn = country->regDmnEnum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700466 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700467
Sujithd6bad492009-02-09 13:27:08 +0530468 ah->regulatory.regpair = ath9k_get_regpair(regdmn);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800469
Sujithd6bad492009-02-09 13:27:08 +0530470 if (!ah->regulatory.regpair) {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800471 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
472 "No regulatory domain pair found, cannot continue\n");
473 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700474 }
475
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800476 if (!country)
477 country = ath9k_regd_find_country_by_rd(regdmn);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700478
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800479 if (country) {
Sujithd6bad492009-02-09 13:27:08 +0530480 ah->regulatory.alpha2[0] = country->isoName[0];
481 ah->regulatory.alpha2[1] = country->isoName[1];
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800482 } else {
Sujithd6bad492009-02-09 13:27:08 +0530483 ah->regulatory.alpha2[0] = '0';
484 ah->regulatory.alpha2[1] = '0';
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800485 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700486
487 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY,
Luis R. Rodriguez0c6666e2009-01-26 06:48:10 -0800488 "Country alpha2 being used: %c%c\n"
Sujithd6bad492009-02-09 13:27:08 +0530489 "Regulatory.Regpair detected: 0x%0x\n",
490 ah->regulatory.alpha2[0], ah->regulatory.alpha2[1],
491 ah->regulatory.regpair->regDmnEnum);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700492
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800493 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700494}
495
Bob Copelandfc2ada32009-03-30 22:30:27 -0400496static
497u32 ath9k_regd_get_band_ctl(struct ath_hw *ah, enum ieee80211_band band)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700498{
Sujithd6bad492009-02-09 13:27:08 +0530499 if (!ah->regulatory.regpair ||
Bob Copelandd0f48f92009-02-12 13:38:55 -0500500 (ah->regulatory.country_code == CTRY_DEFAULT &&
501 is_wwr_sku(ath9k_regd_get_eepromRD(ah)))) {
Bob Copelandfc2ada32009-03-30 22:30:27 -0400502 return SD_NO_CTL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700503 }
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800504
Bob Copelandfc2ada32009-03-30 22:30:27 -0400505 switch (band) {
506 case IEEE80211_BAND_2GHZ:
507 return ah->regulatory.regpair->reg_2ghz_ctl;
508 case IEEE80211_BAND_5GHZ:
509 return ah->regulatory.regpair->reg_5ghz_ctl;
510 default:
511 return NO_CTL;
512 }
513
514 return NO_CTL;
515}
516
517u32 ath9k_regd_get_ctl(struct ath_hw *ah, struct ath9k_channel *chan)
518{
519 u32 ctl = ath9k_regd_get_band_ctl(ah, chan->chan->band);
520
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800521 if (IS_CHAN_B(chan))
Bob Copelandfc2ada32009-03-30 22:30:27 -0400522 ctl |= CTL_11B;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800523 else if (IS_CHAN_G(chan))
Bob Copelandfc2ada32009-03-30 22:30:27 -0400524 ctl |= CTL_11G;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800525 else
Bob Copelandfc2ada32009-03-30 22:30:27 -0400526 ctl |= CTL_11A;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -0800527
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700528 return ctl;
529}