dat[3] = sc->wi_tx_key % 4;
dat[3] = sc->wi_tx_key << 6;
wi_do_hostencrypt(struct wi_softc *sc, caddr_t buf, int len){	u_int32_t i, crc, klen;	u_int8_t state[RC4STATE], key[RC4KEYLEN];	u_int8_t x, y, *dat;	if (!sc->wi_icv_flag) {		sc->wi_icv = arc4random();		sc->wi_icv_flag++;        } else		sc->wi_icv++;	/*	 * Skip 'bad' IVs from Fluhrer/Mantin/Shamir:	 * (B, 255, N) with 3 <= B < 8	 */	if (sc->wi_icv >= 0x03ff00 &&            (sc->wi_icv & 0xf8ff00) == 0x00ff00)                sc->wi_icv += 0x000100;	/* prepend 24bit IV to tx key, byte order does not matter */	key[0] = sc->wi_icv >> 16;	key[1] = sc->wi_icv >> 8;	key[2] = sc->wi_icv;	klen = sc->wi_keys.wi_keys[sc->wi_tx_key].wi_keylen +	    IEEE80211_WEP_IVLEN;	if (klen > RC4KEYLEN)		klen = RC4KEYLEN;	bcopy((char *)&sc->wi_keys.wi_keys[sc->wi_tx_key].wi_keydat,	    (char *)key + IEEE80211_WEP_IVLEN, klen - IEEE80211_WEP_IVLEN);	/* rc4 keysetup */	x = y = 0;	for (i = 0; i < RC4STATE; i++)		state[i] = i;	for (i = 0; i < RC4STATE; i++) {		y = (key[x] + state[i] + y) % RC4STATE;		RC4SWAP(x, y);		x = (x + 1) % klen;	}	/* output: IV, tx keyid, rc4(data), rc4(crc32(data)) */	dat = buf;	dat[0] = key[0];	dat[1] = key[1];	dat[2] = key[2];	dat[3] = sc->wi_tx_key % 4;	dat += 4;	/* compute rc4 over data, crc32 over data */	crc = ~0;	x = y = 0;	for (i = 0; i < len; i++) {		x = (x + 1) % RC4STATE;		y = (state[x] + y) % RC4STATE;		RC4SWAP(x, y);		crc = crc32_tab[(crc ^ dat[i]) & 0xff] ^ (crc >> 8);		dat[i] ^= state[(state[x] + state[y]) % RC4STATE];	}	crc = ~crc;	dat += len;	/* append crc32 and encrypt */	dat[0] = crc >> 24;	dat[1] = crc >> 16;	dat[2] = crc >> 8;	dat[3] = crc;	for (i = 0; i < IEEE80211_WEP_CRCLEN; i++) {		x = (x + 1) % RC4STATE;		y = (state[x] + y) % RC4STATE;		RC4SWAP(x, y);		dat[i] ^= state[(state[x] + state[y]) % RC4STATE];	}}