done: 
int ieee80211_wx_set_encode(struct ieee80211_device *ieee,			    struct iw_request_info *info,			    union iwreq_data *wrqu, char *keybuf){	struct iw_point *erq = &(wrqu->encoding);	struct net_device *dev = ieee->dev;	struct ieee80211_security sec = {		.flags = 0	};	int i, key, key_provided, len;	struct ieee80211_crypt_data **crypt;	int host_crypto = ieee->host_encrypt || ieee->host_decrypt;	IEEE80211_DEBUG_WX("SET_ENCODE\n");	key = erq->flags & IW_ENCODE_INDEX;	if (key) {		if (key > WEP_KEYS)			return -EINVAL;		key--;		key_provided = 1;	} else {		key_provided = 0;		key = ieee->tx_keyidx;	}	IEEE80211_DEBUG_WX("Key: %d [%s]\n", key, key_provided ?			   "provided" : "default");	crypt = &ieee->crypt[key];	if (erq->flags & IW_ENCODE_DISABLED) {		if (key_provided && *crypt) {			IEEE80211_DEBUG_WX("Disabling encryption on key %d.\n",					   key);			ieee80211_crypt_delayed_deinit(ieee, crypt);		} else			IEEE80211_DEBUG_WX("Disabling encryption.\n");		/* Check all the keys to see if any are still configured,		 * and if no key index was provided, de-init them all */		for (i = 0; i < WEP_KEYS; i++) {			if (ieee->crypt[i] != NULL) {				if (key_provided)					break;				ieee80211_crypt_delayed_deinit(ieee,							       &ieee->crypt[i]);			}		}		if (i == WEP_KEYS) {			sec.enabled = 0;			sec.encrypt = 0;			sec.level = SEC_LEVEL_0;			sec.flags |= SEC_ENABLED | SEC_LEVEL;		}		goto done;	}	sec.enabled = 1;	sec.encrypt = 1;	sec.flags |= SEC_ENABLED;	if (*crypt != NULL && (*crypt)->ops != NULL &&	    strcmp((*crypt)->ops->name, "WEP") != 0) {		/* changing to use WEP; deinit previously used algorithm		 * on this key */		ieee80211_crypt_delayed_deinit(ieee, crypt);	}	if (*crypt == NULL && host_crypto) {		struct ieee80211_crypt_data *new_crypt;		/* take WEP into use */		new_crypt = kmalloc(sizeof(struct ieee80211_crypt_data),				    GFP_KERNEL);		if (new_crypt == NULL)			return -ENOMEM;		memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));		new_crypt->ops = ieee80211_get_crypto_ops("WEP");		if (!new_crypt->ops) {			request_module("ieee80211_crypt_wep");			new_crypt->ops = ieee80211_get_crypto_ops("WEP");		}		if (new_crypt->ops && try_module_get(new_crypt->ops->owner))			new_crypt->priv = new_crypt->ops->init(ieee, key);		if (!new_crypt->ops || !new_crypt->priv) {			kfree(new_crypt);			new_crypt = NULL;			printk(KERN_WARNING "%s: could not initialize WEP: "			       "load module ieee80211_crypt_wep\n", dev->name);			return -EOPNOTSUPP;		}		*crypt = new_crypt;	}	/* If a new key was provided, set it up */	if (erq->length > 0) {		len = erq->length <= 5 ? 5 : 13;		memcpy(sec.keys[key], keybuf, erq->length);		if (len > erq->length)			memset(sec.keys[key] + erq->length, 0,			       len - erq->length);		IEEE80211_DEBUG_WX("Setting key %d to '%s' (%d:%d bytes)\n",				   key, escape_essid(sec.keys[key], len),				   erq->length, len);		sec.key_sizes[key] = len;		if (*crypt)			(*crypt)->ops->set_key(sec.keys[key], len, NULL,					       (*crypt)->priv);		sec.flags |= (1 << key);		/* This ensures a key will be activated if no key is		 * explicitely set */		if (key == sec.active_key)			sec.flags |= SEC_ACTIVE_KEY;	} else {		if (host_crypto) {			len = (*crypt)->ops->get_key(sec.keys[key], WEP_KEY_LEN,						     NULL, (*crypt)->priv);			if (len == 0) {				/* Set a default key of all 0 */				IEEE80211_DEBUG_WX("Setting key %d to all "						   "zero.\n", key);				memset(sec.keys[key], 0, 13);				(*crypt)->ops->set_key(sec.keys[key], 13, NULL,						       (*crypt)->priv);				sec.key_sizes[key] = 13;				sec.flags |= (1 << key);			}		}		/* No key data - just set the default TX key index */		if (key_provided) {			IEEE80211_DEBUG_WX("Setting key %d to default Tx "					   "key.\n", key);			ieee->tx_keyidx = key;			sec.active_key = key;			sec.flags |= SEC_ACTIVE_KEY;		}	}      done:	ieee->open_wep = !(erq->flags & IW_ENCODE_RESTRICTED);	sec.auth_mode = ieee->open_wep ? WLAN_AUTH_OPEN : WLAN_AUTH_SHARED_KEY;	sec.flags |= SEC_AUTH_MODE;	IEEE80211_DEBUG_WX("Auth: %s\n", sec.auth_mode == WLAN_AUTH_OPEN ?			   "OPEN" : "SHARED KEY");	/* For now we just support WEP, so only set that security level...	 * TODO: When WPA is added this is one place that needs to change */	sec.flags |= SEC_LEVEL;	sec.level = SEC_LEVEL_1;	/* 40 and 104 bit WEP */	if (ieee->set_security)		ieee->set_security(dev, &sec);	/* Do not reset port if card is in Managed mode since resetting will	 * generate new IEEE 802.11 authentication which may end up in looping	 * with IEEE 802.1X.  If your hardware requires a reset after WEP	 * configuration (for example... Prism2), implement the reset_port in	 * the callbacks structures used to initialize the 802.11 stack. */	if (ieee->reset_on_keychange &&	    ieee->iw_mode != IW_MODE_INFRA &&	    ieee->reset_port && ieee->reset_port(dev)) {		printk(KERN_DEBUG "%s: reset_port failed\n", dev->name);		return -EINVAL;	}	return 0;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/259bf1fd8a7cc0f6b47fd8a9ac5e2dfc33182a3d/ieee80211_wx.c/clean/net/ieee80211/ieee80211_wx.c