key.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. /*
  2. * Copyright (c) 2009 Atheros Communications Inc.
  3. * Copyright (c) 2010 Bruno Randolf <br1@einfach.org>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <asm/unaligned.h>
  18. #include <net/mac80211.h>
  19. #include "ath.h"
  20. #include "reg.h"
  21. #define REG_READ (common->ops->read)
  22. #define REG_WRITE(_ah, _reg, _val) (common->ops->write)(_ah, _val, _reg)
  23. #define IEEE80211_WEP_NKID 4 /* number of key ids */
  24. /************************/
  25. /* Key Cache Management */
  26. /************************/
  27. bool ath_hw_keyreset(struct ath_common *common, u16 entry)
  28. {
  29. u32 keyType;
  30. void *ah = common->ah;
  31. if (entry >= common->keymax) {
  32. ath_err(common, "keycache entry %u out of range\n", entry);
  33. return false;
  34. }
  35. keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
  36. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
  37. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
  38. REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
  39. REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
  40. REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
  41. REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
  42. REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
  43. REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
  44. if (keyType == AR_KEYTABLE_TYPE_TKIP) {
  45. u16 micentry = entry + 64;
  46. REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
  47. REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
  48. REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
  49. REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
  50. if (common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED) {
  51. REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
  52. REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
  53. AR_KEYTABLE_TYPE_CLR);
  54. }
  55. }
  56. return true;
  57. }
  58. EXPORT_SYMBOL(ath_hw_keyreset);
  59. static bool ath_hw_keysetmac(struct ath_common *common,
  60. u16 entry, const u8 *mac)
  61. {
  62. u32 macHi, macLo;
  63. u32 unicast_flag = AR_KEYTABLE_VALID;
  64. void *ah = common->ah;
  65. if (entry >= common->keymax) {
  66. ath_err(common, "keycache entry %u out of range\n", entry);
  67. return false;
  68. }
  69. if (mac != NULL) {
  70. /*
  71. * AR_KEYTABLE_VALID indicates that the address is a unicast
  72. * address, which must match the transmitter address for
  73. * decrypting frames.
  74. * Not setting this bit allows the hardware to use the key
  75. * for multicast frame decryption.
  76. */
  77. if (mac[0] & 0x01)
  78. unicast_flag = 0;
  79. macHi = (mac[5] << 8) | mac[4];
  80. macLo = (mac[3] << 24) |
  81. (mac[2] << 16) |
  82. (mac[1] << 8) |
  83. mac[0];
  84. macLo >>= 1;
  85. macLo |= (macHi & 1) << 31;
  86. macHi >>= 1;
  87. } else {
  88. macLo = macHi = 0;
  89. }
  90. REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
  91. REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | unicast_flag);
  92. return true;
  93. }
  94. static bool ath_hw_set_keycache_entry(struct ath_common *common, u16 entry,
  95. const struct ath_keyval *k,
  96. const u8 *mac)
  97. {
  98. void *ah = common->ah;
  99. u32 key0, key1, key2, key3, key4;
  100. u32 keyType;
  101. if (entry >= common->keymax) {
  102. ath_err(common, "keycache entry %u out of range\n", entry);
  103. return false;
  104. }
  105. switch (k->kv_type) {
  106. case ATH_CIPHER_AES_OCB:
  107. keyType = AR_KEYTABLE_TYPE_AES;
  108. break;
  109. case ATH_CIPHER_AES_CCM:
  110. if (!(common->crypt_caps & ATH_CRYPT_CAP_CIPHER_AESCCM)) {
  111. ath_dbg(common, ATH_DBG_ANY,
  112. "AES-CCM not supported by this mac rev\n");
  113. return false;
  114. }
  115. keyType = AR_KEYTABLE_TYPE_CCM;
  116. break;
  117. case ATH_CIPHER_TKIP:
  118. keyType = AR_KEYTABLE_TYPE_TKIP;
  119. if (entry + 64 >= common->keymax) {
  120. ath_dbg(common, ATH_DBG_ANY,
  121. "entry %u inappropriate for TKIP\n", entry);
  122. return false;
  123. }
  124. break;
  125. case ATH_CIPHER_WEP:
  126. if (k->kv_len < WLAN_KEY_LEN_WEP40) {
  127. ath_dbg(common, ATH_DBG_ANY,
  128. "WEP key length %u too small\n", k->kv_len);
  129. return false;
  130. }
  131. if (k->kv_len <= WLAN_KEY_LEN_WEP40)
  132. keyType = AR_KEYTABLE_TYPE_40;
  133. else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
  134. keyType = AR_KEYTABLE_TYPE_104;
  135. else
  136. keyType = AR_KEYTABLE_TYPE_128;
  137. break;
  138. case ATH_CIPHER_CLR:
  139. keyType = AR_KEYTABLE_TYPE_CLR;
  140. break;
  141. default:
  142. ath_err(common, "cipher %u not supported\n", k->kv_type);
  143. return false;
  144. }
  145. key0 = get_unaligned_le32(k->kv_val + 0);
  146. key1 = get_unaligned_le16(k->kv_val + 4);
  147. key2 = get_unaligned_le32(k->kv_val + 6);
  148. key3 = get_unaligned_le16(k->kv_val + 10);
  149. key4 = get_unaligned_le32(k->kv_val + 12);
  150. if (k->kv_len <= WLAN_KEY_LEN_WEP104)
  151. key4 &= 0xff;
  152. /*
  153. * Note: Key cache registers access special memory area that requires
  154. * two 32-bit writes to actually update the values in the internal
  155. * memory. Consequently, the exact order and pairs used here must be
  156. * maintained.
  157. */
  158. if (keyType == AR_KEYTABLE_TYPE_TKIP) {
  159. u16 micentry = entry + 64;
  160. /*
  161. * Write inverted key[47:0] first to avoid Michael MIC errors
  162. * on frames that could be sent or received at the same time.
  163. * The correct key will be written in the end once everything
  164. * else is ready.
  165. */
  166. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
  167. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
  168. /* Write key[95:48] */
  169. REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
  170. REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
  171. /* Write key[127:96] and key type */
  172. REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
  173. REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
  174. /* Write MAC address for the entry */
  175. (void) ath_hw_keysetmac(common, entry, mac);
  176. if (common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED) {
  177. /*
  178. * TKIP uses two key cache entries:
  179. * Michael MIC TX/RX keys in the same key cache entry
  180. * (idx = main index + 64):
  181. * key0 [31:0] = RX key [31:0]
  182. * key1 [15:0] = TX key [31:16]
  183. * key1 [31:16] = reserved
  184. * key2 [31:0] = RX key [63:32]
  185. * key3 [15:0] = TX key [15:0]
  186. * key3 [31:16] = reserved
  187. * key4 [31:0] = TX key [63:32]
  188. */
  189. u32 mic0, mic1, mic2, mic3, mic4;
  190. mic0 = get_unaligned_le32(k->kv_mic + 0);
  191. mic2 = get_unaligned_le32(k->kv_mic + 4);
  192. mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
  193. mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
  194. mic4 = get_unaligned_le32(k->kv_txmic + 4);
  195. /* Write RX[31:0] and TX[31:16] */
  196. REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
  197. REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
  198. /* Write RX[63:32] and TX[15:0] */
  199. REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
  200. REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
  201. /* Write TX[63:32] and keyType(reserved) */
  202. REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
  203. REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
  204. AR_KEYTABLE_TYPE_CLR);
  205. } else {
  206. /*
  207. * TKIP uses four key cache entries (two for group
  208. * keys):
  209. * Michael MIC TX/RX keys are in different key cache
  210. * entries (idx = main index + 64 for TX and
  211. * main index + 32 + 96 for RX):
  212. * key0 [31:0] = TX/RX MIC key [31:0]
  213. * key1 [31:0] = reserved
  214. * key2 [31:0] = TX/RX MIC key [63:32]
  215. * key3 [31:0] = reserved
  216. * key4 [31:0] = reserved
  217. *
  218. * Upper layer code will call this function separately
  219. * for TX and RX keys when these registers offsets are
  220. * used.
  221. */
  222. u32 mic0, mic2;
  223. mic0 = get_unaligned_le32(k->kv_mic + 0);
  224. mic2 = get_unaligned_le32(k->kv_mic + 4);
  225. /* Write MIC key[31:0] */
  226. REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
  227. REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
  228. /* Write MIC key[63:32] */
  229. REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
  230. REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
  231. /* Write TX[63:32] and keyType(reserved) */
  232. REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
  233. REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
  234. AR_KEYTABLE_TYPE_CLR);
  235. }
  236. /* MAC address registers are reserved for the MIC entry */
  237. REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
  238. REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
  239. /*
  240. * Write the correct (un-inverted) key[47:0] last to enable
  241. * TKIP now that all other registers are set with correct
  242. * values.
  243. */
  244. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
  245. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
  246. } else {
  247. /* Write key[47:0] */
  248. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
  249. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
  250. /* Write key[95:48] */
  251. REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
  252. REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
  253. /* Write key[127:96] and key type */
  254. REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
  255. REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
  256. /* Write MAC address for the entry */
  257. (void) ath_hw_keysetmac(common, entry, mac);
  258. }
  259. return true;
  260. }
  261. static int ath_setkey_tkip(struct ath_common *common, u16 keyix, const u8 *key,
  262. struct ath_keyval *hk, const u8 *addr,
  263. bool authenticator)
  264. {
  265. const u8 *key_rxmic;
  266. const u8 *key_txmic;
  267. key_txmic = key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
  268. key_rxmic = key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
  269. if (addr == NULL) {
  270. /*
  271. * Group key installation - only two key cache entries are used
  272. * regardless of splitmic capability since group key is only
  273. * used either for TX or RX.
  274. */
  275. if (authenticator) {
  276. memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
  277. memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_mic));
  278. } else {
  279. memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
  280. memcpy(hk->kv_txmic, key_rxmic, sizeof(hk->kv_mic));
  281. }
  282. return ath_hw_set_keycache_entry(common, keyix, hk, addr);
  283. }
  284. if (common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED) {
  285. /* TX and RX keys share the same key cache entry. */
  286. memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
  287. memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
  288. return ath_hw_set_keycache_entry(common, keyix, hk, addr);
  289. }
  290. /* Separate key cache entries for TX and RX */
  291. /* TX key goes at first index, RX key at +32. */
  292. memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
  293. if (!ath_hw_set_keycache_entry(common, keyix, hk, NULL)) {
  294. /* TX MIC entry failed. No need to proceed further */
  295. ath_err(common, "Setting TX MIC Key Failed\n");
  296. return 0;
  297. }
  298. memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
  299. /* XXX delete tx key on failure? */
  300. return ath_hw_set_keycache_entry(common, keyix + 32, hk, addr);
  301. }
  302. static int ath_reserve_key_cache_slot_tkip(struct ath_common *common)
  303. {
  304. int i;
  305. for (i = IEEE80211_WEP_NKID; i < common->keymax / 2; i++) {
  306. if (test_bit(i, common->keymap) ||
  307. test_bit(i + 64, common->keymap))
  308. continue; /* At least one part of TKIP key allocated */
  309. if (!(common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED) &&
  310. (test_bit(i + 32, common->keymap) ||
  311. test_bit(i + 64 + 32, common->keymap)))
  312. continue; /* At least one part of TKIP key allocated */
  313. /* Found a free slot for a TKIP key */
  314. return i;
  315. }
  316. return -1;
  317. }
  318. static int ath_reserve_key_cache_slot(struct ath_common *common,
  319. u32 cipher)
  320. {
  321. int i;
  322. if (cipher == WLAN_CIPHER_SUITE_TKIP)
  323. return ath_reserve_key_cache_slot_tkip(common);
  324. /* First, try to find slots that would not be available for TKIP. */
  325. if (!(common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED)) {
  326. for (i = IEEE80211_WEP_NKID; i < common->keymax / 4; i++) {
  327. if (!test_bit(i, common->keymap) &&
  328. (test_bit(i + 32, common->keymap) ||
  329. test_bit(i + 64, common->keymap) ||
  330. test_bit(i + 64 + 32, common->keymap)))
  331. return i;
  332. if (!test_bit(i + 32, common->keymap) &&
  333. (test_bit(i, common->keymap) ||
  334. test_bit(i + 64, common->keymap) ||
  335. test_bit(i + 64 + 32, common->keymap)))
  336. return i + 32;
  337. if (!test_bit(i + 64, common->keymap) &&
  338. (test_bit(i , common->keymap) ||
  339. test_bit(i + 32, common->keymap) ||
  340. test_bit(i + 64 + 32, common->keymap)))
  341. return i + 64;
  342. if (!test_bit(i + 64 + 32, common->keymap) &&
  343. (test_bit(i, common->keymap) ||
  344. test_bit(i + 32, common->keymap) ||
  345. test_bit(i + 64, common->keymap)))
  346. return i + 64 + 32;
  347. }
  348. } else {
  349. for (i = IEEE80211_WEP_NKID; i < common->keymax / 2; i++) {
  350. if (!test_bit(i, common->keymap) &&
  351. test_bit(i + 64, common->keymap))
  352. return i;
  353. if (test_bit(i, common->keymap) &&
  354. !test_bit(i + 64, common->keymap))
  355. return i + 64;
  356. }
  357. }
  358. /* No partially used TKIP slots, pick any available slot */
  359. for (i = IEEE80211_WEP_NKID; i < common->keymax; i++) {
  360. /* Do not allow slots that could be needed for TKIP group keys
  361. * to be used. This limitation could be removed if we know that
  362. * TKIP will not be used. */
  363. if (i >= 64 && i < 64 + IEEE80211_WEP_NKID)
  364. continue;
  365. if (!(common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED)) {
  366. if (i >= 32 && i < 32 + IEEE80211_WEP_NKID)
  367. continue;
  368. if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID)
  369. continue;
  370. }
  371. if (!test_bit(i, common->keymap))
  372. return i; /* Found a free slot for a key */
  373. }
  374. /* No free slot found */
  375. return -1;
  376. }
  377. /*
  378. * Configure encryption in the HW.
  379. */
  380. int ath_key_config(struct ath_common *common,
  381. struct ieee80211_vif *vif,
  382. struct ieee80211_sta *sta,
  383. struct ieee80211_key_conf *key)
  384. {
  385. struct ath_keyval hk;
  386. const u8 *mac = NULL;
  387. u8 gmac[ETH_ALEN];
  388. int ret = 0;
  389. int idx;
  390. memset(&hk, 0, sizeof(hk));
  391. switch (key->cipher) {
  392. case WLAN_CIPHER_SUITE_WEP40:
  393. case WLAN_CIPHER_SUITE_WEP104:
  394. hk.kv_type = ATH_CIPHER_WEP;
  395. break;
  396. case WLAN_CIPHER_SUITE_TKIP:
  397. hk.kv_type = ATH_CIPHER_TKIP;
  398. break;
  399. case WLAN_CIPHER_SUITE_CCMP:
  400. hk.kv_type = ATH_CIPHER_AES_CCM;
  401. break;
  402. default:
  403. return -EOPNOTSUPP;
  404. }
  405. hk.kv_len = key->keylen;
  406. memcpy(hk.kv_val, key->key, key->keylen);
  407. if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
  408. switch (vif->type) {
  409. case NL80211_IFTYPE_AP:
  410. memcpy(gmac, vif->addr, ETH_ALEN);
  411. gmac[0] |= 0x01;
  412. mac = gmac;
  413. idx = ath_reserve_key_cache_slot(common, key->cipher);
  414. break;
  415. case NL80211_IFTYPE_ADHOC:
  416. if (!sta) {
  417. idx = key->keyidx;
  418. break;
  419. }
  420. memcpy(gmac, sta->addr, ETH_ALEN);
  421. gmac[0] |= 0x01;
  422. mac = gmac;
  423. idx = ath_reserve_key_cache_slot(common, key->cipher);
  424. break;
  425. default:
  426. idx = key->keyidx;
  427. break;
  428. }
  429. } else if (key->keyidx) {
  430. if (WARN_ON(!sta))
  431. return -EOPNOTSUPP;
  432. mac = sta->addr;
  433. if (vif->type != NL80211_IFTYPE_AP) {
  434. /* Only keyidx 0 should be used with unicast key, but
  435. * allow this for client mode for now. */
  436. idx = key->keyidx;
  437. } else
  438. return -EIO;
  439. } else {
  440. if (WARN_ON(!sta))
  441. return -EOPNOTSUPP;
  442. mac = sta->addr;
  443. idx = ath_reserve_key_cache_slot(common, key->cipher);
  444. }
  445. if (idx < 0)
  446. return -ENOSPC; /* no free key cache entries */
  447. if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
  448. ret = ath_setkey_tkip(common, idx, key->key, &hk, mac,
  449. vif->type == NL80211_IFTYPE_AP);
  450. else
  451. ret = ath_hw_set_keycache_entry(common, idx, &hk, mac);
  452. if (!ret)
  453. return -EIO;
  454. set_bit(idx, common->keymap);
  455. if (key->cipher == WLAN_CIPHER_SUITE_TKIP) {
  456. set_bit(idx + 64, common->keymap);
  457. set_bit(idx, common->tkip_keymap);
  458. set_bit(idx + 64, common->tkip_keymap);
  459. if (!(common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED)) {
  460. set_bit(idx + 32, common->keymap);
  461. set_bit(idx + 64 + 32, common->keymap);
  462. set_bit(idx + 32, common->tkip_keymap);
  463. set_bit(idx + 64 + 32, common->tkip_keymap);
  464. }
  465. }
  466. return idx;
  467. }
  468. EXPORT_SYMBOL(ath_key_config);
  469. /*
  470. * Delete Key.
  471. */
  472. void ath_key_delete(struct ath_common *common, struct ieee80211_key_conf *key)
  473. {
  474. ath_hw_keyreset(common, key->hw_key_idx);
  475. if (key->hw_key_idx < IEEE80211_WEP_NKID)
  476. return;
  477. clear_bit(key->hw_key_idx, common->keymap);
  478. if (key->cipher != WLAN_CIPHER_SUITE_TKIP)
  479. return;
  480. clear_bit(key->hw_key_idx + 64, common->keymap);
  481. clear_bit(key->hw_key_idx, common->tkip_keymap);
  482. clear_bit(key->hw_key_idx + 64, common->tkip_keymap);
  483. if (!(common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED)) {
  484. ath_hw_keyreset(common, key->hw_key_idx + 32);
  485. clear_bit(key->hw_key_idx + 32, common->keymap);
  486. clear_bit(key->hw_key_idx + 64 + 32, common->keymap);
  487. clear_bit(key->hw_key_idx + 32, common->tkip_keymap);
  488. clear_bit(key->hw_key_idx + 64 + 32, common->tkip_keymap);
  489. }
  490. }
  491. EXPORT_SYMBOL(ath_key_delete);