--- madwifi/wlan/if_ieee80211wireless.c-orig	2004-05-12 13:58:43.000000000 -0700
+++ madwifi/wlan/if_ieee80211wireless.c	2004-05-12 14:00:46.000000000 -0700
@@ -198,7 +198,7 @@
 			  struct iw_point *erq, char *keybuf)
 {
 	struct ieee80211com *ic = dev->priv;
-	int kid, error, wepchange;
+	int kid, error, wepchange = 0, zerokey = 0, i;
 
 	if ((erq->flags & IW_ENCODE_DISABLED) == 0) {
 		/*
@@ -212,6 +212,8 @@
 			return -error;
 		if (erq->length > IEEE80211_KEYBUF_SIZE)
 			return -EINVAL;
+		for (i = 0; i < erq->length && keybuf[i] == 0; i++);
+		zerokey = (i == erq->length);
 		/* XXX no way to install 0-length key */
 		if (erq->length > 0) {
 			memcpy(ic->ic_nw_keys[kid].wk_key, keybuf, erq->length);
@@ -223,9 +225,11 @@
 			if (ic->ic_nw_keys[kid].wk_len == 0)
 				return -EINVAL;
 		}
-		ic->ic_wep_txkey = kid;
-		wepchange = (ic->ic_flags & IEEE80211_F_WEPON) == 0;
-		ic->ic_flags |= IEEE80211_F_WEPON;
+		if (zerokey) {
+			ic->ic_wep_txkey = kid;
+			wepchange = (ic->ic_flags & IEEE80211_F_WEPON) == 0;
+			ic->ic_flags |= IEEE80211_F_WEPON;
+		}
 	} else {
 		if ((ic->ic_flags & IEEE80211_F_WEPON) == 0)
 			return 0;

