Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 2 Oct 2015 21:25:49 +0000 (UTC)
From:      Adrian Chadd <adrian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r288523 - head/sys/net80211
Message-ID:  <201510022125.t92LPnbR009619@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: adrian
Date: Fri Oct  2 21:25:48 2015
New Revision: 288523
URL: https://svnweb.freebsd.org/changeset/base/288523

Log:
  net80211: separate ieee80211_crypto_get_keyid() from ieee80211_crypto_encap()
  
  Tested:
  
  * rum(4), STA mode
  * rsu(4), STA mode
  * urtwn(4), STA mode
  
  Submitted by:	<s3erios@gmail.com>
  Differential Revision:	https://reviews.freebsd.org/D3637

Modified:
  head/sys/net80211/ieee80211_crypto.c
  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.c
==============================================================================
--- head/sys/net80211/ieee80211_crypto.c	Fri Oct  2 21:09:49 2015	(r288522)
+++ head/sys/net80211/ieee80211_crypto.c	Fri Oct  2 21:25:48 2015	(r288523)
@@ -521,6 +521,16 @@ ieee80211_crypto_setkey(struct ieee80211
 	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 @@ ieee80211_crypto_encap(struct ieee80211_
 	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 @@ ieee80211_crypto_encap(struct ieee80211_
 			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);
 }
 
 /*

Modified: head/sys/net80211/ieee80211_crypto.h
==============================================================================
--- head/sys/net80211/ieee80211_crypto.h	Fri Oct  2 21:09:49 2015	(r288522)
+++ head/sys/net80211/ieee80211_crypto.h	Fri Oct  2 21:25:48 2015	(r288523)
@@ -178,8 +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 *);
-	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_register(const str
 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 *,

Modified: head/sys/net80211/ieee80211_crypto_ccmp.c
==============================================================================
--- head/sys/net80211/ieee80211_crypto_ccmp.c	Fri Oct  2 21:09:49 2015	(r288522)
+++ head/sys/net80211/ieee80211_crypto_ccmp.c	Fri Oct  2 21:25:48 2015	(r288523)
@@ -63,7 +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	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 @@ ccmp_setkey(struct ieee80211_key *k)
  * 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 @@ 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 */

Modified: head/sys/net80211/ieee80211_crypto_none.c
==============================================================================
--- head/sys/net80211/ieee80211_crypto_none.c	Fri Oct  2 21:09:49 2015	(r288522)
+++ head/sys/net80211/ieee80211_crypto_none.c	Fri Oct  2 21:25:48 2015	(r288523)
@@ -48,7 +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	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 @@ none_setkey(struct ieee80211_key *k)
 }
 
 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;
 }

Modified: head/sys/net80211/ieee80211_crypto_tkip.c
==============================================================================
--- head/sys/net80211/ieee80211_crypto_tkip.c	Fri Oct  2 21:09:49 2015	(r288522)
+++ head/sys/net80211/ieee80211_crypto_tkip.c	Fri Oct  2 21:25:48 2015	(r288523)
@@ -54,7 +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	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 @@ tkip_setkey(struct ieee80211_key *k)
  * 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 @@ tkip_encap(struct ieee80211_key *k, stru
 	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 */

Modified: head/sys/net80211/ieee80211_crypto_wep.c
==============================================================================
--- head/sys/net80211/ieee80211_crypto_wep.c	Fri Oct  2 21:09:49 2015	(r288522)
+++ head/sys/net80211/ieee80211_crypto_wep.c	Fri Oct  2 21:25:48 2015	(r288523)
@@ -50,7 +50,7 @@ __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	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 @@ wep_setkey(struct ieee80211_key *k)
  * 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 @@ wep_encap(struct ieee80211_key *k, struc
 	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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201510022125.t92LPnbR009619>