diff options
Diffstat (limited to 'net/mac80211/tkip.c')
-rw-r--r-- | net/mac80211/tkip.c | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/net/mac80211/tkip.c b/net/mac80211/tkip.c index 3abe194e4d55..45d59f19c29f 100644 --- a/net/mac80211/tkip.c +++ b/net/mac80211/tkip.c | |||
@@ -214,6 +214,59 @@ void ieee80211_tkip_gen_rc4key(struct ieee80211_key *key, u8 *ta, | |||
214 | key->u.tkip.iv16, rc4key); | 214 | key->u.tkip.iv16, rc4key); |
215 | } | 215 | } |
216 | 216 | ||
217 | void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf, | ||
218 | struct sk_buff *skb, enum ieee80211_tkip_key_type type, | ||
219 | u8 *outkey) | ||
220 | { | ||
221 | struct ieee80211_key *key = (struct ieee80211_key *) | ||
222 | container_of(keyconf, struct ieee80211_key, conf); | ||
223 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | ||
224 | u8 *data = (u8 *) hdr; | ||
225 | u16 fc = le16_to_cpu(hdr->frame_control); | ||
226 | int hdr_len = ieee80211_get_hdrlen(fc); | ||
227 | u8 *ta = hdr->addr2; | ||
228 | u16 iv16; | ||
229 | u32 iv32; | ||
230 | |||
231 | iv16 = data[hdr_len] << 8; | ||
232 | iv16 += data[hdr_len + 2]; | ||
233 | iv32 = data[hdr_len + 4] + | ||
234 | (data[hdr_len + 5] >> 8) + | ||
235 | (data[hdr_len + 6] >> 16) + | ||
236 | (data[hdr_len + 7] >> 24); | ||
237 | |||
238 | #ifdef CONFIG_TKIP_DEBUG | ||
239 | printk(KERN_DEBUG "TKIP encrypt: iv16 = 0x%04x, iv32 = 0x%08x\n", | ||
240 | iv16, iv32); | ||
241 | |||
242 | if (iv32 != key->u.tkip.iv32) { | ||
243 | printk(KERN_DEBUG "skb: iv32 = 0x%08x key: iv32 = 0x%08x\n", | ||
244 | iv32, key->u.tkip.iv32); | ||
245 | printk(KERN_DEBUG "Wrap around of iv16 in the middle of a " | ||
246 | "fragmented packet\n"); | ||
247 | } | ||
248 | #endif /* CONFIG_TKIP_DEBUG */ | ||
249 | |||
250 | /* Update the p1k only when the iv16 in the packet wraps around, this | ||
251 | * might occur after the wrap around of iv16 in the key in case of | ||
252 | * fragmented packets. */ | ||
253 | if (iv16 == 0 || !key->u.tkip.tx_initialized) { | ||
254 | /* IV16 wrapped around - perform TKIP phase 1 */ | ||
255 | tkip_mixing_phase1(ta, &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY], | ||
256 | iv32, key->u.tkip.p1k); | ||
257 | key->u.tkip.tx_initialized = 1; | ||
258 | } | ||
259 | |||
260 | if (type == IEEE80211_TKIP_P1_KEY) { | ||
261 | memcpy(outkey, key->u.tkip.p1k, sizeof(u16) * 5); | ||
262 | return; | ||
263 | } | ||
264 | |||
265 | tkip_mixing_phase2(key->u.tkip.p1k, | ||
266 | &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY], iv16, outkey); | ||
267 | } | ||
268 | EXPORT_SYMBOL(ieee80211_get_tkip_key); | ||
269 | |||
217 | /* Encrypt packet payload with TKIP using @key. @pos is a pointer to the | 270 | /* Encrypt packet payload with TKIP using @key. @pos is a pointer to the |
218 | * beginning of the buffer containing payload. This payload must include | 271 | * beginning of the buffer containing payload. This payload must include |
219 | * headroom of eight octets for IV and Ext. IV and taildroom of four octets | 272 | * headroom of eight octets for IV and Ext. IV and taildroom of four octets |
@@ -238,7 +291,7 @@ void ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm, | |||
238 | int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm, | 291 | int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm, |
239 | struct ieee80211_key *key, | 292 | struct ieee80211_key *key, |
240 | u8 *payload, size_t payload_len, u8 *ta, | 293 | u8 *payload, size_t payload_len, u8 *ta, |
241 | int only_iv, int queue, | 294 | u8 *ra, int only_iv, int queue, |
242 | u32 *out_iv32, u16 *out_iv16) | 295 | u32 *out_iv32, u16 *out_iv16) |
243 | { | 296 | { |
244 | u32 iv32; | 297 | u32 iv32; |
@@ -315,6 +368,19 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm, | |||
315 | printk("\n"); | 368 | printk("\n"); |
316 | } | 369 | } |
317 | #endif /* CONFIG_TKIP_DEBUG */ | 370 | #endif /* CONFIG_TKIP_DEBUG */ |
371 | if (key->local->ops->update_tkip_key && | ||
372 | key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) { | ||
373 | u8 bcast[ETH_ALEN] = | ||
374 | {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; | ||
375 | u8 *sta_addr = key->sta->addr; | ||
376 | |||
377 | if (is_multicast_ether_addr(ra)) | ||
378 | sta_addr = bcast; | ||
379 | |||
380 | key->local->ops->update_tkip_key( | ||
381 | local_to_hw(key->local), &key->conf, | ||
382 | sta_addr, iv32, key->u.tkip.p1k_rx[queue]); | ||
383 | } | ||
318 | } | 384 | } |
319 | 385 | ||
320 | tkip_mixing_phase2(key->u.tkip.p1k_rx[queue], | 386 | tkip_mixing_phase2(key->u.tkip.p1k_rx[queue], |