git: 7140d2464579 - stable/13 - LinuxKPI: 802.11: improve assertion and tkip code

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Mon, 26 Jun 2023 12:08:39 UTC
The branch stable/13 has been updated by bz:

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

commit 7140d2464579e918d5e59ba1a9b2b0b148536c86
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2023-04-20 16:01:05 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2023-06-26 09:14:04 +0000

    LinuxKPI: 802.11: improve assertion and tkip code
    
    Move a KASSERT out of a function and make it a CTASSERT with
    appropriate comments.
    
    Skeleton implement two tkip functions, still left TODO, initializing
    variables with dummy values to quiten compiler warnings.  It is
    unclear to me if we should still ever properly implement TKIP
    compat code at this point.  If so the current code gives a good
    idea what needs to be done in addition to allocating references
    to real state along with keyconf.
    
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit 35f7fa4ac1aea8af9a4f2428b3f0a346151b4071)
---
 sys/compat/linuxkpi/common/include/net/mac80211.h | 38 ++++++++++++++++++++---
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/sys/compat/linuxkpi/common/include/net/mac80211.h b/sys/compat/linuxkpi/common/include/net/mac80211.h
index 1fcee420232c..77045f866e8b 100644
--- a/sys/compat/linuxkpi/common/include/net/mac80211.h
+++ b/sys/compat/linuxkpi/common/include/net/mac80211.h
@@ -1756,6 +1756,11 @@ ieee80211_tu_to_usec(unsigned long tu)
 	return (tu * IEEE80211_DUR_TU);
 }
 
+/*
+ * Below we assume that the two values from different emums are the same.
+ * Make sure this does not accidentally change.
+ */
+CTASSERT((int)IEEE80211_ACTION_SM_TPCREP == (int)IEEE80211_ACTION_RADIO_MEASUREMENT_LMREP);
 
 static __inline bool
 ieee80211_action_contains_tpc(struct sk_buff *skb)
@@ -1783,10 +1788,10 @@ ieee80211_action_contains_tpc(struct sk_buff *skb)
 	    mgmt->u.action.category != IEEE80211_ACTION_CAT_RADIO_MEASUREMENT)
 		return (false);
 
-	/* Check that it is TPC Report or Link Measurement Report? */
-	KASSERT((int)IEEE80211_ACTION_SM_TPCREP == (int)IEEE80211_ACTION_RADIO_MEASUREMENT_LMREP,
-	    ("%s: SM_TPCREP %d != RADIO_MEASUREMENT_LMREP %d\n", __func__,
-	    IEEE80211_ACTION_SM_TPCREP, IEEE80211_ACTION_RADIO_MEASUREMENT_LMREP));
+	/*
+	 * Check that it is TPC Report or Link Measurement Report?
+	 * The values of each are the same (see CTASSERT above function).
+	 */
 	if (mgmt->u.action.u.tpc_report.spec_mgmt != IEEE80211_ACTION_SM_TPCREP)
 		return (false);
 
@@ -1834,7 +1839,12 @@ static __inline void
 ieee80211_get_tkip_rx_p1k(struct ieee80211_key_conf *keyconf,
     const u8 *addr, uint32_t iv32, u16 *p1k)
 {
+
+	KASSERT(keyconf != NULL && addr != NULL && p1k != NULL,
+	    ("%s: keyconf %p addr %p p1k %p\n", __func__, keyconf, addr, p1k));
+
 	TODO();
+	memset(p1k, 0xfa, 5 * sizeof(*p1k));	/* Just initializing. */
 }
 
 static __inline size_t
@@ -2051,7 +2061,27 @@ static __inline void
 ieee80211_get_key_rx_seq(struct ieee80211_key_conf *keyconf, uint8_t tid,
     struct ieee80211_key_seq *seq)
 {
+
+	KASSERT(keyconf != NULL && seq != NULL, ("%s: keyconf %p seq %p\n",
+	    __func__, keyconf, seq));
+
 	TODO();
+	switch (keyconf->cipher) {
+	case WLAN_CIPHER_SUITE_CCMP:
+	case WLAN_CIPHER_SUITE_CCMP_256:
+		memset(seq->ccmp.pn, 0xfa, sizeof(seq->ccmp.pn));	/* XXX TODO */
+		break;
+	case WLAN_CIPHER_SUITE_AES_CMAC:
+		memset(seq->aes_cmac.pn, 0xfa, sizeof(seq->aes_cmac.pn));	/* XXX TODO */
+		break;
+	case WLAN_CIPHER_SUITE_TKIP:
+		seq->tkip.iv32 = 0xfa;		/* XXX TODO */
+		seq->tkip.iv16 = 0xfa;		/* XXX TODO */
+		break;
+	default:
+		pr_debug("%s: unsupported cipher suite %d\n", __func__, keyconf->cipher);
+		break;
+	}
 }
 
 static __inline void