git: 1a8315228fff - stable/13 - LinuxKPI: 80211: improve linuxkpi_ieee80211_get_tid()

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Wed, 21 Sep 2022 14:01:29 UTC
The branch stable/13 has been updated by bz:

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

commit 1a8315228fff747c9bb0a2e639d94505c7ac22d8
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-09-05 20:57:17 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-09-21 11:46:46 +0000

    LinuxKPI: 80211: improve linuxkpi_ieee80211_get_tid()
    
    Continue what was started in 26a36948331bd08d9afaddfc0da724eacdb953dd
    in iwlwifi and extend out internal implementation of
    linuxkpi_ieee80211_get_tid() by an argument as to whether "no-QoS"
    answers are acceptable.  For the LinuxKPI ieee80211_get_tid() set
    this to false as the Linux derived drivers seem to do extra checks
    for the QoS-Data frame before acquiring the tid.
    Add KASSERTs to enforce the extra argument.
    This allows us to use the net80211 variant in LinuxKPI for other
    means explicitly documenting that we do accept a IEEE80211_NONQOS_TID.
    
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit ec190d91500676614feaf6456084369325ddcaa0)
---
 sys/compat/linuxkpi/common/include/net/mac80211.h |  6 +++---
 sys/compat/linuxkpi/common/src/linux_80211.c      | 14 ++++++++++++--
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/sys/compat/linuxkpi/common/include/net/mac80211.h b/sys/compat/linuxkpi/common/include/net/mac80211.h
index 13ae7bb99376..03bef9fbb97d 100644
--- a/sys/compat/linuxkpi/common/include/net/mac80211.h
+++ b/sys/compat/linuxkpi/common/include/net/mac80211.h
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2020-2021 The FreeBSD Foundation
+ * Copyright (c) 2020-2022 The FreeBSD Foundation
  * Copyright (c) 2020-2022 Bjoern A. Zeeb
  *
  * This software was developed by Björn Zeeb under sponsorship from
@@ -967,7 +967,7 @@ void linuxkpi_ieee80211_scan_completed(struct ieee80211_hw *,
     struct cfg80211_scan_info *);
 void linuxkpi_ieee80211_rx(struct ieee80211_hw *, struct sk_buff *,
     struct ieee80211_sta *, struct napi_struct *);
-uint8_t linuxkpi_ieee80211_get_tid(struct ieee80211_hdr *);
+uint8_t linuxkpi_ieee80211_get_tid(struct ieee80211_hdr *, bool);
 struct ieee80211_sta *linuxkpi_ieee80211_find_sta(struct ieee80211_vif *,
     const u8 *);
 struct ieee80211_sta *linuxkpi_ieee80211_find_sta_by_ifaddr(
@@ -1452,7 +1452,7 @@ static __inline uint8_t
 ieee80211_get_tid(struct ieee80211_hdr *hdr)
 {
 
-	return (linuxkpi_ieee80211_get_tid(hdr));
+	return (linuxkpi_ieee80211_get_tid(hdr, false));
 }
 
 static __inline struct sk_buff *
diff --git a/sys/compat/linuxkpi/common/src/linux_80211.c b/sys/compat/linuxkpi/common/src/linux_80211.c
index 3381218b2623..282ed2d99dd5 100644
--- a/sys/compat/linuxkpi/common/src/linux_80211.c
+++ b/sys/compat/linuxkpi/common/src/linux_80211.c
@@ -4056,12 +4056,22 @@ err:
 }
 
 uint8_t
-linuxkpi_ieee80211_get_tid(struct ieee80211_hdr *hdr)
+linuxkpi_ieee80211_get_tid(struct ieee80211_hdr *hdr, bool nonqos_ok)
 {
 	const struct ieee80211_frame *wh;
+	uint8_t tid;
+
+	/* Linux seems to assume this is a QOS-Data-Frame */
+	KASSERT(nonqos_ok || ieee80211_is_data_qos(hdr->frame_control),
+	   ("%s: hdr %p fc %#06x not qos_data\n", __func__, hdr,
+	   hdr->frame_control));
 
 	wh = (const struct ieee80211_frame *)hdr;
-	return (ieee80211_gettid(wh));
+	tid = ieee80211_gettid(wh);
+	KASSERT(nonqos_ok || tid == (tid & IEEE80211_QOS_TID), ("%s: tid %u "
+	   "not expected (%u?)\n", __func__, tid, IEEE80211_NONQOS_TID));
+
+	return (tid);
 }
 
 struct wiphy *