TKIP Spin 3
Subsystems (2)
PATCH v2 7/7 iwlwifi-2.6: enables RX TKIP decryption in HW
In reply to Tomas WinklerFrom: Emmanuel Grumbach <[email protected]>
This patch enables RX TKIP decryption in HW.
--- drivers/net/wireless/iwlwifi/iwl4965-base.c | 51 +++++++++++++++++++++++++++ 1 files changed, 51 insertions(+), 0 deletions(-)
drivers/net/wireless/iwlwifi/iwl4965-base.c +51 -0
@@ -7179,6 +7179,56 @@ out_unlock:return rc; } +static void iwl4965_mac_update_tkip_key (struct ieee80211_hw *hw, +struct ieee80211_key_conf *keyconf,const u8 *addr, +u32 iv32,u16 *phase1key) +{ +struct iwl_priv *priv = hw->priv; +u8 sta_id =IWL_INVALID_STATION ; +unsigned long flags; +__le16 key_flags =0 ; +int i; +DECLARE_MAC_BUF (mac); + +IWL_DEBUG_MAC80211 ("enter\n" ); + + sta_id =iwl4965_hw_find_station (priv, addr); +if (sta_id ==IWL_INVALID_STATION ) { +IWL_DEBUG_MAC80211 ("leave - %s not in station map.\n" , +print_mac (mac, addr)); +return ; + } + +iwl4965_scan_cancel_timeout (priv,100 ); + + key_flags |= (STA_KEY_FLG_TKIP |STA_KEY_FLG_MAP_KEY_MSK ); + key_flags |=cpu_to_le16 (keyconf->keyidx <<STA_KEY_FLG_KEYID_POS ); + key_flags &= ~STA_KEY_FLG_INVALID ; + +if (sta_id == priv->hw_setting.bcast_sta_id) + key_flags |=STA_KEY_MULTICAST_MSK ; + +spin_lock_irqsave (&priv->sta_lock, flags); + + priv->stations[sta_id].sta.key.key_offset = + (sta_id %STA_KEY_MAX_NUM );/* FIXME */ + priv->stations[sta_id].sta.key.key_flags = key_flags; + priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8 ) iv32; + +for (i =0 ; i <5 ; i++) + priv->stations[sta_id].sta.key.tkip_rx_ttak[i] = +cpu_to_le16 (phase1key[i]); + + priv->stations[sta_id].sta.sta.modify_mask =STA_MODIFY_KEY_MASK ; + priv->stations[sta_id].sta.mode =STA_CONTROL_MODIFY_MSK ; + +iwl4965_send_add_station (priv, &priv->stations[sta_id].sta,CMD_ASYNC ); + +spin_unlock_irqrestore (&priv->sta_lock, flags); + +IWL_DEBUG_MAC80211 ("leave\n" ); +} +static int iwl4965_mac_set_key (struct ieee80211_hw *hw,enum set_key_cmd cmd,const u8 *local_addr,const u8 *addr,struct ieee80211_key_conf *key)
@@ -8120,6 +8170,7 @@ static struct ieee80211_ops iwl4965_hw_ops = { .config_interface = iwl4965_mac_config_interface, .configure_filter = iwl4965_configure_filter, .set_key = iwl4965_mac_set_key, + .update_tkip_key = iwl4965_mac_update_tkip_key, .get_stats = iwl4965_mac_get_stats, .get_tx_stats = iwl4965_mac_get_tx_stats, .conf_tx = iwl4965_mac_conf_tx,
Signature · 9 lines
1.5.4.1 --------------------------------------------------------------------- Intel Israel (74) Limited This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
PATCH v2 5/7 mac80211: allows driver to request a Phase 1 RX key
In reply to Tomas WinklerFrom: Emmanuel Grumbach <[email protected]>
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.
--- include/net/mac80211.h | 17 +++++++++++++++++ net/mac80211/tkip.c | 15 ++++++++++++++- net/mac80211/tkip.h | 2 +- net/mac80211/wpa.c | 2 +- 4 files changed, 33 insertions(+), 3 deletions(-)
include/net/mac80211.h +17 -0
@@ -827,6 +827,16 @@ static inline void SET_IEEE80211_PERM_ADDR(struct ieee80211_hw *hw, u8 *addr)* parameter is guaranteed to be valid until another call to set_key() * removes it, but it can only be used as a cookie to differentiate * keys. +* +* In TKIP some HW need to be provided a phase 1 key, for RX decryption +* acceleration (i.e. iwlwifi). Those drivers should provide update_tkip_key +* handler. +* The update_tkip_key() call updates the driver with the new phase 1 key. +* This happens everytime the iv16 wraps around (every 65536 packets). The +* set_key() call will happen only once for each key (unless the AP did +* rekeying), it will not include a valid phase 1 key. The valid phase 1 key is +* provided by udpate_tkip_key only. The trigger that makes mac80211 call this +* handler is software decryption with wrap around of iv16. */ /**
@@ -1003,6 +1013,10 @@ enum ieee80211_ampdu_mlme_action {* and remove_interface calls, i.e. while the interface with the * given local_address is enabled. * +* @update_tkip_key: See the section "Hardware crypto acceleration" +* This callback will be called in the context of Rx. Called for drivers +* which set IEEE80211_KEY_FLAG_TKIP_REQ_RX_P1_KEY. +* * @hw_scan: Ask the hardware to service the scan request, no need to start * the scan state machine in stack. The scan must honour the channel * configuration done by the regulatory agent in the wiphy's registered
@@ -1094,6 +1108,9 @@ struct ieee80211_ops {int (*set_key)(struct ieee80211_hw *hw,enum set_key_cmd cmd,const u8 *local_address,const u8 *address,struct ieee80211_key_conf *key); +void (*update_tkip_key)(struct ieee80211_hw *hw, +struct ieee80211_key_conf *conf,const u8 *address, +u32 iv32,u16 *phase1key);int (*hw_scan)(struct ieee80211_hw *hw,u8 *ssid,size_t len);int (*get_stats)(struct ieee80211_hw *hw,struct ieee80211_low_level_stats *stats);
net/mac80211/tkip.c +14 -1
@@ -291,7 +291,7 @@ void ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm,int ieee80211_tkip_decrypt_data (struct crypto_blkcipher *tfm,struct ieee80211_key *key,u8 *payload,size_t payload_len,u8 *ta, -int only_iv,int queue, +u8 *ra,int only_iv,int queue,u32 *out_iv32,u16 *out_iv16) {u32 iv32;
@@ -368,6 +368,19 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,printk ("\n" ); }#endif /* CONFIG_TKIP_DEBUG */ +if (key->local->ops->update_tkip_key && + key->flags &KEY_FLAG_UPLOADED_TO_HARDWARE ) { +u8 bcast[ETH_ALEN ] = + {0xff ,0xff ,0xff ,0xff ,0xff ,0xff }; +u8 *sta_addr = key->sta->addr; + +if (is_multicast_ether_addr (ra)) + sta_addr = bcast; + + key->local->ops->update_tkip_key ( +local_to_hw (key->local), &key->conf, + sta_addr, iv32, key->u.tkip.p1k_rx[queue]); + } } tkip_mixing_phase2(key->u.tkip.p1k_rx[queue],
net/mac80211/tkip.h +1 -1
@@ -31,7 +31,7 @@ enum {int ieee80211_tkip_decrypt_data (struct crypto_blkcipher *tfm,struct ieee80211_key *key,u8 *payload,size_t payload_len,u8 *ta, -int only_iv,int queue, +u8 *ra,int only_iv,int queue,u32 *out_iv32,u16 *out_iv16);#endif /* TKIP_H */
net/mac80211/wpa.c +1 -1
@@ -312,7 +312,7 @@ ieee80211_crypto_tkip_decrypt(struct ieee80211_rx_data *rx) res =ieee80211_tkip_decrypt_data (rx->local->wep_rx_tfm, key, skb->data + hdrlen, skb->len - hdrlen, rx->sta->addr, - hwaccel, rx->queue, + hdr->addr1, hwaccel, rx->queue, &rx->tkip_iv32, &rx->tkip_iv16);if (res !=TKIP_DECRYPT_OK || wpa_test) {
Signature · 9 lines
1.5.4.1 --------------------------------------------------------------------- Intel Israel (74) Limited This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
This series fixes 3 patches from the previous TKIP patches according Johannes comments
---------------------------------------------------------------------
Intel Israel (74) Limited
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
PATCH v2 4/7 mac80211: get a TKIP phase key from skb
From: Emmanuel Grumbach <[email protected]>
This patch makes mac80211 able to compute a TKIP key from an skb. The requested key can be a phase 1 or a phase 2 key. This is useful for drivers who need to provide tkip key to their HW to enable HW encryption.
--- include/net/mac80211.h | 30 +++++++++++++++++++++++++++ net/mac80211/tkip.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 0 deletions(-)
include/net/mac80211.h +30 -0
@@ -644,6 +644,21 @@ enum sta_notify_cmd { };/** +* enum ieee80211_tkip_key_type - get tkip key +* +* Used by drivers which need to get a tkip key for skb. Some drivers need a +* phase 1 key, others need a phase 2 key. A single function allows the driver +* to get the key, this enum indicates what type of key is required. +* +* @IEEE80211_TKIP_P1_KEY: the driver needs a phase 1 key +* @IEEE80211_TKIP_P2_KEY: the driver needs a phase 2 key +*/ +enum ieee80211_tkip_key_type { +IEEE80211_TKIP_P1_KEY , +IEEE80211_TKIP_P2_KEY , +}; + +/** * enum ieee80211_hw_flags - hardware flags * * These flags are used to indicate hardware capabilities to
@@ -1472,6 +1487,21 @@ int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb);int ieee80211_get_hdrlen (u16 fc);/** +* ieee80211_get_tkip_key - get a TKIP rc4 for skb +* +* This function computes a TKIP rc4 key for an skb. It computes +* a phase 1 key if needed (iv16 wraps around). This function is to +* be used by drivers which can do HW encryption but need to compute +* to phase 1/2 key in SW. +* +* @keyconf: the parameter passed with the set key +* @skb: the skb for which the key is needed +* @rc4key: a buffer to which the key will be written +*/ +void ieee80211_get_tkip_key (struct ieee80211_key_conf *keyconf, +struct sk_buff *skb, +enum ieee80211_tkip_key_type type,u8 *key); +/** * ieee80211_wake_queue - wake specific queue * @hw: pointer as obtained from ieee80211_alloc_hw(). * @queue: queue number (counted from zero).
net/mac80211/tkip.c +53 -0
59 lines not on this page · raw message
Signature · 9 lines
1.5.4.1 --------------------------------------------------------------------- Intel Israel (74) Limited This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
Re: [PATCH 4/7 V2] mac80211: get a TKIP phase key from skb
Quoted 9 lines · Tomas Winkler
From: Emmanuel Grumbach <[email protected]>
This patch makes mac80211 able to compute a TKIP key from an skb. The requested key can be a phase 1 or a phase 2 key. This is useful for drivers who need to provide tkip key to their HW to enable HW encryption.
Signed-off-by Emmanuel Grumbach <[email protected]>Signed-off-by Tomas Winkler <[email protected]>
Looks good, thanks
Quoted 117 lines
--- include/net/mac80211.h | 30 +++++++++++++++++++++++++++ net/mac80211/tkip.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 0 deletions(-)include/net/mac80211.h +30
-0@@ -644,6 +644,21 @@ enum sta_notify_cmd { };/** +* enum ieee80211_tkip_key_type - get tkip key +* +* Used by drivers which need to get a tkip key for skb. Some drivers need a +* phase 1 key, others need a phase 2 key. A single function allows the driver +* to get the key, this enum indicates what type of key is required. +* +* @IEEE80211_TKIP_P1_KEY: the driver needs a phase 1 key +* @IEEE80211_TKIP_P2_KEY: the driver needs a phase 2 key +*/ +enum ieee80211_tkip_key_type { +IEEE80211_TKIP_P1_KEY , +IEEE80211_TKIP_P2_KEY , +}; + +/** * enum ieee80211_hw_flags - hardware flags * * These flags are used to indicate hardware capabilities to @@ -1472,6 +1487,21 @@ int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb);int ieee80211_get_hdrlen (u16 fc);/** +* ieee80211_get_tkip_key - get a TKIP rc4 for skb +* +* This function computes a TKIP rc4 key for an skb. It computes +* a phase 1 key if needed (iv16 wraps around). This function is to +* be used by drivers which can do HW encryption but need to compute +* to phase 1/2 key in SW. +* +* @keyconf: the parameter passed with the set key +* @skb: the skb for which the key is needed +* @rc4key: a buffer to which the key will be written +*/ +void ieee80211_get_tkip_key (struct ieee80211_key_conf *keyconf, +struct sk_buff *skb, +enum ieee80211_tkip_key_type type,u8 *key); +/** * ieee80211_wake_queue - wake specific queue * @hw: pointer as obtained from ieee80211_alloc_hw(). * @queue: queue number (counted from zero). net/mac80211/tkip.c +53
-0@@ -214,6 +214,59 @@ void ieee80211_tkip_gen_rc4key(struct ieee80211_key *key, u8 *ta, key->u.tkip.iv16, rc4key); } +void ieee80211_get_tkip_key (struct ieee80211_key_conf *keyconf, +struct sk_buff *skb,enum ieee80211_tkip_key_type type, +u8 *outkey) +{ +struct ieee80211_key *key = (struct ieee80211_key *) + container_of(keyconf, struct ieee80211_key, conf); +struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; +u8 *data = (u8 *) hdr; +u16 fc =le16_to_cpu (hdr->frame_control); +int hdr_len =ieee80211_get_hdrlen (fc); +u8 *ta = hdr->addr2; +u16 iv16; +u32 iv32; + + iv16 = data[hdr_len] <<8 ; + iv16 += data[hdr_len +2 ]; + iv32 = data[hdr_len +4 ] + + (data[hdr_len +5 ] >>8 ) + + (data[hdr_len +6 ] >>16 ) + + (data[hdr_len +7 ] >>24 ); + +#ifdef CONFIG_TKIP_DEBUG +printk (KERN_DEBUG "TKIP encrypt: iv16 = 0x%04x, iv32 = 0x%08x\n" , + iv16, iv32); + +if (iv32 != key->u.tkip.iv32) { +printk (KERN_DEBUG "skb: iv32 = 0x%08x key: iv32 = 0x%08x\n" , + iv32, key->u.tkip.iv32); +printk (KERN_DEBUG "Wrap around of iv16 in the middle of a " +"fragmented packet\n" ); + } +#endif /* CONFIG_TKIP_DEBUG */ + +/* Update the p1k only when the iv16 in the packet wraps around, this +* might occur after the wrap around of iv16 in the key in case of +* fragmented packets. */ +if (iv16 ==0 || !key->u.tkip.tx_initialized) { +/* IV16 wrapped around - perform TKIP phase 1 */ +tkip_mixing_phase1 (ta, &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY ], + iv32, key->u.tkip.p1k); + key->u.tkip.tx_initialized =1 ; + } + +if (type ==IEEE80211_TKIP_P1_KEY ) { +memcpy (outkey, key->u.tkip.p1k,sizeof (u16) *5 ); +return ; + } + +tkip_mixing_phase2 (key->u.tkip.p1k, + &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY ], iv16, outkey); +} +EXPORT_SYMBOL (ieee80211_get_tkip_key); +/* Encrypt packet payload with TKIP using @key. @pos is a pointer to the * beginning of the buffer containing payload. This payload must include * headroom of eight octets for IV and Ext. IV and taildroom of four octets
Re: [PATCH 5/7 V2] mac80211: allows driver to request a Phase 1 RX key
In reply to Tomas WinklerQuoted 11 lines · Tomas Winkler
From: Emmanuel Grumbach <[email protected]>
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 toupdate_tkip_keywith a new phase 1 RX key.Signed-off-by Emmanuel Grumbach <[email protected]>Signed-off-by Tomas Winkler <[email protected]>
Looks good, thanks
Quoted 108 lines
--- include/net/mac80211.h | 17 +++++++++++++++++ net/mac80211/tkip.c | 15 ++++++++++++++- net/mac80211/tkip.h | 2 +- net/mac80211/wpa.c | 2 +- 4 files changed, 33 insertions(+), 3 deletions(-)include/net/mac80211.h +17
-0@@ -827,6 +827,16 @@ static inline void SET_IEEE80211_PERM_ADDR(struct ieee80211_hw *hw, u8 *addr)* parameter is guaranteed to be valid until another call to set_key() * removes it, but it can only be used as a cookie to differentiate * keys. +* +* In TKIP some HW need to be provided a phase 1 key, for RX decryption +* acceleration (i.e. iwlwifi). Those drivers should provide update_tkip_key +* handler. +* The update_tkip_key() call updates the driver with the new phase 1 key. +* This happens everytime the iv16 wraps around (every 65536 packets). The +* set_key() call will happen only once for each key (unless the AP did +* rekeying), it will not include a valid phase 1 key. The valid phase 1 key is +* provided by udpate_tkip_key only. The trigger that makes mac80211 call this +* handler is software decryption with wrap around of iv16. */ /** @@ -1003,6 +1013,10 @@ enum ieee80211_ampdu_mlme_action {* and remove_interface calls, i.e. while the interface with the * given local_address is enabled. * +* @update_tkip_key: See the section "Hardware crypto acceleration" +* This callback will be called in the context of Rx. Called for drivers +* which set IEEE80211_KEY_FLAG_TKIP_REQ_RX_P1_KEY. +* * @hw_scan: Ask the hardware to service the scan request, no need to start * the scan state machine in stack. The scan must honour the channel * configuration done by the regulatory agent in the wiphy's registered @@ -1094,6 +1108,9 @@ struct ieee80211_ops {int (*set_key)(struct ieee80211_hw *hw,enum set_key_cmd cmd,const u8 *local_address,const u8 *address,struct ieee80211_key_conf *key); +void (*update_tkip_key)(struct ieee80211_hw *hw, +struct ieee80211_key_conf *conf,const u8 *address, +u32 iv32,u16 *phase1key);int (*hw_scan)(struct ieee80211_hw *hw,u8 *ssid,size_t len);int (*get_stats)(struct ieee80211_hw *hw,struct ieee80211_low_level_stats *stats);net/mac80211/tkip.c +14
-1@@ -291,7 +291,7 @@ void ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm,int ieee80211_tkip_decrypt_data (struct crypto_blkcipher *tfm,struct ieee80211_key *key,u8 *payload,size_t payload_len,u8 *ta, -int only_iv,int queue, +u8 *ra,int only_iv,int queue,u32 *out_iv32,u16 *out_iv16) {u32 iv32;@@ -368,6 +368,19 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,printk ("\n" ); }#endif /* CONFIG_TKIP_DEBUG */ +if (key->local->ops->update_tkip_key && + key->flags &KEY_FLAG_UPLOADED_TO_HARDWARE ) { +u8 bcast[ETH_ALEN ] = + {0xff ,0xff ,0xff ,0xff ,0xff ,0xff }; +u8 *sta_addr = key->sta->addr; + +if (is_multicast_ether_addr (ra)) + sta_addr = bcast; + + key->local->ops->update_tkip_key ( +local_to_hw (key->local), &key->conf, + sta_addr, iv32, key->u.tkip.p1k_rx[queue]); + } } tkip_mixing_phase2(key->u.tkip.p1k_rx[queue],net/mac80211/tkip.h +1
-1@@ -31,7 +31,7 @@ enum {int ieee80211_tkip_decrypt_data (struct crypto_blkcipher *tfm,struct ieee80211_key *key,u8 *payload,size_t payload_len,u8 *ta, -int only_iv,int queue, +u8 *ra,int only_iv,int queue,u32 *out_iv32,u16 *out_iv16);#endif /* TKIP_H */ net/mac80211/wpa.c +1
-1@@ -312,7 +312,7 @@ ieee80211_crypto_tkip_decrypt(struct ieee80211_rx_data *rx) res =ieee80211_tkip_decrypt_data (rx->local->wep_rx_tfm, key, skb->data + hdrlen, skb->len - hdrlen, rx->sta->addr, - hwaccel, rx->queue, + hdr->addr1, hwaccel, rx->queue, &rx->tkip_iv32, &rx->tkip_iv16);if (res !=TKIP_DECRYPT_OK || wpa_test) {