522-ath9k_remove_duplicate_code.patch 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. --- a/drivers/net/wireless/ath/ath9k/main.c
  2. +++ b/drivers/net/wireless/ath/ath9k/main.c
  3. @@ -622,234 +622,6 @@ static u32 ath_get_extchanmode(struct at
  4. return chanmode;
  5. }
  6. -static int ath_setkey_tkip(struct ath_common *common, u16 keyix, const u8 *key,
  7. - struct ath9k_keyval *hk, const u8 *addr,
  8. - bool authenticator)
  9. -{
  10. - struct ath_hw *ah = common->ah;
  11. - const u8 *key_rxmic;
  12. - const u8 *key_txmic;
  13. -
  14. - key_txmic = key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
  15. - key_rxmic = key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
  16. -
  17. - if (addr == NULL) {
  18. - /*
  19. - * Group key installation - only two key cache entries are used
  20. - * regardless of splitmic capability since group key is only
  21. - * used either for TX or RX.
  22. - */
  23. - if (authenticator) {
  24. - memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
  25. - memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_mic));
  26. - } else {
  27. - memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
  28. - memcpy(hk->kv_txmic, key_rxmic, sizeof(hk->kv_mic));
  29. - }
  30. - return ath9k_hw_set_keycache_entry(ah, keyix, hk, addr);
  31. - }
  32. - if (!common->splitmic) {
  33. - /* TX and RX keys share the same key cache entry. */
  34. - memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
  35. - memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
  36. - return ath9k_hw_set_keycache_entry(ah, keyix, hk, addr);
  37. - }
  38. -
  39. - /* Separate key cache entries for TX and RX */
  40. -
  41. - /* TX key goes at first index, RX key at +32. */
  42. - memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
  43. - if (!ath9k_hw_set_keycache_entry(ah, keyix, hk, NULL)) {
  44. - /* TX MIC entry failed. No need to proceed further */
  45. - ath_print(common, ATH_DBG_FATAL,
  46. - "Setting TX MIC Key Failed\n");
  47. - return 0;
  48. - }
  49. -
  50. - memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
  51. - /* XXX delete tx key on failure? */
  52. - return ath9k_hw_set_keycache_entry(ah, keyix + 32, hk, addr);
  53. -}
  54. -
  55. -static int ath_reserve_key_cache_slot_tkip(struct ath_common *common)
  56. -{
  57. - int i;
  58. -
  59. - for (i = IEEE80211_WEP_NKID; i < common->keymax / 2; i++) {
  60. - if (test_bit(i, common->keymap) ||
  61. - test_bit(i + 64, common->keymap))
  62. - continue; /* At least one part of TKIP key allocated */
  63. - if (common->splitmic &&
  64. - (test_bit(i + 32, common->keymap) ||
  65. - test_bit(i + 64 + 32, common->keymap)))
  66. - continue; /* At least one part of TKIP key allocated */
  67. -
  68. - /* Found a free slot for a TKIP key */
  69. - return i;
  70. - }
  71. - return -1;
  72. -}
  73. -
  74. -static int ath_reserve_key_cache_slot(struct ath_common *common)
  75. -{
  76. - int i;
  77. -
  78. - /* First, try to find slots that would not be available for TKIP. */
  79. - if (common->splitmic) {
  80. - for (i = IEEE80211_WEP_NKID; i < common->keymax / 4; i++) {
  81. - if (!test_bit(i, common->keymap) &&
  82. - (test_bit(i + 32, common->keymap) ||
  83. - test_bit(i + 64, common->keymap) ||
  84. - test_bit(i + 64 + 32, common->keymap)))
  85. - return i;
  86. - if (!test_bit(i + 32, common->keymap) &&
  87. - (test_bit(i, common->keymap) ||
  88. - test_bit(i + 64, common->keymap) ||
  89. - test_bit(i + 64 + 32, common->keymap)))
  90. - return i + 32;
  91. - if (!test_bit(i + 64, common->keymap) &&
  92. - (test_bit(i , common->keymap) ||
  93. - test_bit(i + 32, common->keymap) ||
  94. - test_bit(i + 64 + 32, common->keymap)))
  95. - return i + 64;
  96. - if (!test_bit(i + 64 + 32, common->keymap) &&
  97. - (test_bit(i, common->keymap) ||
  98. - test_bit(i + 32, common->keymap) ||
  99. - test_bit(i + 64, common->keymap)))
  100. - return i + 64 + 32;
  101. - }
  102. - } else {
  103. - for (i = IEEE80211_WEP_NKID; i < common->keymax / 2; i++) {
  104. - if (!test_bit(i, common->keymap) &&
  105. - test_bit(i + 64, common->keymap))
  106. - return i;
  107. - if (test_bit(i, common->keymap) &&
  108. - !test_bit(i + 64, common->keymap))
  109. - return i + 64;
  110. - }
  111. - }
  112. -
  113. - /* No partially used TKIP slots, pick any available slot */
  114. - for (i = IEEE80211_WEP_NKID; i < common->keymax; i++) {
  115. - /* Do not allow slots that could be needed for TKIP group keys
  116. - * to be used. This limitation could be removed if we know that
  117. - * TKIP will not be used. */
  118. - if (i >= 64 && i < 64 + IEEE80211_WEP_NKID)
  119. - continue;
  120. - if (common->splitmic) {
  121. - if (i >= 32 && i < 32 + IEEE80211_WEP_NKID)
  122. - continue;
  123. - if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID)
  124. - continue;
  125. - }
  126. -
  127. - if (!test_bit(i, common->keymap))
  128. - return i; /* Found a free slot for a key */
  129. - }
  130. -
  131. - /* No free slot found */
  132. - return -1;
  133. -}
  134. -
  135. -static int ath_key_config(struct ath_common *common,
  136. - struct ieee80211_vif *vif,
  137. - struct ieee80211_sta *sta,
  138. - struct ieee80211_key_conf *key)
  139. -{
  140. - struct ath_hw *ah = common->ah;
  141. - struct ath9k_keyval hk;
  142. - const u8 *mac = NULL;
  143. - int ret = 0;
  144. - int idx;
  145. -
  146. - memset(&hk, 0, sizeof(hk));
  147. -
  148. - switch (key->alg) {
  149. - case ALG_WEP:
  150. - hk.kv_type = ATH9K_CIPHER_WEP;
  151. - break;
  152. - case ALG_TKIP:
  153. - hk.kv_type = ATH9K_CIPHER_TKIP;
  154. - break;
  155. - case ALG_CCMP:
  156. - hk.kv_type = ATH9K_CIPHER_AES_CCM;
  157. - break;
  158. - default:
  159. - return -EOPNOTSUPP;
  160. - }
  161. -
  162. - hk.kv_len = key->keylen;
  163. - memcpy(hk.kv_val, key->key, key->keylen);
  164. -
  165. - if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
  166. - /* For now, use the default keys for broadcast keys. This may
  167. - * need to change with virtual interfaces. */
  168. - idx = key->keyidx;
  169. - } else if (key->keyidx) {
  170. - if (WARN_ON(!sta))
  171. - return -EOPNOTSUPP;
  172. - mac = sta->addr;
  173. -
  174. - if (vif->type != NL80211_IFTYPE_AP) {
  175. - /* Only keyidx 0 should be used with unicast key, but
  176. - * allow this for client mode for now. */
  177. - idx = key->keyidx;
  178. - } else
  179. - return -EIO;
  180. - } else {
  181. - if (WARN_ON(!sta))
  182. - return -EOPNOTSUPP;
  183. - mac = sta->addr;
  184. -
  185. - if (key->alg == ALG_TKIP)
  186. - idx = ath_reserve_key_cache_slot_tkip(common);
  187. - else
  188. - idx = ath_reserve_key_cache_slot(common);
  189. - if (idx < 0)
  190. - return -ENOSPC; /* no free key cache entries */
  191. - }
  192. -
  193. - if (key->alg == ALG_TKIP)
  194. - ret = ath_setkey_tkip(common, idx, key->key, &hk, mac,
  195. - vif->type == NL80211_IFTYPE_AP);
  196. - else
  197. - ret = ath9k_hw_set_keycache_entry(ah, idx, &hk, mac);
  198. -
  199. - if (!ret)
  200. - return -EIO;
  201. -
  202. - set_bit(idx, common->keymap);
  203. - if (key->alg == ALG_TKIP) {
  204. - set_bit(idx + 64, common->keymap);
  205. - if (common->splitmic) {
  206. - set_bit(idx + 32, common->keymap);
  207. - set_bit(idx + 64 + 32, common->keymap);
  208. - }
  209. - }
  210. -
  211. - return idx;
  212. -}
  213. -
  214. -static void ath_key_delete(struct ath_common *common, struct ieee80211_key_conf *key)
  215. -{
  216. - struct ath_hw *ah = common->ah;
  217. -
  218. - ath9k_hw_keyreset(ah, key->hw_key_idx);
  219. - if (key->hw_key_idx < IEEE80211_WEP_NKID)
  220. - return;
  221. -
  222. - clear_bit(key->hw_key_idx, common->keymap);
  223. - if (key->alg != ALG_TKIP)
  224. - return;
  225. -
  226. - clear_bit(key->hw_key_idx + 64, common->keymap);
  227. - if (common->splitmic) {
  228. - ath9k_hw_keyreset(ah, key->hw_key_idx + 32);
  229. - clear_bit(key->hw_key_idx + 32, common->keymap);
  230. - clear_bit(key->hw_key_idx + 64 + 32, common->keymap);
  231. - }
  232. -}
  233. -
  234. static void ath9k_bss_assoc_info(struct ath_softc *sc,
  235. struct ieee80211_vif *vif,
  236. struct ieee80211_bss_conf *bss_conf)
  237. @@ -1814,7 +1586,7 @@ static int ath9k_set_key(struct ieee8021
  238. switch (cmd) {
  239. case SET_KEY:
  240. - ret = ath_key_config(common, vif, sta, key);
  241. + ret = ath9k_cmn_key_config(common, vif, sta, key);
  242. if (ret >= 0) {
  243. key->hw_key_idx = ret;
  244. /* push IV and Michael MIC generation to stack */
  245. @@ -1827,7 +1599,7 @@ static int ath9k_set_key(struct ieee8021
  246. }
  247. break;
  248. case DISABLE_KEY:
  249. - ath_key_delete(common, key);
  250. + ath9k_cmn_key_delete(common, key);
  251. break;
  252. default:
  253. ret = -EINVAL;