linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Buesch <mb@bu3sch.de>
To: John Linville <linville@tuxdriver.com>
Cc: linux-wireless@vger.kernel.org, bcm43xx-dev@lists.berlios.de,
	Johannes Berg <johannes@sipsolutions.net>
Subject: [patch 7/7] b43: Fix and cleanup hwcrypto
Date: Fri, 24 Aug 2007 00:22:00 +0200	[thread overview]
Message-ID: <20070823222157.102919000@bu3sch.de> (raw)
In-Reply-To: 20070823222153.073035000@bu3sch.de

This fixes bugs and does a cleanup of the hwcrypto stuff.

Signed-off-by: Michael Buesch <mb@bu3sch.de>
Cc: Johannes Berg <johannes@sipsolutions.net>

Index: wireless-dev-new/drivers/net/wireless/b43/b43.h
===================================================================
--- wireless-dev-new.orig/drivers/net/wireless/b43/b43.h	2007-08-23 22:55:18.000000000 +0200
+++ wireless-dev-new/drivers/net/wireless/b43/b43.h	2007-08-24 00:14:00.000000000 +0200
@@ -571,8 +571,10 @@ struct b43_stats {
 };
 
 struct b43_key {
-	void *keyconf;
-	bool enabled;
+	/* If keyconf is NULL, this key is disabled.
+	 * keyconf is a cookie. Don't derefenrence it outside of the set_key
+	 * path, because b43 doesn't own it. */
+	struct ieee80211_key_conf *keyconf;
 	u8 algorithm;
 };
 
Index: wireless-dev-new/drivers/net/wireless/b43/main.c
===================================================================
--- wireless-dev-new.orig/drivers/net/wireless/b43/main.c	2007-08-23 23:42:20.000000000 +0200
+++ wireless-dev-new/drivers/net/wireless/b43/main.c	2007-08-24 00:03:09.000000000 +0200
@@ -806,31 +806,29 @@ static int b43_key_write(struct b43_wlde
 {
 	int i;
 	int sta_keys_start;
+	bool removal = 0;
 
 	if (key_len > B43_SEC_KEYSIZE)
 		return -EINVAL;
 	if (index < 0) {
-		/* Per station key with associated MAC address.
-		 * Look if it already exists, if yes update, otherwise
-		 * allocate a new key.
-		 */
+		/* Either pairwise key or address is 00:00:00:00:00:00
+		 * for transmit-only keys. Search the index. */
 		if (b43_new_kidx_api(dev))
 			sta_keys_start = 4;
 		else
 			sta_keys_start = 8;
 		for (i = sta_keys_start; i < dev->max_nr_keys; i++) {
 			if (dev->key[i].keyconf == keyconf) {
-				/*
-				 * we already have this key so we must be
-				 * in removal (there is no update)
-				 */
+				/* we already have this key so we must be
+				 * in removal (there is no update) */
+				removal = 1;
 				index = i;
 				break;
 			}
 		}
 		if (index < 0) {
 			for (i = sta_keys_start; i < dev->max_nr_keys; i++) {
-				if (!dev->key[i].enabled) {
+				if (!dev->key[i].keyconf) {
 					/* found empty */
 					index = i;
 					break;
@@ -851,6 +849,7 @@ static int b43_key_write(struct b43_wlde
 		do_key_write(dev, index + 4, algorithm, key, key_len, NULL);
 	}
 	keyconf->hw_key_idx = index;
+	dev->key[index].keyconf = removal ? NULL : keyconf;
 
 	return 0;
 }
@@ -864,7 +863,7 @@ static void b43_clear_keys(struct b43_wl
 	for (i = 0; i < dev->max_nr_keys; i++) {
 		do_key_write(dev, i, B43_SEC_ALGO_NONE,
 			     zero, B43_SEC_KEYSIZE, zero);
-		dev->key[i].enabled = 0;
+		dev->key[i].keyconf = NULL;
 	}
 }
 
@@ -2960,7 +2959,6 @@ static int b43_dev_set_key(struct ieee80
 		}
 		if (err)
 			goto out_unlock;
-		dev->key[key->hw_key_idx].enabled = 1;
 
 		if (algorithm == B43_SEC_ALGO_WEP40 ||
 		    algorithm == B43_SEC_ALGO_WEP104) {
@@ -2974,16 +2972,11 @@ static int b43_dev_set_key(struct ieee80
 		static const u8 zero[B43_SEC_KEYSIZE] = { 0 };
 
 		algorithm = B43_SEC_ALGO_NONE;
-		if (is_broadcast_ether_addr(addr)) {
-			err = b43_key_write(dev, index, algorithm,
-					    zero, B43_SEC_KEYSIZE,
-					    NULL, key);
-		} else {
-			err = b43_key_write(dev, -1, algorithm,
-					    zero, B43_SEC_KEYSIZE,
-					    addr, key);
-		}
-		dev->key[key->hw_key_idx].enabled = 0;
+		err = b43_key_write(dev, index, algorithm,
+				    zero, B43_SEC_KEYSIZE,
+				    NULL, key);
+		if (err)
+			goto out_unlock;
 		break;
 	}
 	default:
Index: wireless-dev-new/drivers/net/wireless/b43/xmit.c
===================================================================
--- wireless-dev-new.orig/drivers/net/wireless/b43/xmit.c	2007-08-23 22:55:18.000000000 +0200
+++ wireless-dev-new/drivers/net/wireless/b43/xmit.c	2007-08-24 00:06:28.000000000 +0200
@@ -234,23 +234,20 @@ static void generate_txhdr_fw4(struct b4
 
 		B43_WARN_ON(key_idx >= dev->max_nr_keys);
 		key = &(dev->key[key_idx]);
+		B43_WARN_ON(!key->keyconf);
 
-		if (key->enabled) {
-			/* Hardware appends ICV. */
-			plcp_fragment_len += txctl->icv_len;
-
-			key_idx = b43_kidx_to_fw(dev, key_idx);
-			mac_ctl |= (key_idx << B43_TX4_MAC_KEYIDX_SHIFT) &
-			    B43_TX4_MAC_KEYIDX;
-			mac_ctl |=
-			    (key->
-			     algorithm << B43_TX4_MAC_KEYALG_SHIFT) &
-			    B43_TX4_MAC_KEYALG;
-			wlhdr_len = ieee80211_get_hdrlen(fctl);
-			iv_len = min((size_t) txctl->iv_len,
-				     ARRAY_SIZE(txhdr->iv));
-			memcpy(txhdr->iv, ((u8 *) wlhdr) + wlhdr_len, iv_len);
-		}
+		/* Hardware appends ICV. */
+		plcp_fragment_len += txctl->icv_len;
+
+		key_idx = b43_kidx_to_fw(dev, key_idx);
+		mac_ctl |= (key_idx << B43_TX4_MAC_KEYIDX_SHIFT) &
+			   B43_TX4_MAC_KEYIDX;
+		mac_ctl |= (key->algorithm << B43_TX4_MAC_KEYALG_SHIFT) &
+			   B43_TX4_MAC_KEYALG;
+		wlhdr_len = ieee80211_get_hdrlen(fctl);
+		iv_len = min((size_t) txctl->iv_len,
+			     ARRAY_SIZE(txhdr->iv));
+		memcpy(txhdr->iv, ((u8 *) wlhdr) + wlhdr_len, iv_len);
 	}
 	b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->plcp),
 			      plcp_fragment_len, rate);

-- 


  parent reply	other threads:[~2007-08-23 22:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-23 22:21 [patch 0/7] New patch series for merge Michael Buesch
2007-08-23 22:21 ` [patch 1/7] b43: Change Kconfig help text Michael Buesch
2007-08-23 22:21 ` [patch 2/7] b43: Fix oops when firmware not found Michael Buesch
2007-08-23 22:21 ` [patch 3/7] b43: allow disabling hardware encryption Michael Buesch
2007-08-23 22:21 ` [patch 4/7] b43: Add debugfs file to extract LO calibration data Michael Buesch
2007-08-23 22:21 ` [patch 5/7] b43: Fix hwcrypto keyidx for new firmware Michael Buesch
2007-08-23 22:21 ` [patch 6/7] b43: Add missing stuff to pwork Michael Buesch
2007-08-23 22:22 ` Michael Buesch [this message]
2007-08-24 10:08   ` [patch 7/7] b43: Fix and cleanup hwcrypto Johannes Berg
2007-08-24 10:16     ` Michael Buesch
2007-08-24 10:27       ` Johannes Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070823222157.102919000@bu3sch.de \
    --to=mb@bu3sch.de \
    --cc=bcm43xx-dev@lists.berlios.de \
    --cc=johannes@sipsolutions.net \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linville@tuxdriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).