[PATCH 3/3] staging: rtl8712: Introduce auth_algorithm macros

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 drivers/staging/rtl8712/mlme_linux.c          |  5 ++--
 drivers/staging/rtl8712/rtl871x_ioctl_linux.c | 25 ++++++++++---------
 drivers/staging/rtl8712/rtl871x_ioctl_set.c   |  3 ++-
 drivers/staging/rtl8712/rtl871x_mlme.c        |  7 +++---
 drivers/staging/rtl8712/rtl871x_security.h    |  5 ++++
 5 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/rtl8712/mlme_linux.c b/drivers/staging/rtl8712/mlme_linux.c
index fa6b0adec746..fcd2e0a9487a 100644
--- a/drivers/staging/rtl8712/mlme_linux.c
+++ b/drivers/staging/rtl8712/mlme_linux.c
@@ -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_;
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
index f832501cc196..832c6c64aa68 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
@@ -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 =
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_set.c b/drivers/staging/rtl8712/rtl871x_ioctl_set.c
index 569d26425250..9ddfe7a1d715 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_set.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_set.c
@@ -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
diff --git a/drivers/staging/rtl8712/rtl871x_mlme.c b/drivers/staging/rtl8712/rtl871x_mlme.c
index 66f9fc51c147..1ca94e90dfe6 100644
--- a/drivers/staging/rtl8712/rtl871x_mlme.c
+++ b/drivers/staging/rtl8712/rtl871x_mlme.c
@@ -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 */
diff --git a/drivers/staging/rtl8712/rtl871x_security.h b/drivers/staging/rtl8712/rtl871x_security.h
index 5727a84838d3..34e5aecf92ae 100644
--- a/drivers/staging/rtl8712/rtl871x_security.h
+++ b/drivers/staging/rtl8712/rtl871x_security.h
@@ -24,6 +24,11 @@
 #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
 
-- 
2.34.1







[Index of Archives]     [Linux Driver Development]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux