Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 138c0c68 authored by Dan Williams's avatar Dan Williams Committed by John W. Linville
Browse files

airo: simplify WEP index and capability checks



Do the computation once at init time; don't ask the hardware
every time.

Signed-off-by: default avatarDan Williams <dcbw@redhat.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent f65b56d6
Loading
Loading
Loading
Loading
+27 −32
Original line number Original line Diff line number Diff line
@@ -1233,6 +1233,9 @@ struct airo_info {
#define	PCI_SHARED_LEN		2*MPI_MAX_FIDS*PKTSIZE+RIDSIZE
#define	PCI_SHARED_LEN		2*MPI_MAX_FIDS*PKTSIZE+RIDSIZE
	char			proc_name[IFNAMSIZ];
	char			proc_name[IFNAMSIZ];


	int			wep_capable;
	int			max_wep_idx;

	/* WPA-related stuff */
	/* WPA-related stuff */
	unsigned int bssListFirst;
	unsigned int bssListFirst;
	unsigned int bssListNext;
	unsigned int bssListNext;
@@ -2836,6 +2839,9 @@ static struct net_device *_init_airo_card( unsigned short irq, int port,
		rc = -EIO;
		rc = -EIO;
		goto err_out_wifi;
		goto err_out_wifi;
	}
	}
	/* WEP capability discovery */
	ai->wep_capable = (cap_rid.softCap & cpu_to_le16(0x02)) ? 1 : 0;
	ai->max_wep_idx = (cap_rid.softCap & cpu_to_le16(0x80)) ? 3 : 0;


	airo_print_info(dev->name, "Firmware version %x.%x.%02x",
	airo_print_info(dev->name, "Firmware version %x.%x.%02x",
	                ((le16_to_cpu(cap_rid.softVer) >> 8) & 0xF),
	                ((le16_to_cpu(cap_rid.softVer) >> 8) & 0xF),
@@ -6265,11 +6271,9 @@ static int airo_get_mode(struct net_device *dev,
	return 0;
	return 0;
}
}


static inline int valid_index(CapabilityRid *p, int index)
static inline int valid_index(struct airo_info *ai, int index)
{
{
	if (index < 0)
	return (index >= 0) && (index <= ai->max_wep_idx);
		return 0;
	return index < (p->softCap & cpu_to_le16(0x80) ? 4 : 1);
}
}


/*------------------------------------------------------------------*/
/*------------------------------------------------------------------*/
@@ -6282,16 +6286,12 @@ static int airo_set_encode(struct net_device *dev,
			   char *extra)
			   char *extra)
{
{
	struct airo_info *local = dev->ml_priv;
	struct airo_info *local = dev->ml_priv;
	CapabilityRid cap_rid;		/* Card capability info */
	int perm = ( dwrq->flags & IW_ENCODE_TEMP ? 0 : 1 );
	int perm = ( dwrq->flags & IW_ENCODE_TEMP ? 0 : 1 );
	__le16 currentAuthType = local->config.authType;
	__le16 currentAuthType = local->config.authType;


	/* Is WEP supported ? */
	if (!local->wep_capable)
	readCapabilityRid(local, &cap_rid, 1);
	/* Older firmware doesn't support this...
	if(!(cap_rid.softCap & cpu_to_le16(2))) {
		return -EOPNOTSUPP;
		return -EOPNOTSUPP;
	} */

	readConfigRid(local, 1);
	readConfigRid(local, 1);


	/* Basic checking: do we have a key to set ?
	/* Basic checking: do we have a key to set ?
@@ -6304,13 +6304,16 @@ static int airo_set_encode(struct net_device *dev,
		wep_key_t key;
		wep_key_t key;
		int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
		int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
		int current_index = get_wep_key(local, 0xffff);
		int current_index = get_wep_key(local, 0xffff);

		/* Check the size of the key */
		/* Check the size of the key */
		if (dwrq->length > MAX_KEY_SIZE) {
		if (dwrq->length > MAX_KEY_SIZE) {
			return -EINVAL;
			return -EINVAL;
		}
		}

		/* Check the index (none -> use current) */
		/* Check the index (none -> use current) */
		if (!valid_index(&cap_rid, index))
		if (!valid_index(local, index))
			index = current_index;
			index = current_index;

		/* Set the length */
		/* Set the length */
		if (dwrq->length > MIN_KEY_SIZE)
		if (dwrq->length > MIN_KEY_SIZE)
			key.len = MAX_KEY_SIZE;
			key.len = MAX_KEY_SIZE;
@@ -6339,13 +6342,14 @@ static int airo_set_encode(struct net_device *dev,
	} else {
	} else {
		/* Do we want to just set the transmit key index ? */
		/* Do we want to just set the transmit key index ? */
		int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
		int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
		if (valid_index(&cap_rid, index)) {
		if (valid_index(local, index))
			set_wep_key(local, index, NULL, 0, perm, 1);
			set_wep_key(local, index, NULL, 0, perm, 1);
		} else
		else {
			/* Don't complain if only change the mode */
			/* Don't complain if only change the mode */
			if (!(dwrq->flags & IW_ENCODE_MODE))
			if (!(dwrq->flags & IW_ENCODE_MODE))
				return -EINVAL;
				return -EINVAL;
		}
		}
	}
	/* Read the flags */
	/* Read the flags */
	if(dwrq->flags & IW_ENCODE_DISABLED)
	if(dwrq->flags & IW_ENCODE_DISABLED)
		local->config.authType = AUTH_OPEN;	// disable encryption
		local->config.authType = AUTH_OPEN;	// disable encryption
@@ -6370,14 +6374,12 @@ static int airo_get_encode(struct net_device *dev,
{
{
	struct airo_info *local = dev->ml_priv;
	struct airo_info *local = dev->ml_priv;
	int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
	int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
	CapabilityRid cap_rid;		/* Card capability info */


	/* Is it supported ? */
	if (!local->wep_capable)
	readCapabilityRid(local, &cap_rid, 1);
	if(!(cap_rid.softCap & cpu_to_le16(2))) {
		return -EOPNOTSUPP;
		return -EOPNOTSUPP;
	}

	readConfigRid(local, 1);
	readConfigRid(local, 1);

	/* Check encryption mode */
	/* Check encryption mode */
	switch(local->config.authType)	{
	switch(local->config.authType)	{
		case AUTH_ENCRYPT:
		case AUTH_ENCRYPT:
@@ -6396,7 +6398,7 @@ static int airo_get_encode(struct net_device *dev,
	memset(extra, 0, 16);
	memset(extra, 0, 16);


	/* Which key do we want ? -1 -> tx index */
	/* Which key do we want ? -1 -> tx index */
	if (!valid_index(&cap_rid, index))
	if (!valid_index(local, index))
		index = get_wep_key(local, 0xffff);
		index = get_wep_key(local, 0xffff);
	dwrq->flags |= index + 1;
	dwrq->flags |= index + 1;
	/* Copy the key to the user buffer */
	/* Copy the key to the user buffer */
@@ -6419,24 +6421,20 @@ static int airo_set_encodeext(struct net_device *dev,
	struct airo_info *local = dev->ml_priv;
	struct airo_info *local = dev->ml_priv;
	struct iw_point *encoding = &wrqu->encoding;
	struct iw_point *encoding = &wrqu->encoding;
	struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
	struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
	CapabilityRid cap_rid;		/* Card capability info */
	int perm = ( encoding->flags & IW_ENCODE_TEMP ? 0 : 1 );
	int perm = ( encoding->flags & IW_ENCODE_TEMP ? 0 : 1 );
	__le16 currentAuthType = local->config.authType;
	__le16 currentAuthType = local->config.authType;
	int idx, key_len, alg = ext->alg, set_key = 1;
	int idx, key_len, alg = ext->alg, set_key = 1;
	wep_key_t key;
	wep_key_t key;


	/* Is WEP supported ? */
	if (!local->wep_capable)
	readCapabilityRid(local, &cap_rid, 1);
	/* Older firmware doesn't support this...
	if(!(cap_rid.softCap & cpu_to_le16(2))) {
		return -EOPNOTSUPP;
		return -EOPNOTSUPP;
	} */

	readConfigRid(local, 1);
	readConfigRid(local, 1);


	/* Determine and validate the key index */
	/* Determine and validate the key index */
	idx = encoding->flags & IW_ENCODE_INDEX;
	idx = encoding->flags & IW_ENCODE_INDEX;
	if (idx) {
	if (idx) {
		if (!valid_index(&cap_rid, idx - 1))
		if (!valid_index(local, idx - 1))
			return -EINVAL;
			return -EINVAL;
		idx--;
		idx--;
	} else
	} else
@@ -6505,14 +6503,11 @@ static int airo_get_encodeext(struct net_device *dev,
	struct airo_info *local = dev->ml_priv;
	struct airo_info *local = dev->ml_priv;
	struct iw_point *encoding = &wrqu->encoding;
	struct iw_point *encoding = &wrqu->encoding;
	struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
	struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
	CapabilityRid cap_rid;		/* Card capability info */
	int idx, max_key_len;
	int idx, max_key_len;


	/* Is it supported ? */
	if (!local->wep_capable)
	readCapabilityRid(local, &cap_rid, 1);
	if(!(cap_rid.softCap & cpu_to_le16(2))) {
		return -EOPNOTSUPP;
		return -EOPNOTSUPP;
	}

	readConfigRid(local, 1);
	readConfigRid(local, 1);


	max_key_len = encoding->length - sizeof(*ext);
	max_key_len = encoding->length - sizeof(*ext);
@@ -6521,7 +6516,7 @@ static int airo_get_encodeext(struct net_device *dev,


	idx = encoding->flags & IW_ENCODE_INDEX;
	idx = encoding->flags & IW_ENCODE_INDEX;
	if (idx) {
	if (idx) {
		if (!valid_index(&cap_rid, idx - 1))
		if (!valid_index(local, idx - 1))
			return -EINVAL;
			return -EINVAL;
		idx--;
		idx--;
	} else
	} else