17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 #include <linux/kernel.h>
20 #include <linux/export.h>
36 #define ATH9K_2GHZ_CH01_11 REG_RULE(2412-10, 2462+10, 40, 0, 20, 0)
39 #define ATH9K_2GHZ_CH12_13 REG_RULE(2467-10, 2472+10, 40, 0, 20,\
40 NL80211_RRF_PASSIVE_SCAN)
41 #define ATH9K_2GHZ_CH14 REG_RULE(2484-10, 2484+10, 40, 0, 20,\
42 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_OFDM)
45 #define ATH9K_5GHZ_5150_5350 REG_RULE(5150-10, 5350+10, 40, 0, 30,\
46 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
47 #define ATH9K_5GHZ_5470_5850 REG_RULE(5470-10, 5850+10, 40, 0, 30,\
48 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
49 #define ATH9K_5GHZ_5725_5850 REG_RULE(5725-10, 5850+10, 40, 0, 30,\
50 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
52 #define ATH9K_2GHZ_ALL ATH9K_2GHZ_CH01_11, \
56 #define ATH9K_5GHZ_ALL ATH9K_5GHZ_5150_5350, \
60 #define ATH9K_5GHZ_NO_MIDBAND ATH9K_5GHZ_5150_5350, \
116 static inline bool is_wwr_sku(
u16 regd)
130 return is_wwr_sku(ath_regd_get_eepromRD(reg));
137 return &ath_world_regdom_64;
143 switch (reg->
regpair->regDmnEnum) {
147 return &ath_world_regdom_60_61_62;
150 return &ath_world_regdom_63_65;
152 return &ath_world_regdom_64;
155 return &ath_world_regdom_66_69;
160 return &ath_world_regdom_67_68_6A_6C;
163 return ath_default_world_regdomain();
175 static bool ath_is_radar_freq(
u16 center_freq)
177 return (center_freq >= 5260 && center_freq <= 5700);
190 ath_reg_apply_beaconing_flags(
struct wiphy *
wiphy,
203 if (!wiphy->
bands[band])
231 if (!(reg_rule->
flags &
235 if (!(reg_rule->
flags &
251 ath_reg_apply_active_scan_flags(
struct wiphy *wiphy,
303 static void ath_reg_apply_radar_flags(
struct wiphy *wiphy)
335 static void ath_reg_apply_world_flags(
struct wiphy *wiphy,
339 switch (reg->
regpair->regDmnEnum) {
345 ath_reg_apply_beaconing_flags(wiphy, initiator);
348 ath_reg_apply_beaconing_flags(wiphy, initiator);
349 ath_reg_apply_active_scan_flags(wiphy, initiator);
354 static u16 ath_regd_find_country_by_name(
char *alpha2)
358 for (i = 0; i <
ARRAY_SIZE(allCountries); i++) {
359 if (!
memcmp(allCountries[i].isoName, alpha2, 2))
360 return allCountries[i].countryCode;
375 ath_reg_apply_radar_flags(wiphy);
404 country_code = ath_regd_find_country_by_name(request->
alpha2);
405 if (country_code == (
u16) -1)
413 __ath_regd_init(reg);
415 ath_reg_apply_world_flags(wiphy, request->
initiator, reg);
426 u16 rd = ath_regd_get_eepromRD(reg);
431 u16 cc = rd & ~COUNTRY_ERD_FLAG;
433 "ath: EEPROM indicates we should expect "
435 for (i = 0; i <
ARRAY_SIZE(allCountries); i++)
436 if (allCountries[i].countryCode == cc)
442 "should expect a direct regpair map\n");
443 for (i = 0; i <
ARRAY_SIZE(regDomainPairs); i++)
444 if (regDomainPairs[i].regDmnEnum == rd)
448 "ath: invalid regulatory domain/country code 0x%x\n", rd);
458 for (i = 0; i <
ARRAY_SIZE(allCountries); i++) {
459 if (allCountries[i].countryCode == countryCode)
460 return &allCountries[
i];
467 ath_regd_find_country_by_rd(
int regdmn)
471 for (i = 0; i <
ARRAY_SIZE(allCountries); i++) {
473 return &allCountries[
i];
479 static u16 ath_regd_get_default_country(
u16 rd)
481 if (rd & COUNTRY_ERD_FLAG) {
483 u16 cc = rd & ~COUNTRY_ERD_FLAG;
485 country = ath_regd_find_country(cc);
494 ath_get_regpair(
int regdmn)
500 for (i = 0; i <
ARRAY_SIZE(regDomainPairs); i++) {
502 return ®DomainPairs[
i];
510 int (*reg_notifier)(
struct wiphy *wiphy,
523 regd = ath_world_regdomain(reg);
531 regd = ath_default_world_regdomain();
534 ath_reg_apply_radar_flags(wiphy);
562 ath_regd_sanitize(reg);
566 if (!ath_regd_is_eeprom_valid(reg)) {
567 pr_err(
"Invalid EEPROM contents\n");
571 regdmn = ath_regd_get_eepromRD(reg);
572 reg->
country_code = ath_regd_get_default_country(regdmn);
577 "country code should be used\n");
587 if (country ==
NULL) {
589 "ath: no valid country maps found for "
590 "country code: 0x%0x\n",
596 "regdmn code: 0x%0x\n",
601 reg->
regpair = ath_get_regpair(regdmn);
605 "No regulatory domain pair found, cannot continue\n");
610 country = ath_regd_find_country_by_rd(regdmn);
631 int (*reg_notifier)(
struct wiphy *wiphy,
638 r = __ath_regd_init(reg);
646 ath_regd_init_wiphy(reg, wiphy, reg_notifier);
657 is_wwr_sku(ath_regd_get_eepromRD(reg)))) {
663 return reg->
regpair->reg_2ghz_ctl;
665 return reg->
regpair->reg_5ghz_ctl;