git: 44b254d9d329 - stable/13 - LinuxKPI: 802.11: implement cfg80211_get_ies_channel_number()

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Wed, 18 Jan 2023 16:24:54 UTC
The branch stable/13 has been updated by bz:

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

commit 44b254d9d32939ef223cb0e3df1ea085a3a5efd2
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-12-31 01:59:20 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2023-01-18 13:25:46 +0000

    LinuxKPI: 802.11: implement cfg80211_get_ies_channel_number()
    
    Using the previous changes implement cfg80211_get_ies_channel_number()
    either based on DSPARMS (or for the future HTINFO).
    
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit 13d87d92e401523f8d8e817720d40dc31cdfa444)
---
 sys/compat/linuxkpi/common/include/net/cfg80211.h | 28 +++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/sys/compat/linuxkpi/common/include/net/cfg80211.h b/sys/compat/linuxkpi/common/include/net/cfg80211.h
index e6f1bd88309d..ee6697bb4d4a 100644
--- a/sys/compat/linuxkpi/common/include/net/cfg80211.h
+++ b/sys/compat/linuxkpi/common/include/net/cfg80211.h
@@ -1677,12 +1677,36 @@ cfg80211_channel_is_psc(struct linuxkpi_ieee80211_channel *channel)
 	return (false);
 }
 
-static __inline int
+static inline int
 cfg80211_get_ies_channel_number(const uint8_t *ie, size_t len,
     enum nl80211_band band, enum cfg80211_bss_frame_type ftype)
 {
+	const struct element *elem;
 
-	TODO();
+	switch (band) {
+	case NL80211_BAND_6GHZ:
+		TODO();
+		break;
+	case NL80211_BAND_5GHZ:
+	case NL80211_BAND_2GHZ:
+		/* DSPARAMS has the channel number. */
+		elem = cfg80211_find_elem(IEEE80211_ELEMID_DSPARMS, ie, len);
+		if (elem != NULL && elem->datalen == 1)
+			return (elem->data[0]);
+		/* HTINFO has the primary center channel. */
+		elem = cfg80211_find_elem(IEEE80211_ELEMID_HTINFO, ie, len);
+		if (elem != NULL &&
+		    elem->datalen >= (sizeof(struct ieee80211_ie_htinfo) - 2)) {
+			const struct ieee80211_ie_htinfo *htinfo;
+			htinfo = (const struct ieee80211_ie_htinfo *)elem;
+			return (htinfo->hi_ctrlchannel);
+		}
+		/* What else? */
+		break;
+	default:
+		IMPROVE("Unsupported");
+		break;
+	}
 	return (-1);
 }