iwd.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.linux.dev
Cc: James Prestwood <prestwoj@gmail.com>
Subject: [PATCH 04/10] wiphy: add getter for HT capabilities
Date: Tue, 20 Dec 2022 13:43:12 -0800	[thread overview]
Message-ID: <20221220214318.2041986-4-prestwoj@gmail.com> (raw)
In-Reply-To: <20221220214318.2041986-1-prestwoj@gmail.com>

This adds some additional parsing to obtain the AMPDU parameter
byte as well as wiphy_get_ht_capabilities() which returns the
complete IE (combining the 3 separate kernel attributes).
---
 src/wiphy.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/wiphy.h |  3 +++
 2 files changed, 56 insertions(+)

diff --git a/src/wiphy.c b/src/wiphy.c
index 4ea7c3f8..ab8aa6c0 100644
--- a/src/wiphy.c
+++ b/src/wiphy.c
@@ -910,6 +910,42 @@ bool wiphy_country_is_unknown(struct wiphy *wiphy)
 			(cc[0] == 'X' && cc[1] == 'X'));
 }
 
+const uint8_t *wiphy_get_ht_capabilities(const struct wiphy *wiphy,
+						enum band_freq band,
+						size_t *size)
+{
+	static uint8_t ht_capa[26];
+	const struct band *bandp = wiphy_get_band(wiphy, band);
+
+	if (!bandp)
+		return NULL;
+
+	if (!bandp->ht_supported)
+		return NULL;
+
+	memset(ht_capa, 0, sizeof(ht_capa));
+
+	/*
+	 * The kernel segments the HT capabilities element into multiple
+	 * attributes. For convenience on the caller just combine them and
+	 * return the full IE rather than adding 3 separate getters. This also
+	 * provides a way to check if HT is supported.
+	 */
+	memcpy(ht_capa, bandp->ht_capabilities, 2);
+	ht_capa[2] = bandp->ht_ampdu_params;
+	memcpy(ht_capa + 3, bandp->ht_mcs_set, 16);
+
+	/*
+	 * TODO: HT Extended capabilities, beamforming, and ASEL capabilities
+	 * are not available to get from the kernel, leave as zero.
+	 */
+
+	if (size)
+		*size = sizeof(ht_capa);
+
+	return ht_capa;
+}
+
 int wiphy_estimate_data_rate(struct wiphy *wiphy,
 				const void *ies, uint16_t ies_len,
 				const struct scan_bss *bss,
@@ -1617,6 +1653,23 @@ static void parse_supported_bands(struct wiphy *wiphy,
 				memcpy(band->ht_capabilities, data, len);
 				band->ht_supported = true;
 				break;
+			/*
+			 * AMPDU factor/density are part of A-MPDU Parameters,
+			 * 802.11-2020 Section 9.4.2.55.3.
+			 */
+			case NL80211_BAND_ATTR_HT_AMPDU_FACTOR:
+				if (L_WARN_ON(len != 1))
+					continue;
+
+				band->ht_ampdu_params |= l_get_u8(data) & 0x3;
+				break;
+			case NL80211_BAND_ATTR_HT_AMPDU_DENSITY:
+				if (L_WARN_ON(len != 1))
+					continue;
+
+				band->ht_ampdu_params |=
+						(l_get_u8(data) & 0x7) >> 2;
+				break;
 			case NL80211_BAND_ATTR_IFTYPE_DATA:
 				if (!l_genl_attr_recurse(&attr, &nested))
 					continue;
diff --git a/src/wiphy.h b/src/wiphy.h
index 6616da61..5cf22537 100644
--- a/src/wiphy.h
+++ b/src/wiphy.h
@@ -138,6 +138,9 @@ bool wiphy_get_rsnxe(const struct wiphy *wiphy, uint8_t *buf, size_t len);
 void wiphy_get_reg_domain_country(struct wiphy *wiphy, char *out);
 bool wiphy_country_is_unknown(struct wiphy *wiphy);
 
+const uint8_t *wiphy_get_ht_capabilities(const struct wiphy *wiphy,
+						enum band_freq band,
+						size_t *size);
 void wiphy_generate_random_address(struct wiphy *wiphy, uint8_t addr[static 6]);
 void wiphy_generate_address_from_ssid(struct wiphy *wiphy, const char *ssid,
 					uint8_t addr[static 6]);
-- 
2.34.3


  parent reply	other threads:[~2022-12-20 21:43 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-20 21:43 [PATCH 01/10] ap: make supported rates a common builder James Prestwood
2022-12-20 21:43 ` [PATCH 02/10] nl80211util: parse additional channel restriction flags James Prestwood
2022-12-20 21:43 ` [PATCH 03/10] band: add ampdu_params value James Prestwood
2022-12-20 21:43 ` James Prestwood [this message]
2022-12-27 17:22   ` [PATCH 04/10] wiphy: add getter for HT capabilities Denis Kenzior
2022-12-20 21:43 ` [PATCH 05/10] band: add APIs to generate a chandef from frequency James Prestwood
2022-12-27 18:07   ` Denis Kenzior
2022-12-28 19:50     ` James Prestwood
2022-12-28 21:10       ` Denis Kenzior
2022-12-20 21:43 ` [PATCH 06/10] band: add band_chandef_width_to_string James Prestwood
2022-12-27 17:33   ` Denis Kenzior
2022-12-20 21:43 ` [PATCH 07/10] wiphy: add wiphy_supports_uapsd James Prestwood
2022-12-20 21:43 ` [PATCH 08/10] ap: include WMM parameter IE James Prestwood
2022-12-27 18:09   ` Denis Kenzior
2022-12-20 21:43 ` [PATCH 09/10] ap: build HT Capabilities/Operation elements James Prestwood
2022-12-20 21:43 ` [PATCH 10/10] ap: generate chandef for starting AP James Prestwood
2022-12-27 16:59 ` [PATCH 01/10] ap: make supported rates a common builder Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221220214318.2041986-4-prestwoj@gmail.com \
    --to=prestwoj@gmail.com \
    --cc=iwd@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).