Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 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 | |
| 9 | #include <linux/netdevice.h> |
| 10 | #include <linux/types.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <linux/skbuff.h> |
| 13 | #include <linux/compiler.h> |
Harvey Harrison | f14df80 | 2008-07-02 11:05:35 -0700 | [diff] [blame^] | 14 | #include <linux/ieee80211.h> |
| 15 | #include <asm/unaligned.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 16 | #include <net/mac80211.h> |
Johannes Berg | eb063c1 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 17 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 18 | #include "ieee80211_i.h" |
| 19 | #include "michael.h" |
| 20 | #include "tkip.h" |
| 21 | #include "aes_ccm.h" |
| 22 | #include "wpa.h" |
| 23 | |
| 24 | static int ieee80211_get_hdr_info(const struct sk_buff *skb, u8 **sa, u8 **da, |
| 25 | u8 *qos_tid, u8 **data, size_t *data_len) |
| 26 | { |
| 27 | struct ieee80211_hdr *hdr; |
| 28 | size_t hdrlen; |
Harvey Harrison | d5184ca | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 29 | __le16 fc; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 30 | |
Harvey Harrison | d5184ca | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 31 | hdr = (struct ieee80211_hdr *)skb->data; |
| 32 | fc = hdr->frame_control; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 33 | |
Harvey Harrison | d5184ca | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 34 | hdrlen = ieee80211_hdrlen(fc); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 35 | |
Harvey Harrison | d5184ca | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 36 | *sa = ieee80211_get_SA(hdr); |
| 37 | *da = ieee80211_get_DA(hdr); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 38 | |
| 39 | *data = skb->data + hdrlen; |
| 40 | *data_len = skb->len - hdrlen; |
| 41 | |
Harvey Harrison | d5184ca | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 42 | if (ieee80211_is_data_qos(fc)) |
Harvey Harrison | 73e1f7c | 2008-07-02 11:05:34 -0700 | [diff] [blame] | 43 | *qos_tid = (*ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK) | 0x80; |
Harvey Harrison | d5184ca | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 44 | else |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 45 | *qos_tid = 0; |
| 46 | |
| 47 | return skb->len < hdrlen ? -1 : 0; |
| 48 | } |
| 49 | |
| 50 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 51 | ieee80211_tx_result |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 52 | ieee80211_tx_h_michael_mic_add(struct ieee80211_tx_data *tx) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 53 | { |
Luis R. Rodriguez | ffd7891 | 2008-06-21 10:02:46 -0400 | [diff] [blame] | 54 | u8 *data, *sa, *da, *key, *mic, qos_tid, key_offset; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 55 | size_t data_len; |
| 56 | u16 fc; |
| 57 | struct sk_buff *skb = tx->skb; |
| 58 | int authenticator; |
| 59 | int wpa_test = 0; |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 60 | int tail; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 61 | |
| 62 | fc = tx->fc; |
| 63 | |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 64 | if (!tx->key || tx->key->conf.alg != ALG_TKIP || skb->len < 24 || |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 65 | !WLAN_FC_DATA_PRESENT(fc)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 66 | return TX_CONTINUE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 67 | |
| 68 | if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 69 | return TX_DROP; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 70 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 71 | if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) && |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 72 | !(tx->flags & IEEE80211_TX_FRAGMENTED) && |
Johannes Berg | 7848ba7 | 2007-09-14 11:10:25 -0400 | [diff] [blame] | 73 | !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) && |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 74 | !wpa_test) { |
| 75 | /* hwaccel - with no need for preallocated room for Michael MIC |
| 76 | */ |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 77 | return TX_CONTINUE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 80 | tail = MICHAEL_MIC_LEN; |
| 81 | if (!(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) |
| 82 | tail += TKIP_ICV_LEN; |
| 83 | |
| 84 | if (WARN_ON(skb_tailroom(skb) < tail || |
| 85 | skb_headroom(skb) < TKIP_IV_LEN)) |
| 86 | return TX_DROP; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 87 | |
| 88 | #if 0 |
| 89 | authenticator = fc & IEEE80211_FCTL_FROMDS; /* FIX */ |
| 90 | #else |
| 91 | authenticator = 1; |
| 92 | #endif |
Luis R. Rodriguez | ffd7891 | 2008-06-21 10:02:46 -0400 | [diff] [blame] | 93 | /* At this point we know we're using ALG_TKIP. To get the MIC key |
| 94 | * we now will rely on the offset from the ieee80211_key_conf::key */ |
| 95 | key_offset = authenticator ? |
| 96 | NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY : |
| 97 | NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY; |
| 98 | key = &tx->key->conf.key[key_offset]; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 99 | mic = skb_put(skb, MICHAEL_MIC_LEN); |
| 100 | michael_mic(key, da, sa, qos_tid & 0x0f, data, data_len, mic); |
| 101 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 102 | return TX_CONTINUE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 106 | ieee80211_rx_result |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 107 | ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 108 | { |
Luis R. Rodriguez | ffd7891 | 2008-06-21 10:02:46 -0400 | [diff] [blame] | 109 | u8 *data, *sa, *da, *key = NULL, qos_tid, key_offset; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 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; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 115 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 116 | |
| 117 | fc = rx->fc; |
| 118 | |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 119 | /* |
| 120 | * No way to verify the MIC if the hardware stripped it |
| 121 | */ |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 122 | if (rx->status->flag & RX_FLAG_MMIC_STRIPPED) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 123 | return RX_CONTINUE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 124 | |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 125 | if (!rx->key || rx->key->conf.alg != ALG_TKIP || |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 126 | !(rx->fc & IEEE80211_FCTL_PROTECTED) || !WLAN_FC_DATA_PRESENT(fc)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 127 | return RX_CONTINUE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 128 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 129 | if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len) |
| 130 | || data_len < MICHAEL_MIC_LEN) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 131 | return RX_DROP_UNUSABLE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 132 | |
| 133 | data_len -= MICHAEL_MIC_LEN; |
| 134 | |
| 135 | #if 0 |
| 136 | authenticator = fc & IEEE80211_FCTL_TODS; /* FIX */ |
| 137 | #else |
| 138 | authenticator = 1; |
| 139 | #endif |
Luis R. Rodriguez | ffd7891 | 2008-06-21 10:02:46 -0400 | [diff] [blame] | 140 | /* At this point we know we're using ALG_TKIP. To get the MIC key |
| 141 | * we now will rely on the offset from the ieee80211_key_conf::key */ |
| 142 | key_offset = authenticator ? |
| 143 | NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY : |
| 144 | NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY; |
| 145 | key = &rx->key->conf.key[key_offset]; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 146 | michael_mic(key, da, sa, qos_tid & 0x0f, data, data_len, mic); |
| 147 | if (memcmp(mic, data + data_len, MICHAEL_MIC_LEN) != 0 || wpa_test) { |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 148 | if (!(rx->flags & IEEE80211_RX_RA_MATCH)) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 149 | return RX_DROP_UNUSABLE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 150 | |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 151 | mac80211_ev_michael_mic_failure(rx->dev, rx->key->conf.keyidx, |
Johannes Berg | eb063c1 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 152 | (void *) skb->data); |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 153 | return RX_DROP_UNUSABLE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 156 | /* remove Michael MIC from payload */ |
| 157 | skb_trim(skb, skb->len - MICHAEL_MIC_LEN); |
| 158 | |
Johannes Berg | 50741ae | 2007-09-26 15:19:45 +0200 | [diff] [blame] | 159 | /* update IV in key information to be able to detect replays */ |
Harvey Harrison | b0f76b3 | 2008-05-14 16:26:19 -0700 | [diff] [blame] | 160 | rx->key->u.tkip.rx[rx->queue].iv32 = rx->tkip_iv32; |
| 161 | rx->key->u.tkip.rx[rx->queue].iv16 = rx->tkip_iv16; |
Johannes Berg | 50741ae | 2007-09-26 15:19:45 +0200 | [diff] [blame] | 162 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 163 | return RX_CONTINUE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 167 | static int tkip_encrypt_skb(struct ieee80211_tx_data *tx, struct sk_buff *skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 168 | { |
| 169 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 170 | struct ieee80211_key *key = tx->key; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 171 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Harvey Harrison | d5184ca | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 172 | unsigned int hdrlen; |
| 173 | int len, tail; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 174 | u8 *pos; |
| 175 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 176 | info->control.icv_len = TKIP_ICV_LEN; |
| 177 | info->control.iv_len = TKIP_IV_LEN; |
| 178 | |
| 179 | if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) && |
| 180 | !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) { |
| 181 | /* hwaccel - with no need for preallocated room for IV/ICV */ |
| 182 | info->control.hw_key = &tx->key->conf; |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 183 | return 0; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 184 | } |
| 185 | |
Harvey Harrison | d5184ca | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 186 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 187 | len = skb->len - hdrlen; |
| 188 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 189 | if (tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 190 | tail = 0; |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 191 | else |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 192 | tail = TKIP_ICV_LEN; |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 193 | |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 194 | if (WARN_ON(skb_tailroom(skb) < tail || |
| 195 | skb_headroom(skb) < TKIP_IV_LEN)) |
| 196 | return -1; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 197 | |
| 198 | pos = skb_push(skb, TKIP_IV_LEN); |
| 199 | memmove(pos, pos + TKIP_IV_LEN, hdrlen); |
| 200 | pos += hdrlen; |
| 201 | |
| 202 | /* Increase IV for the frame */ |
Harvey Harrison | b0f76b3 | 2008-05-14 16:26:19 -0700 | [diff] [blame] | 203 | key->u.tkip.tx.iv16++; |
| 204 | if (key->u.tkip.tx.iv16 == 0) |
| 205 | key->u.tkip.tx.iv32++; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 206 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 207 | if (tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 208 | /* hwaccel - with preallocated room for IV */ |
Harvey Harrison | c801242 | 2008-06-11 14:22:00 -0700 | [diff] [blame] | 209 | ieee80211_tkip_add_iv(pos, key, key->u.tkip.tx.iv16); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 210 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 211 | info->control.hw_key = &tx->key->conf; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | /* Add room for ICV */ |
| 216 | skb_put(skb, TKIP_ICV_LEN); |
| 217 | |
| 218 | hdr = (struct ieee80211_hdr *) skb->data; |
| 219 | ieee80211_tkip_encrypt_data(tx->local->wep_tx_tfm, |
| 220 | key, pos, len, hdr->addr2); |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 225 | ieee80211_tx_result |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 226 | ieee80211_crypto_tkip_encrypt(struct ieee80211_tx_data *tx) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 227 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 228 | struct sk_buff *skb = tx->skb; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 229 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 230 | ieee80211_tx_set_protected(tx); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 231 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 232 | if (tkip_encrypt_skb(tx, skb) < 0) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 233 | return TX_DROP; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 234 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 235 | if (tx->extra_frag) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 236 | int i; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 237 | for (i = 0; i < tx->num_extra_frag; i++) { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 238 | if (tkip_encrypt_skb(tx, tx->extra_frag[i]) < 0) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 239 | return TX_DROP; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 243 | return TX_CONTINUE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 247 | ieee80211_rx_result |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 248 | ieee80211_crypto_tkip_decrypt(struct ieee80211_rx_data *rx) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 249 | { |
| 250 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 251 | int hdrlen, res, hwaccel = 0, wpa_test = 0; |
| 252 | struct ieee80211_key *key = rx->key; |
| 253 | struct sk_buff *skb = rx->skb; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 254 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 255 | |
Harvey Harrison | d5184ca | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 256 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 257 | |
Johannes Berg | 4f0d18e | 2007-09-26 15:19:40 +0200 | [diff] [blame] | 258 | if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 259 | return RX_CONTINUE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 260 | |
| 261 | if (!rx->sta || skb->len - hdrlen < 12) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 262 | return RX_DROP_UNUSABLE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 263 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 264 | if (rx->status->flag & RX_FLAG_DECRYPTED) { |
| 265 | if (rx->status->flag & RX_FLAG_IV_STRIPPED) { |
Johannes Berg | 7848ba7 | 2007-09-14 11:10:25 -0400 | [diff] [blame] | 266 | /* |
| 267 | * Hardware took care of all processing, including |
| 268 | * replay protection, and stripped the ICV/IV so |
| 269 | * we cannot do any checks here. |
| 270 | */ |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 271 | return RX_CONTINUE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | /* let TKIP code verify IV, but skip decryption */ |
| 275 | hwaccel = 1; |
| 276 | } |
| 277 | |
| 278 | res = ieee80211_tkip_decrypt_data(rx->local->wep_rx_tfm, |
| 279 | key, skb->data + hdrlen, |
| 280 | skb->len - hdrlen, rx->sta->addr, |
Emmanuel Grumbach | 9ae4fda | 2008-03-20 15:06:42 +0200 | [diff] [blame] | 281 | hdr->addr1, hwaccel, rx->queue, |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 282 | &rx->tkip_iv32, |
| 283 | &rx->tkip_iv16); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 284 | if (res != TKIP_DECRYPT_OK || wpa_test) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 285 | return RX_DROP_UNUSABLE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 286 | |
| 287 | /* Trim ICV */ |
| 288 | skb_trim(skb, skb->len - TKIP_ICV_LEN); |
| 289 | |
| 290 | /* Remove IV */ |
| 291 | memmove(skb->data + TKIP_IV_LEN, skb->data, hdrlen); |
| 292 | skb_pull(skb, TKIP_IV_LEN); |
| 293 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 294 | return RX_CONTINUE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | |
| 298 | static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad, |
| 299 | int encrypted) |
| 300 | { |
Harvey Harrison | f14df80 | 2008-07-02 11:05:35 -0700 | [diff] [blame^] | 301 | __le16 mask_fc; |
| 302 | int a4_included; |
| 303 | u8 qos_tid; |
| 304 | u16 data_len, len_a; |
| 305 | unsigned int hdrlen; |
| 306 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 307 | |
Harvey Harrison | f14df80 | 2008-07-02 11:05:35 -0700 | [diff] [blame^] | 308 | /* |
| 309 | * Mask FC: zero subtype b4 b5 b6 |
| 310 | * Retry, PwrMgt, MoreData; set Protected |
| 311 | */ |
| 312 | mask_fc = hdr->frame_control; |
| 313 | mask_fc &= ~cpu_to_le16(0x0070 | IEEE80211_FCTL_RETRY | |
| 314 | IEEE80211_FCTL_PM | IEEE80211_FCTL_MOREDATA); |
| 315 | mask_fc |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 316 | |
Harvey Harrison | f14df80 | 2008-07-02 11:05:35 -0700 | [diff] [blame^] | 317 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
| 318 | len_a = hdrlen - 2; |
| 319 | a4_included = ieee80211_has_a4(hdr->frame_control); |
| 320 | |
| 321 | if (ieee80211_is_data_qos(hdr->frame_control)) |
| 322 | qos_tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK; |
| 323 | else |
| 324 | qos_tid = 0; |
| 325 | |
| 326 | data_len = skb->len - hdrlen - CCMP_HDR_LEN; |
| 327 | if (encrypted) |
| 328 | data_len -= CCMP_MIC_LEN; |
| 329 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 330 | /* First block, b_0 */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 331 | b_0[0] = 0x59; /* flags: Adata: 1, M: 011, L: 001 */ |
| 332 | /* Nonce: QoS Priority | A2 | PN */ |
| 333 | b_0[1] = qos_tid; |
Harvey Harrison | 73e1f7c | 2008-07-02 11:05:34 -0700 | [diff] [blame] | 334 | memcpy(&b_0[2], hdr->addr2, ETH_ALEN); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 335 | memcpy(&b_0[8], pn, CCMP_PN_LEN); |
| 336 | /* l(m) */ |
Harvey Harrison | f14df80 | 2008-07-02 11:05:35 -0700 | [diff] [blame^] | 337 | put_unaligned_be16(data_len, &b_0[14]); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 338 | |
| 339 | /* AAD (extra authenticate-only data) / masked 802.11 header |
| 340 | * FC | A1 | A2 | A3 | SC | [A4] | [QC] */ |
Harvey Harrison | f14df80 | 2008-07-02 11:05:35 -0700 | [diff] [blame^] | 341 | put_unaligned_be16(len_a, &aad[0]); |
| 342 | put_unaligned(mask_fc, (__le16 *)&aad[2]); |
Harvey Harrison | 73e1f7c | 2008-07-02 11:05:34 -0700 | [diff] [blame] | 343 | memcpy(&aad[4], &hdr->addr1, 3 * ETH_ALEN); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 344 | |
| 345 | /* Mask Seq#, leave Frag# */ |
| 346 | aad[22] = *((u8 *) &hdr->seq_ctrl) & 0x0f; |
| 347 | aad[23] = 0; |
Harvey Harrison | f14df80 | 2008-07-02 11:05:35 -0700 | [diff] [blame^] | 348 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 349 | if (a4_included) { |
Harvey Harrison | 73e1f7c | 2008-07-02 11:05:34 -0700 | [diff] [blame] | 350 | memcpy(&aad[24], hdr->addr4, ETH_ALEN); |
Harvey Harrison | f14df80 | 2008-07-02 11:05:35 -0700 | [diff] [blame^] | 351 | aad[30] = qos_tid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 352 | aad[31] = 0; |
Harvey Harrison | f14df80 | 2008-07-02 11:05:35 -0700 | [diff] [blame^] | 353 | } else { |
Harvey Harrison | 73e1f7c | 2008-07-02 11:05:34 -0700 | [diff] [blame] | 354 | memset(&aad[24], 0, ETH_ALEN + IEEE80211_QOS_CTL_LEN); |
Harvey Harrison | f14df80 | 2008-07-02 11:05:35 -0700 | [diff] [blame^] | 355 | aad[24] = qos_tid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | |
| 359 | |
| 360 | static inline void ccmp_pn2hdr(u8 *hdr, u8 *pn, int key_id) |
| 361 | { |
| 362 | hdr[0] = pn[5]; |
| 363 | hdr[1] = pn[4]; |
| 364 | hdr[2] = 0; |
| 365 | hdr[3] = 0x20 | (key_id << 6); |
| 366 | hdr[4] = pn[3]; |
| 367 | hdr[5] = pn[2]; |
| 368 | hdr[6] = pn[1]; |
| 369 | hdr[7] = pn[0]; |
| 370 | } |
| 371 | |
| 372 | |
| 373 | static inline int ccmp_hdr2pn(u8 *pn, u8 *hdr) |
| 374 | { |
| 375 | pn[0] = hdr[7]; |
| 376 | pn[1] = hdr[6]; |
| 377 | pn[2] = hdr[5]; |
| 378 | pn[3] = hdr[4]; |
| 379 | pn[4] = hdr[1]; |
| 380 | pn[5] = hdr[0]; |
| 381 | return (hdr[3] >> 6) & 0x03; |
| 382 | } |
| 383 | |
| 384 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 385 | static int ccmp_encrypt_skb(struct ieee80211_tx_data *tx, struct sk_buff *skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 386 | { |
| 387 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 388 | struct ieee80211_key *key = tx->key; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 389 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 390 | int hdrlen, len, tail; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 391 | u8 *pos, *pn, *b_0, *aad, *scratch; |
| 392 | int i; |
| 393 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 394 | info->control.icv_len = CCMP_MIC_LEN; |
| 395 | info->control.iv_len = CCMP_HDR_LEN; |
| 396 | |
| 397 | if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) && |
| 398 | !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) { |
| 399 | /* hwaccel - with no need for preallocated room for CCMP " |
| 400 | * header or MIC fields */ |
| 401 | info->control.hw_key = &tx->key->conf; |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 402 | return 0; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 403 | } |
| 404 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 405 | scratch = key->u.ccmp.tx_crypto_buf; |
| 406 | b_0 = scratch + 3 * AES_BLOCK_LEN; |
| 407 | aad = scratch + 4 * AES_BLOCK_LEN; |
| 408 | |
Harvey Harrison | d5184ca | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 409 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 410 | len = skb->len - hdrlen; |
| 411 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 412 | if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 413 | tail = 0; |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 414 | else |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 415 | tail = CCMP_MIC_LEN; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 416 | |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 417 | if (WARN_ON(skb_tailroom(skb) < tail || |
| 418 | skb_headroom(skb) < CCMP_HDR_LEN)) |
| 419 | return -1; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 420 | |
| 421 | pos = skb_push(skb, CCMP_HDR_LEN); |
| 422 | memmove(pos, pos + CCMP_HDR_LEN, hdrlen); |
| 423 | hdr = (struct ieee80211_hdr *) pos; |
| 424 | pos += hdrlen; |
| 425 | |
| 426 | /* PN = PN + 1 */ |
| 427 | pn = key->u.ccmp.tx_pn; |
| 428 | |
| 429 | for (i = CCMP_PN_LEN - 1; i >= 0; i--) { |
| 430 | pn[i]++; |
| 431 | if (pn[i]) |
| 432 | break; |
| 433 | } |
| 434 | |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 435 | ccmp_pn2hdr(pos, pn, key->conf.keyidx); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 436 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 437 | if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 438 | /* hwaccel - with preallocated room for CCMP header */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 439 | info->control.hw_key = &tx->key->conf; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | pos += CCMP_HDR_LEN; |
| 444 | ccmp_special_blocks(skb, pn, b_0, aad, 0); |
| 445 | ieee80211_aes_ccm_encrypt(key->u.ccmp.tfm, scratch, b_0, aad, pos, len, |
| 446 | pos, skb_put(skb, CCMP_MIC_LEN)); |
| 447 | |
| 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 452 | ieee80211_tx_result |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 453 | ieee80211_crypto_ccmp_encrypt(struct ieee80211_tx_data *tx) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 454 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 455 | struct sk_buff *skb = tx->skb; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 456 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 457 | ieee80211_tx_set_protected(tx); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 458 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 459 | if (ccmp_encrypt_skb(tx, skb) < 0) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 460 | return TX_DROP; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 461 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 462 | if (tx->extra_frag) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 463 | int i; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 464 | for (i = 0; i < tx->num_extra_frag; i++) { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 465 | if (ccmp_encrypt_skb(tx, tx->extra_frag[i]) < 0) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 466 | return TX_DROP; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 467 | } |
| 468 | } |
| 469 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 470 | return TX_CONTINUE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 474 | ieee80211_rx_result |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 475 | ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 476 | { |
| 477 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 478 | int hdrlen; |
| 479 | struct ieee80211_key *key = rx->key; |
| 480 | struct sk_buff *skb = rx->skb; |
| 481 | u8 pn[CCMP_PN_LEN]; |
| 482 | int data_len; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 483 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 484 | |
Harvey Harrison | d5184ca | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 485 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 486 | |
Johannes Berg | 4f0d18e | 2007-09-26 15:19:40 +0200 | [diff] [blame] | 487 | if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 488 | return RX_CONTINUE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 489 | |
| 490 | data_len = skb->len - hdrlen - CCMP_HDR_LEN - CCMP_MIC_LEN; |
| 491 | if (!rx->sta || data_len < 0) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 492 | return RX_DROP_UNUSABLE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 493 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 494 | if ((rx->status->flag & RX_FLAG_DECRYPTED) && |
| 495 | (rx->status->flag & RX_FLAG_IV_STRIPPED)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 496 | return RX_CONTINUE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 497 | |
| 498 | (void) ccmp_hdr2pn(pn, skb->data + hdrlen); |
| 499 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 500 | if (memcmp(pn, key->u.ccmp.rx_pn[rx->queue], CCMP_PN_LEN) <= 0) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 501 | key->u.ccmp.replays++; |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 502 | return RX_DROP_UNUSABLE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 505 | if (!(rx->status->flag & RX_FLAG_DECRYPTED)) { |
Johannes Berg | 7848ba7 | 2007-09-14 11:10:25 -0400 | [diff] [blame] | 506 | /* hardware didn't decrypt/verify MIC */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 507 | u8 *scratch, *b_0, *aad; |
| 508 | |
| 509 | scratch = key->u.ccmp.rx_crypto_buf; |
| 510 | b_0 = scratch + 3 * AES_BLOCK_LEN; |
| 511 | aad = scratch + 4 * AES_BLOCK_LEN; |
| 512 | |
| 513 | ccmp_special_blocks(skb, pn, b_0, aad, 1); |
| 514 | |
| 515 | if (ieee80211_aes_ccm_decrypt( |
| 516 | key->u.ccmp.tfm, scratch, b_0, aad, |
| 517 | skb->data + hdrlen + CCMP_HDR_LEN, data_len, |
| 518 | skb->data + skb->len - CCMP_MIC_LEN, |
| 519 | skb->data + hdrlen + CCMP_HDR_LEN)) { |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 520 | return RX_DROP_UNUSABLE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 521 | } |
| 522 | } |
| 523 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 524 | memcpy(key->u.ccmp.rx_pn[rx->queue], pn, CCMP_PN_LEN); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 525 | |
| 526 | /* Remove CCMP header and MIC */ |
| 527 | skb_trim(skb, skb->len - CCMP_MIC_LEN); |
| 528 | memmove(skb->data + CCMP_HDR_LEN, skb->data, hdrlen); |
| 529 | skb_pull(skb, CCMP_HDR_LEN); |
| 530 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 531 | return RX_CONTINUE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 532 | } |