diff options
Diffstat (limited to 'net/mac80211/tkip.c')
-rw-r--r-- | net/mac80211/tkip.c | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/net/mac80211/tkip.c b/net/mac80211/tkip.c index 964b7faa7f17..7ef491e9d66d 100644 --- a/net/mac80211/tkip.c +++ b/net/mac80211/tkip.c | |||
@@ -100,7 +100,7 @@ static void tkip_mixing_phase1(const u8 *tk, struct tkip_ctx *ctx, | |||
100 | p1k[3] += tkipS(p1k[2] ^ get_unaligned_le16(tk + 12 + j)); | 100 | p1k[3] += tkipS(p1k[2] ^ get_unaligned_le16(tk + 12 + j)); |
101 | p1k[4] += tkipS(p1k[3] ^ get_unaligned_le16(tk + 0 + j)) + i; | 101 | p1k[4] += tkipS(p1k[3] ^ get_unaligned_le16(tk + 0 + j)) + i; |
102 | } | 102 | } |
103 | ctx->initialized = 1; | 103 | ctx->state = TKIP_STATE_PHASE1_DONE; |
104 | } | 104 | } |
105 | 105 | ||
106 | static void tkip_mixing_phase2(const u8 *tk, struct tkip_ctx *ctx, | 106 | static void tkip_mixing_phase2(const u8 *tk, struct tkip_ctx *ctx, |
@@ -183,7 +183,7 @@ void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf, | |||
183 | /* Update the p1k only when the iv16 in the packet wraps around, this | 183 | /* Update the p1k only when the iv16 in the packet wraps around, this |
184 | * might occur after the wrap around of iv16 in the key in case of | 184 | * might occur after the wrap around of iv16 in the key in case of |
185 | * fragmented packets. */ | 185 | * fragmented packets. */ |
186 | if (iv16 == 0 || !ctx->initialized) | 186 | if (iv16 == 0 || ctx->state == TKIP_STATE_NOT_INIT) |
187 | tkip_mixing_phase1(tk, ctx, hdr->addr2, iv32); | 187 | tkip_mixing_phase1(tk, ctx, hdr->addr2, iv32); |
188 | 188 | ||
189 | if (type == IEEE80211_TKIP_P1_KEY) { | 189 | if (type == IEEE80211_TKIP_P1_KEY) { |
@@ -195,11 +195,13 @@ void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf, | |||
195 | } | 195 | } |
196 | EXPORT_SYMBOL(ieee80211_get_tkip_key); | 196 | EXPORT_SYMBOL(ieee80211_get_tkip_key); |
197 | 197 | ||
198 | /* Encrypt packet payload with TKIP using @key. @pos is a pointer to the | 198 | /* |
199 | * Encrypt packet payload with TKIP using @key. @pos is a pointer to the | ||
199 | * beginning of the buffer containing payload. This payload must include | 200 | * beginning of the buffer containing payload. This payload must include |
200 | * headroom of eight octets for IV and Ext. IV and taildroom of four octets | 201 | * the IV/Ext.IV and space for (taildroom) four octets for ICV. |
201 | * for ICV. @payload_len is the length of payload (_not_ including extra | 202 | * @payload_len is the length of payload (_not_ including IV/ICV length). |
202 | * headroom and tailroom). @ta is the transmitter addresses. */ | 203 | * @ta is the transmitter addresses. |
204 | */ | ||
203 | void ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm, | 205 | void ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm, |
204 | struct ieee80211_key *key, | 206 | struct ieee80211_key *key, |
205 | u8 *pos, size_t payload_len, u8 *ta) | 207 | u8 *pos, size_t payload_len, u8 *ta) |
@@ -209,12 +211,11 @@ void ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm, | |||
209 | const u8 *tk = &key->conf.key[NL80211_TKIP_DATA_OFFSET_ENCR_KEY]; | 211 | const u8 *tk = &key->conf.key[NL80211_TKIP_DATA_OFFSET_ENCR_KEY]; |
210 | 212 | ||
211 | /* Calculate per-packet key */ | 213 | /* Calculate per-packet key */ |
212 | if (ctx->iv16 == 0 || !ctx->initialized) | 214 | if (ctx->iv16 == 0 || ctx->state == TKIP_STATE_NOT_INIT) |
213 | tkip_mixing_phase1(tk, ctx, ta, ctx->iv32); | 215 | tkip_mixing_phase1(tk, ctx, ta, ctx->iv32); |
214 | 216 | ||
215 | tkip_mixing_phase2(tk, ctx, ctx->iv16, rc4key); | 217 | tkip_mixing_phase2(tk, ctx, ctx->iv16, rc4key); |
216 | 218 | ||
217 | pos = ieee80211_tkip_add_iv(pos, key, key->u.tkip.tx.iv16); | ||
218 | ieee80211_wep_encrypt_data(tfm, rc4key, 16, pos, payload_len); | 219 | ieee80211_wep_encrypt_data(tfm, rc4key, 16, pos, payload_len); |
219 | } | 220 | } |
220 | 221 | ||
@@ -259,7 +260,7 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm, | |||
259 | if ((keyid >> 6) != key->conf.keyidx) | 260 | if ((keyid >> 6) != key->conf.keyidx) |
260 | return TKIP_DECRYPT_INVALID_KEYIDX; | 261 | return TKIP_DECRYPT_INVALID_KEYIDX; |
261 | 262 | ||
262 | if (key->u.tkip.rx[queue].initialized && | 263 | if (key->u.tkip.rx[queue].state != TKIP_STATE_NOT_INIT && |
263 | (iv32 < key->u.tkip.rx[queue].iv32 || | 264 | (iv32 < key->u.tkip.rx[queue].iv32 || |
264 | (iv32 == key->u.tkip.rx[queue].iv32 && | 265 | (iv32 == key->u.tkip.rx[queue].iv32 && |
265 | iv16 <= key->u.tkip.rx[queue].iv16))) { | 266 | iv16 <= key->u.tkip.rx[queue].iv16))) { |
@@ -275,11 +276,11 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm, | |||
275 | 276 | ||
276 | if (only_iv) { | 277 | if (only_iv) { |
277 | res = TKIP_DECRYPT_OK; | 278 | res = TKIP_DECRYPT_OK; |
278 | key->u.tkip.rx[queue].initialized = 1; | 279 | key->u.tkip.rx[queue].state = TKIP_STATE_PHASE1_HW_UPLOADED; |
279 | goto done; | 280 | goto done; |
280 | } | 281 | } |
281 | 282 | ||
282 | if (!key->u.tkip.rx[queue].initialized || | 283 | if (key->u.tkip.rx[queue].state == TKIP_STATE_NOT_INIT || |
283 | key->u.tkip.rx[queue].iv32 != iv32) { | 284 | key->u.tkip.rx[queue].iv32 != iv32) { |
284 | /* IV16 wrapped around - perform TKIP phase 1 */ | 285 | /* IV16 wrapped around - perform TKIP phase 1 */ |
285 | tkip_mixing_phase1(tk, &key->u.tkip.rx[queue], ta, iv32); | 286 | tkip_mixing_phase1(tk, &key->u.tkip.rx[queue], ta, iv32); |
@@ -299,18 +300,18 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm, | |||
299 | printk("\n"); | 300 | printk("\n"); |
300 | } | 301 | } |
301 | #endif | 302 | #endif |
302 | if (key->local->ops->update_tkip_key && | 303 | } |
303 | key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) { | 304 | if (key->local->ops->update_tkip_key && |
304 | u8 bcast[ETH_ALEN] = | 305 | key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE && |
305 | {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; | 306 | key->u.tkip.rx[queue].state != TKIP_STATE_PHASE1_HW_UPLOADED) { |
306 | u8 *sta_addr = key->sta->sta.addr; | 307 | struct ieee80211_sub_if_data *sdata = key->sdata; |
307 | 308 | ||
308 | if (is_multicast_ether_addr(ra)) | 309 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
309 | sta_addr = bcast; | 310 | sdata = container_of(key->sdata->bss, |
310 | 311 | struct ieee80211_sub_if_data, u.ap); | |
311 | drv_update_tkip_key(key->local, &key->conf, sta_addr, | 312 | drv_update_tkip_key(key->local, sdata, &key->conf, key->sta, |
312 | iv32, key->u.tkip.rx[queue].p1k); | 313 | iv32, key->u.tkip.rx[queue].p1k); |
313 | } | 314 | key->u.tkip.rx[queue].state = TKIP_STATE_PHASE1_HW_UPLOADED; |
314 | } | 315 | } |
315 | 316 | ||
316 | tkip_mixing_phase2(tk, &key->u.tkip.rx[queue], iv16, rc4key); | 317 | tkip_mixing_phase2(tk, &key->u.tkip.rx[queue], iv16, rc4key); |