git: f064d44badfa - main - run: rum: migrate to new net80211 encryption key API

From: Adrian Chadd <adrian_at_FreeBSD.org>
Date: Wed, 11 Feb 2026 06:05:19 UTC
The branch main has been updated by adrian:

URL: https://cgit.FreeBSD.org/src/commit/?id=f064d44badfa9eee3e62d2d7dacd77a968f0a6dd

commit f064d44badfa9eee3e62d2d7dacd77a968f0a6dd
Author:     Adrian Chadd <adrian@FreeBSD.org>
AuthorDate: 2025-12-29 18:55:52 +0000
Commit:     Adrian Chadd <adrian@FreeBSD.org>
CommitDate: 2026-02-11 06:03:53 +0000

    run: rum: migrate to new net80211 encryption key API
    
    Migrate to the new encryption key API rather than poking at the
    key struct directly.
    
    Locally tested:
    
     * STA mode - run0: MAC/BBP RT2860 (rev 0x0101), RF RT2820 (MIMO 2T2R), address 00:0e:2e:e5:ae:3a
    
    Differential Revision:  https://reviews.freebsd.org/D54462
---
 sys/dev/usb/wlan/if_rum.c | 26 ++++++++++++++++----------
 sys/dev/usb/wlan/if_run.c | 15 ++++++++++-----
 2 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/sys/dev/usb/wlan/if_rum.c b/sys/dev/usb/wlan/if_rum.c
index b822766f0ba5..4a4a150146a1 100644
--- a/sys/dev/usb/wlan/if_rum.c
+++ b/sys/dev/usb/wlan/if_rum.c
@@ -193,8 +193,8 @@ static uint32_t		rum_read(struct rum_softc *, uint16_t);
 static void		rum_read_multi(struct rum_softc *, uint16_t, void *,
 			    int);
 static usb_error_t	rum_write(struct rum_softc *, uint16_t, uint32_t);
-static usb_error_t	rum_write_multi(struct rum_softc *, uint16_t, void *,
-			    size_t);
+static usb_error_t	rum_write_multi(struct rum_softc *, uint16_t,
+			    const void *, size_t);
 static usb_error_t	rum_setbits(struct rum_softc *, uint16_t, uint32_t);
 static usb_error_t	rum_clrbits(struct rum_softc *, uint16_t, uint32_t);
 static usb_error_t	rum_modbits(struct rum_softc *, uint16_t, uint32_t,
@@ -1460,7 +1460,8 @@ rum_tx_crypto_flags(struct rum_softc *sc, struct ieee80211_node *ni,
 	if (!(k->wk_flags & IEEE80211_KEY_SWCRYPT)) {
 		cipher = k->wk_cipher->ic_cipher;
 		pos = k->wk_keyix;
-		mode = rum_crypto_mode(sc, cipher, k->wk_keylen);
+		mode = rum_crypto_mode(sc, cipher,
+		    ieee80211_crypto_get_key_len(k));
 		if (mode == 0)
 			return 0;
 
@@ -1843,7 +1844,8 @@ rum_write(struct rum_softc *sc, uint16_t reg, uint32_t val)
 }
 
 static usb_error_t
-rum_write_multi(struct rum_softc *sc, uint16_t reg, void *buf, size_t len)
+rum_write_multi(struct rum_softc *sc, uint16_t reg, const void *buf,
+    size_t len)
 {
 	struct usb_device_request req;
 	usb_error_t error;
@@ -1858,7 +1860,8 @@ rum_write_multi(struct rum_softc *sc, uint16_t reg, void *buf, size_t len)
 		USETW(req.wIndex, reg + offset);
 		USETW(req.wLength, MIN(len - offset, 64));
 
-		error = rum_do_request(sc, &req, (char *)buf + offset);
+		error = rum_do_request(sc, &req, __DECONST(char *, buf)
+		    + offset);
 		if (error != 0) {
 			device_printf(sc->sc_dev,
 			    "could not multi write MAC register: %s\n",
@@ -2859,15 +2862,16 @@ rum_common_key_set(struct rum_softc *sc, struct ieee80211_key *k,
     uint16_t base)
 {
 
-	if (rum_write_multi(sc, base, k->wk_key, k->wk_keylen))
+	if (rum_write_multi(sc, base, ieee80211_crypto_get_key_data(k),
+	    ieee80211_crypto_get_key_len(k)))
 		return EIO;
 
 	if (k->wk_cipher->ic_cipher == IEEE80211_CIPHER_TKIP) {
 		if (rum_write_multi(sc, base + IEEE80211_KEYBUF_SIZE,
-		    k->wk_txmic, 8))
+		    ieee80211_crypto_get_key_txmic_data(k), 8))
 			return EIO;
 		if (rum_write_multi(sc, base + IEEE80211_KEYBUF_SIZE + 8,
-		    k->wk_rxmic, 8))
+		    ieee80211_crypto_get_key_rxmic_data(k), 8))
 			return EIO;
 	}
 
@@ -2886,7 +2890,8 @@ rum_group_key_set_cb(struct rum_softc *sc, union sec_param *data,
 		sc->sc_clr_shkeys = 1;
 	}
 
-	mode = rum_crypto_mode(sc, k->wk_cipher->ic_cipher, k->wk_keylen);
+	mode = rum_crypto_mode(sc, k->wk_cipher->ic_cipher,
+	    ieee80211_crypto_get_key_len(k));
 	if (mode == 0)
 		goto print_err;
 
@@ -2941,7 +2946,8 @@ rum_pair_key_set_cb(struct rum_softc *sc, union sec_param *data,
 	uint8_t buf[IEEE80211_ADDR_LEN + 1];
 	uint8_t mode;
 
-	mode = rum_crypto_mode(sc, k->wk_cipher->ic_cipher, k->wk_keylen);
+	mode = rum_crypto_mode(sc, k->wk_cipher->ic_cipher,
+	    ieee80211_crypto_get_key_len(k));
 	if (mode == 0)
 		goto print_err;
 
diff --git a/sys/dev/usb/wlan/if_run.c b/sys/dev/usb/wlan/if_run.c
index 147aa4044057..7d993caaf2a3 100644
--- a/sys/dev/usb/wlan/if_run.c
+++ b/sys/dev/usb/wlan/if_run.c
@@ -2375,7 +2375,7 @@ run_key_set_cb(void *arg)
 	/* map net80211 cipher to RT2860 security mode */
 	switch (cipher) {
 	case IEEE80211_CIPHER_WEP:
-		if(k->wk_keylen < 8)
+		if(ieee80211_crypto_get_key_len(k) < 8) /* TODO: add a specific WEP40/WEP104 call! */
 			mode = RT2860_MODE_WEP40;
 		else
 			mode = RT2860_MODE_WEP104;
@@ -2408,15 +2408,20 @@ run_key_set_cb(void *arg)
 	}
 
 	if (cipher == IEEE80211_CIPHER_TKIP) {
-		if(run_write_region_1(sc, base, k->wk_key, 16))
+		if (run_write_region_1(sc, base,
+		    ieee80211_crypto_get_key_data(k), 16))
 			return;
-		if(run_write_region_1(sc, base + 16, &k->wk_key[16], 8))	/* wk_txmic */
+		if (run_write_region_1(sc, base + 16,
+		    ieee80211_crypto_get_key_txmic_data(k), 8))	/* wk_txmic */
 			return;
-		if(run_write_region_1(sc, base + 24, &k->wk_key[24], 8))	/* wk_rxmic */
+		if (run_write_region_1(sc, base + 24,
+		    ieee80211_crypto_get_key_rxmic_data(k), 8))	/* wk_rxmic */
 			return;
 	} else {
 		/* roundup len to 16-bit: XXX fix write_region_1() instead */
-		if(run_write_region_1(sc, base, k->wk_key, (k->wk_keylen + 1) & ~1))
+		if (run_write_region_1(sc, base,
+		    ieee80211_crypto_get_key_data(k),
+		    (ieee80211_crypto_get_key_len(k) + 1) & ~1))
 			return;
 	}