]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
staging: rtl8712: Introduce auth_algorithm macros
authorDominik Karol Piątkowski <dominik.karol.piatkowski@protonmail.com>
Sat, 12 Oct 2024 16:17:55 +0000 (16:17 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 13 Oct 2024 13:48:53 +0000 (15:48 +0200)
Currently, auth_algorithm is assigned/compared to using hardcoded
numbers. Some of the lines are commented, some of them are not.

This patch introduces macros that replace numeric assignments and
comparisons of auth_algorithm, increasing readability.

Signed-off-by: Dominik Karol Piątkowski <dominik.karol.piatkowski@protonmail.com>
Tested-by:
Link: https://lore.kernel.org/r/20241012161638.67030-4-dominik.karol.piatkowski@protonmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/rtl8712/mlme_linux.c
drivers/staging/rtl8712/rtl871x_ioctl_linux.c
drivers/staging/rtl8712/rtl871x_ioctl_set.c
drivers/staging/rtl8712/rtl871x_mlme.c
drivers/staging/rtl8712/rtl871x_security.h

index fa6b0adec746916d0385a2592ae973a42efdf8cc..fcd2e0a9487a3be67074e309e7ae6a71aa6fddb0 100644 (file)
@@ -19,6 +19,7 @@
 #include "osdep_service.h"
 #include "drv_types.h"
 #include "mlme_osdep.h"
+#include "rtl871x_security.h"
 
 static void sitesurvey_ctrl_handler(struct timer_list *t)
 {
@@ -92,7 +93,7 @@ void r8712_os_indicate_disconnect(struct _adapter *adapter)
 
        r8712_indicate_wx_disassoc_event(adapter);
        netif_carrier_off(adapter->pnetdev);
-       if (adapter->securitypriv.auth_algorithm == 2) { /*/802.1x*/
+       if (adapter->securitypriv.auth_algorithm == _AUTH_8021x_) {
                /* We have to backup the PMK information for WiFi PMK Caching
                 * test item. Backup the btkip_countermeasure information.
                 * When the countermeasure is trigger, the driver have to
@@ -121,7 +122,7 @@ void r8712_os_indicate_disconnect(struct _adapter *adapter)
        } else { /*reset values in securitypriv*/
                struct security_priv *sec_priv = &adapter->securitypriv;
 
-               sec_priv->auth_algorithm = 0; /*open system*/
+               sec_priv->auth_algorithm = _AUTH_OPEN_SYSTEM_;
                sec_priv->privacy_algorithm = _NO_PRIVACY_;
                sec_priv->PrivacyKeyIndex = 0;
                sec_priv->XGrpPrivacy = _NO_PRIVACY_;
index f832501cc196cf7c2b380dc0e8313f34e95b25df..832c6c64aa68cb23da939ba4fb7fd70b1f163e25 100644 (file)
@@ -26,6 +26,7 @@
 #include "rtl871x_ioctl.h"
 #include "rtl871x_ioctl_set.h"
 #include "rtl871x_mp_ioctl.h"
+#include "rtl871x_security.h"
 #include "mlme_osdep.h"
 #include <linux/wireless.h>
 #include <linux/module.h>
@@ -325,18 +326,18 @@ static int wpa_set_auth_algs(struct net_device *dev, u32 value)
                                                 Ndis802_11Encryption1Enabled;
                padapter->securitypriv.ndisauthtype =
                                                 Ndis802_11AuthModeAutoSwitch;
-               padapter->securitypriv.auth_algorithm = 3;
+               padapter->securitypriv.auth_algorithm = _AUTH_AUTHSWITCH_;
        } else if (value & AUTH_ALG_SHARED_KEY) {
                padapter->securitypriv.ndisencryptstatus =
                                                 Ndis802_11Encryption1Enabled;
                padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeShared;
-               padapter->securitypriv.auth_algorithm = 1;
+               padapter->securitypriv.auth_algorithm = _AUTH_SHARED_SYSTEM_;
        } else if (value & AUTH_ALG_OPEN_SYSTEM) {
                if (padapter->securitypriv.ndisauthtype <
                                                 Ndis802_11AuthModeWPAPSK) {
                        padapter->securitypriv.ndisauthtype =
                                                 Ndis802_11AuthModeOpen;
-                       padapter->securitypriv.auth_algorithm = 0;
+                       padapter->securitypriv.auth_algorithm = _AUTH_OPEN_SYSTEM_;
                }
        } else {
                ret = -EINVAL;
@@ -414,7 +415,7 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
                }
                goto exit;
        }
-       if (padapter->securitypriv.auth_algorithm == 2) { /* 802_1x */
+       if (padapter->securitypriv.auth_algorithm == _AUTH_8021x_) {
                struct sta_info *psta, *pbcmc_sta;
                struct sta_priv *pstapriv = &padapter->stapriv;
                struct security_priv *spriv = &padapter->securitypriv;
@@ -472,13 +473,13 @@ static int r871x_set_wpa_ie(struct _adapter *padapter, char *pie,
                }
                if (r8712_parse_wpa_ie(buf, ielen, &group_cipher,
                                       &pairwise_cipher) == 0) {
-                       padapter->securitypriv.auth_algorithm = 2;
+                       padapter->securitypriv.auth_algorithm = _AUTH_8021x_;
                        padapter->securitypriv.ndisauthtype =
                                  Ndis802_11AuthModeWPAPSK;
                }
                if (r8712_parse_wpa2_ie(buf, ielen, &group_cipher,
                                        &pairwise_cipher) == 0) {
-                       padapter->securitypriv.auth_algorithm = 2;
+                       padapter->securitypriv.auth_algorithm = _AUTH_8021x_;
                        padapter->securitypriv.ndisauthtype =
                                  Ndis802_11AuthModeWPA2PSK;
                }
@@ -1450,7 +1451,7 @@ static int r8711_wx_set_enc(struct net_device *dev,
                                 Ndis802_11EncryptionDisabled;
                padapter->securitypriv.privacy_algorithm = _NO_PRIVACY_;
                padapter->securitypriv.XGrpPrivacy = _NO_PRIVACY_;
-               padapter->securitypriv.auth_algorithm = 0; /* open system */
+               padapter->securitypriv.auth_algorithm = _AUTH_OPEN_SYSTEM_;
                authmode = Ndis802_11AuthModeOpen;
                padapter->securitypriv.ndisauthtype = authmode;
                return 0;
@@ -1469,7 +1470,7 @@ static int r8711_wx_set_enc(struct net_device *dev,
                netdev_info(dev, "r8712u: %s: IW_ENCODE_OPEN\n", __func__);
                padapter->securitypriv.ndisencryptstatus =
                                 Ndis802_11Encryption1Enabled;
-               padapter->securitypriv.auth_algorithm = 0; /* open system */
+               padapter->securitypriv.auth_algorithm = _AUTH_OPEN_SYSTEM_;
                padapter->securitypriv.privacy_algorithm = _NO_PRIVACY_;
                padapter->securitypriv.XGrpPrivacy = _NO_PRIVACY_;
                authmode = Ndis802_11AuthModeOpen;
@@ -1479,7 +1480,7 @@ static int r8711_wx_set_enc(struct net_device *dev,
                                "r8712u: %s: IW_ENCODE_RESTRICTED\n", __func__);
                padapter->securitypriv.ndisencryptstatus =
                                 Ndis802_11Encryption1Enabled;
-               padapter->securitypriv.auth_algorithm = 1; /* shared system */
+               padapter->securitypriv.auth_algorithm = _AUTH_SHARED_SYSTEM_;
                padapter->securitypriv.privacy_algorithm = _WEP40_;
                padapter->securitypriv.XGrpPrivacy = _WEP40_;
                authmode = Ndis802_11AuthModeShared;
@@ -1487,7 +1488,7 @@ static int r8711_wx_set_enc(struct net_device *dev,
        } else {
                padapter->securitypriv.ndisencryptstatus =
                                 Ndis802_11Encryption1Enabled;
-               padapter->securitypriv.auth_algorithm = 0; /* open system */
+               padapter->securitypriv.auth_algorithm = _AUTH_OPEN_SYSTEM_;
                padapter->securitypriv.privacy_algorithm = _NO_PRIVACY_;
                padapter->securitypriv.XGrpPrivacy = _NO_PRIVACY_;
                authmode = Ndis802_11AuthModeOpen;
@@ -1672,7 +1673,7 @@ static int r871x_wx_set_auth(struct net_device *dev,
                                  _NO_PRIVACY_;
                        padapter->securitypriv.XGrpPrivacy =
                                  _NO_PRIVACY_;
-                       padapter->securitypriv.auth_algorithm = 0;
+                       padapter->securitypriv.auth_algorithm = _AUTH_OPEN_SYSTEM_;
                        padapter->securitypriv.ndisauthtype =
                                  Ndis802_11AuthModeOpen;
                }
@@ -2017,7 +2018,7 @@ static int wpa_set_param(struct net_device *dev, u8 name, u32 value)
 
        switch (name) {
        case IEEE_PARAM_WPA_ENABLED:
-               padapter->securitypriv.auth_algorithm = 2; /* 802.1x */
+               padapter->securitypriv.auth_algorithm = _AUTH_8021x_;
                switch ((value) & 0xff) {
                case 1: /* WPA */
                        padapter->securitypriv.ndisauthtype =
index 569d264252505880eb7489042c151e33fc4483f1..9ddfe7a1d71598abd4e0bb6644fae1714416146c 100644 (file)
@@ -19,6 +19,7 @@
 #include "osdep_service.h"
 #include "drv_types.h"
 #include "rtl871x_ioctl_set.h"
+#include "rtl871x_security.h"
 #include "usb_osintf.h"
 #include "usb_ops.h"
 
@@ -318,7 +319,7 @@ u8 r8712_set_802_11_authentication_mode(struct _adapter *padapter,
 
        psecuritypriv->ndisauthtype = authmode;
        if (psecuritypriv->ndisauthtype > 3)
-               psecuritypriv->auth_algorithm = 2; /* 802.1x */
+               psecuritypriv->auth_algorithm = _AUTH_8021x_;
        if (r8712_set_auth(padapter, psecuritypriv))
                ret = false;
        else
index 66f9fc51c147215563975309ff8e31b83da7d7c3..1ca94e90dfe6942ea836ec5de687b347f3b789ca 100644 (file)
@@ -23,6 +23,7 @@
 #include "recv_osdep.h"
 #include "xmit_osdep.h"
 #include "mlme_osdep.h"
+#include "rtl871x_security.h"
 #include "sta_info.h"
 #include "wifi.h"
 #include "wlan_bssdef.h"
@@ -768,7 +769,7 @@ void r8712_joinbss_event_callback(struct _adapter *adapter, u8 *pbuf)
                                        ptarget_sta->aid = pnetwork->join_res;
                                        ptarget_sta->qos_option = 1;
                                        ptarget_sta->mac_id = 5;
-                                       if (adapter->securitypriv.auth_algorithm == 2) {
+                                       if (adapter->securitypriv.auth_algorithm == _AUTH_8021x_) {
                                                adapter->securitypriv.binstallGrpkey = false;
                                                adapter->securitypriv.busetkipkey = false;
                                                adapter->securitypriv.bgrpkey_handshake = false;
@@ -869,7 +870,7 @@ void r8712_stassoc_event_callback(struct _adapter *adapter, u8 *pbuf)
        psta->mac_id = le32_to_cpu(pstassoc->cam_id);
        /* psta->aid = (uint)pstassoc->cam_id; */
 
-       if (adapter->securitypriv.auth_algorithm == 2)
+       if (adapter->securitypriv.auth_algorithm == _AUTH_8021x_)
                psta->XPrivacy = adapter->securitypriv.privacy_algorithm;
        psta->ieee8021x_blocked = false;
        spin_lock_irqsave(&pmlmepriv->lock, irqL);
@@ -1160,7 +1161,7 @@ int r8712_set_key(struct _adapter *adapter,
                ret = -ENOMEM;
                goto err_free_cmd;
        }
-       if (psecuritypriv->auth_algorithm == 2) { /* 802.1X */
+       if (psecuritypriv->auth_algorithm == _AUTH_8021x_) {
                psetkeyparm->algorithm =
                         (u8)psecuritypriv->XGrpPrivacy;
        } else { /* WEP */
index 5727a84838d32326d56aa964ed09f81648c14c54..34e5aecf92ae99064caef7b3c475ed81a3a982e8 100644 (file)
 #define _AES_          0x4
 #define _WEP104_       0x5
 
+#define _AUTH_OPEN_SYSTEM_     0x0
+#define _AUTH_SHARED_SYSTEM_   0x1
+#define _AUTH_8021x_           0x2
+#define _AUTH_AUTHSWITCH_      0x3
+
 #define _WPA_IE_ID_    0xdd
 #define _WPA2_IE_ID_   0x30