staging: rtl8723au: Make rtw_cfg80211_add_wep() take a struct rtw_wep_key
authorJes Sorensen <Jes.Sorensen@redhat.com>
Wed, 21 May 2014 07:37:38 +0000 (09:37 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 23 May 2014 07:27:42 +0000 (16:27 +0900)
This allows the removal of the ugly struct ndis_8802_11_wep and simplify
rtw_cfg80211_add_wep(). In addition remove unused element ndiswep from
struct security_priv.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/rtl8723au/include/rtw_security.h
drivers/staging/rtl8723au/include/wlan_bssdef.h
drivers/staging/rtl8723au/os_dep/ioctl_cfg80211.c

index f44fd33343296edc510b6e1a5011efa2a0d21d69..8b8433365e32d0e6e88306d27b88da7ac23ec3fd 100644 (file)
@@ -142,7 +142,6 @@ struct security_priv {
        u32 ndisauthtype;       /*  enum ndis_802_11_auth_mode */
        u32 ndisencryptstatus;  /*  NDIS_802_11_ENCRYPTION_STATUS */
        struct wlan_bssid_ex sec_bss;  /* for joinbss (h2c buffer) usage */
-       struct ndis_802_11_wep ndiswep;
        u8 assoc_info[600];
        u8 szofcapability[256]; /* for wpa2 usage */
        u8 oidassociation[512]; /* for wpa/wpa2 usage */
index e6b225c7d5d5c54e48395f1fa5d76ce8d9ae60a6..76a4578d4bba6e45613da49f5c71e98d827f54a1 100644 (file)
@@ -99,13 +99,6 @@ struct ndis_802_11_key {
        u8 KeyMaterial[32]; /*  variable length depending on above field */
 };
 
-struct ndis_802_11_wep {
-       u32     Length;        /*  Length of this structure */
-       u32     KeyIndex;      /*  0 is the per-client key, 1-N are global */
-       u32     KeyLength;     /*  length of key in bytes */
-       u8     KeyMaterial[16];/*  variable length depending on above field */
-};
-
 enum NDIS_802_11_STATUS_TYPE {
        Ndis802_11StatusType_Authentication,
        Ndis802_11StatusType_MediaStreamMode,
index bc27b590443ab9a2487a24a9e4b5afa45ea34004..c84ce00a717fc9b1e9525a7ff7fbb7f93fb5cc79 100644 (file)
@@ -1936,22 +1936,19 @@ exit:
 }
 
 static int rtw_cfg80211_add_wep(struct rtw_adapter *padapter,
-                               struct ndis_802_11_wep *wep)
+                               struct rtw_wep_key *wep, u8 keyid)
 {
-       int keyid, res;
+       int res;
        struct security_priv *psecuritypriv = &padapter->securitypriv;
 
-       keyid = wep->KeyIndex & 0x3fffffff;
-
-       if (keyid >= 4) {
+       if (keyid >= NUM_WEP_KEYS) {
                RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_,
                         ("%s:keyid>4 =>fail\n", __func__));
                res = _FAIL;
                goto exit;
        }
 
-       switch (wep->KeyLength)
-       {
+       switch (wep->keylen) {
        case 5:
                psecuritypriv->dot11PrivacyAlgrthm = WLAN_CIPHER_SUITE_WEP40;
                RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
@@ -1971,14 +1968,10 @@ static int rtw_cfg80211_add_wep(struct rtw_adapter *padapter,
        }
 
        RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
-                ("%s:before memcpy, wep->KeyLength = 0x%x "
-                 "wep->KeyIndex = 0x%x  keyid =%x\n", __func__,
-                 wep->KeyLength, wep->KeyIndex, keyid));
-
-       memcpy(&psecuritypriv->wep_key[keyid].key, &wep->KeyMaterial,
-              wep->KeyLength);
+                ("%s:before memcpy, wep->KeyLength = 0x%x keyid =%x\n",
+                 __func__, wep->keylen, keyid));
 
-       psecuritypriv->wep_key[keyid].keylen = wep->KeyLength;
+       memcpy(&psecuritypriv->wep_key[keyid], wep, sizeof(struct rtw_wep_key));
 
        psecuritypriv->dot11PrivacyKeyIndex = keyid;
 
@@ -2176,57 +2169,43 @@ static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
        if ((psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_Shared ||
             psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_Auto) &&
            sme->key) {
-               u32 wep_key_idx, wep_key_len, wep_total_len;
-               struct ndis_802_11_wep *pwep = NULL;
+               struct rtw_wep_key wep_key;
+               u8 wep_key_idx, wep_key_len;
                DBG_8723A("%s(): Shared/Auto WEP\n", __func__);
 
                wep_key_idx = sme->key_idx;
                wep_key_len = sme->key_len;
 
-               if (sme->key_idx > WEP_KEYS) {
+               if (wep_key_idx > WEP_KEYS || !wep_key_len ||
+                   wep_key_len > WLAN_KEY_LEN_WEP104) {
                        ret = -EINVAL;
                        goto exit;
                }
 
-               if (wep_key_len > 0) {
-                       wep_key_len = wep_key_len <= 5 ? 5 : 13;
-                       wep_total_len =
-                               wep_key_len +
-                               offsetof(struct ndis_802_11_wep, KeyMaterial);
-                       pwep = (struct ndis_802_11_wep *)kmalloc(wep_total_len,
-                                                                GFP_KERNEL);
-                       if (pwep == NULL) {
-                               DBG_8723A(" wpa_set_encryption: pwep "
-                                         "allocate fail !!!\n");
-                               ret = -ENOMEM;
-                               goto exit;
-                       }
+               wep_key_len = wep_key_len <= 5 ? 5 : 13;
 
-                       memset(pwep, 0, wep_total_len);
+               memset(&wep_key, 0, sizeof(struct rtw_wep_key));
 
-                       pwep->KeyLength = wep_key_len;
-                       pwep->Length = wep_total_len;
+               wep_key.keylen = wep_key_len;
 
-                       if (wep_key_len == 13) {
-                               padapter->securitypriv.dot11PrivacyAlgrthm =
-                                   WLAN_CIPHER_SUITE_WEP104;
-                               padapter->securitypriv.dot118021XGrpPrivacy =
-                                   WLAN_CIPHER_SUITE_WEP104;
-                       }
+               if (wep_key_len == 13) {
+                       padapter->securitypriv.dot11PrivacyAlgrthm =
+                               WLAN_CIPHER_SUITE_WEP104;
+                       padapter->securitypriv.dot118021XGrpPrivacy =
+                               WLAN_CIPHER_SUITE_WEP104;
                } else {
-                       ret = -EINVAL;
-                       goto exit;
+                       padapter->securitypriv.dot11PrivacyAlgrthm =
+                               WLAN_CIPHER_SUITE_WEP40;
+                       padapter->securitypriv.dot118021XGrpPrivacy =
+                               WLAN_CIPHER_SUITE_WEP40;
                }
 
-               pwep->KeyIndex = wep_key_idx;
-
-               memcpy(pwep->KeyMaterial, (void *)sme->key, pwep->KeyLength);
+               memcpy(wep_key.key, (void *)sme->key, wep_key.keylen);
 
-               if (rtw_cfg80211_add_wep(padapter, pwep) != _SUCCESS)
+               if (rtw_cfg80211_add_wep(padapter, &wep_key, wep_key_idx) !=
+                   _SUCCESS)
                        ret = -EOPNOTSUPP;
 
-               kfree(pwep);
-
                if (ret < 0)
                        goto exit;
        }