Skip to contentSkip to conversation

monitor: parse RNR element

PATCH In review James Prestwood 2 participants 5 messages Aug 9, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 monitor: parse RNR element

---
 monitor/nlmon.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 117 insertions(+)
monitor/nlmon.c +117 -0
index 34c5eed6..54aaa465 100644
@@ -2278,6 +2278,121 @@ static void print_rsnx(unsigned int level, const char *label,
 		print_attr(level + 1, "SAE Hash-to-Element");
 }
 
+static void print_bss_parameters(unsigned int level, uint8_t parameters)
+{
+	print_attr(level, "BSS Parameters");
+
+	if (test_bit(&parameters, 0))
+		print_attr(level + 1, "OCT Recommended");
+
+	if (test_bit(&parameters, 1))
+		print_attr(level + 1, "Same SSID");
+
+	if (test_bit(&parameters, 2))
+		print_attr(level + 1, "Multiple BSSID");
+
+	if (test_bit(&parameters, 3))
+		print_attr(level + 1, "Transmitted BSSID");
+
+	if (test_bit(&parameters, 4))
+		print_attr(level + 1, "2.4/5GHz Co-Located ESS member");
+
+	if (test_bit(&parameters, 5))
+		print_attr(level + 1, "Unsolicited Probe Responses Active");
+
+	if (test_bit(&parameters, 6))
+		print_attr(level + 1, "Co-Located AP");
+}
+
+static void print_reduced_neighbor_report(unsigned int level, const char *label,
+					const void *data, uint16_t size)
+{
+	const uint8_t *ptr = data;
+	unsigned int field_count = 0;
+
+	print_attr(level, "%s", label);
+
+	if (size < 5) {
+		print_attr(level + 1, "error parsing");
+		return;
+	}
+
+	level++;
+
+	while (ptr < (uint8_t *)data + size) {
+		uint16_t hdr = l_get_le16(ptr);
+		uint8_t oper = l_get_u8(ptr + 2);
+		uint8_t chan = l_get_u8(ptr + 3);
+		uint8_t count = bit_field((uint8_t)(hdr & 0xff), 4, 4);
+		uint8_t type = bit_field((uint8_t)(hdr & 0xff), 0, 2);
+		uint8_t filtered = test_bit(&hdr, 2);
+		uint8_t info_size = (hdr & 0xff00) >> 8;
+		uint8_t i;
+
+		ptr += 4;
+
+		print_attr(level, "Field #%u", field_count);
+
+		/* TBTT Information Header */
+		print_attr(level + 1, "Info Field Type: %u", type);
+		print_attr(level + 1, "Filtered Neighbor AP: %u", filtered);
+		print_attr(level + 1, "Information Count: %u", count);
+		print_attr(level + 1, "Information Length: %u", info_size);
+
+		print_attr(level + 1, "Operating Class: %u", oper);
+		print_attr(level + 1, "Channel: %u", chan);
+
+		level++;
+
+		/* Information Set(s) */
+		for (i = 0; i <= count; i++) {
+			const uint8_t *info = ptr;
+
+			if (info + info_size > (uint8_t *)data + size ||
+					info_size == 0 || info_size == 3 ||
+					info_size == 4 || info_size == 10) {
+				print_attr(level + 1, "error parsing");
+				return;
+			}
+
+			print_attr(level, "Information Set #%u", i);
+
+			if (info_size >= 1)
+				print_attr(level + 1,
+						"Neighbor TBTT Offset: %u TU's",
+						l_get_u8(info++));
+
+			if (info_size >= 7) {
+				print_attr(level + 1, "BSSID: "MAC,
+						MAC_STR(info));
+				info += 6;
+			}
+
+			if (info_size == 5 || info_size == 6 ||
+					info_size >= 11) {
+				print_attr(level + 1, "Short SSID: %08x",
+						l_get_u32(info));
+				info += 4;
+			}
+
+			if (info_size == 2 || info_size == 6 ||
+					info_size == 8 || info_size == 9 ||
+					info_size >= 12)
+				print_bss_parameters(level + 1, *info++);
+
+			if (info_size == 9 || info_size >= 13)
+				print_attr(level + 1, "20 MHz PSD: %d",
+						(int8_t)*info++);
+
+			ptr += info_size;
+		}
+
+		level--;
+
+		field_count++;
+	}
+}
+
 static struct attr_entry ie_entry[] = {
 	{ IE_TYPE_SSID,				"SSID",
 		ATTR_CUSTOM,	{ .function = print_ie_ssid } },
@@ -2340,6 +2455,8 @@ static struct attr_entry ie_entry[] = {
 		ATTR_CUSTOM,	{ .function = print_fast_bss_transition } },
 	{ IE_TYPE_MOBILITY_DOMAIN,		"Mobility Domain",
 		ATTR_CUSTOM,	{ .function = print_mobility_domain } },
+	{ IE_TYPE_REDUCED_NEIGHBOR_REPORT,	"Reduced Neighbor Report",
+		ATTR_CUSTOM,	{ .function = print_reduced_neighbor_report } },
 	{ IE_TYPE_RSNX,				"RSNX",
 		ATTR_CUSTOM,	{ .function = print_rsnx } },
 	{ },
Signature · 1 line
2.34.3
#1 lore raw

PATCH v2 2/4 monitor: add better array type support

The ATTR_ARRAY type was quite limited, only supporting u16/u32 and addresses. This changes the union to a struct so nested/function can be defined along with array_type.

---
 monitor/nlmon.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
monitor/nlmon.c +19 -3
index 54aaa465..8b70b055 100644
@@ -139,7 +139,8 @@ struct attr_entry {
 	uint16_t attr;
 	const char *str;
 	enum attr_type type;
-	union {
+
+	struct {
 		const struct attr_entry *nested;
 		enum attr_type array_type;
 		attr_func_t function;
@@ -6691,6 +6692,7 @@ static void print_value(int indent, const char *label, enum attr_type type,
 }
 
 static void print_array(int indent, enum attr_type type,
+						const struct attr_entry *entry,
 						const void *buf, uint32_t len)
 {
 	const struct nlattr *nla;
@@ -6700,8 +6702,22 @@ static void print_array(int indent, enum attr_type type,
 		char str[8];
 
 		snprintf(str, sizeof(str), "%u", nla_type);
-		print_value(indent, str, type,
+
+		switch (type) {
+		case ATTR_NESTED:
+			if (entry->nested)
+				print_attributes(indent + 1, entry->nested,
+					NLA_DATA(nla), NLA_PAYLOAD(nla));
+			else
+				printf("missing nested table\n");
+			break;
+		default:
+			print_value(indent, str, type,
 				NLA_DATA(nla), NLA_PAYLOAD(nla));
+			break;
+		}
+
+
 	}
 }
 
@@ -6832,7 +6848,7 @@ static void print_attributes(int indent, const struct attr_entry *table,
 						NLA_PAYLOAD(nla));
 			if (array_type == ATTR_UNSPEC)
 				printf("missing type\n");
-			print_array(indent + 1, array_type,
+			print_array(indent + 1, array_type, &table[i],
 					NLA_DATA(nla), NLA_PAYLOAD(nla));
 			break;
 		case ATTR_FLAG_OR_U16:
Signature · 1 line
2.34.3
#2 lore raw

Re: [PATCH v2 2/4] monitor: add better array type support

Hi James,

Quoted 7 lines · James Prestwood

The ATTR_ARRAY type was quite limited, only supporting u16/u32 and addresses. This changes the union to a struct so nested/function can be defined along with array_type.

---
  monitor/nlmon.c | 22 +++++++++++++++++++---
  1 file changed, 19 insertions(+), 3 deletions(-)

<snip>

monitor/nlmon.c static void print_array(int indent, enum attr_type type, · line 6721

Quoted 8 lines
monitor/nlmon.c +6 -0
+		default:
+			print_value(indent, str, type,
  				NLA_DATA(nla), NLA_PAYLOAD(nla));
+			break;
+		}
+
+
  	}

I took out these empty lines above. All applied, thanks.

Regards,
-Denis

#3 lore raw

PATCH v2 3/4 monitor: print out type of unknown element

In reply to James Prestwood

This changes the string from "Reserved" to "Unknown" which feels more fitting, and also prints out the NL type of the unknown element.

---
 monitor/nlmon.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
monitor/nlmon.c +2 -2
index 8b70b055..e880ca1e 100644
@@ -6743,7 +6743,7 @@ static void print_attributes(int indent, const struct attr_entry *table,
 		int64_t val_s64;
 		uint8_t *ptr;
 
-		str = "Reserved";
+		str = "Unknown";
 		type = ATTR_UNSPEC;
 		array_type = ATTR_UNSPEC;
 		nested = NULL;
@@ -6763,7 +6763,7 @@ static void print_attributes(int indent, const struct attr_entry *table,
 
 		switch (type) {
 		case ATTR_UNSPEC:
-			print_attr(indent, "%s: len %u", str,
+			print_attr(indent, "%s: %u len %u", str, nla_type,
 						NLA_PAYLOAD(nla));
 			print_hexdump(indent + 1,
 					NLA_DATA(nla), NLA_PAYLOAD(nla));
Signature · 1 line
2.34.3
#4 lore raw

PATCH v2 4/4 monitor: add support for HE element

In reply to James Prestwood

Support for the HE IE.

---
 monitor/nlmon.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
monitor/nlmon.c +20 -0
index e880ca1e..4210c46e 100644
@@ -5539,6 +5539,24 @@ static void print_band_rates(unsigned int level, const char *label,
 	}
 }
 
+static const struct attr_entry iftype_data_table[] = {
+	{ NL80211_BAND_IFTYPE_ATTR_IFTYPES, "Interface Types", ATTR_NESTED,
+			{ iftype_table } },
+	{ NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC, "HE MAC Capabilities",
+			ATTR_BINARY },
+	{ NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY, "HE PHY Capabilities",
+			ATTR_BINARY },
+	{ NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET, "HE NSS/MCS Set",
+			ATTR_BINARY },
+	{ NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE, "HE PPE Thresholds",
+			ATTR_BINARY },
+	{ NL80211_BAND_IFTYPE_ATTR_MAX, "Highest band HE capability attribute",
+			ATTR_BINARY },
+	{ NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA, "HE 6GHz band capabilities",
+			ATTR_BINARY },
+	{ }
+};
+
 static const struct attr_entry wiphy_bands_table[] = {
 	{ NL80211_BAND_ATTR_FREQS, "Frequencies",
 			ATTR_CUSTOM, { .function = print_band_frequencies } },
@@ -5552,6 +5570,8 @@ static const struct attr_entry wiphy_bands_table[] = {
 	{ NL80211_BAND_ATTR_HT_AMPDU_DENSITY, "AMPDU Density" },
 	{ NL80211_BAND_ATTR_VHT_MCS_SET, "VHT MCS Set" },
 	{ NL80211_BAND_ATTR_VHT_CAPA, "VHT Capabilities" },
+	{ NL80211_BAND_ATTR_IFTYPE_DATA, "Interface Type Data",
+			ATTR_ARRAY, { iftype_data_table, ATTR_NESTED }  },
 	{ }
 };
 
Signature · 1 line
2.34.3