Skip to contentSkip to conversation

use is_valid_ether_addr() macro in wireless drivers

PATCH In review Helge Deller 3 participants 4 messages Jan 26, 2008 – Jan 29, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 use is_valid_ether_addr() macro in wireless drivers

use is_valid_ether_addr() macro instead of hand-coded checks for valid IP address.

 airo.c      |    5 +----
 atmel.c     |    5 +----
 ipw2100.c   |   10 +---------
 ipw2200.c   |   10 +---------
 orinoco.c   |    5 +----
 wl3501_cs.c |    3 +--
 6 files changed, 6 insertions(+), 32 deletions(-)
drivers/net/wireless/airo.c +1 -4
index 074055e..714952b 100644
@@ -5977,13 +5977,10 @@ static int airo_set_wap(struct net_device *dev,
 	Cmd cmd;
 	Resp rsp;
 	APListRid APList_rid;
-	static const u8 any[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
-	static const u8 off[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
 
 	if (awrq->sa_family != ARPHRD_ETHER)
 		return -EINVAL;
-	else if (!memcmp(any, awrq->sa_data, ETH_ALEN) ||
-	         !memcmp(off, awrq->sa_data, ETH_ALEN)) {
+	else if (!is_valid_ether_addr(awrq->sa_data)) {
 		memset(&cmd, 0, sizeof(cmd));
 		cmd.cmd=CMD_LOSE_SYNC;
 		if (down_interruptible(&local->sem))
drivers/net/wireless/atmel.c +1 -4
index 059ce3f..6b7a6a3 100644
@@ -2440,15 +2440,12 @@ static int atmel_set_wap(struct net_device *dev,
 {
 	struct atmel_private *priv = netdev_priv(dev);
 	int i;
-	static const u8 any[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
-	static const u8 off[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
 	unsigned long flags;
 
 	if (awrq->sa_family != ARPHRD_ETHER)
 		return -EINVAL;
 
-	if (!memcmp(any, awrq->sa_data, 6) ||
-	    !memcmp(off, awrq->sa_data, 6)) {
+	if (!is_valid_ether_addr(awrq->sa_data)) {
 		del_timer_sync(&priv->management_timer);
 		spin_lock_irqsave(&priv->irqlock, flags);
 		atmel_scan(priv, 1);
drivers/net/wireless/ipw2100.c +1 -9
index fc6cdd8..9a7ff0d 100644
@@ -6897,13 +6897,6 @@ static int ipw2100_wx_set_wap(struct net_device *dev,
 {
 	struct ipw2100_priv *priv = ieee80211_priv(dev);
 	int err = 0;
-
-	static const unsigned char any[] = {
-		0xff, 0xff, 0xff, 0xff, 0xff, 0xff
-	};
-	static const unsigned char off[] = {
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-	};
 	DECLARE_MAC_BUF(mac);
 
 	// sanity checks
@@ -6916,8 +6909,7 @@ static int ipw2100_wx_set_wap(struct net_device *dev,
 		goto done;
 	}
 
-	if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
-	    !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
+	if (!is_valid_ether_addr(wrqu->ap_addr.sa_data)) {
 		/* we disable mandatory BSSID association */
 		IPW_DEBUG_WX("exit - disable mandatory BSSID\n");
 		priv->config &= ~CFG_STATIC_BSSID;
drivers/net/wireless/ipw2200.c +1 -9
index 003f73f..686fe6a 100644
@@ -8923,18 +8923,10 @@ static int ipw_wx_set_wap(struct net_device *dev,
 	struct ipw_priv *priv = ieee80211_priv(dev);
 	DECLARE_MAC_BUF(mac);
 
-	static const unsigned char any[] = {
-		0xff, 0xff, 0xff, 0xff, 0xff, 0xff
-	};
-	static const unsigned char off[] = {
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-	};
-
 	if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
 		return -EINVAL;
 	mutex_lock(&priv->mutex);
-	if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
-	    !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
+	if (!is_valid_ether_addr(wrqu->ap_addr.sa_data)) {
 		/* we disable mandatory BSSID association */
 		IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
 		priv->config &= ~CFG_STATIC_BSSID;
drivers/net/wireless/orinoco.c +1 -4
index ca6c2da..890baaf 100644
@@ -2614,15 +2614,12 @@ static int orinoco_ioctl_setwap(struct net_device *dev,
 	struct orinoco_private *priv = netdev_priv(dev);
 	int err = -EINPROGRESS;		/* Call commit handler */
 	unsigned long flags;
-	static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-	static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 
 	if (orinoco_lock(priv, &flags) != 0)
 		return -EBUSY;
 
 	/* Enable automatic roaming - no sanity checks are needed */
-	if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
-	    memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
+	if (!is_valid_ether_addr(ap_addr->sa_data)) {
 		priv->bssid_fixed = 0;
 		memset(priv->desired_bssid, 0, ETH_ALEN);
 
drivers/net/wireless/wl3501_cs.c +1 -2
index 42a36b3..7251e71 100644
@@ -1577,13 +1577,12 @@ static int wl3501_set_wap(struct net_device *dev, struct iw_request_info *info,
 			  union iwreq_data *wrqu, char *extra)
 {
 	struct wl3501_card *this = netdev_priv(dev);
-	static const u8 bcast[ETH_ALEN] = { 255, 255, 255, 255, 255, 255 };
 	int rc = -EINVAL;
 
 	/* FIXME: we support other ARPHRDs...*/
 	if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
 		goto out;
-	if (!memcmp(bcast, wrqu->ap_addr.sa_data, ETH_ALEN)) {
+	if (!is_valid_ether_addr(wrqu->ap_addr.sa_data)) {
 		/* FIXME: rescan? */
 	} else
 		memcpy(this->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
#1 lore raw
Quoted 13 lines · On Saturday 26 January 2008 22:38:18 Helge Deller wrote:

use is_valid_ether_addr() macro instead of hand-coded checks for valid IP address.

drivers/net/wireless/wl3501_cs.c +0 -1
index 42a36b3..7251e71 100644
@@ -1577,13 +1577,12 @@ static int wl3501_set_wap(struct net_device *dev, struct iw_request_info *info,
 			  union iwreq_data *wrqu, char *extra)
 {
 	struct wl3501_card *this = netdev_priv(dev);
-	static const u8 bcast[ETH_ALEN] = { 255, 255, 255, 255, 255, 255 };

drivers/net/wireless/wl3501_cs.c static int wl3501_set_wap(struct net_device *dev, struct iw_request_info *info, · line 1588

Quoted 10 lines
drivers/net/wireless/wl3501_cs.c +1 -1
 	int rc = -EINVAL;
 
 	/* FIXME: we support other ARPHRDs...*/
 	if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
 		goto out;
-	if (!memcmp(bcast, wrqu->ap_addr.sa_data, ETH_ALEN)) {
+	if (!is_valid_ether_addr(wrqu->ap_addr.sa_data)) {
 		/* FIXME: rescan? */
 	} else
 		memcpy(this->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);

This is a semantical change.
If the original code is correct, this should be is_broadcast_ether_addr()

Signature · 1 line
Greetings Michael.
#2 lore raw
Quoted 16 lines · Michael Buesch
Quoted 15 lines · On Saturday 26 January 2008 22:38:18 Helge Deller wrote:

use is_valid_ether_addr() macro instead of hand-coded checks for valid IP address.

drivers/net/wireless/wl3501_cs.c +0 -1
index 42a36b3..7251e71 100644
@@ -1577,13 +1577,12 @@ static int wl3501_set_wap(struct net_device *dev, struct iw_request_info *info,
 			  union iwreq_data *wrqu, char *extra)
 {
 	struct wl3501_card *this = netdev_priv(dev);
-	static const u8 bcast[ETH_ALEN] = { 255, 255, 255, 255, 255, 255 };
 	int rc = -EINVAL;
 
Quoted 11 lines

drivers/net/wireless/wl3501_cs.c static int wl3501_set_wap(struct net_device *dev, struct iw_request_info *info, · line 1588

Quoted 8 lines
drivers/net/wireless/wl3501_cs.c +1 -1
 	/* FIXME: we support other ARPHRDs...*/
 	if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
 		goto out;
-	if (!memcmp(bcast, wrqu->ap_addr.sa_data, ETH_ALEN)) {
+	if (!is_valid_ether_addr(wrqu->ap_addr.sa_data)) {
 		/* FIXME: rescan? */
 	} else
 		memcpy(this->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);

This is a semantical change.
If the original code is correct, this should be is_broadcast_ether_addr()

Yes, but the original code is probably wrong.
So I think my patch fixes a bug here as well.

Helge

maintainer
#3 lore raw
In reply to Helge Deller
Quoted 2 lines · Helge Deller

use is_valid_ether_addr() macro instead of hand-coded checks for valid IP address.

Ahem. IP addresses? In any case, this patch is totally bogus, these are not checks for invalid MAC addresses but rather a check for the special any/off addresses. Please read the iwconfig man page.

drivers/net/wireless/airo.c static int airo_set_wap(struct net_device *dev, · line 5983

Quoted 3 lines
drivers/net/wireless/airo.c +1 -2
-	else if (!memcmp(any, awrq->sa_data, ETH_ALEN) ||
-	         !memcmp(off, awrq->sa_data, ETH_ALEN)) {
+	else if (!is_valid_ether_addr(awrq->sa_data)) {

NACK anyway. These adresses ("any", "off") are actually special for wext, this has nothing to do whether they are invalid or not.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
drivers/net/wireless/wl3501_cs.c +1 -1
-   if (!memcmp(bcast, wrqu->ap_addr.sa_data, ETH_ALEN)) {
+   if (!is_valid_ether_addr(wrqu->ap_addr.sa_data)) {
            /* FIXME: rescan? */
    } else
            memcpy(this->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
Quoted 6 lines
Quoted 2 lines

This is a semantical change.
If the original code is correct, this should be

is_broadcast_ether_addr()

Yes, but the original code is probably wrong.
So I think my patch fixes a bug here as well.

Not at all. Yes, it is unfortunate that drivers have to have this knowledge about wext internals, but that's how wext is designed.

johannes