svn commit: r301762 - head/sys/dev/urtwn

Andriy Voskoboinyk avos at FreeBSD.org
Thu Jun 9 21:19:47 UTC 2016


Author: avos
Date: Thu Jun  9 21:19:46 2016
New Revision: 301762
URL: https://svnweb.freebsd.org/changeset/base/301762

Log:
  urtwn: reinstall group keys on every device startup.
  
  Since key table is cleared on every device shutdown,
  static WEP keys (which are set only once) need to be
  reinstalled manually every time when device starts running.
  
  Tested with RTL8188EU, STA (all ciphers) / IBSS (WPA-none) modes.

Modified:
  head/sys/dev/urtwn/if_urtwn.c
  head/sys/dev/urtwn/if_urtwnvar.h

Modified: head/sys/dev/urtwn/if_urtwn.c
==============================================================================
--- head/sys/dev/urtwn/if_urtwn.c	Thu Jun  9 20:49:26 2016	(r301761)
+++ head/sys/dev/urtwn/if_urtwn.c	Thu Jun  9 21:19:46 2016	(r301762)
@@ -373,6 +373,8 @@ static void		urtwn_set_chan(struct urtwn
 static void		urtwn_iq_calib(struct urtwn_softc *);
 static void		urtwn_lc_calib(struct urtwn_softc *);
 static void		urtwn_temp_calib(struct urtwn_softc *);
+static void		urtwn_setup_static_keys(struct urtwn_softc *,
+			    struct urtwn_vap *);
 static int		urtwn_init(struct urtwn_softc *);
 static void		urtwn_stop(struct urtwn_softc *);
 static void		urtwn_abort_xfers(struct urtwn_softc *);
@@ -2340,12 +2342,28 @@ static int
 urtwn_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k)
 {
 	struct urtwn_softc *sc = vap->iv_ic->ic_softc;
+	struct urtwn_vap *uvp = URTWN_VAP(vap);
 
 	if (k->wk_flags & IEEE80211_KEY_SWCRYPT) {
 		/* Not for us. */
 		return (1);
 	}
 
+	if (&vap->iv_nw_keys[0] <= k &&
+	    k < &vap->iv_nw_keys[IEEE80211_WEP_NKID]) {
+		URTWN_LOCK(sc);
+		uvp->keys[k->wk_keyix] = k;
+		if ((sc->sc_flags & URTWN_RUNNING) == 0) {
+			/*
+			 * The device was not started;
+			 * the key will be installed later.
+			 */
+			URTWN_UNLOCK(sc);
+			return (1);
+		}
+		URTWN_UNLOCK(sc);
+	}
+
 	return (!urtwn_cmd_sleepable(sc, k, sizeof(*k), urtwn_key_set_cb));
 }
 
@@ -2353,12 +2371,25 @@ static int
 urtwn_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k)
 {
 	struct urtwn_softc *sc = vap->iv_ic->ic_softc;
+	struct urtwn_vap *uvp = URTWN_VAP(vap);
 
 	if (k->wk_flags & IEEE80211_KEY_SWCRYPT) {
 		/* Not for us. */
 		return (1);
 	}
 
+	if (&vap->iv_nw_keys[0] <= k &&
+	    k < &vap->iv_nw_keys[IEEE80211_WEP_NKID]) {
+		URTWN_LOCK(sc);                  
+		uvp->keys[k->wk_keyix] = NULL;
+		if ((sc->sc_flags & URTWN_RUNNING) == 0) {
+			/* All keys are removed on device reset. */
+			URTWN_UNLOCK(sc);
+			return (1);
+		}
+		URTWN_UNLOCK(sc);
+	}
+
 	return (!urtwn_cmd_sleepable(sc, k, sizeof(*k), urtwn_key_del_cb));
 }
 
@@ -5230,6 +5261,20 @@ urtwn_temp_calib(struct urtwn_softc *sc)
 	}
 }
 
+static void
+urtwn_setup_static_keys(struct urtwn_softc *sc, struct urtwn_vap *uvp)
+{
+	int i;
+
+	for (i = 0; i < IEEE80211_WEP_NKID; i++) {
+		const struct ieee80211_key *k = uvp->keys[i];
+		if (k != NULL) {
+			urtwn_cmd_sleepable(sc, k, sizeof(*k),
+			    urtwn_key_set_cb);
+		}
+	}
+}
+
 static int
 urtwn_init(struct urtwn_softc *sc)
 {
@@ -5418,12 +5463,6 @@ urtwn_init(struct urtwn_softc *sc)
 	    R92C_SECCFG_TXENC_ENA | R92C_SECCFG_RXDEC_ENA |
 	    R92C_SECCFG_TXBCKEY_DEF | R92C_SECCFG_RXBCKEY_DEF);
 
-	/*
-	 * Install static keys (if any).
-	 * Must be called after urtwn_cam_init().
-	 */
-	ieee80211_runtask(ic, &sc->cmdq_task);
-
 	/* Enable hardware sequence numbering. */
 	urtwn_write_1(sc, R92C_HWSEQ_CTRL, R92C_TX_QUEUE_ALL);
 
@@ -5459,6 +5498,13 @@ urtwn_init(struct urtwn_softc *sc)
 
 	sc->sc_flags |= URTWN_RUNNING;
 
+	/*
+	 * Install static keys (if any).
+	 * Must be called after urtwn_cam_init().
+	 */
+	if (vap != NULL)
+		urtwn_setup_static_keys(sc, URTWN_VAP(vap));
+
 	callout_reset(&sc->sc_watchdog_ch, hz, urtwn_watchdog, sc);
 fail:
 	if (usb_err != USB_ERR_NORMAL_COMPLETION)

Modified: head/sys/dev/urtwn/if_urtwnvar.h
==============================================================================
--- head/sys/dev/urtwn/if_urtwnvar.h	Thu Jun  9 20:49:26 2016	(r301761)
+++ head/sys/dev/urtwn/if_urtwnvar.h	Thu Jun  9 21:19:46 2016	(r301762)
@@ -107,6 +107,8 @@ struct urtwn_vap {
 	struct mbuf		*bcn_mbuf;
 	struct task		tsf_task_adhoc;
 
+	const struct ieee80211_key	*keys[IEEE80211_WEP_NKID];
+
 	int			(*newstate)(struct ieee80211vap *,
 				    enum ieee80211_state, int);
 	void			(*recv_mgmt)(struct ieee80211_node *,


More information about the svn-src-head mailing list