Index: head/sys/net80211/ieee80211_crypto.h =================================================================== --- head/sys/net80211/ieee80211_crypto.h +++ head/sys/net80211/ieee80211_crypto.h @@ -178,8 +178,7 @@ void* (*ic_attach)(struct ieee80211vap *, struct ieee80211_key *); void (*ic_detach)(struct ieee80211_key *); int (*ic_setkey)(struct ieee80211_key *); - int (*ic_encap)(struct ieee80211_key *, struct mbuf *, - uint8_t keyid); + int (*ic_encap)(struct ieee80211_key *, struct mbuf *); int (*ic_decap)(struct ieee80211_key *, struct mbuf *, int); int (*ic_enmic)(struct ieee80211_key *, struct mbuf *, int); int (*ic_demic)(struct ieee80211_key *, struct mbuf *, int); @@ -193,6 +192,8 @@ void ieee80211_crypto_unregister(const struct ieee80211_cipher *); int ieee80211_crypto_available(u_int cipher); +uint8_t ieee80211_crypto_get_keyid(struct ieee80211vap *vap, + struct ieee80211_key *k); struct ieee80211_key *ieee80211_crypto_encap(struct ieee80211_node *, struct mbuf *); struct ieee80211_key *ieee80211_crypto_decap(struct ieee80211_node *, Index: head/sys/net80211/ieee80211_crypto.c =================================================================== --- head/sys/net80211/ieee80211_crypto.c +++ head/sys/net80211/ieee80211_crypto.c @@ -521,6 +521,16 @@ return dev_key_set(vap, key); } +uint8_t +ieee80211_crypto_get_keyid(struct ieee80211vap *vap, struct ieee80211_key *k) +{ + if (k >= &vap->iv_nw_keys[0] && + k < &vap->iv_nw_keys[IEEE80211_WEP_NKID]) + return (k - vap->iv_nw_keys); + else + return (0); +} + /* * Add privacy headers appropriate for the specified key. */ @@ -531,7 +541,6 @@ struct ieee80211_key *k; struct ieee80211_frame *wh; const struct ieee80211_cipher *cip; - uint8_t keyid; /* * Multicast traffic always uses the multicast key. @@ -550,14 +559,12 @@ vap->iv_stats.is_tx_nodefkey++; return NULL; } - keyid = vap->iv_def_txkey; k = &vap->iv_nw_keys[vap->iv_def_txkey]; - } else { - keyid = 0; + } else k = &ni->ni_ucastkey; - } + cip = k->wk_cipher; - return (cip->ic_encap(k, m, keyid<<6) ? k : NULL); + return (cip->ic_encap(k, m) ? k : NULL); } /* Index: head/sys/net80211/ieee80211_crypto_ccmp.c =================================================================== --- head/sys/net80211/ieee80211_crypto_ccmp.c +++ head/sys/net80211/ieee80211_crypto_ccmp.c @@ -63,7 +63,7 @@ static void *ccmp_attach(struct ieee80211vap *, struct ieee80211_key *); static void ccmp_detach(struct ieee80211_key *); static int ccmp_setkey(struct ieee80211_key *); -static int ccmp_encap(struct ieee80211_key *k, struct mbuf *, uint8_t keyid); +static int ccmp_encap(struct ieee80211_key *, struct mbuf *); static int ccmp_decap(struct ieee80211_key *, struct mbuf *, int); static int ccmp_enmic(struct ieee80211_key *, struct mbuf *, int); static int ccmp_demic(struct ieee80211_key *, struct mbuf *, int); @@ -138,11 +138,13 @@ * Add privacy headers appropriate for the specified key. */ static int -ccmp_encap(struct ieee80211_key *k, struct mbuf *m, uint8_t keyid) +ccmp_encap(struct ieee80211_key *k, struct mbuf *m) { struct ccmp_ctx *ctx = k->wk_private; struct ieee80211com *ic = ctx->cc_ic; + struct ieee80211vap *vap = ctx->cc_vap; uint8_t *ivp; + uint8_t keyid; int hdrlen; hdrlen = ieee80211_hdrspace(ic, mtod(m, void *)); @@ -157,6 +159,8 @@ ovbcopy(ivp + ccmp.ic_header, ivp, hdrlen); ivp += hdrlen; + keyid = ieee80211_crypto_get_keyid(vap, k) << 6; + k->wk_keytsc++; /* XXX wrap at 48 bits */ ivp[0] = k->wk_keytsc >> 0; /* PN0 */ ivp[1] = k->wk_keytsc >> 8; /* PN1 */ Index: head/sys/net80211/ieee80211_crypto_none.c =================================================================== --- head/sys/net80211/ieee80211_crypto_none.c +++ head/sys/net80211/ieee80211_crypto_none.c @@ -48,7 +48,7 @@ static void *none_attach(struct ieee80211vap *, struct ieee80211_key *); static void none_detach(struct ieee80211_key *); static int none_setkey(struct ieee80211_key *); -static int none_encap(struct ieee80211_key *, struct mbuf *, uint8_t); +static int none_encap(struct ieee80211_key *, struct mbuf *); static int none_decap(struct ieee80211_key *, struct mbuf *, int); static int none_enmic(struct ieee80211_key *, struct mbuf *, int); static int none_demic(struct ieee80211_key *, struct mbuf *, int); @@ -88,19 +88,22 @@ } static int -none_encap(struct ieee80211_key *k, struct mbuf *m, uint8_t keyid) +none_encap(struct ieee80211_key *k, struct mbuf *m) { struct ieee80211vap *vap = k->wk_private; #ifdef IEEE80211_DEBUG struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); #endif + uint8_t keyid; + + keyid = ieee80211_crypto_get_keyid(vap, k); /* * The specified key is not setup; this can * happen, at least, when changing keys. */ IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr1, - "key id %u is not set (encap)", keyid>>6); + "key id %u is not set (encap)", keyid); vap->iv_stats.is_tx_badcipher++; return 0; } Index: head/sys/net80211/ieee80211_crypto_tkip.c =================================================================== --- head/sys/net80211/ieee80211_crypto_tkip.c +++ head/sys/net80211/ieee80211_crypto_tkip.c @@ -54,7 +54,7 @@ static void *tkip_attach(struct ieee80211vap *, struct ieee80211_key *); static void tkip_detach(struct ieee80211_key *); static int tkip_setkey(struct ieee80211_key *); -static int tkip_encap(struct ieee80211_key *, struct mbuf *m, uint8_t keyid); +static int tkip_encap(struct ieee80211_key *, struct mbuf *); static int tkip_enmic(struct ieee80211_key *, struct mbuf *, int); static int tkip_decap(struct ieee80211_key *, struct mbuf *, int); static int tkip_demic(struct ieee80211_key *, struct mbuf *, int); @@ -152,12 +152,13 @@ * Add privacy headers and do any s/w encryption required. */ static int -tkip_encap(struct ieee80211_key *k, struct mbuf *m, uint8_t keyid) +tkip_encap(struct ieee80211_key *k, struct mbuf *m) { struct tkip_ctx *ctx = k->wk_private; struct ieee80211vap *vap = ctx->tc_vap; struct ieee80211com *ic = vap->iv_ic; uint8_t *ivp; + uint8_t keyid; int hdrlen; /* @@ -185,6 +186,8 @@ memmove(ivp, ivp + tkip.ic_header, hdrlen); ivp += hdrlen; + keyid = ieee80211_crypto_get_keyid(vap, k) << 6; + ivp[0] = k->wk_keytsc >> 8; /* TSC1 */ ivp[1] = (ivp[0] | 0x20) & 0x7f; /* WEP seed */ ivp[2] = k->wk_keytsc >> 0; /* TSC0 */ Index: head/sys/net80211/ieee80211_crypto_wep.c =================================================================== --- head/sys/net80211/ieee80211_crypto_wep.c +++ head/sys/net80211/ieee80211_crypto_wep.c @@ -50,7 +50,7 @@ static void *wep_attach(struct ieee80211vap *, struct ieee80211_key *); static void wep_detach(struct ieee80211_key *); static int wep_setkey(struct ieee80211_key *); -static int wep_encap(struct ieee80211_key *, struct mbuf *, uint8_t keyid); +static int wep_encap(struct ieee80211_key *, struct mbuf *); static int wep_decap(struct ieee80211_key *, struct mbuf *, int hdrlen); static int wep_enmic(struct ieee80211_key *, struct mbuf *, int); static int wep_demic(struct ieee80211_key *, struct mbuf *, int); @@ -121,12 +121,14 @@ * Add privacy headers appropriate for the specified key. */ static int -wep_encap(struct ieee80211_key *k, struct mbuf *m, uint8_t keyid) +wep_encap(struct ieee80211_key *k, struct mbuf *m) { struct wep_ctx *ctx = k->wk_private; + struct ieee80211vap *vap = ctx->wc_vap; struct ieee80211com *ic = ctx->wc_ic; uint32_t iv; uint8_t *ivp; + uint8_t keyid; int hdrlen; hdrlen = ieee80211_hdrspace(ic, mtod(m, void *)); @@ -141,6 +143,8 @@ ovbcopy(ivp + wep.ic_header, ivp, hdrlen); ivp += hdrlen; + keyid = ieee80211_crypto_get_keyid(vap, k) << 6; + /* * XXX * IV must not duplicate during the lifetime of the key.