diff mbox series

iw: Only print EHT info if fields are defined.

Message ID 20230515211524.470451-1-greearb@candelatech.com (mailing list archive)
State Not Applicable
Delegated to: Johannes Berg
Headers show
Series iw: Only print EHT info if fields are defined. | expand

Commit Message

Ben Greear May 15, 2023, 9:15 p.m. UTC
From: Ben Greear <greearb@candelatech.com>

Without this patch, a bunch of blank EHT fields are printed when
iw phy info is run against an /ax phy devices.

Signed-off-by: Ben Greear <greearb@candelatech.com>
---
 util.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/util.c b/util.c
index 8a2ba10..31b0308 100644
--- a/util.c
+++ b/util.c
@@ -1588,6 +1588,7 @@  void print_eht_info(struct nlattr *nl_iftype, int band)
 	__u8 ppet[31] = { 0 };
 	__u16 he_phy_cap[6] = { 0 };
 	size_t len, mcs_len = 0, ppet_len = 0;
+	bool did_one = false;
 
 	nla_parse(tb, NL80211_BAND_IFTYPE_ATTR_MAX,
 		  nla_data(nl_iftype), nla_len(nl_iftype), NULL);
@@ -1595,11 +1596,8 @@  void print_eht_info(struct nlattr *nl_iftype, int band)
 	if (!tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES])
 		return;
 
-	printf("\t\tEHT Iftypes: ");
-	print_iftype_line(tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES]);
-	printf("\n");
-
 	if (tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MAC]) {
+		did_one = true;
 		len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MAC]);
 		if (len > sizeof(mac_cap))
 			len = sizeof(mac_cap);
@@ -1609,6 +1607,7 @@  void print_eht_info(struct nlattr *nl_iftype, int band)
 	}
 
 	if (tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PHY]) {
+		did_one = true;
 		len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PHY]);
 
 		if (len > sizeof(phy_cap))
@@ -1620,6 +1619,7 @@  void print_eht_info(struct nlattr *nl_iftype, int band)
 	}
 
 	if (tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MCS_SET]) {
+		did_one = true;
 		len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MCS_SET]);
 		if (len > sizeof(mcs_set))
 			len = sizeof(mcs_set);
@@ -1632,6 +1632,7 @@  void print_eht_info(struct nlattr *nl_iftype, int band)
 	}
 
 	if (tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PPE]) {
+		did_one = true;
 		len = nla_len(tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PPE]);
 		if (len > sizeof(ppet))
 			len = sizeof(ppet);
@@ -1651,6 +1652,13 @@  void print_eht_info(struct nlattr *nl_iftype, int band)
 		       len);
 	}
 
+	if (!did_one)
+		return;
+
+	printf("\t\tEHT Iftypes: ");
+	print_iftype_line(tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES]);
+	printf("\n");
+
 	__print_eht_capa(band, mac_cap, phy_cap, mcs_set, mcs_len, ppet, ppet_len,
 			 he_phy_cap, true);
 }