monitor: parse RNR element
PATCH 1/4 monitor: parse RNR element
--- monitor/nlmon.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+)
monitor/nlmon.c +117 -0
@@ -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 (¶meters,0 )) +print_attr (level +1 ,"OCT Recommended" ); + +if (test_bit (¶meters,1 )) +print_attr (level +1 ,"Same SSID" ); + +if (test_bit (¶meters,2 )) +print_attr (level +1 ,"Multiple BSSID" ); + +if (test_bit (¶meters,3 )) +print_attr (level +1 ,"Transmitted BSSID" ); + +if (test_bit (¶meters,4 )) +print_attr (level +1 ,"2.4/5GHz Co-Located ESS member" ); + +if (test_bit (¶meters,5 )) +print_attr (level +1 ,"Unsolicited Probe Responses Active" ); + +if (test_bit (¶meters,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
PATCH 2/4 monitor: add more array type support
The ATTR_ARRAY type was quite limited, only supporting u16/u32 and addresses. This moves 'array_type' out of the union in attr_entry which allows nested/function to be supplied along with array_type.
This poses an issue with defining const entries unless array_type is moved *after* the union. Otherwise nearly every single definition would require setting array_type to zero in the const definition.
Instead array_type will come after the union, and the few definitions which use ATTR_ARRAY have been updated to fix the compile errors.
--- monitor/nlmon.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-)
monitor/nlmon.c +23 -9
@@ -139,11 +139,13 @@ struct attr_entry {uint16_t attr;const char *str;enum attr_type type; +union {const struct attr_entry *nested; -enum attr_type array_type;attr_func_t function; }; + +enum attr_type array_type; }; static void print_attributes(int indent, const struct attr_entry *table,
@@ -6230,11 +6232,9 @@ static const struct attr_entry attr_table[] = { {NL80211_ATTR_MAX_NUM_SCAN_SSIDS , "Max Number Scan SSIDs", ATTR_U8 }, { NL80211_ATTR_SCAN_FREQUENCIES, -"Scan Frequencies" ,ATTR_ARRAY , - { .array_type = ATTR_U32 } }, + "Scan Frequencies", ATTR_ARRAY, {}, ATTR_U32 }, { NL80211_ATTR_SCAN_SSIDS, -"Scan SSIDs" ,ATTR_ARRAY , - { .array_type = ATTR_BINARY } }, + "Scan SSIDs", ATTR_ARRAY, {}, ATTR_BINARY }, { NL80211_ATTR_GENERATION, "Generation", ATTR_U32 }, { NL80211_ATTR_BSS,
@@ -6488,8 +6488,7 @@ static const struct attr_entry attr_table[] = { {NL80211_ATTR_ACL_POLICY , "ACL Policy", ATTR_U32 }, { NL80211_ATTR_MAC_ADDRS, -"MAC Addresses" ,ATTR_ARRAY , - { .array_type = ATTR_ADDRESS } }, + "MAC Addresses", ATTR_ARRAY, {}, ATTR_ADDRESS }, { NL80211_ATTR_MAC_ACL_MAX, "MAC ACL Max" }, { NL80211_ATTR_RADAR_EVENT,
@@ -6691,6 +6690,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 +6700,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 +6846,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
PATCH 3/4 monitor: print out type of unknown element
In reply to James PrestwoodThis 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
@@ -6741,7 +6741,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 ;
@@ -6761,7 +6761,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
PATCH 4/4 monitor: add support for HE element
In reply to James PrestwoodSupport for the HE IE.
--- monitor/nlmon.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
monitor/nlmon.c +20 -0
@@ -5540,6 +5540,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 } },
@@ -5553,6 +5571,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