]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
completely unify MCS parsing
authorJohannes Berg <johannes@sipsolutions.net>
Tue, 8 Dec 2009 09:11:22 +0000 (10:11 +0100)
committerJohannes Berg <johannes@sipsolutions.net>
Tue, 8 Dec 2009 09:11:22 +0000 (10:11 +0100)
Luis left two different ways to parse the MCS set,
one of which was completely endianness broken. Fix
this up by using the correct one in both places.

info.c
iw.h
scan.c
util.c

diff --git a/info.c b/info.c
index 4a86377077d4a74948bd6bdd5db03baffce412b5..69af2164f81af49ef7020debb12a2f474c0d5448 100644 (file)
--- a/info.c
+++ b/info.c
@@ -83,48 +83,8 @@ static int print_phy_handler(struct nl_msg *msg, void *arg)
                        print_ampdu_spacing(spacing);
                }
                if (tb_band[NL80211_BAND_ATTR_HT_MCS_SET] &&
-                   nla_len(tb_band[NL80211_BAND_ATTR_HT_MCS_SET]) == 16) {
-                       /* As defined in 7.3.2.57.4 Supported MCS Set field */
-                       unsigned int tx_max_num_spatial_streams, max_rx_supp_data_rate;
-                       unsigned char *mcs = nla_data(tb_band[NL80211_BAND_ATTR_HT_MCS_SET]);
-                       bool tx_mcs_set_defined, tx_mcs_set_equal, tx_unequal_modulation;
-
-                       max_rx_supp_data_rate = ((mcs[10] >> 8) & ((mcs[11] & 0x3) << 8));
-                       tx_mcs_set_defined = !!(mcs[12] & (1 << 0));
-                       tx_mcs_set_equal = !(mcs[12] & (1 << 1));
-                       tx_max_num_spatial_streams = ((mcs[12] >> 2) & 3) + 1;
-                       tx_unequal_modulation = !!(mcs[12] & (1 << 4));
-
-                       if (max_rx_supp_data_rate)
-                               printf("\t\tHT Max RX data rate: %d Mbps\n", max_rx_supp_data_rate);
-                       /* XXX: else see 9.6.0e.5.3 how to get this I think */
-
-                       if (tx_mcs_set_defined) {
-                               if (tx_mcs_set_equal) {
-                                       printf("\t\tHT TX/RX MCS rate indexes supported:\n");
-                                       print_mcs_index(&mcs[0]);
-                               } else {
-                                       printf("\t\tHT RX MCS rate indexes supported:");
-                                       print_mcs_index(&mcs[0]);
-
-                                       if (tx_unequal_modulation)
-                                               printf("\t\tTX unequal modulation supported\n");
-                                       else
-                                               printf("\t\tTX unequal modulation not supported\n");
-
-                                       printf("\t\tHT TX Max spatial streams: %d\n",
-                                               tx_max_num_spatial_streams);
-
-                                       printf("\t\tHT TX MCS rate indexes supported may differ\n");
-                               }
-                       }
-                       else {
-                               printf("\t\tHT RX MCS rate indexes supported:");
-                               print_mcs_index(&mcs[0]);
-                               printf("\t\tHT TX MCS rates indexes are undefined\n");
-                       }
-
-               }
+                   nla_len(tb_band[NL80211_BAND_ATTR_HT_MCS_SET]) == 16)
+                       print_ht_mcs(nla_data(tb_band[NL80211_BAND_ATTR_HT_MCS_SET]));
 #endif
 
                printf("\t\tFrequencies:\n");
diff --git a/iw.h b/iw.h
index f480dbd1c5f977a97e1763edab5bf373dd84d3af..5e1bc455a6c675b2fa59b3db05cf306cb9b03ea0 100644 (file)
--- a/iw.h
+++ b/iw.h
@@ -120,7 +120,7 @@ void mac_addr_n2a(char *mac_addr, unsigned char *arg);
 
 int parse_keys(struct nl_msg *msg, char **argv, int argc);
 
-void print_mcs_index(__u8 *mcs);
+void print_ht_mcs(const __u8 *mcs);
 void print_ampdu_length(__u8 exponent);
 void print_ampdu_spacing(__u8 spacing);
 void print_ht_capability(__u16 cap);
diff --git a/scan.c b/scan.c
index 16bb5464caecef37e80a2d2ed696aff10489f85e..d37ae7c2b28b88b3b9d97beaeb65298cb2282e9e 100644 (file)
--- a/scan.c
+++ b/scan.c
@@ -423,77 +423,15 @@ static void print_rsn(const uint8_t type, uint8_t len, const uint8_t *data)
 
 static void print_ht_capa(const uint8_t type, uint8_t len, const uint8_t *data)
 {
-#define PRINT_HT_CAP(_cond, _str) \
-       do { \
-               if (_cond) \
-                       printf("\t\t\t" _str "\n"); \
-       } while (0)
-       struct ht_cap_data {
-               __u16 cap;
-               __u8 ampdu_params;
-               struct {
-                       __u8 rx_mcs_bitmask[10]; /* last 3 bits reserved */
-                       __u16 max_rx_rate_1mbps: 10,
-                             reserved_0: 6;
-                       __u8 tx_rx_mcs_defined:1,
-                            tx_rx_mcs_not_equal:1,
-                            tx_max_streams:2,
-                            tx_unequal_modulation:1,
-                            reserved_1:3; /* 3 reserved bits here */
-                       __u8 reserved_2[3]; /* 24 reserved bits here = 27 */
-               } mcs_set;
-               __u16 ht_extend_cap;
-               __u32 tx_beamform_cap;
-               __u8 asel_cap;
-       } __attribute__((packed)) ht_cap;
-       struct ht_cap_data *htc = &ht_cap;
-       __u8 ampdu_exponent, ampdu_spacing;
-       bool tx_rx_mcs_equal = false;
-
        if (len != 26) {
                printf("\n\t\tHT Capability IE len != expected 26 bytes, skipping parse\n");
                return;
        }
-
-       memcpy(&ht_cap, data, 26);
-
        printf("\n");
-       print_ht_capability(htc->cap);
-
-
-       ampdu_exponent = htc->ampdu_params & 0x3;
-       print_ampdu_length(ampdu_exponent);
-
-       ampdu_spacing = (htc->ampdu_params >> 2) & 0x3;
-       print_ampdu_spacing(ampdu_spacing);
-
-       if (htc->mcs_set.tx_rx_mcs_defined && htc->mcs_set.tx_rx_mcs_not_equal)
-               tx_rx_mcs_equal = true;
-       if (tx_rx_mcs_equal)
-               printf("\t\tSupported TX/RX MCS Indexes:");
-       else
-               printf("\t\tSupported RX MCS Indexes:");
-
-       print_mcs_index(htc->mcs_set.rx_mcs_bitmask);
-
-       if (!htc->mcs_set.tx_rx_mcs_defined) {
-               /* This is actually quite common */
-               printf("\t\tNo TX MCS set defined\n");
-               goto out;
-       }
-
-       if (htc->mcs_set.tx_rx_mcs_not_equal) {
-               printf("\t\tMaximum supported TX spatial streams: %d\n",
-                      htc->mcs_set.tx_max_streams);
-               printf("\t\tTX unequal modulation ");
-               if (htc->mcs_set.tx_unequal_modulation)
-                       printf("supported\n");
-               else
-                       printf("unsupported\n");
-       }
-
-out:
-       return;
+       print_ht_capability(data[0] | (data[1] << 8));
+       print_ampdu_length(data[2] & 3);
+       print_ampdu_spacing((data[2] >> 2) & 3);
+       print_ht_mcs(data + 3);
 }
 
 static void print_capabilities(const uint8_t type, uint8_t len, const uint8_t *data)
diff --git a/util.c b/util.c
index 50ea9f51f96711240ac8a36a8702ad698d2025d4..13ebfab60f694eb24c4ebd0c62c5080b20da540f 100644 (file)
--- a/util.c
+++ b/util.c
@@ -293,7 +293,7 @@ int parse_keys(struct nl_msg *msg, char **argv, int argc)
        return 2;
 }
 
-void print_mcs_index(__u8 *mcs)
+static void print_mcs_index(const __u8 *mcs)
 {
        unsigned int mcs_bit, prev_bit = -2, prev_cont = 0;
 
@@ -430,3 +430,44 @@ void print_ht_capability(__u16 cap)
        PRINT_HT_CAP((cap & BIT(15)), "L-SIG TXOP protection");
 #undef PRINT_HT_CAP
 }
+
+void print_ht_mcs(const __u8 *mcs)
+{
+       /* As defined in 7.3.2.57.4 Supported MCS Set field */
+       unsigned int tx_max_num_spatial_streams, max_rx_supp_data_rate;
+       bool tx_mcs_set_defined, tx_mcs_set_equal, tx_unequal_modulation;
+
+       max_rx_supp_data_rate = ((mcs[10] >> 8) & ((mcs[11] & 0x3) << 8));
+       tx_mcs_set_defined = !!(mcs[12] & (1 << 0));
+       tx_mcs_set_equal = !(mcs[12] & (1 << 1));
+       tx_max_num_spatial_streams = ((mcs[12] >> 2) & 3) + 1;
+       tx_unequal_modulation = !!(mcs[12] & (1 << 4));
+
+       if (max_rx_supp_data_rate)
+               printf("\t\tHT Max RX data rate: %d Mbps\n", max_rx_supp_data_rate);
+       /* XXX: else see 9.6.0e.5.3 how to get this I think */
+
+       if (tx_mcs_set_defined) {
+               if (tx_mcs_set_equal) {
+                       printf("\t\tHT TX/RX MCS rate indexes supported:\n");
+                       print_mcs_index(mcs);
+               } else {
+                       printf("\t\tHT RX MCS rate indexes supported:");
+                       print_mcs_index(mcs);
+
+                       if (tx_unequal_modulation)
+                               printf("\t\tTX unequal modulation supported\n");
+                       else
+                               printf("\t\tTX unequal modulation not supported\n");
+
+                       printf("\t\tHT TX Max spatial streams: %d\n",
+                               tx_max_num_spatial_streams);
+
+                       printf("\t\tHT TX MCS rate indexes supported may differ\n");
+               }
+       } else {
+               printf("\t\tHT RX MCS rate indexes supported:");
+               print_mcs_index(mcs);
+               printf("\t\tHT TX MCS rates indexes are undefined\n");
+       }
+}