diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2020-11-30 16:09:34 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2020-11-30 16:09:34 +0000 |
commit | 0de2fe85d5c810b0bfb4e612311c319c78595330 (patch) | |
tree | f0e95bd67ad9fae2d3827f685598ff34b3a2a25c /sys/dev/usb | |
parent | 2d6807e7139cc792ba63be5aa13d596df01ec3dc (diff) |
Fix deferred key tasks along the same lines as urtwn(4) and run(4).
athn(4) tested by stsp@, who points out that otus(4) and rsu(4) don't yet invoke
the code path to do their own key setting.
ok stsp@
Diffstat (limited to 'sys/dev/usb')
-rw-r--r-- | sys/dev/usb/if_athn_usb.c | 13 | ||||
-rw-r--r-- | sys/dev/usb/if_athn_usb.h | 3 | ||||
-rw-r--r-- | sys/dev/usb/if_otus.c | 25 | ||||
-rw-r--r-- | sys/dev/usb/if_otusreg.h | 5 | ||||
-rw-r--r-- | sys/dev/usb/if_rsu.c | 19 | ||||
-rw-r--r-- | sys/dev/usb/if_rsureg.h | 4 |
6 files changed, 57 insertions, 12 deletions
diff --git a/sys/dev/usb/if_athn_usb.c b/sys/dev/usb/if_athn_usb.c index 21a302f5066..281c53c7ff9 100644 --- a/sys/dev/usb/if_athn_usb.c +++ b/sys/dev/usb/if_athn_usb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_athn_usb.c,v 1.58 2020/07/13 08:31:32 stsp Exp $ */ +/* $OpenBSD: if_athn_usb.c,v 1.59 2020/11/30 16:09:33 krw Exp $ */ /*- * Copyright (c) 2011 Damien Bergamini <damien.bergamini@free.fr> @@ -1646,7 +1646,8 @@ athn_usb_set_key(struct ieee80211com *ic, struct ieee80211_node *ni, cmd.ni = (ni != NULL) ? ieee80211_ref_node(ni) : NULL; cmd.key = k; athn_usb_do_async(usc, athn_usb_set_key_cb, &cmd, sizeof(cmd)); - return (0); + usc->sc_key_tasks++; + return EBUSY; } void @@ -1656,9 +1657,17 @@ athn_usb_set_key_cb(struct athn_usb_softc *usc, void *arg) struct athn_usb_cmd_key *cmd = arg; int s; + usc->sc_key_tasks--; + s = splnet(); athn_usb_write_barrier(&usc->sc_sc); athn_set_key(ic, cmd->ni, cmd->key); + if (usc->sc_key_tasks == 0) { + DPRINTF(("marking port %s valid\n", + ether_sprintf(cmd->ni->ni_macaddr))); + cmd->ni->ni_port_valid = 1; + ieee80211_set_link_state(ic, LINK_STATE_UP); + } if (cmd->ni != NULL) ieee80211_release_node(ic, cmd->ni); splx(s); diff --git a/sys/dev/usb/if_athn_usb.h b/sys/dev/usb/if_athn_usb.h index 0f5525eff24..a45c996311f 100644 --- a/sys/dev/usb/if_athn_usb.h +++ b/sys/dev/usb/if_athn_usb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_athn_usb.h,v 1.11 2020/04/27 08:21:35 stsp Exp $ */ +/* $OpenBSD: if_athn_usb.h,v 1.12 2020/11/30 16:09:33 krw Exp $ */ /*- * Copyright (c) 2011 Damien Bergamini <damien.bergamini@free.fr> @@ -485,4 +485,5 @@ struct athn_usb_softc { void (*sc_node_free)(struct ieee80211com *, struct ieee80211_node *); + int sc_key_tasks; }; diff --git a/sys/dev/usb/if_otus.c b/sys/dev/usb/if_otus.c index 0517a00e51a..9aa771ecad9 100644 --- a/sys/dev/usb/if_otus.c +++ b/sys/dev/usb/if_otus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_otus.c,v 1.67 2020/07/31 10:49:32 mglocker Exp $ */ +/* $OpenBSD: if_otus.c,v 1.68 2020/11/30 16:09:33 krw Exp $ */ /*- * Copyright (c) 2009 Damien Bergamini <damien.bergamini@free.fr> @@ -2054,9 +2054,10 @@ otus_set_key(struct ieee80211com *ic, struct ieee80211_node *ni, /* Do it in a process context. */ cmd.key = *k; - cmd.associd = (ni != NULL) ? ni->ni_associd : 0; + cmd.ni = *ni; otus_do_async(sc, otus_set_key_cb, &cmd, sizeof cmd); - return 0; + sc->sc_key_tasks++ + return EBUSY; } void @@ -2068,6 +2069,8 @@ otus_set_key_cb(struct otus_softc *sc, void *arg) uint16_t cipher; int error; + sc->sc_keys_tasks--; + memset(&key, 0, sizeof key); if (k->k_flags & IEEE80211_KEY_GROUP) { key.uid = htole16(k->k_id); @@ -2093,18 +2096,32 @@ otus_set_key_cb(struct otus_softc *sc, void *arg) cipher = AR_CIPHER_AES; break; default: + IEEE80211_SEND_MGMT(ic, cmd->ni, IEEE80211_FC0_SUBTYPE_DEAUTH, + IEEE80211_REASON_AUTH_LEAVE); + ieee80211_new_state(ic, IEEE80211_S_SCAN, -1); return; } key.cipher = htole16(cipher); memcpy(key.key, k->k_key, MIN(k->k_len, 16)); error = otus_cmd(sc, AR_CMD_EKEY, &key, sizeof key, NULL); - if (error != 0 || k->k_cipher != IEEE80211_CIPHER_TKIP) + if (error != 0 || k->k_cipher != IEEE80211_CIPHER_TKIP) { + IEEE80211_SEND_MGMT(ic, cmd->ni, IEEE80211_FC0_SUBTYPE_DEAUTH, + IEEE80211_REASON_AUTH_LEAVE); + ieee80211_new_state(ic, IEEE80211_S_SCAN, -1); return; + } /* TKIP: set Tx/Rx MIC Key. */ key.kix = htole16(1); memcpy(key.key, k->k_key + 16, 16); (void)otus_cmd(sc, AR_CMD_EKEY, &key, sizeof key, NULL); + + if (sc->sc_key_tasks == 0) { + DPRINTF(("marking port %s valid\n", + ether_sprintf(cmd->ni->ni_macaddr))); + cmd->ni->ni_port_valid = 1; + ieee80211_set_link_state(ic, LINK_STATE_UP); + } } void diff --git a/sys/dev/usb/if_otusreg.h b/sys/dev/usb/if_otusreg.h index 6188a2a02ae..df08de1fc6e 100644 --- a/sys/dev/usb/if_otusreg.h +++ b/sys/dev/usb/if_otusreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_otusreg.h,v 1.11 2019/01/15 22:08:32 stsp Exp $ */ +/* $OpenBSD: if_otusreg.h,v 1.12 2020/11/30 16:09:33 krw Exp $ */ /*- * Copyright (c) 2009 Damien Bergamini <damien.bergamini@free.fr> @@ -923,7 +923,7 @@ struct otus_cmd_newstate { struct otus_cmd_key { struct ieee80211_key key; - uint16_t associd; + struct ieee80211_node *ni; }; struct otus_softc { @@ -994,4 +994,5 @@ struct otus_softc { #define sc_txtap sc_txtapu.th int sc_txtap_len; #endif + int sc_key_tasks; }; diff --git a/sys/dev/usb/if_rsu.c b/sys/dev/usb/if_rsu.c index 1d9e4975133..a2d7b48749a 100644 --- a/sys/dev/usb/if_rsu.c +++ b/sys/dev/usb/if_rsu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_rsu.c,v 1.47 2020/07/31 10:49:32 mglocker Exp $ */ +/* $OpenBSD: if_rsu.c,v 1.48 2020/11/30 16:09:33 krw Exp $ */ /*- * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr> @@ -898,17 +898,22 @@ rsu_set_key(struct ieee80211com *ic, struct ieee80211_node *ni, /* Do it in a process context. */ cmd.key = *k; + cmd.ni = ni; rsu_do_async(sc, rsu_set_key_cb, &cmd, sizeof(cmd)); - return (0); + sc->sc_key_tasks++; + return EBUSY; } void rsu_set_key_cb(struct rsu_softc *sc, void *arg) { struct rsu_cmd_key *cmd = arg; + struct ieee80211com *ic = &sc->sc_ic; struct ieee80211_key *k = &cmd->key; struct r92s_fw_cmd_set_key key; + sc->sc_key_tasks--; + memset(&key, 0, sizeof(key)); /* Map net80211 cipher to HW crypto algorithm. */ switch (k->k_cipher) { @@ -925,12 +930,22 @@ rsu_set_key_cb(struct rsu_softc *sc, void *arg) key.algo = R92S_KEY_ALGO_AES; break; default: + IEEE80211_SEND_MGMT(ic, cmd->ni, IEEE80211_FC0_SUBTYPE_DEAUTH, + IEEE80211_REASON_AUTH_LEAVE); + ieee80211_new_state(ic, IEEE80211_S_SCAN, -1); return; } key.id = k->k_id; key.grpkey = (k->k_flags & IEEE80211_KEY_GROUP) != 0; memcpy(key.key, k->k_key, MIN(k->k_len, sizeof(key.key))); (void)rsu_fw_cmd(sc, R92S_CMD_SET_KEY, &key, sizeof(key)); + + if (sc->sc_key_tasks == 0) { + DPRINTF(("marking port %s valid\n", + ether_sprintf(cmd->ni->ni_macaddr))); + cmd->ni->ni_port_valid = 1; + ieee80211_set_link_state(ic, LINK_STATE_UP); + } } /* ARGSUSED */ diff --git a/sys/dev/usb/if_rsureg.h b/sys/dev/usb/if_rsureg.h index 825558a3b93..4c9dc307eec 100644 --- a/sys/dev/usb/if_rsureg.h +++ b/sys/dev/usb/if_rsureg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_rsureg.h,v 1.3 2013/04/15 09:23:01 mglocker Exp $ */ +/* $OpenBSD: if_rsureg.h,v 1.4 2020/11/30 16:09:33 krw Exp $ */ /*- * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr> @@ -704,6 +704,7 @@ struct rsu_cmd_newstate { struct rsu_cmd_key { struct ieee80211_key key; + struct ieee80211_node *ni; }; struct rsu_host_cmd_ring { @@ -754,4 +755,5 @@ struct rsu_softc { #define sc_txtap sc_txtapu.th int sc_txtap_len; #endif + int sc_key_tasks; }; |