Skip to content

Commit 9ae4fda

Browse files
egrumbachlinvjw
authored andcommitted
mac80211: allows driver to request a Phase 1 RX key
This patch makes mac80211 able to send a phase1 key for TKIP decryption. This is needed for drivers that don't do the rekeying by themselves (i.e. iwlwifi). Upon IV16 wrap around, the packet is decrypted in SW, if decryption is ok, mac80211 calls to update_tkip_key with a new phase 1 RX key. Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com> Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent 5d2cdcd commit 9ae4fda

4 files changed

Lines changed: 33 additions & 3 deletions

File tree

‎include/net/mac80211.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,16 @@ static inline void SET_IEEE80211_PERM_ADDR(struct ieee80211_hw *hw, u8 *addr)
827827
* parameter is guaranteed to be valid until another call to set_key()
828828
* removes it, but it can only be used as a cookie to differentiate
829829
* keys.
830+
*
831+
* In TKIP some HW need to be provided a phase 1 key, for RX decryption
832+
* acceleration (i.e. iwlwifi). Those drivers should provide update_tkip_key
833+
* handler.
834+
* The update_tkip_key() call updates the driver with the new phase 1 key.
835+
* This happens everytime the iv16 wraps around (every 65536 packets). The
836+
* set_key() call will happen only once for each key (unless the AP did
837+
* rekeying), it will not include a valid phase 1 key. The valid phase 1 key is
838+
* provided by udpate_tkip_key only. The trigger that makes mac80211 call this
839+
* handler is software decryption with wrap around of iv16.
830840
*/
831841

832842
/**
@@ -1003,6 +1013,10 @@ enum ieee80211_ampdu_mlme_action {
10031013
* and remove_interface calls, i.e. while the interface with the
10041014
* given local_address is enabled.
10051015
*
1016+
* @update_tkip_key: See the section "Hardware crypto acceleration"
1017+
* This callback will be called in the context of Rx. Called for drivers
1018+
* which set IEEE80211_KEY_FLAG_TKIP_REQ_RX_P1_KEY.
1019+
*
10061020
* @hw_scan: Ask the hardware to service the scan request, no need to start
10071021
* the scan state machine in stack. The scan must honour the channel
10081022
* configuration done by the regulatory agent in the wiphy's registered
@@ -1094,6 +1108,9 @@ struct ieee80211_ops {
10941108
int (*set_key)(struct ieee80211_hw *hw, enum set_key_cmd cmd,
10951109
const u8 *local_address, const u8 *address,
10961110
struct ieee80211_key_conf *key);
1111+
void (*update_tkip_key)(struct ieee80211_hw *hw,
1112+
struct ieee80211_key_conf *conf, const u8 *address,
1113+
u32 iv32, u16 *phase1key);
10971114
int (*hw_scan)(struct ieee80211_hw *hw, u8 *ssid, size_t len);
10981115
int (*get_stats)(struct ieee80211_hw *hw,
10991116
struct ieee80211_low_level_stats *stats);

‎net/mac80211/tkip.c‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ void ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm,
291291
int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
292292
struct ieee80211_key *key,
293293
u8 *payload, size_t payload_len, u8 *ta,
294-
int only_iv, int queue,
294+
u8 *ra, int only_iv, int queue,
295295
u32 *out_iv32, u16 *out_iv16)
296296
{
297297
u32 iv32;
@@ -368,6 +368,19 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
368368
printk("\n");
369369
}
370370
#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+
}
371384
}
372385

373386
tkip_mixing_phase2(key->u.tkip.p1k_rx[queue],

‎net/mac80211/tkip.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ enum {
3131
int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
3232
struct ieee80211_key *key,
3333
u8 *payload, size_t payload_len, u8 *ta,
34-
int only_iv, int queue,
34+
u8 *ra, int only_iv, int queue,
3535
u32 *out_iv32, u16 *out_iv16);
3636

3737
#endif /* TKIP_H */

‎net/mac80211/wpa.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ ieee80211_crypto_tkip_decrypt(struct ieee80211_rx_data *rx)
312312
res = ieee80211_tkip_decrypt_data(rx->local->wep_rx_tfm,
313313
key, skb->data + hdrlen,
314314
skb->len - hdrlen, rx->sta->addr,
315-
hwaccel, rx->queue,
315+
hdr->addr1, hwaccel, rx->queue,
316316
&rx->tkip_iv32,
317317
&rx->tkip_iv16);
318318
if (res != TKIP_DECRYPT_OK || wpa_test) {

0 commit comments

Comments
 (0)