regd.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. /*
  2. * Copyright (c) 2008-2009 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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  17. #include <linux/kernel.h>
  18. #include <linux/export.h>
  19. #include <net/cfg80211.h>
  20. #include <net/mac80211.h>
  21. #include "regd.h"
  22. #include "regd_common.h"
  23. static int __ath_regd_init(struct ath_regulatory *reg);
  24. /*
  25. * This is a set of common rules used by our world regulatory domains.
  26. * We have 12 world regulatory domains. To save space we consolidate
  27. * the regulatory domains in 5 structures by frequency and change
  28. * the flags on our reg_notifier() on a case by case basis.
  29. */
  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)
  32. /* 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)
  37. /* We allow IBSS on these on a case by case basis by regulatory domain */
  38. #define ATH9K_5GHZ_5150_5350 REG_RULE(5150-10, 5350+10, 80, 0, 30,\
  39. NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
  40. #define ATH9K_5GHZ_5470_5850 REG_RULE(5470-10, 5850+10, 80, 0, 30,\
  41. NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
  42. #define ATH9K_5GHZ_5725_5850 REG_RULE(5725-10, 5850+10, 80, 0, 30,\
  43. NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
  44. #define ATH9K_2GHZ_ALL ATH9K_2GHZ_CH01_11, \
  45. ATH9K_2GHZ_CH12_13, \
  46. ATH9K_2GHZ_CH14
  47. #define ATH9K_5GHZ_ALL ATH9K_5GHZ_5150_5350, \
  48. ATH9K_5GHZ_5470_5850
  49. /* This one skips what we call "mid band" */
  50. #define ATH9K_5GHZ_NO_MIDBAND ATH9K_5GHZ_5150_5350, \
  51. ATH9K_5GHZ_5725_5850
  52. /* Can be used for:
  53. * 0x60, 0x61, 0x62 */
  54. static const struct ieee80211_regdomain ath_world_regdom_60_61_62 = {
  55. .n_reg_rules = 5,
  56. .alpha2 = "99",
  57. .reg_rules = {
  58. ATH9K_2GHZ_ALL,
  59. ATH9K_5GHZ_ALL,
  60. }
  61. };
  62. /* Can be used by 0x63 and 0x65 */
  63. static const struct ieee80211_regdomain ath_world_regdom_63_65 = {
  64. .n_reg_rules = 4,
  65. .alpha2 = "99",
  66. .reg_rules = {
  67. ATH9K_2GHZ_CH01_11,
  68. ATH9K_2GHZ_CH12_13,
  69. ATH9K_5GHZ_NO_MIDBAND,
  70. }
  71. };
  72. /* Can be used by 0x64 only */
  73. static const struct ieee80211_regdomain ath_world_regdom_64 = {
  74. .n_reg_rules = 3,
  75. .alpha2 = "99",
  76. .reg_rules = {
  77. ATH9K_2GHZ_CH01_11,
  78. ATH9K_5GHZ_NO_MIDBAND,
  79. }
  80. };
  81. /* Can be used by 0x66 and 0x69 */
  82. static const struct ieee80211_regdomain ath_world_regdom_66_69 = {
  83. .n_reg_rules = 3,
  84. .alpha2 = "99",
  85. .reg_rules = {
  86. ATH9K_2GHZ_CH01_11,
  87. ATH9K_5GHZ_ALL,
  88. }
  89. };
  90. /* Can be used by 0x67, 0x68, 0x6A and 0x6C */
  91. static const struct ieee80211_regdomain ath_world_regdom_67_68_6A_6C = {
  92. .n_reg_rules = 4,
  93. .alpha2 = "99",
  94. .reg_rules = {
  95. ATH9K_2GHZ_CH01_11,
  96. ATH9K_2GHZ_CH12_13,
  97. ATH9K_5GHZ_ALL,
  98. }
  99. };
  100. static inline bool is_wwr_sku(u16 regd)
  101. {
  102. return ((regd & COUNTRY_ERD_FLAG) != COUNTRY_ERD_FLAG) &&
  103. (((regd & WORLD_SKU_MASK) == WORLD_SKU_PREFIX) ||
  104. (regd == WORLD));
  105. }
  106. static u16 ath_regd_get_eepromRD(struct ath_regulatory *reg)
  107. {
  108. return reg->current_rd & ~WORLDWIDE_ROAMING_FLAG;
  109. }
  110. bool ath_is_world_regd(struct ath_regulatory *reg)
  111. {
  112. return is_wwr_sku(ath_regd_get_eepromRD(reg));
  113. }
  114. EXPORT_SYMBOL(ath_is_world_regd);
  115. static const struct ieee80211_regdomain *ath_default_world_regdomain(void)
  116. {
  117. /* this is the most restrictive */
  118. return &ath_world_regdom_64;
  119. }
  120. static const struct
  121. ieee80211_regdomain *ath_world_regdomain(struct ath_regulatory *reg)
  122. {
  123. switch (reg->regpair->regDmnEnum) {
  124. case 0x60:
  125. case 0x61:
  126. case 0x62:
  127. return &ath_world_regdom_60_61_62;
  128. case 0x63:
  129. case 0x65:
  130. return &ath_world_regdom_63_65;
  131. case 0x64:
  132. return &ath_world_regdom_64;
  133. case 0x66:
  134. case 0x69:
  135. return &ath_world_regdom_66_69;
  136. case 0x67:
  137. case 0x68:
  138. case 0x6A:
  139. case 0x6C:
  140. return &ath_world_regdom_67_68_6A_6C;
  141. default:
  142. WARN_ON(1);
  143. return ath_default_world_regdomain();
  144. }
  145. }
  146. bool ath_is_49ghz_allowed(u16 regdomain)
  147. {
  148. /* possibly more */
  149. return regdomain == MKK9_MKKC;
  150. }
  151. EXPORT_SYMBOL(ath_is_49ghz_allowed);
  152. /* Frequency is one where radar detection is required */
  153. static bool ath_is_radar_freq(u16 center_freq)
  154. {
  155. return (center_freq >= 5260 && center_freq <= 5700);
  156. }
  157. /*
  158. * N.B: These exception rules do not apply radar freqs.
  159. *
  160. * - We enable adhoc (or beaconing) if allowed by 11d
  161. * - We enable active scan if the channel is allowed by 11d
  162. * - If no country IE has been processed and a we determine we have
  163. * received a beacon on a channel we can enable active scan and
  164. * adhoc (or beaconing).
  165. */
  166. static void
  167. ath_reg_apply_beaconing_flags(struct wiphy *wiphy,
  168. enum nl80211_reg_initiator initiator)
  169. {
  170. enum ieee80211_band band;
  171. struct ieee80211_supported_band *sband;
  172. const struct ieee80211_reg_rule *reg_rule;
  173. struct ieee80211_channel *ch;
  174. unsigned int i;
  175. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  176. if (!wiphy->bands[band])
  177. continue;
  178. sband = wiphy->bands[band];
  179. for (i = 0; i < sband->n_channels; i++) {
  180. ch = &sband->channels[i];
  181. if (ath_is_radar_freq(ch->center_freq) ||
  182. (ch->flags & IEEE80211_CHAN_RADAR))
  183. continue;
  184. if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) {
  185. reg_rule = freq_reg_info(wiphy, ch->center_freq);
  186. if (IS_ERR(reg_rule))
  187. continue;
  188. /*
  189. * If 11d had a rule for this channel ensure
  190. * we enable adhoc/beaconing if it allows us to
  191. * use it. Note that we would have disabled it
  192. * by applying our static world regdomain by
  193. * default during init, prior to calling our
  194. * regulatory_hint().
  195. */
  196. if (!(reg_rule->flags &
  197. NL80211_RRF_NO_IBSS))
  198. ch->flags &=
  199. ~IEEE80211_CHAN_NO_IBSS;
  200. if (!(reg_rule->flags &
  201. NL80211_RRF_PASSIVE_SCAN))
  202. ch->flags &=
  203. ~IEEE80211_CHAN_PASSIVE_SCAN;
  204. } else {
  205. if (ch->beacon_found)
  206. ch->flags &= ~(IEEE80211_CHAN_NO_IBSS |
  207. IEEE80211_CHAN_PASSIVE_SCAN);
  208. }
  209. }
  210. }
  211. }
  212. /* Allows active scan scan on Ch 12 and 13 */
  213. static void
  214. ath_reg_apply_active_scan_flags(struct wiphy *wiphy,
  215. enum nl80211_reg_initiator initiator)
  216. {
  217. struct ieee80211_supported_band *sband;
  218. struct ieee80211_channel *ch;
  219. const struct ieee80211_reg_rule *reg_rule;
  220. sband = wiphy->bands[IEEE80211_BAND_2GHZ];
  221. if (!sband)
  222. return;
  223. /*
  224. * If no country IE has been received always enable active scan
  225. * on these channels. This is only done for specific regulatory SKUs
  226. */
  227. if (initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) {
  228. ch = &sband->channels[11]; /* CH 12 */
  229. if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
  230. ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
  231. ch = &sband->channels[12]; /* CH 13 */
  232. if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
  233. ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
  234. return;
  235. }
  236. /*
  237. * If a country IE has been received check its rule for this
  238. * channel first before enabling active scan. The passive scan
  239. * would have been enforced by the initial processing of our
  240. * custom regulatory domain.
  241. */
  242. ch = &sband->channels[11]; /* CH 12 */
  243. reg_rule = freq_reg_info(wiphy, ch->center_freq);
  244. if (!IS_ERR(reg_rule)) {
  245. if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN))
  246. if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
  247. ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
  248. }
  249. ch = &sband->channels[12]; /* CH 13 */
  250. reg_rule = freq_reg_info(wiphy, ch->center_freq);
  251. if (!IS_ERR(reg_rule)) {
  252. if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN))
  253. if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
  254. ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
  255. }
  256. }
  257. /* Always apply Radar/DFS rules on freq range 5260 MHz - 5700 MHz */
  258. static void ath_reg_apply_radar_flags(struct wiphy *wiphy)
  259. {
  260. struct ieee80211_supported_band *sband;
  261. struct ieee80211_channel *ch;
  262. unsigned int i;
  263. if (!wiphy->bands[IEEE80211_BAND_5GHZ])
  264. return;
  265. sband = wiphy->bands[IEEE80211_BAND_5GHZ];
  266. for (i = 0; i < sband->n_channels; i++) {
  267. ch = &sband->channels[i];
  268. if (!ath_is_radar_freq(ch->center_freq))
  269. 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. static void ath_reg_apply_world_flags(struct wiphy *wiphy,
  287. enum nl80211_reg_initiator initiator,
  288. struct ath_regulatory *reg)
  289. {
  290. switch (reg->regpair->regDmnEnum) {
  291. case 0x60:
  292. case 0x63:
  293. case 0x66:
  294. case 0x67:
  295. case 0x6C:
  296. ath_reg_apply_beaconing_flags(wiphy, initiator);
  297. break;
  298. case 0x68:
  299. ath_reg_apply_beaconing_flags(wiphy, initiator);
  300. ath_reg_apply_active_scan_flags(wiphy, initiator);
  301. break;
  302. }
  303. }
  304. static u16 ath_regd_find_country_by_name(char *alpha2)
  305. {
  306. unsigned int i;
  307. for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
  308. if (!memcmp(allCountries[i].isoName, alpha2, 2))
  309. return allCountries[i].countryCode;
  310. }
  311. return -1;
  312. }
  313. static int __ath_reg_dyn_country(struct wiphy *wiphy,
  314. struct ath_regulatory *reg,
  315. struct regulatory_request *request)
  316. {
  317. u16 country_code;
  318. if (!ath_is_world_regd(reg))
  319. return -EINVAL;
  320. country_code = ath_regd_find_country_by_name(request->alpha2);
  321. if (country_code == (u16) -1)
  322. return -EINVAL;
  323. reg->current_rd = COUNTRY_ERD_FLAG;
  324. reg->current_rd |= country_code;
  325. __ath_regd_init(reg);
  326. ath_reg_apply_world_flags(wiphy, request->initiator, reg);
  327. return 0;
  328. }
  329. static void ath_reg_dyn_country(struct wiphy *wiphy,
  330. struct ath_regulatory *reg,
  331. struct regulatory_request *request)
  332. {
  333. if (__ath_reg_dyn_country(wiphy, reg, request))
  334. return;
  335. printk(KERN_DEBUG "ath: regdomain 0x%0x "
  336. "dynamically updated by %s\n",
  337. reg->current_rd,
  338. reg_initiator_name(request->initiator));
  339. }
  340. void ath_reg_notifier_apply(struct wiphy *wiphy,
  341. struct regulatory_request *request,
  342. struct ath_regulatory *reg)
  343. {
  344. struct ath_common *common = container_of(reg, struct ath_common,
  345. regulatory);
  346. /* We always apply this */
  347. ath_reg_apply_radar_flags(wiphy);
  348. /*
  349. * This would happen when we have sent a custom regulatory request
  350. * a world regulatory domain and the scheduler hasn't yet processed
  351. * any pending requests in the queue.
  352. */
  353. if (!request)
  354. return;
  355. switch (request->initiator) {
  356. case NL80211_REGDOM_SET_BY_CORE:
  357. /*
  358. * If common->reg_world_copy is world roaming it means we *were*
  359. * world roaming... so we now have to restore that data.
  360. */
  361. if (!ath_is_world_regd(&common->reg_world_copy))
  362. break;
  363. memcpy(reg, &common->reg_world_copy,
  364. sizeof(struct ath_regulatory));
  365. break;
  366. case NL80211_REGDOM_SET_BY_DRIVER:
  367. case NL80211_REGDOM_SET_BY_USER:
  368. break;
  369. case NL80211_REGDOM_SET_BY_COUNTRY_IE:
  370. ath_reg_dyn_country(wiphy, reg, request);
  371. break;
  372. }
  373. }
  374. EXPORT_SYMBOL(ath_reg_notifier_apply);
  375. static bool ath_regd_is_eeprom_valid(struct ath_regulatory *reg)
  376. {
  377. u16 rd = ath_regd_get_eepromRD(reg);
  378. int i;
  379. if (rd & COUNTRY_ERD_FLAG) {
  380. /* EEPROM value is a country code */
  381. u16 cc = rd & ~COUNTRY_ERD_FLAG;
  382. printk(KERN_DEBUG
  383. "ath: EEPROM indicates we should expect "
  384. "a country code\n");
  385. for (i = 0; i < ARRAY_SIZE(allCountries); i++)
  386. if (allCountries[i].countryCode == cc)
  387. return true;
  388. } else {
  389. /* EEPROM value is a regpair value */
  390. if (rd != CTRY_DEFAULT)
  391. printk(KERN_DEBUG "ath: EEPROM indicates we "
  392. "should expect a direct regpair map\n");
  393. for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++)
  394. if (regDomainPairs[i].regDmnEnum == rd)
  395. return true;
  396. }
  397. printk(KERN_DEBUG
  398. "ath: invalid regulatory domain/country code 0x%x\n", rd);
  399. return false;
  400. }
  401. /* EEPROM country code to regpair mapping */
  402. static struct country_code_to_enum_rd*
  403. ath_regd_find_country(u16 countryCode)
  404. {
  405. int i;
  406. for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
  407. if (allCountries[i].countryCode == countryCode)
  408. return &allCountries[i];
  409. }
  410. return NULL;
  411. }
  412. /* EEPROM rd code to regpair mapping */
  413. static struct country_code_to_enum_rd*
  414. ath_regd_find_country_by_rd(int regdmn)
  415. {
  416. int i;
  417. for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
  418. if (allCountries[i].regDmnEnum == regdmn)
  419. return &allCountries[i];
  420. }
  421. return NULL;
  422. }
  423. /* Returns the map of the EEPROM set RD to a country code */
  424. static u16 ath_regd_get_default_country(u16 rd)
  425. {
  426. if (rd & COUNTRY_ERD_FLAG) {
  427. struct country_code_to_enum_rd *country = NULL;
  428. u16 cc = rd & ~COUNTRY_ERD_FLAG;
  429. country = ath_regd_find_country(cc);
  430. if (country != NULL)
  431. return cc;
  432. }
  433. return CTRY_DEFAULT;
  434. }
  435. static struct reg_dmn_pair_mapping*
  436. ath_get_regpair(int regdmn)
  437. {
  438. int i;
  439. if (regdmn == NO_ENUMRD)
  440. return NULL;
  441. for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
  442. if (regDomainPairs[i].regDmnEnum == regdmn)
  443. return &regDomainPairs[i];
  444. }
  445. return NULL;
  446. }
  447. static int
  448. ath_regd_init_wiphy(struct ath_regulatory *reg,
  449. struct wiphy *wiphy,
  450. void (*reg_notifier)(struct wiphy *wiphy,
  451. struct regulatory_request *request))
  452. {
  453. const struct ieee80211_regdomain *regd;
  454. wiphy->reg_notifier = reg_notifier;
  455. wiphy->flags |= WIPHY_FLAG_STRICT_REGULATORY;
  456. if (ath_is_world_regd(reg)) {
  457. /*
  458. * Anything applied here (prior to wiphy registration) gets
  459. * saved on the wiphy orig_* parameters
  460. */
  461. regd = ath_world_regdomain(reg);
  462. wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY;
  463. } else {
  464. /*
  465. * This gets applied in the case of the absence of CRDA,
  466. * it's our own custom world regulatory domain, similar to
  467. * cfg80211's but we enable passive scanning.
  468. */
  469. regd = ath_default_world_regdomain();
  470. }
  471. wiphy_apply_custom_regulatory(wiphy, regd);
  472. ath_reg_apply_radar_flags(wiphy);
  473. ath_reg_apply_world_flags(wiphy, NL80211_REGDOM_SET_BY_DRIVER, reg);
  474. return 0;
  475. }
  476. /*
  477. * Some users have reported their EEPROM programmed with
  478. * 0x8000 set, this is not a supported regulatory domain
  479. * but since we have more than one user with it we need
  480. * a solution for them. We default to 0x64, which is the
  481. * default Atheros world regulatory domain.
  482. */
  483. static void ath_regd_sanitize(struct ath_regulatory *reg)
  484. {
  485. if (reg->current_rd != COUNTRY_ERD_FLAG)
  486. return;
  487. printk(KERN_DEBUG "ath: EEPROM regdomain sanitized\n");
  488. reg->current_rd = 0x64;
  489. }
  490. static int __ath_regd_init(struct ath_regulatory *reg)
  491. {
  492. struct country_code_to_enum_rd *country = NULL;
  493. u16 regdmn;
  494. if (!reg)
  495. return -EINVAL;
  496. ath_regd_sanitize(reg);
  497. printk(KERN_DEBUG "ath: EEPROM regdomain: 0x%0x\n", reg->current_rd);
  498. if (!ath_regd_is_eeprom_valid(reg)) {
  499. pr_err("Invalid EEPROM contents\n");
  500. return -EINVAL;
  501. }
  502. regdmn = ath_regd_get_eepromRD(reg);
  503. reg->country_code = ath_regd_get_default_country(regdmn);
  504. if (reg->country_code == CTRY_DEFAULT &&
  505. regdmn == CTRY_DEFAULT) {
  506. printk(KERN_DEBUG "ath: EEPROM indicates default "
  507. "country code should be used\n");
  508. reg->country_code = CTRY_UNITED_STATES;
  509. }
  510. if (reg->country_code == CTRY_DEFAULT) {
  511. country = NULL;
  512. } else {
  513. printk(KERN_DEBUG "ath: doing EEPROM country->regdmn "
  514. "map search\n");
  515. country = ath_regd_find_country(reg->country_code);
  516. if (country == NULL) {
  517. printk(KERN_DEBUG
  518. "ath: no valid country maps found for "
  519. "country code: 0x%0x\n",
  520. reg->country_code);
  521. return -EINVAL;
  522. } else {
  523. regdmn = country->regDmnEnum;
  524. printk(KERN_DEBUG "ath: country maps to "
  525. "regdmn code: 0x%0x\n",
  526. regdmn);
  527. }
  528. }
  529. reg->regpair = ath_get_regpair(regdmn);
  530. if (!reg->regpair) {
  531. printk(KERN_DEBUG "ath: "
  532. "No regulatory domain pair found, cannot continue\n");
  533. return -EINVAL;
  534. }
  535. if (!country)
  536. country = ath_regd_find_country_by_rd(regdmn);
  537. if (country) {
  538. reg->alpha2[0] = country->isoName[0];
  539. reg->alpha2[1] = country->isoName[1];
  540. } else {
  541. reg->alpha2[0] = '0';
  542. reg->alpha2[1] = '0';
  543. }
  544. printk(KERN_DEBUG "ath: Country alpha2 being used: %c%c\n",
  545. reg->alpha2[0], reg->alpha2[1]);
  546. printk(KERN_DEBUG "ath: Regpair used: 0x%0x\n",
  547. reg->regpair->regDmnEnum);
  548. return 0;
  549. }
  550. int
  551. ath_regd_init(struct ath_regulatory *reg,
  552. struct wiphy *wiphy,
  553. void (*reg_notifier)(struct wiphy *wiphy,
  554. struct regulatory_request *request))
  555. {
  556. struct ath_common *common = container_of(reg, struct ath_common,
  557. regulatory);
  558. int r;
  559. r = __ath_regd_init(reg);
  560. if (r)
  561. return r;
  562. if (ath_is_world_regd(reg))
  563. memcpy(&common->reg_world_copy, reg,
  564. sizeof(struct ath_regulatory));
  565. ath_regd_init_wiphy(reg, wiphy, reg_notifier);
  566. return 0;
  567. }
  568. EXPORT_SYMBOL(ath_regd_init);
  569. u32 ath_regd_get_band_ctl(struct ath_regulatory *reg,
  570. enum ieee80211_band band)
  571. {
  572. if (!reg->regpair ||
  573. (reg->country_code == CTRY_DEFAULT &&
  574. is_wwr_sku(ath_regd_get_eepromRD(reg)))) {
  575. return SD_NO_CTL;
  576. }
  577. switch (band) {
  578. case IEEE80211_BAND_2GHZ:
  579. return reg->regpair->reg_2ghz_ctl;
  580. case IEEE80211_BAND_5GHZ:
  581. return reg->regpair->reg_5ghz_ctl;
  582. default:
  583. return NO_CTL;
  584. }
  585. }
  586. EXPORT_SYMBOL(ath_regd_get_band_ctl);