ath9k_hw: add multicast key search support
PATCH 1/3 ath9k_hw: add multicast key search support
If a MAC address for a key table entry is flagged with the multicast bit (0x01), indicate to the hardware that multicast lookup instead of unicast lookup should be used. The multicast bit itself never makes it to the actual keytable entry register, as it is shifted out.
--- drivers/net/wireless/ath/ath9k/hw.c | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-)
drivers/net/wireless/ath/ath9k/hw.c +12 -1
@@ -1489,6 +1489,7 @@ EXPORT_SYMBOL(ath9k_hw_keyreset);bool ath9k_hw_keysetmac (struct ath_hw *ah,u16 entry,const u8 *mac) {u32 macHi, macLo; +u32 unicast_flag =AR_KEYTABLE_VALID ;if (entry >= ah->caps.keycache_size) { ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
@@ -1497,6 +1498,16 @@ bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac) }if (mac !=NULL ) { +/* +* AR_KEYTABLE_VALID indicates that the address is a unicast +* address, which must match the transmitter address for +* decrypting frames. +* Not setting this bit allows the hardware to use the key +* for multicast frame decryption. +*/ +if (mac[0 ] &0x01 ) + unicast_flag =0 ; + macHi = (mac[5 ] <<8 ) | mac[4 ]; macLo = (mac[3 ] <<24 ) | (mac[2] << 16) |
@@ -1509,7 +1520,7 @@ bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac) macLo = macHi =0 ; }REG_WRITE (ah,AR_KEYTABLE_MAC0 (entry), macLo); -REG_WRITE (ah,AR_KEYTABLE_MAC1 (entry), macHi |AR_KEYTABLE_VALID ); +REG_WRITE (ah,AR_KEYTABLE_MAC1 (entry), macHi | unicast_flag);return true; }
Signature · 1 line
1.6.4.2
PATCH 2/3 ath9k_common: use allocated key cache entries for multi BSS crypto support
This patch replaces the buggy 'ath9k: Group Key fix for VAPs' change.
For AP mode group keys, use the BSSID as lookup mac address, with the multicast keysearch bit set.
For IBSS mode, use the peer's MAC address with multicast keysearch. For STA mode, keep using the group key slots.
--- drivers/net/wireless/ath/ath9k/common.c | 37 ++++++++++++++++++++++-------- 1 files changed, 27 insertions(+), 10 deletions(-)
drivers/net/wireless/ath/ath9k/common.c +27 -10
@@ -475,10 +475,14 @@ static int ath_reserve_key_cache_slot_tkip(struct ath_common *common)return -1 ; } -static int ath_reserve_key_cache_slot (struct ath_common *common) +static int ath_reserve_key_cache_slot (struct ath_common *common, +enum ieee80211_key_alg alg) {int i; +if (alg ==ALG_TKIP ) +return ath_reserve_key_cache_slot_tkip (common); +/* First, try to find slots that would not be available for TKIP. */ if (common->splitmic) {for (i =IEEE80211_WEP_NKID ; i < common->keymax /4 ; i++) {
@@ -547,6 +551,7 @@ int ath9k_cmn_key_config(struct ath_common *common,struct ath_hw *ah = common->ah;struct ath9k_keyval hk;const u8 *mac =NULL ; +u8 gmac[ETH_ALEN ];int ret =0 ;int idx;
@@ -570,9 +575,23 @@ int ath9k_cmn_key_config(struct ath_common *common,memcpy (hk.kv_val, key->key, key->keylen);if (!(key->flags &IEEE80211_KEY_FLAG_PAIRWISE )) { -/* For now, use the default keys for broadcast keys. This may -* need to change with virtual interfaces. */ - idx = key->keyidx; +switch (vif->type) { +case NL80211_IFTYPE_AP : +memcpy (gmac, vif->addr,ETH_ALEN ); + gmac[0 ] |=0x01 ; + mac = gmac; + idx =ath_reserve_key_cache_slot (common, key->alg); +break ; +case NL80211_IFTYPE_ADHOC : +memcpy (gmac, sta->addr,ETH_ALEN ); + gmac[0 ] |=0x01 ; + mac = gmac; + idx =ath_reserve_key_cache_slot (common, key->alg); +break ; +default : + idx = key->keyidx; +break ; + } }else if (key->keyidx) {if (WARN_ON (!sta))return -EOPNOTSUPP ;
@@ -589,14 +608,12 @@ int ath9k_cmn_key_config(struct ath_common *common,return -EOPNOTSUPP ; mac = sta->addr; -if (key->alg ==ALG_TKIP ) - idx =ath_reserve_key_cache_slot_tkip (common); -else - idx =ath_reserve_key_cache_slot (common); -if (idx <0 ) -return -ENOSPC ;/* no free key cache entries */ + idx =ath_reserve_key_cache_slot (common, key->alg); } +if (idx <0 ) +return -ENOSPC ;/* no free key cache entries */ +if (key->alg ==ALG_TKIP ) ret =ath_setkey_tkip (common, idx, key->key, &hk, mac, vif->type ==NL80211_IFTYPE_AP );
Signature · 1 line
1.6.4.2
PATCH 3/3 ath9k: use the key handling code from ath9k_common instead of duplicating it
--- drivers/net/wireless/ath/ath9k/main.c | 232 +-------------------------------- 1 files changed, 2 insertions(+), 230 deletions(-)
drivers/net/wireless/ath/ath9k/main.c +2 -230
@@ -615,234 +615,6 @@ static u32 ath_get_extchanmode(struct ath_softc *sc,return chanmode; } -static int ath_setkey_tkip (struct ath_common *common,u16 keyix,const u8 *key, -struct ath9k_keyval *hk,const u8 *addr, -bool authenticator) -{ -struct ath_hw *ah = common->ah; -const u8 *key_rxmic; -const u8 *key_txmic; - - key_txmic = key +NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY ; - key_rxmic = key +NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY ; - -if (addr ==NULL ) { -/* -* Group key installation - only two key cache entries are used -* regardless of splitmic capability since group key is only -* used either for TX or RX. -*/ -if (authenticator) { -memcpy (hk->kv_mic, key_txmic,sizeof (hk->kv_mic)); -memcpy (hk->kv_txmic, key_txmic,sizeof (hk->kv_mic)); - }else { -memcpy (hk->kv_mic, key_rxmic,sizeof (hk->kv_mic)); -memcpy (hk->kv_txmic, key_rxmic,sizeof (hk->kv_mic)); - } -return ath9k_hw_set_keycache_entry (ah, keyix, hk, addr); - } -if (!common->splitmic) { -/* TX and RX keys share the same key cache entry. */ -memcpy (hk->kv_mic, key_rxmic,sizeof (hk->kv_mic)); -memcpy (hk->kv_txmic, key_txmic,sizeof (hk->kv_txmic)); -return ath9k_hw_set_keycache_entry (ah, keyix, hk, addr); - } - -/* Separate key cache entries for TX and RX */ - -/* TX key goes at first index, RX key at +32. */ -memcpy (hk->kv_mic, key_txmic,sizeof (hk->kv_mic)); -if (!ath9k_hw_set_keycache_entry (ah, keyix, hk,NULL )) { -/* TX MIC entry failed. No need to proceed further */ -ath_print (common,ATH_DBG_FATAL , -"Setting TX MIC Key Failed\n" ); -return 0 ; - } - -memcpy (hk->kv_mic, key_rxmic,sizeof (hk->kv_mic)); -/* XXX delete tx key on failure? */ -return ath9k_hw_set_keycache_entry (ah, keyix +32 , hk, addr); -} - -static int ath_reserve_key_cache_slot_tkip (struct ath_common *common) -{ -int i; - -for (i =IEEE80211_WEP_NKID ; i < common->keymax /2 ; i++) { -if (test_bit (i, common->keymap) || -test_bit (i +64 , common->keymap)) -continue ;/* At least one part of TKIP key allocated */ -if (common->splitmic && - (test_bit (i +32 , common->keymap) || -test_bit (i +64 +32 , common->keymap))) -continue ;/* At least one part of TKIP key allocated */ - -/* Found a free slot for a TKIP key */ -return i; - } -return -1 ; -} - -static int ath_reserve_key_cache_slot (struct ath_common *common) -{ -int i; - -/* First, try to find slots that would not be available for TKIP. */ -if (common->splitmic) { -for (i =IEEE80211_WEP_NKID ; i < common->keymax /4 ; i++) { -if (!test_bit (i, common->keymap) && - (test_bit (i +32 , common->keymap) || -test_bit (i +64 , common->keymap) || -test_bit (i +64 +32 , common->keymap))) -return i; -if (!test_bit (i +32 , common->keymap) && - (test_bit (i, common->keymap) || -test_bit (i +64 , common->keymap) || -test_bit (i +64 +32 , common->keymap))) -return i +32 ; -if (!test_bit (i +64 , common->keymap) && - (test_bit (i , common->keymap) || -test_bit (i +32 , common->keymap) || -test_bit (i +64 +32 , common->keymap))) -return i +64 ; -if (!test_bit (i +64 +32 , common->keymap) && - (test_bit (i, common->keymap) || -test_bit (i +32 , common->keymap) || -test_bit (i +64 , common->keymap))) -return i +64 +32 ; - } - }else { -for (i =IEEE80211_WEP_NKID ; i < common->keymax /2 ; i++) { -if (!test_bit (i, common->keymap) && -test_bit (i +64 , common->keymap)) -return i; -if (test_bit (i, common->keymap) && - !test_bit (i +64 , common->keymap)) -return i +64 ; - } - } - -/* No partially used TKIP slots, pick any available slot */ -for (i =IEEE80211_WEP_NKID ; i < common->keymax; i++) { -/* Do not allow slots that could be needed for TKIP group keys -* to be used. This limitation could be removed if we know that -* TKIP will not be used. */ -if (i >=64 && i <64 +IEEE80211_WEP_NKID ) -continue ; -if (common->splitmic) { -if (i >=32 && i <32 +IEEE80211_WEP_NKID ) -continue ; -if (i >=64 +32 && i <64 +32 +IEEE80211_WEP_NKID ) -continue ; - } - -if (!test_bit (i, common->keymap)) -return i;/* Found a free slot for a key */ - } - -/* No free slot found */ -return -1 ; -} - -static int ath_key_config (struct ath_common *common, -struct ieee80211_vif *vif, -struct ieee80211_sta *sta, -struct ieee80211_key_conf *key) -{ -struct ath_hw *ah = common->ah; -struct ath9k_keyval hk; -const u8 *mac =NULL ; -int ret =0 ; -int idx; - -memset (&hk,0 ,sizeof (hk)); - -switch (key->alg) { -case ALG_WEP : - hk.kv_type =ATH9K_CIPHER_WEP ; -break ; -case ALG_TKIP : - hk.kv_type =ATH9K_CIPHER_TKIP ; -break ; -case ALG_CCMP : - hk.kv_type =ATH9K_CIPHER_AES_CCM ; -break ; -default : -return -EOPNOTSUPP ; - } - - hk.kv_len = key->keylen; -memcpy (hk.kv_val, key->key, key->keylen); - -if (!(key->flags &IEEE80211_KEY_FLAG_PAIRWISE )) { -/* For now, use the default keys for broadcast keys. This may -* need to change with virtual interfaces. */ - idx = key->keyidx; - }else if (key->keyidx) { -if (WARN_ON (!sta)) -return -EOPNOTSUPP ; - mac = sta->addr; - -if (vif->type !=NL80211_IFTYPE_AP ) { -/* Only keyidx 0 should be used with unicast key, but -* allow this for client mode for now. */ - idx = key->keyidx; - }else -return -EIO ; - }else { -if (WARN_ON (!sta)) -return -EOPNOTSUPP ; - mac = sta->addr; - -if (key->alg ==ALG_TKIP ) - idx =ath_reserve_key_cache_slot_tkip (common); -else - idx =ath_reserve_key_cache_slot (common); -if (idx <0 ) -return -ENOSPC ;/* no free key cache entries */ - } - -if (key->alg ==ALG_TKIP ) - ret =ath_setkey_tkip (common, idx, key->key, &hk, mac, - vif->type ==NL80211_IFTYPE_AP ); -else - ret =ath9k_hw_set_keycache_entry (ah, idx, &hk, mac); - -if (!ret) -return -EIO ; - -set_bit (idx, common->keymap); -if (key->alg ==ALG_TKIP ) { -set_bit (idx +64 , common->keymap); -if (common->splitmic) { -set_bit (idx +32 , common->keymap); -set_bit (idx +64 +32 , common->keymap); - } - } - -return idx; -} - -static void ath_key_delete (struct ath_common *common,struct ieee80211_key_conf *key) -{ -struct ath_hw *ah = common->ah; - -ath9k_hw_keyreset (ah, key->hw_key_idx); -if (key->hw_key_idx <IEEE80211_WEP_NKID ) -return ; - -clear_bit (key->hw_key_idx, common->keymap); -if (key->alg !=ALG_TKIP ) -return ; - -clear_bit (key->hw_key_idx +64 , common->keymap); -if (common->splitmic) { -ath9k_hw_keyreset (ah, key->hw_key_idx +32 ); -clear_bit (key->hw_key_idx +32 , common->keymap); -clear_bit (key->hw_key_idx +64 +32 , common->keymap); - } -} -static void ath9k_bss_assoc_info (struct ath_softc *sc,struct ieee80211_vif *vif,struct ieee80211_bss_conf *bss_conf)
@@ -1804,7 +1576,7 @@ static int ath9k_set_key(struct ieee80211_hw *hw,switch (cmd) {case SET_KEY : - ret =ath_key_config (common, vif, sta, key); + ret =ath9k_cmn_key_config (common, vif, sta, key);if (ret >=0 ) { key->hw_key_idx = ret;/* push IV and Michael MIC generation to stack */
@@ -1817,7 +1589,7 @@ static int ath9k_set_key(struct ieee80211_hw *hw, }break ;case DISABLE_KEY : -ath_key_delete (common, key); +ath9k_cmn_key_delete (common, key);break ;default : ret = -EINVAL ;
Signature · 1 line
1.6.4.2