From owner-svn-src-head@freebsd.org Sat Oct 3 00:50:16 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 10320A0E956; Sat, 3 Oct 2015 00:50:16 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E98441D50; Sat, 3 Oct 2015 00:50:15 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t930oFol093573; Sat, 3 Oct 2015 00:50:15 GMT (envelope-from adrian@FreeBSD.org) Received: (from adrian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t930oElb093568; Sat, 3 Oct 2015 00:50:14 GMT (envelope-from adrian@FreeBSD.org) Message-Id: <201510030050.t930oElb093568@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: adrian set sender to adrian@FreeBSD.org using -f From: Adrian Chadd Date: Sat, 3 Oct 2015 00:50:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r288526 - head/sys/net80211 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 Oct 2015 00:50:16 -0000 Author: adrian Date: Sat Oct 3 00:50:13 2015 New Revision: 288526 URL: https://svnweb.freebsd.org/changeset/base/288526 Log: net80211: add new method for ieee80211_cipher (ic_setiv). This can be used to update IV state for the caller without adding information to the mbuf. Some hardware (eg rum) apparently requires bits of this. Submitted by: Differential Revision: https://reviews.freebsd.org/D3638 Modified: head/sys/net80211/ieee80211_crypto.h head/sys/net80211/ieee80211_crypto_ccmp.c head/sys/net80211/ieee80211_crypto_none.c head/sys/net80211/ieee80211_crypto_tkip.c head/sys/net80211/ieee80211_crypto_wep.c Modified: head/sys/net80211/ieee80211_crypto.h ============================================================================== --- head/sys/net80211/ieee80211_crypto.h Sat Oct 3 00:03:07 2015 (r288525) +++ head/sys/net80211/ieee80211_crypto.h Sat Oct 3 00:50:13 2015 (r288526) @@ -178,6 +178,7 @@ struct ieee80211_cipher { void* (*ic_attach)(struct ieee80211vap *, struct ieee80211_key *); void (*ic_detach)(struct ieee80211_key *); int (*ic_setkey)(struct ieee80211_key *); + void (*ic_setiv)(struct ieee80211_key *, uint8_t *); 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); Modified: head/sys/net80211/ieee80211_crypto_ccmp.c ============================================================================== --- head/sys/net80211/ieee80211_crypto_ccmp.c Sat Oct 3 00:03:07 2015 (r288525) +++ head/sys/net80211/ieee80211_crypto_ccmp.c Sat Oct 3 00:50:13 2015 (r288526) @@ -63,6 +63,7 @@ struct ccmp_ctx { static void *ccmp_attach(struct ieee80211vap *, struct ieee80211_key *); static void ccmp_detach(struct ieee80211_key *); static int ccmp_setkey(struct ieee80211_key *); +static void ccmp_setiv(struct ieee80211_key *, uint8_t *); 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); @@ -78,6 +79,7 @@ static const struct ieee80211_cipher ccm .ic_attach = ccmp_attach, .ic_detach = ccmp_detach, .ic_setkey = ccmp_setkey, + .ic_setiv = ccmp_setiv, .ic_encap = ccmp_encap, .ic_decap = ccmp_decap, .ic_enmic = ccmp_enmic, @@ -134,6 +136,26 @@ ccmp_setkey(struct ieee80211_key *k) return 1; } +static void +ccmp_setiv(struct ieee80211_key *k, uint8_t *ivp) +{ + struct ccmp_ctx *ctx = k->wk_private; + struct ieee80211vap *vap = ctx->cc_vap; + uint8_t keyid; + + keyid = ieee80211_crypto_get_keyid(vap, k) << 6; + + k->wk_keytsc++; + ivp[0] = k->wk_keytsc >> 0; /* PN0 */ + ivp[1] = k->wk_keytsc >> 8; /* PN1 */ + ivp[2] = 0; /* Reserved */ + ivp[3] = keyid | IEEE80211_WEP_EXTIV; /* KeyID | ExtID */ + ivp[4] = k->wk_keytsc >> 16; /* PN2 */ + ivp[5] = k->wk_keytsc >> 24; /* PN3 */ + ivp[6] = k->wk_keytsc >> 32; /* PN4 */ + ivp[7] = k->wk_keytsc >> 40; /* PN5 */ +} + /* * Add privacy headers appropriate for the specified key. */ @@ -142,9 +164,7 @@ ccmp_encap(struct ieee80211_key *k, stru { 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 *)); @@ -159,17 +179,7 @@ ccmp_encap(struct ieee80211_key *k, stru 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 */ - ivp[2] = 0; /* Reserved */ - ivp[3] = keyid | IEEE80211_WEP_EXTIV; /* KeyID | ExtID */ - ivp[4] = k->wk_keytsc >> 16; /* PN2 */ - ivp[5] = k->wk_keytsc >> 24; /* PN3 */ - ivp[6] = k->wk_keytsc >> 32; /* PN4 */ - ivp[7] = k->wk_keytsc >> 40; /* PN5 */ + ccmp_setiv(k, ivp); /* * Finally, do software encrypt if needed. Modified: head/sys/net80211/ieee80211_crypto_none.c ============================================================================== --- head/sys/net80211/ieee80211_crypto_none.c Sat Oct 3 00:03:07 2015 (r288525) +++ head/sys/net80211/ieee80211_crypto_none.c Sat Oct 3 00:50:13 2015 (r288526) @@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$"); static void *none_attach(struct ieee80211vap *, struct ieee80211_key *); static void none_detach(struct ieee80211_key *); static int none_setkey(struct ieee80211_key *); +static void none_setiv(struct ieee80211_key *, 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); @@ -62,6 +63,7 @@ const struct ieee80211_cipher ieee80211_ .ic_attach = none_attach, .ic_detach = none_detach, .ic_setkey = none_setkey, + .ic_setiv = none_setiv, .ic_encap = none_encap, .ic_decap = none_decap, .ic_enmic = none_enmic, @@ -87,6 +89,11 @@ none_setkey(struct ieee80211_key *k) return 1; } +static void +none_setiv(struct ieee80211_key *k, uint8_t *ivp) +{ +} + static int none_encap(struct ieee80211_key *k, struct mbuf *m) { Modified: head/sys/net80211/ieee80211_crypto_tkip.c ============================================================================== --- head/sys/net80211/ieee80211_crypto_tkip.c Sat Oct 3 00:03:07 2015 (r288525) +++ head/sys/net80211/ieee80211_crypto_tkip.c Sat Oct 3 00:50:13 2015 (r288526) @@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$"); static void *tkip_attach(struct ieee80211vap *, struct ieee80211_key *); static void tkip_detach(struct ieee80211_key *); static int tkip_setkey(struct ieee80211_key *); +static void tkip_setiv(struct ieee80211_key *, uint8_t *); 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); @@ -69,6 +70,7 @@ static const struct ieee80211_cipher tki .ic_attach = tkip_attach, .ic_detach = tkip_detach, .ic_setkey = tkip_setkey, + .ic_setiv = tkip_setiv, .ic_encap = tkip_encap, .ic_decap = tkip_decap, .ic_enmic = tkip_enmic, @@ -146,6 +148,26 @@ tkip_setkey(struct ieee80211_key *k) return 1; } +static void +tkip_setiv(struct ieee80211_key *k, uint8_t *ivp) +{ + struct tkip_ctx *ctx = k->wk_private; + struct ieee80211vap *vap = ctx->tc_vap; + uint8_t keyid; + + keyid = ieee80211_crypto_get_keyid(vap, k) << 6; + + k->wk_keytsc++; + ivp[0] = k->wk_keytsc >> 8; /* TSC1 */ + ivp[1] = (ivp[0] | 0x20) & 0x7f; /* WEP seed */ + ivp[2] = k->wk_keytsc >> 0; /* TSC0 */ + ivp[3] = keyid | IEEE80211_WEP_EXTIV; /* KeyID | ExtID */ + ivp[4] = k->wk_keytsc >> 16; /* TSC2 */ + ivp[5] = k->wk_keytsc >> 24; /* TSC3 */ + ivp[6] = k->wk_keytsc >> 32; /* TSC4 */ + ivp[7] = k->wk_keytsc >> 40; /* TSC5 */ +} + /* * Add privacy headers and do any s/w encryption required. */ @@ -156,7 +178,6 @@ tkip_encap(struct ieee80211_key *k, stru struct ieee80211vap *vap = ctx->tc_vap; struct ieee80211com *ic = vap->iv_ic; uint8_t *ivp; - uint8_t keyid; int hdrlen; /* @@ -184,17 +205,7 @@ tkip_encap(struct ieee80211_key *k, stru memmove(ivp, ivp + tkip.ic_header, hdrlen); ivp += hdrlen; - keyid = ieee80211_crypto_get_keyid(vap, k) << 6; - - k->wk_keytsc++; - ivp[0] = k->wk_keytsc >> 8; /* TSC1 */ - ivp[1] = (ivp[0] | 0x20) & 0x7f; /* WEP seed */ - ivp[2] = k->wk_keytsc >> 0; /* TSC0 */ - ivp[3] = keyid | IEEE80211_WEP_EXTIV; /* KeyID | ExtID */ - ivp[4] = k->wk_keytsc >> 16; /* TSC2 */ - ivp[5] = k->wk_keytsc >> 24; /* TSC3 */ - ivp[6] = k->wk_keytsc >> 32; /* TSC4 */ - ivp[7] = k->wk_keytsc >> 40; /* TSC5 */ + tkip_setiv(k, ivp); /* * Finally, do software encrypt if needed. Modified: head/sys/net80211/ieee80211_crypto_wep.c ============================================================================== --- head/sys/net80211/ieee80211_crypto_wep.c Sat Oct 3 00:03:07 2015 (r288525) +++ head/sys/net80211/ieee80211_crypto_wep.c Sat Oct 3 00:50:13 2015 (r288526) @@ -50,8 +50,9 @@ __FBSDID("$FreeBSD$"); static void *wep_attach(struct ieee80211vap *, struct ieee80211_key *); static void wep_detach(struct ieee80211_key *); static int wep_setkey(struct ieee80211_key *); +static void wep_setiv(struct ieee80211_key *, uint8_t *); static int wep_encap(struct ieee80211_key *, struct mbuf *); -static int wep_decap(struct ieee80211_key *, struct mbuf *, int hdrlen); +static int wep_decap(struct ieee80211_key *, struct mbuf *, int); static int wep_enmic(struct ieee80211_key *, struct mbuf *, int); static int wep_demic(struct ieee80211_key *, struct mbuf *, int); @@ -64,6 +65,7 @@ static const struct ieee80211_cipher wep .ic_attach = wep_attach, .ic_detach = wep_detach, .ic_setkey = wep_setkey, + .ic_setiv = wep_setiv, .ic_encap = wep_encap, .ic_decap = wep_decap, .ic_enmic = wep_enmic, @@ -117,31 +119,13 @@ wep_setkey(struct ieee80211_key *k) return k->wk_keylen >= 40/NBBY; } -/* - * Add privacy headers appropriate for the specified key. - */ -static int -wep_encap(struct ieee80211_key *k, struct mbuf *m) +static void +wep_setiv(struct ieee80211_key *k, uint8_t *ivp) { 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 *)); - - /* - * Copy down 802.11 header and add the IV + KeyID. - */ - M_PREPEND(m, wep.ic_header, M_NOWAIT); - if (m == NULL) - return 0; - ivp = mtod(m, uint8_t *); - ovbcopy(ivp + wep.ic_header, ivp, hdrlen); - ivp += hdrlen; keyid = ieee80211_crypto_get_keyid(vap, k) << 6; @@ -186,6 +170,32 @@ wep_encap(struct ieee80211_key *k, struc ivp[0] = iv >> 16; #endif ivp[3] = keyid; +} + +/* + * Add privacy headers appropriate for the specified key. + */ +static int +wep_encap(struct ieee80211_key *k, struct mbuf *m) +{ + struct wep_ctx *ctx = k->wk_private; + struct ieee80211com *ic = ctx->wc_ic; + uint8_t *ivp; + int hdrlen; + + hdrlen = ieee80211_hdrspace(ic, mtod(m, void *)); + + /* + * Copy down 802.11 header and add the IV + KeyID. + */ + M_PREPEND(m, wep.ic_header, M_NOWAIT); + if (m == NULL) + return 0; + ivp = mtod(m, uint8_t *); + ovbcopy(ivp + wep.ic_header, ivp, hdrlen); + ivp += hdrlen; + + wep_setiv(k, ivp); /* * Finally, do software encrypt if needed.