staging: rtl8723au: Introduce struct rtw_wep_key to store our wep keys
authorJes Sorensen <Jes.Sorensen@redhat.com>
Wed, 21 May 2014 07:37:35 +0000 (09:37 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 23 May 2014 07:27:42 +0000 (16:27 +0900)
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/rtl8723au/core/rtw_ioctl_set.c
drivers/staging/rtl8723au/core/rtw_mlme.c
drivers/staging/rtl8723au/core/rtw_security.c
drivers/staging/rtl8723au/include/rtw_security.h
drivers/staging/rtl8723au/os_dep/ioctl_cfg80211.c

index 347ea99..19e2e68 100644 (file)
@@ -396,7 +396,8 @@ int rtw_set_802_11_add_wep23a(struct rtw_adapter* padapter,
                RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
                         ("MgntActrtw_set_802_11_add_wep23a:wep->KeyLength!= 5 "
                          "or 13\n"));
-                       break;
+               res = _FAIL;
+               goto exit;
        }
 
        RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
@@ -404,29 +405,29 @@ int rtw_set_802_11_add_wep23a(struct rtw_adapter* padapter,
                  "wep->KeyIndex = 0x%x  keyid =%x\n",
                  wep->KeyLength, wep->KeyIndex, keyid));
 
-       memcpy(&psecuritypriv->dot11DefKey[keyid].skey[0],
-              &wep->KeyMaterial, wep->KeyLength);
+       memcpy(&psecuritypriv->wep_key[keyid].key, &wep->KeyMaterial,
+              wep->KeyLength);
 
-       psecuritypriv->dot11DefKeylen[keyid] = wep->KeyLength;
+       psecuritypriv->wep_key[keyid].keylen = wep->KeyLength;
 
        psecuritypriv->dot11PrivacyKeyIndex = keyid;
 
        RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
-                ("rtw_set_802_11_add_wep23a:security key material : %x %x %x %x "
-                 "%x %x %x %x %x %x %x %x %x\n",
-                 psecuritypriv->dot11DefKey[keyid].skey[0],
-                 psecuritypriv->dot11DefKey[keyid].skey[1],
-                 psecuritypriv->dot11DefKey[keyid].skey[2],
-                 psecuritypriv->dot11DefKey[keyid].skey[3],
-                 psecuritypriv->dot11DefKey[keyid].skey[4],
-                 psecuritypriv->dot11DefKey[keyid].skey[5],
-                 psecuritypriv->dot11DefKey[keyid].skey[6],
-                 psecuritypriv->dot11DefKey[keyid].skey[7],
-                 psecuritypriv->dot11DefKey[keyid].skey[8],
-                 psecuritypriv->dot11DefKey[keyid].skey[9],
-                 psecuritypriv->dot11DefKey[keyid].skey[10],
-                 psecuritypriv->dot11DefKey[keyid].skey[11],
-                 psecuritypriv->dot11DefKey[keyid].skey[12]));
+                ("rtw_set_802_11_add_wep23a:security key material : "
+                 "%x %x %x %x %x %x %x %x %x %x %x %x %x\n",
+                 psecuritypriv->wep_key[keyid].key[0],
+                 psecuritypriv->wep_key[keyid].key[1],
+                 psecuritypriv->wep_key[keyid].key[2],
+                 psecuritypriv->wep_key[keyid].key[3],
+                 psecuritypriv->wep_key[keyid].key[4],
+                 psecuritypriv->wep_key[keyid].key[5],
+                 psecuritypriv->wep_key[keyid].key[6],
+                 psecuritypriv->wep_key[keyid].key[7],
+                 psecuritypriv->wep_key[keyid].key[8],
+                 psecuritypriv->wep_key[keyid].key[9],
+                 psecuritypriv->wep_key[keyid].key[10],
+                 psecuritypriv->wep_key[keyid].key[11],
+                 psecuritypriv->wep_key[keyid].key[12]));
 
        res = rtw_set_key23a(padapter, psecuritypriv, keyid, 1);
 
index 42efc17..5dace9b 100644 (file)
@@ -1914,12 +1914,12 @@ int rtw_set_key23a(struct rtw_adapter *adapter,
        case WLAN_CIPHER_SUITE_WEP40:
                keylen = 5;
                memcpy(&psetkeyparm->key[0],
-                      &psecuritypriv->dot11DefKey[keyid].skey[0], keylen);
+                      &psecuritypriv->wep_key[keyid].key, keylen);
                break;
        case WLAN_CIPHER_SUITE_WEP104:
                keylen = 13;
                memcpy(&psetkeyparm->key[0],
-                      &psecuritypriv->dot11DefKey[keyid].skey[0], keylen);
+                      &psecuritypriv->wep_key[keyid].key, keylen);
                break;
        case WLAN_CIPHER_SUITE_TKIP:
                keylen = 16;
index aeb503b..d6c07ad 100644 (file)
@@ -175,12 +175,12 @@ void rtw_wep_encrypt23a(struct rtw_adapter *padapter,
                return;
 
        index = psecuritypriv->dot11PrivacyKeyIndex;
-       keylength = psecuritypriv->dot11DefKeylen[index];
+       keylength = psecuritypriv->wep_key[index].keylen;
 
        for (curfragnum = 0; curfragnum < pattrib->nr_frags ; curfragnum++) {
                iv = pframe + pattrib->hdrlen;
                memcpy(&wepkey[0], iv, 3);
-               memcpy(&wepkey[3], &psecuritypriv->dot11DefKey[index].skey[0],
+               memcpy(&wepkey[3], &psecuritypriv->wep_key[index].key,
                       keylength);
                payload = pframe + pattrib->iv_len + pattrib->hdrlen;
 
@@ -233,11 +233,10 @@ void rtw_wep_decrypt23a(struct rtw_adapter *padapter,
        iv = pframe + prxattrib->hdrlen;
        /* keyindex = (iv[3]&0x3); */
        keyindex = prxattrib->key_index;
-       keylength = psecuritypriv->dot11DefKeylen[keyindex];
+       keylength = psecuritypriv->wep_key[keyindex].keylen;
        memcpy(&wepkey[0], iv, 3);
        /* memcpy(&wepkey[3], &psecuritypriv->dot11DefKey[psecuritypriv->dot11PrivacyKeyIndex].skey[0], keylength); */
-       memcpy(&wepkey[3], &psecuritypriv->dot11DefKey[keyindex].skey[0],
-                  keylength);
+       memcpy(&wepkey[3], &psecuritypriv->wep_key[keyindex].key, keylength);
        length = skb->len - prxattrib->hdrlen - prxattrib->iv_len;
 
        payload = pframe + prxattrib->iv_len + prxattrib->hdrlen;
@@ -250,7 +249,7 @@ void rtw_wep_decrypt23a(struct rtw_adapter *padapter,
        *((u32 *)crc) = le32_to_cpu(getcrc32(payload, length - 4));
 
        if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] ||
-               crc[1] != payload[length - 3] || crc[0] != payload[length - 4]) {
+           crc[1] != payload[length - 3] || crc[0] != payload[length - 4]) {
                RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
                         ("rtw_wep_decrypt23a:icv error crc[3](%x)!= payload"
                          "[length-1](%x) || crc[2](%x)!= payload[length-2](%x)"
index e235ecd..f44fd33 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <osdep_service.h>
 #include <drv_types.h>
+#include <net/lib80211.h>
 
 
 #define is_wep_enc(alg) (alg == WLAN_CIPHER_SUITE_WEP40 || \
@@ -84,6 +85,10 @@ union Keytype {
        u32    lkey[4];
 };
 
+struct rtw_wep_key {
+       u8 key[WLAN_KEY_LEN_WEP104 + 1]; /* 14 */
+       u16 keylen;
+};
 
 struct rt_pmkid_list {
        u8      bUsed;
@@ -104,8 +109,7 @@ struct security_priv {
        u32       dot11PrivacyKeyIndex; /*  this is only valid for legendary
                                         * wep, 0~3 for key id. (tx key index)
                                         */
-       union Keytype dot11DefKey[4];   /*  this is only valid for def. key */
-       u32     dot11DefKeylen[4];
+       struct rtw_wep_key wep_key[NUM_WEP_KEYS];
 
        u32 dot118021XGrpPrivacy;       /* specify the privacy algthm.
                                         * used for Grp key
index e5662a8..08d6b34 100644 (file)
@@ -532,7 +532,7 @@ exit:
        return res;
 }
 
-static int set_wep_key(struct rtw_adapter *padapter, u8 *key, u8 keylen,
+static int set_wep_key(struct rtw_adapter *padapter, u8 *key, u16 keylen,
                       u8 keyid)
 {
        u32 alg;
@@ -556,7 +556,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev,
                                          u32 param_len)
 {
        int ret = 0;
-       u32 wep_key_len;
+       u16 wep_key_len;
        u8 wep_key_idx;
        struct sta_info *psta = NULL, *pbcmc_sta = NULL;
        struct rtw_adapter *padapter = netdev_priv(dev);
@@ -636,10 +636,10 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev,
                        psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx;
                }
 
-               memcpy(&psecuritypriv->dot11DefKey[wep_key_idx].skey[0],
+               memcpy(&psecuritypriv->wep_key[wep_key_idx].key,
                       param->u.crypt.key, wep_key_len);
 
-               psecuritypriv->dot11DefKeylen[wep_key_idx] = wep_key_len;
+               psecuritypriv->wep_key[wep_key_idx].keylen = wep_key_len;
 
                set_wep_key(padapter, param->u.crypt.key, wep_key_len,
                            wep_key_idx);
@@ -883,7 +883,8 @@ static int rtw_cfg80211_set_encryption(struct net_device *dev,
                                       struct ieee_param *param, u32 param_len)
 {
        int ret = 0;
-       u32 wep_key_idx, wep_key_len;
+       u32 wep_key_idx;
+       u16 wep_key_len;
        struct rtw_adapter *padapter = netdev_priv(dev);
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
        struct security_priv *psecuritypriv = &padapter->securitypriv;
@@ -942,10 +943,10 @@ static int rtw_cfg80211_set_encryption(struct net_device *dev,
                        psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx;
                }
 
-               memcpy(&psecuritypriv->dot11DefKey[wep_key_idx].skey[0],
+               memcpy(&psecuritypriv->wep_key[wep_key_idx].key,
                       param->u.crypt.key, wep_key_len);
 
-               psecuritypriv->dot11DefKeylen[wep_key_idx] = wep_key_len;
+               psecuritypriv->wep_key[wep_key_idx].keylen = wep_key_len;
 
                rtw_set_key23a(padapter, psecuritypriv, wep_key_idx, 0);
 
@@ -1201,9 +1202,9 @@ static int cfg80211_rtw_set_default_key(struct wiphy *wiphy,
        DBG_8723A("%s(%s): key_index =%d, unicast =%d, multicast =%d.\n",
                  __func__, ndev->name, key_index, unicast, multicast);
 
-       if ((key_index < WEP_KEYS) &&
-           ((psecuritypriv->dot11PrivacyAlgrthm == WLAN_CIPHER_SUITE_WEP40) ||
-            (psecuritypriv->dot11PrivacyAlgrthm == WLAN_CIPHER_SUITE_WEP104))) {
+       if (key_index < NUM_WEP_KEYS &&
+           (psecuritypriv->dot11PrivacyAlgrthm == WLAN_CIPHER_SUITE_WEP40 ||
+            psecuritypriv->dot11PrivacyAlgrthm == WLAN_CIPHER_SUITE_WEP104)) {
                /* set wep default key */
                psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
 
@@ -1211,9 +1212,11 @@ static int cfg80211_rtw_set_default_key(struct wiphy *wiphy,
 
                psecuritypriv->dot11PrivacyAlgrthm = WLAN_CIPHER_SUITE_WEP40;
                psecuritypriv->dot118021XGrpPrivacy = WLAN_CIPHER_SUITE_WEP40;
-               if (psecuritypriv->dot11DefKeylen[key_index] == 13) {
-                       psecuritypriv->dot11PrivacyAlgrthm = WLAN_CIPHER_SUITE_WEP104;
-                       psecuritypriv->dot118021XGrpPrivacy = WLAN_CIPHER_SUITE_WEP104;
+               if (psecuritypriv->wep_key[key_index].keylen == 13) {
+                       psecuritypriv->dot11PrivacyAlgrthm =
+                               WLAN_CIPHER_SUITE_WEP104;
+                       psecuritypriv->dot118021XGrpPrivacy =
+                               WLAN_CIPHER_SUITE_WEP104;
                }
 
                /* set the flag to represent that wep default key