regd.c 17 KB

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