wpa.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. /*
  2. * Copyright 2002-2004, Instant802 Networks, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/netdevice.h>
  9. #include <linux/types.h>
  10. #include <linux/slab.h>
  11. #include <linux/skbuff.h>
  12. #include <linux/compiler.h>
  13. #include <net/mac80211.h>
  14. #include "ieee80211_i.h"
  15. #include "michael.h"
  16. #include "tkip.h"
  17. #include "aes_ccm.h"
  18. #include "wpa.h"
  19. static int ieee80211_get_hdr_info(const struct sk_buff *skb, u8 **sa, u8 **da,
  20. u8 *qos_tid, u8 **data, size_t *data_len)
  21. {
  22. struct ieee80211_hdr *hdr;
  23. size_t hdrlen;
  24. u16 fc;
  25. int a4_included;
  26. u8 *pos;
  27. hdr = (struct ieee80211_hdr *) skb->data;
  28. fc = le16_to_cpu(hdr->frame_control);
  29. hdrlen = 24;
  30. if ((fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) ==
  31. (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
  32. hdrlen += ETH_ALEN;
  33. *sa = hdr->addr4;
  34. *da = hdr->addr3;
  35. } else if (fc & IEEE80211_FCTL_FROMDS) {
  36. *sa = hdr->addr3;
  37. *da = hdr->addr1;
  38. } else if (fc & IEEE80211_FCTL_TODS) {
  39. *sa = hdr->addr2;
  40. *da = hdr->addr3;
  41. } else {
  42. *sa = hdr->addr2;
  43. *da = hdr->addr1;
  44. }
  45. if (fc & 0x80)
  46. hdrlen += 2;
  47. *data = skb->data + hdrlen;
  48. *data_len = skb->len - hdrlen;
  49. a4_included = (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  50. (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS);
  51. if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
  52. fc & IEEE80211_STYPE_QOS_DATA) {
  53. pos = (u8 *) &hdr->addr4;
  54. if (a4_included)
  55. pos += 6;
  56. *qos_tid = pos[0] & 0x0f;
  57. *qos_tid |= 0x80; /* qos_included flag */
  58. } else
  59. *qos_tid = 0;
  60. return skb->len < hdrlen ? -1 : 0;
  61. }
  62. ieee80211_tx_result
  63. ieee80211_tx_h_michael_mic_add(struct ieee80211_tx_data *tx)
  64. {
  65. u8 *data, *sa, *da, *key, *mic, qos_tid;
  66. size_t data_len;
  67. u16 fc;
  68. struct sk_buff *skb = tx->skb;
  69. int authenticator;
  70. int wpa_test = 0;
  71. fc = tx->fc;
  72. if (!tx->key || tx->key->conf.alg != ALG_TKIP || skb->len < 24 ||
  73. !WLAN_FC_DATA_PRESENT(fc))
  74. return TX_CONTINUE;
  75. if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len))
  76. return TX_DROP;
  77. if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) &&
  78. !(tx->flags & IEEE80211_TX_FRAGMENTED) &&
  79. !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) &&
  80. !wpa_test) {
  81. /* hwaccel - with no need for preallocated room for Michael MIC
  82. */
  83. return TX_CONTINUE;
  84. }
  85. if (skb_tailroom(skb) < MICHAEL_MIC_LEN) {
  86. I802_DEBUG_INC(tx->local->tx_expand_skb_head);
  87. if (unlikely(pskb_expand_head(skb, TKIP_IV_LEN,
  88. MICHAEL_MIC_LEN + TKIP_ICV_LEN,
  89. GFP_ATOMIC))) {
  90. printk(KERN_DEBUG "%s: failed to allocate more memory "
  91. "for Michael MIC\n", tx->dev->name);
  92. return TX_DROP;
  93. }
  94. }
  95. #if 0
  96. authenticator = fc & IEEE80211_FCTL_FROMDS; /* FIX */
  97. #else
  98. authenticator = 1;
  99. #endif
  100. key = &tx->key->conf.key[authenticator ? ALG_TKIP_TEMP_AUTH_TX_MIC_KEY :
  101. ALG_TKIP_TEMP_AUTH_RX_MIC_KEY];
  102. mic = skb_put(skb, MICHAEL_MIC_LEN);
  103. michael_mic(key, da, sa, qos_tid & 0x0f, data, data_len, mic);
  104. return TX_CONTINUE;
  105. }
  106. ieee80211_rx_result
  107. ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx)
  108. {
  109. u8 *data, *sa, *da, *key = NULL, qos_tid;
  110. size_t data_len;
  111. u16 fc;
  112. u8 mic[MICHAEL_MIC_LEN];
  113. struct sk_buff *skb = rx->skb;
  114. int authenticator = 1, wpa_test = 0;
  115. DECLARE_MAC_BUF(mac);
  116. fc = rx->fc;
  117. /*
  118. * No way to verify the MIC if the hardware stripped it
  119. */
  120. if (rx->status->flag & RX_FLAG_MMIC_STRIPPED)
  121. return RX_CONTINUE;
  122. if (!rx->key || rx->key->conf.alg != ALG_TKIP ||
  123. !(rx->fc & IEEE80211_FCTL_PROTECTED) || !WLAN_FC_DATA_PRESENT(fc))
  124. return RX_CONTINUE;
  125. if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len)
  126. || data_len < MICHAEL_MIC_LEN)
  127. return RX_DROP_UNUSABLE;
  128. data_len -= MICHAEL_MIC_LEN;
  129. #if 0
  130. authenticator = fc & IEEE80211_FCTL_TODS; /* FIX */
  131. #else
  132. authenticator = 1;
  133. #endif
  134. key = &rx->key->conf.key[authenticator ? ALG_TKIP_TEMP_AUTH_RX_MIC_KEY :
  135. ALG_TKIP_TEMP_AUTH_TX_MIC_KEY];
  136. michael_mic(key, da, sa, qos_tid & 0x0f, data, data_len, mic);
  137. if (memcmp(mic, data + data_len, MICHAEL_MIC_LEN) != 0 || wpa_test) {
  138. if (!(rx->flags & IEEE80211_RX_RA_MATCH))
  139. return RX_DROP_UNUSABLE;
  140. printk(KERN_DEBUG "%s: invalid Michael MIC in data frame from "
  141. "%s\n", rx->dev->name, print_mac(mac, sa));
  142. mac80211_ev_michael_mic_failure(rx->dev, rx->key->conf.keyidx,
  143. (void *) skb->data);
  144. return RX_DROP_UNUSABLE;
  145. }
  146. /* remove Michael MIC from payload */
  147. skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
  148. /* update IV in key information to be able to detect replays */
  149. rx->key->u.tkip.iv32_rx[rx->queue] = rx->tkip_iv32;
  150. rx->key->u.tkip.iv16_rx[rx->queue] = rx->tkip_iv16;
  151. return RX_CONTINUE;
  152. }
  153. static int tkip_encrypt_skb(struct ieee80211_tx_data *tx,
  154. struct sk_buff *skb, int test)
  155. {
  156. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  157. struct ieee80211_key *key = tx->key;
  158. int hdrlen, len, tailneed;
  159. u16 fc;
  160. u8 *pos;
  161. fc = le16_to_cpu(hdr->frame_control);
  162. hdrlen = ieee80211_get_hdrlen(fc);
  163. len = skb->len - hdrlen;
  164. if (tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
  165. tailneed = 0;
  166. else
  167. tailneed = TKIP_ICV_LEN;
  168. if ((skb_headroom(skb) < TKIP_IV_LEN ||
  169. skb_tailroom(skb) < tailneed)) {
  170. I802_DEBUG_INC(tx->local->tx_expand_skb_head);
  171. if (unlikely(pskb_expand_head(skb, TKIP_IV_LEN, tailneed,
  172. GFP_ATOMIC)))
  173. return -1;
  174. }
  175. pos = skb_push(skb, TKIP_IV_LEN);
  176. memmove(pos, pos + TKIP_IV_LEN, hdrlen);
  177. pos += hdrlen;
  178. /* Increase IV for the frame */
  179. key->u.tkip.iv16++;
  180. if (key->u.tkip.iv16 == 0)
  181. key->u.tkip.iv32++;
  182. if (tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) {
  183. hdr = (struct ieee80211_hdr *)skb->data;
  184. /* hwaccel - with preallocated room for IV */
  185. ieee80211_tkip_add_iv(pos, key,
  186. (u8) (key->u.tkip.iv16 >> 8),
  187. (u8) (((key->u.tkip.iv16 >> 8) | 0x20) &
  188. 0x7f),
  189. (u8) key->u.tkip.iv16);
  190. tx->control->key_idx = tx->key->conf.hw_key_idx;
  191. return 0;
  192. }
  193. /* Add room for ICV */
  194. skb_put(skb, TKIP_ICV_LEN);
  195. hdr = (struct ieee80211_hdr *) skb->data;
  196. ieee80211_tkip_encrypt_data(tx->local->wep_tx_tfm,
  197. key, pos, len, hdr->addr2);
  198. return 0;
  199. }
  200. ieee80211_tx_result
  201. ieee80211_crypto_tkip_encrypt(struct ieee80211_tx_data *tx)
  202. {
  203. struct sk_buff *skb = tx->skb;
  204. int wpa_test = 0, test = 0;
  205. tx->control->icv_len = TKIP_ICV_LEN;
  206. tx->control->iv_len = TKIP_IV_LEN;
  207. ieee80211_tx_set_protected(tx);
  208. if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) &&
  209. !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV) &&
  210. !wpa_test) {
  211. /* hwaccel - with no need for preallocated room for IV/ICV */
  212. tx->control->key_idx = tx->key->conf.hw_key_idx;
  213. return TX_CONTINUE;
  214. }
  215. if (tkip_encrypt_skb(tx, skb, test) < 0)
  216. return TX_DROP;
  217. if (tx->extra_frag) {
  218. int i;
  219. for (i = 0; i < tx->num_extra_frag; i++) {
  220. if (tkip_encrypt_skb(tx, tx->extra_frag[i], test)
  221. < 0)
  222. return TX_DROP;
  223. }
  224. }
  225. return TX_CONTINUE;
  226. }
  227. ieee80211_rx_result
  228. ieee80211_crypto_tkip_decrypt(struct ieee80211_rx_data *rx)
  229. {
  230. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
  231. u16 fc;
  232. int hdrlen, res, hwaccel = 0, wpa_test = 0;
  233. struct ieee80211_key *key = rx->key;
  234. struct sk_buff *skb = rx->skb;
  235. DECLARE_MAC_BUF(mac);
  236. fc = le16_to_cpu(hdr->frame_control);
  237. hdrlen = ieee80211_get_hdrlen(fc);
  238. if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
  239. return RX_CONTINUE;
  240. if (!rx->sta || skb->len - hdrlen < 12)
  241. return RX_DROP_UNUSABLE;
  242. if (rx->status->flag & RX_FLAG_DECRYPTED) {
  243. if (rx->status->flag & RX_FLAG_IV_STRIPPED) {
  244. /*
  245. * Hardware took care of all processing, including
  246. * replay protection, and stripped the ICV/IV so
  247. * we cannot do any checks here.
  248. */
  249. return RX_CONTINUE;
  250. }
  251. /* let TKIP code verify IV, but skip decryption */
  252. hwaccel = 1;
  253. }
  254. res = ieee80211_tkip_decrypt_data(rx->local->wep_rx_tfm,
  255. key, skb->data + hdrlen,
  256. skb->len - hdrlen, rx->sta->addr,
  257. hdr->addr1, hwaccel, rx->queue,
  258. &rx->tkip_iv32,
  259. &rx->tkip_iv16);
  260. if (res != TKIP_DECRYPT_OK || wpa_test) {
  261. #ifdef CONFIG_MAC80211_DEBUG
  262. if (net_ratelimit())
  263. printk(KERN_DEBUG "%s: TKIP decrypt failed for RX "
  264. "frame from %s (res=%d)\n", rx->dev->name,
  265. print_mac(mac, rx->sta->addr), res);
  266. #endif /* CONFIG_MAC80211_DEBUG */
  267. return RX_DROP_UNUSABLE;
  268. }
  269. /* Trim ICV */
  270. skb_trim(skb, skb->len - TKIP_ICV_LEN);
  271. /* Remove IV */
  272. memmove(skb->data + TKIP_IV_LEN, skb->data, hdrlen);
  273. skb_pull(skb, TKIP_IV_LEN);
  274. return RX_CONTINUE;
  275. }
  276. static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad,
  277. int encrypted)
  278. {
  279. u16 fc;
  280. int a4_included, qos_included;
  281. u8 qos_tid, *fc_pos, *data, *sa, *da;
  282. int len_a;
  283. size_t data_len;
  284. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  285. fc_pos = (u8 *) &hdr->frame_control;
  286. fc = fc_pos[0] ^ (fc_pos[1] << 8);
  287. a4_included = (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  288. (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS);
  289. ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len);
  290. data_len -= CCMP_HDR_LEN + (encrypted ? CCMP_MIC_LEN : 0);
  291. if (qos_tid & 0x80) {
  292. qos_included = 1;
  293. qos_tid &= 0x0f;
  294. } else
  295. qos_included = 0;
  296. /* First block, b_0 */
  297. b_0[0] = 0x59; /* flags: Adata: 1, M: 011, L: 001 */
  298. /* Nonce: QoS Priority | A2 | PN */
  299. b_0[1] = qos_tid;
  300. memcpy(&b_0[2], hdr->addr2, 6);
  301. memcpy(&b_0[8], pn, CCMP_PN_LEN);
  302. /* l(m) */
  303. b_0[14] = (data_len >> 8) & 0xff;
  304. b_0[15] = data_len & 0xff;
  305. /* AAD (extra authenticate-only data) / masked 802.11 header
  306. * FC | A1 | A2 | A3 | SC | [A4] | [QC] */
  307. len_a = a4_included ? 28 : 22;
  308. if (qos_included)
  309. len_a += 2;
  310. aad[0] = 0; /* (len_a >> 8) & 0xff; */
  311. aad[1] = len_a & 0xff;
  312. /* Mask FC: zero subtype b4 b5 b6 */
  313. aad[2] = fc_pos[0] & ~(BIT(4) | BIT(5) | BIT(6));
  314. /* Retry, PwrMgt, MoreData; set Protected */
  315. aad[3] = (fc_pos[1] & ~(BIT(3) | BIT(4) | BIT(5))) | BIT(6);
  316. memcpy(&aad[4], &hdr->addr1, 18);
  317. /* Mask Seq#, leave Frag# */
  318. aad[22] = *((u8 *) &hdr->seq_ctrl) & 0x0f;
  319. aad[23] = 0;
  320. if (a4_included) {
  321. memcpy(&aad[24], hdr->addr4, 6);
  322. aad[30] = 0;
  323. aad[31] = 0;
  324. } else
  325. memset(&aad[24], 0, 8);
  326. if (qos_included) {
  327. u8 *dpos = &aad[a4_included ? 30 : 24];
  328. /* Mask QoS Control field */
  329. dpos[0] = qos_tid;
  330. dpos[1] = 0;
  331. }
  332. }
  333. static inline void ccmp_pn2hdr(u8 *hdr, u8 *pn, int key_id)
  334. {
  335. hdr[0] = pn[5];
  336. hdr[1] = pn[4];
  337. hdr[2] = 0;
  338. hdr[3] = 0x20 | (key_id << 6);
  339. hdr[4] = pn[3];
  340. hdr[5] = pn[2];
  341. hdr[6] = pn[1];
  342. hdr[7] = pn[0];
  343. }
  344. static inline int ccmp_hdr2pn(u8 *pn, u8 *hdr)
  345. {
  346. pn[0] = hdr[7];
  347. pn[1] = hdr[6];
  348. pn[2] = hdr[5];
  349. pn[3] = hdr[4];
  350. pn[4] = hdr[1];
  351. pn[5] = hdr[0];
  352. return (hdr[3] >> 6) & 0x03;
  353. }
  354. static int ccmp_encrypt_skb(struct ieee80211_tx_data *tx,
  355. struct sk_buff *skb, int test)
  356. {
  357. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  358. struct ieee80211_key *key = tx->key;
  359. int hdrlen, len, tailneed;
  360. u16 fc;
  361. u8 *pos, *pn, *b_0, *aad, *scratch;
  362. int i;
  363. scratch = key->u.ccmp.tx_crypto_buf;
  364. b_0 = scratch + 3 * AES_BLOCK_LEN;
  365. aad = scratch + 4 * AES_BLOCK_LEN;
  366. fc = le16_to_cpu(hdr->frame_control);
  367. hdrlen = ieee80211_get_hdrlen(fc);
  368. len = skb->len - hdrlen;
  369. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
  370. tailneed = 0;
  371. else
  372. tailneed = CCMP_MIC_LEN;
  373. if ((skb_headroom(skb) < CCMP_HDR_LEN ||
  374. skb_tailroom(skb) < tailneed)) {
  375. I802_DEBUG_INC(tx->local->tx_expand_skb_head);
  376. if (unlikely(pskb_expand_head(skb, CCMP_HDR_LEN, tailneed,
  377. GFP_ATOMIC)))
  378. return -1;
  379. }
  380. pos = skb_push(skb, CCMP_HDR_LEN);
  381. memmove(pos, pos + CCMP_HDR_LEN, hdrlen);
  382. hdr = (struct ieee80211_hdr *) pos;
  383. pos += hdrlen;
  384. /* PN = PN + 1 */
  385. pn = key->u.ccmp.tx_pn;
  386. for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
  387. pn[i]++;
  388. if (pn[i])
  389. break;
  390. }
  391. ccmp_pn2hdr(pos, pn, key->conf.keyidx);
  392. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) {
  393. /* hwaccel - with preallocated room for CCMP header */
  394. tx->control->key_idx = key->conf.hw_key_idx;
  395. return 0;
  396. }
  397. pos += CCMP_HDR_LEN;
  398. ccmp_special_blocks(skb, pn, b_0, aad, 0);
  399. ieee80211_aes_ccm_encrypt(key->u.ccmp.tfm, scratch, b_0, aad, pos, len,
  400. pos, skb_put(skb, CCMP_MIC_LEN));
  401. return 0;
  402. }
  403. ieee80211_tx_result
  404. ieee80211_crypto_ccmp_encrypt(struct ieee80211_tx_data *tx)
  405. {
  406. struct sk_buff *skb = tx->skb;
  407. int test = 0;
  408. tx->control->icv_len = CCMP_MIC_LEN;
  409. tx->control->iv_len = CCMP_HDR_LEN;
  410. ieee80211_tx_set_protected(tx);
  411. if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) &&
  412. !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
  413. /* hwaccel - with no need for preallocated room for CCMP "
  414. * header or MIC fields */
  415. tx->control->key_idx = tx->key->conf.hw_key_idx;
  416. return TX_CONTINUE;
  417. }
  418. if (ccmp_encrypt_skb(tx, skb, test) < 0)
  419. return TX_DROP;
  420. if (tx->extra_frag) {
  421. int i;
  422. for (i = 0; i < tx->num_extra_frag; i++) {
  423. if (ccmp_encrypt_skb(tx, tx->extra_frag[i], test)
  424. < 0)
  425. return TX_DROP;
  426. }
  427. }
  428. return TX_CONTINUE;
  429. }
  430. ieee80211_rx_result
  431. ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx)
  432. {
  433. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
  434. u16 fc;
  435. int hdrlen;
  436. struct ieee80211_key *key = rx->key;
  437. struct sk_buff *skb = rx->skb;
  438. u8 pn[CCMP_PN_LEN];
  439. int data_len;
  440. DECLARE_MAC_BUF(mac);
  441. fc = le16_to_cpu(hdr->frame_control);
  442. hdrlen = ieee80211_get_hdrlen(fc);
  443. if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
  444. return RX_CONTINUE;
  445. data_len = skb->len - hdrlen - CCMP_HDR_LEN - CCMP_MIC_LEN;
  446. if (!rx->sta || data_len < 0)
  447. return RX_DROP_UNUSABLE;
  448. if ((rx->status->flag & RX_FLAG_DECRYPTED) &&
  449. (rx->status->flag & RX_FLAG_IV_STRIPPED))
  450. return RX_CONTINUE;
  451. (void) ccmp_hdr2pn(pn, skb->data + hdrlen);
  452. if (memcmp(pn, key->u.ccmp.rx_pn[rx->queue], CCMP_PN_LEN) <= 0) {
  453. #ifdef CONFIG_MAC80211_DEBUG
  454. u8 *ppn = key->u.ccmp.rx_pn[rx->queue];
  455. printk(KERN_DEBUG "%s: CCMP replay detected for RX frame from "
  456. "%s (RX PN %02x%02x%02x%02x%02x%02x <= prev. PN "
  457. "%02x%02x%02x%02x%02x%02x)\n", rx->dev->name,
  458. print_mac(mac, rx->sta->addr),
  459. pn[0], pn[1], pn[2], pn[3], pn[4], pn[5],
  460. ppn[0], ppn[1], ppn[2], ppn[3], ppn[4], ppn[5]);
  461. #endif /* CONFIG_MAC80211_DEBUG */
  462. key->u.ccmp.replays++;
  463. return RX_DROP_UNUSABLE;
  464. }
  465. if (!(rx->status->flag & RX_FLAG_DECRYPTED)) {
  466. /* hardware didn't decrypt/verify MIC */
  467. u8 *scratch, *b_0, *aad;
  468. scratch = key->u.ccmp.rx_crypto_buf;
  469. b_0 = scratch + 3 * AES_BLOCK_LEN;
  470. aad = scratch + 4 * AES_BLOCK_LEN;
  471. ccmp_special_blocks(skb, pn, b_0, aad, 1);
  472. if (ieee80211_aes_ccm_decrypt(
  473. key->u.ccmp.tfm, scratch, b_0, aad,
  474. skb->data + hdrlen + CCMP_HDR_LEN, data_len,
  475. skb->data + skb->len - CCMP_MIC_LEN,
  476. skb->data + hdrlen + CCMP_HDR_LEN)) {
  477. #ifdef CONFIG_MAC80211_DEBUG
  478. if (net_ratelimit())
  479. printk(KERN_DEBUG "%s: CCMP decrypt failed "
  480. "for RX frame from %s\n", rx->dev->name,
  481. print_mac(mac, rx->sta->addr));
  482. #endif /* CONFIG_MAC80211_DEBUG */
  483. return RX_DROP_UNUSABLE;
  484. }
  485. }
  486. memcpy(key->u.ccmp.rx_pn[rx->queue], pn, CCMP_PN_LEN);
  487. /* Remove CCMP header and MIC */
  488. skb_trim(skb, skb->len - CCMP_MIC_LEN);
  489. memmove(skb->data + CCMP_HDR_LEN, skb->data, hdrlen);
  490. skb_pull(skb, CCMP_HDR_LEN);
  491. return RX_CONTINUE;
  492. }