Commit 0ca6d8e7 authored by Claudiu Beznea's avatar Claudiu Beznea Committed by Greg Kroah-Hartman

Staging: wlan-ng: replace switch-case statements with macro

This patch removes multiple switch-case statements
with a new macro. The macro will generate the
corresponding bit mask based on the key index
received as input.

Chances since v1:
Corrected patch title
Signed-off-by: default avatarClaudiu Beznea <claudiu.beznea@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2f479125
...@@ -150,6 +150,9 @@ static int prism2_add_key(struct wiphy *wiphy, struct net_device *dev, ...@@ -150,6 +150,9 @@ static int prism2_add_key(struct wiphy *wiphy, struct net_device *dev,
int err = 0; int err = 0;
int result = 0; int result = 0;
if (key_index >= NUM_WEPKEYS)
return -EINVAL;
switch (params->cipher) { switch (params->cipher) {
case WLAN_CIPHER_SUITE_WEP40: case WLAN_CIPHER_SUITE_WEP40:
case WLAN_CIPHER_SUITE_WEP104: case WLAN_CIPHER_SUITE_WEP104:
...@@ -160,27 +163,7 @@ static int prism2_add_key(struct wiphy *wiphy, struct net_device *dev, ...@@ -160,27 +163,7 @@ static int prism2_add_key(struct wiphy *wiphy, struct net_device *dev,
goto exit; goto exit;
/* send key to driver */ /* send key to driver */
switch (key_index) { did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(key_index + 1);
case 0:
did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0;
break;
case 1:
did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1;
break;
case 2:
did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2;
break;
case 3:
did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3;
break;
default:
err = -EINVAL;
goto exit;
}
result = prism2_domibset_pstr32(wlandev, did, result = prism2_domibset_pstr32(wlandev, did,
params->key_len, params->key); params->key_len, params->key);
...@@ -242,36 +225,13 @@ static int prism2_del_key(struct wiphy *wiphy, struct net_device *dev, ...@@ -242,36 +225,13 @@ static int prism2_del_key(struct wiphy *wiphy, struct net_device *dev,
* a key, so we will cheat by setting the key to a bogus value * a key, so we will cheat by setting the key to a bogus value
*/ */
/* send key to driver */ if (key_index >= NUM_WEPKEYS)
switch (key_index) { return -EINVAL;
case 0:
did =
DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0;
break;
case 1:
did =
DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1;
break;
case 2:
did =
DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2;
break;
case 3:
did =
DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3;
break;
default:
err = -EINVAL;
goto exit;
}
/* send key to driver */
did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(key_index + 1);
result = prism2_domibset_pstr32(wlandev, did, 13, "0000000000000"); result = prism2_domibset_pstr32(wlandev, did, 13, "0000000000000");
exit:
if (result) if (result)
err = -EFAULT; err = -EFAULT;
...@@ -529,6 +489,11 @@ static int prism2_connect(struct wiphy *wiphy, struct net_device *dev, ...@@ -529,6 +489,11 @@ static int prism2_connect(struct wiphy *wiphy, struct net_device *dev,
/* Set the encryption - we only support wep */ /* Set the encryption - we only support wep */
if (is_wep) { if (is_wep) {
if (sme->key) { if (sme->key) {
if (sme->key_idx >= NUM_WEPKEYS) {
err = -EINVAL;
goto exit;
}
result = prism2_domibset_uint32(wlandev, result = prism2_domibset_uint32(wlandev,
DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID, DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID,
sme->key_idx); sme->key_idx);
...@@ -536,28 +501,8 @@ static int prism2_connect(struct wiphy *wiphy, struct net_device *dev, ...@@ -536,28 +501,8 @@ static int prism2_connect(struct wiphy *wiphy, struct net_device *dev,
goto exit; goto exit;
/* send key to driver */ /* send key to driver */
switch (sme->key_idx) { did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(
case 0: sme->key_idx + 1);
did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0;
break;
case 1:
did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1;
break;
case 2:
did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2;
break;
case 3:
did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3;
break;
default:
err = -EINVAL;
goto exit;
}
result = prism2_domibset_pstr32(wlandev, result = prism2_domibset_pstr32(wlandev,
did, sme->key_len, did, sme->key_len,
(u8 *)sme->key); (u8 *)sme->key);
......
...@@ -171,6 +171,10 @@ ...@@ -171,6 +171,10 @@
(P80211DID_MKSECTION(1) | \ (P80211DID_MKSECTION(1) | \
P80211DID_MKGROUP(4) | \ P80211DID_MKGROUP(4) | \
P80211DID_MKITEM(4) | 0x0c000000) P80211DID_MKITEM(4) | 0x0c000000)
#define DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(_i) \
(P80211DID_MKSECTION(1) | \
P80211DID_MKGROUP(4) | \
P80211DID_MKITEM(_i) | 0x0c000000)
#define DIDmib_dot11smt_dot11PrivacyTable \ #define DIDmib_dot11smt_dot11PrivacyTable \
(P80211DID_MKSECTION(1) | \ (P80211DID_MKSECTION(1) | \
P80211DID_MKGROUP(6)) P80211DID_MKGROUP(6))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment