mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH iw,v2] iw: fix EHT capabilities on Big Endian platforms
@ 2025-05-02 19:44 Aleksander Jan Bajkowski
  0 siblings, 0 replies; only message in thread
From: Aleksander Jan Bajkowski @ 2025-05-02 19:44 UTC (permalink / raw)
  To: johannes.berg, linux-wireless, linux-kernel; +Cc: Aleksander Jan Bajkowski

IE fields are encoded in Little Endian and are not correctly
printed on Big Endian platforms.

Fixes: 5a71b722270c ("iw: Print local EHT capabilities")
Signed-off-by: Aleksander Jan Bajkowski <olek2@wp.pl>
---
 util.c | 40 +++++++++++++++++++++++++---------------
 1 file changed, 25 insertions(+), 15 deletions(-)

diff --git a/util.c b/util.c
index c6d5974..9403528 100644
--- a/util.c
+++ b/util.c
@@ -1538,22 +1538,31 @@ static void __print_eht_capa(int band,
 	unsigned int i;
 	const char *pre = indent ? "\t" : "";
 
-	#define PRINT_EHT_CAP(_var, _idx, _bit, _str) \
+	#define PRINT_EHT_MAC_CAP(_idx, _bit, _str) \
 	do { \
-		if (_var[_idx] & BIT(_bit)) \
+		if (mac_cap[_idx] & BIT(_bit)) \
 			printf("%s\t\t\t" _str "\n", pre); \
 	} while (0)
 
-	#define PRINT_EHT_CAP_MASK(_var, _idx, _shift, _mask, _str) \
+	#define PRINT_EHT_MAC_CAP_MASK(_idx, _shift, _mask, _str) \
 	do { \
-		if ((_var[_idx] >> _shift) & _mask) \
-			printf("%s\t\t\t" _str ": %d\n", pre, (_var[_idx] >> _shift) & _mask); \
+		if ((mac_cap[_idx] >> _shift) & _mask) \
+			printf("%s\t\t\t" _str ": %d\n", pre, \
+			       (mac_cap[_idx] >> _shift) & _mask); \
+	} while (0)
+
+	#define PRINT_EHT_PHY_CAP(_idx, _bit, _str) \
+	do { \
+		if (le32toh(phy_cap[_idx]) & BIT(_bit)) \
+			printf("%s\t\t\t" _str "\n", pre); \
 	} while (0)
 
-	#define PRINT_EHT_MAC_CAP(...) PRINT_EHT_CAP(mac_cap, __VA_ARGS__)
-	#define PRINT_EHT_MAC_CAP_MASK(...) PRINT_EHT_CAP_MASK(mac_cap, __VA_ARGS__)
-	#define PRINT_EHT_PHY_CAP(...) PRINT_EHT_CAP(phy_cap, __VA_ARGS__)
-	#define PRINT_EHT_PHY_CAP_MASK(...) PRINT_EHT_CAP_MASK(phy_cap, __VA_ARGS__)
+	#define PRINT_EHT_PHY_CAP_MASK(_idx, _shift, _mask, _str) \
+	do { \
+		if ((le32toh(phy_cap[_idx]) >> _shift) & _mask) \
+			printf("%s\t\t\t" _str ": %d\n", pre, \
+			       (le32toh(phy_cap[_idx]) >> _shift) & _mask); \
+	} while (0)
 
 	printf("%s\t\tEHT MAC Capabilities (0x", pre);
 	for (i = 0; i < 2; i++)
@@ -1627,7 +1636,7 @@ static void __print_eht_capa(int band,
 	PRINT_EHT_PHY_CAP(2, 1, "Rx 4096-QAM In Wider Bandwidth DL OFDMA Supported");
 
 	if (!from_ap &&
-	    !(he_phy_cap[0] & ((BIT(1) | BIT(2) | BIT(3) | BIT(4)) << 8))) {
+	    !(le16toh(he_phy_cap[0]) & ((BIT(1) | BIT(2) | BIT(3) | BIT(4)) << 8))) {
 		static const char * const mcs[] = { "0-7", "8-9", "10-11", "12-13" };
 
 		printf("%s\t\tEHT-MCS Map (20 Mhz Non-AP STA) (0x", pre);
@@ -1649,8 +1658,9 @@ static void __print_eht_capa(int band,
 		 * If no Channel Width bits are set, but we are an AP, we use
 		 * this MCS logic also.
 		 */
-		if (he_phy_cap[0] & ((BIT(1) | BIT(2)) << 8) ||
-		    (from_ap && !(he_phy_cap[0] & ((BIT(1) | BIT(2) | BIT(3) | BIT(4)) << 8)))) {
+		if (le16toh(he_phy_cap[0]) & ((BIT(1) | BIT(2)) << 8) ||
+		    (from_ap && !(le16toh(he_phy_cap[0]) &
+		    ((BIT(1) | BIT(2) | BIT(3) | BIT(4)) << 8)))) {
 			printf("%s\t\tEHT-MCS Map (BW <= 80) (0x", pre);
 			for (i = 0; i < 3; i++)
 				printf("%02x", ((__u8 *)mcs_set)[i]);
@@ -1665,7 +1675,7 @@ static void __print_eht_capa(int band,
 		}
 		mcs_set += 3;
 
-		if (he_phy_cap[0] & (BIT(3) << 8)) {
+		if (le16toh(he_phy_cap[0]) & (BIT(3) << 8)) {
 			printf("%s\t\tEHT-MCS Map (BW = 160) (0x", pre);
 			for (i = 0; i < 3; i++)
 				printf("%02x", ((__u8 *)mcs_set)[i]);
@@ -1680,7 +1690,7 @@ static void __print_eht_capa(int band,
 		}
 
 		mcs_set += 3;
-		if (band == NL80211_BAND_6GHZ && (phy_cap[0] & BIT(1))) {
+		if (band == NL80211_BAND_6GHZ && (le32toh(phy_cap[0]) & BIT(1))) {
 			printf("%s\t\tEHT-MCS Map (BW = 320) (0x", pre);
 			for (i = 0; i < 3; i++)
 				printf("%02x", ((__u8 *)mcs_set)[i]);
@@ -1695,7 +1705,7 @@ static void __print_eht_capa(int band,
 		}
 	}
 
-	if (ppet && ppet_len && (phy_cap[1] & BIT(11))) {
+	if (ppet && ppet_len && (le32toh(phy_cap[1]) & BIT(11))) {
 		printf("%s\t\tEHT PPE Thresholds ", pre);
 		for (i = 0; i < ppet_len; i++)
 			if (ppet[i])
-- 
2.39.5


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-05-02 19:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-02 19:44 [PATCH iw,v2] iw: fix EHT capabilities on Big Endian platforms Aleksander Jan Bajkowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®