key.c 16 KB

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