]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
update for VHT channel config
authorJohannes Berg <johannes.berg@intel.com>
Tue, 20 Nov 2012 15:52:12 +0000 (16:52 +0100)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 28 Nov 2012 22:02:49 +0000 (23:02 +0100)
interface.c
phy.c

index 5a7647a9c7f019f39a9f13ae69929e3018badfa8..26e72dce3bb536e1d2b776cc5f0bd6e6cf81b232 100644 (file)
@@ -262,6 +262,26 @@ static char *channel_type_name(enum nl80211_channel_type channel_type)
        }
 }
 
+static char *channel_width_name(enum nl80211_chan_width width)
+{
+       switch (width) {
+       case NL80211_CHAN_WIDTH_20_NOHT:
+               return "20 MHz (no HT)";
+       case NL80211_CHAN_WIDTH_20:
+               return "20 MHz";
+       case NL80211_CHAN_WIDTH_40:
+               return "40 MHz";
+       case NL80211_CHAN_WIDTH_80:
+               return "80 MHz";
+       case NL80211_CHAN_WIDTH_80P80:
+               return "80+80 MHz";
+       case NL80211_CHAN_WIDTH_160:
+               return "160 MHz";
+       default:
+               return "unknown";
+       }
+}
+
 static int print_iface_handler(struct nl_msg *msg, void *arg)
 {
        struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
@@ -306,14 +326,27 @@ static int print_iface_handler(struct nl_msg *msg, void *arg)
                printf("%s\twiphy %d\n", indent, nla_get_u32(tb_msg[NL80211_ATTR_WIPHY]));
        if (tb_msg[NL80211_ATTR_WIPHY_FREQ]) {
                uint32_t freq = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_FREQ]);
-               enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
 
-               if (tb_msg[NL80211_ATTR_WIPHY_CHANNEL_TYPE])
+               printf("%s\tchannel %d (%d MHz)", indent,
+                      ieee80211_frequency_to_channel(freq), freq);
+
+               if (tb_msg[NL80211_ATTR_CHANNEL_WIDTH]) {
+                       printf(", width: %s",
+                               channel_width_name(nla_get_u32(tb_msg[NL80211_ATTR_CHANNEL_WIDTH])));
+                       if (tb_msg[NL80211_ATTR_CENTER_FREQ1])
+                               printf(", center1: %d MHz",
+                                       nla_get_u32(tb_msg[NL80211_ATTR_CENTER_FREQ1]));
+                       if (tb_msg[NL80211_ATTR_CENTER_FREQ2])
+                               printf(", center2: %d MHz",
+                                       nla_get_u32(tb_msg[NL80211_ATTR_CENTER_FREQ2]));
+               } else if (tb_msg[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
+                       enum nl80211_channel_type channel_type;
+
                        channel_type = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
+                       printf(" %s", channel_type_name(channel_type));
+               }
 
-               printf("%s\tchannel %d (%d MHz) %s\n", indent,
-                      ieee80211_frequency_to_channel(freq), freq,
-                      channel_type_name(channel_type));
+               printf("\n");
        }
 
        return NL_SKIP;
diff --git a/phy.c b/phy.c
index 860f29936392830b299694aa755e2d06335793f3..7f8ce26a70b0290c265e0278151b5d854fda46ea 100644 (file)
--- a/phy.c
+++ b/phy.c
@@ -30,6 +30,64 @@ static int handle_name(struct nl80211_state *state,
 COMMAND(set, name, "<new name>", NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_name,
        "Rename this wireless device.");
 
+static int handle_freqs(struct nl_msg *msg, int argc, char **argv)
+{
+       static const struct {
+               const char *name;
+               unsigned int val;
+       } bwmap[] = {
+               { .name = "20", .val = NL80211_CHAN_WIDTH_20, },
+               { .name = "40", .val = NL80211_CHAN_WIDTH_40, },
+               { .name = "80", .val = NL80211_CHAN_WIDTH_80, },
+               { .name = "80+80", .val = NL80211_CHAN_WIDTH_80P80, },
+               { .name = "160", .val = NL80211_CHAN_WIDTH_160, },
+       };
+       uint32_t freq;
+       int i, bwval = NL80211_CHAN_WIDTH_20_NOHT;
+       char *end;
+
+       if (argc < 1)
+               return 1;
+
+       for (i = 0; i < ARRAY_SIZE(bwmap); i++) {
+               if (strcasecmp(bwmap[i].name, argv[0]) == 0) {
+                       bwval = bwmap[i].val;
+                       break;
+               }
+       }
+
+       if (bwval == NL80211_CHAN_WIDTH_20_NOHT)
+               return 1;
+
+       NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, bwval);
+
+       if (argc == 1)
+               return 0;
+
+       /* center freq 1 */
+       if (!*argv[1])
+               return 1;
+       freq = strtoul(argv[1], &end, 10);
+       if (*end)
+               return 1;
+       NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ1, freq);
+
+       if (argc == 2)
+               return 0;
+
+       /* center freq 2 */
+       if (!*argv[2])
+               return 1;
+       freq = strtoul(argv[2], &end, 10);
+       if (*end)
+               return 1;
+       NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ2, freq);
+
+       return 0;
+ nla_put_failure:
+       return -ENOBUFS;
+}
+
 static int handle_freqchan(struct nl_msg *msg, bool chan,
                           int argc, char **argv)
 {
@@ -46,20 +104,9 @@ static int handle_freqchan(struct nl_msg *msg, bool chan,
        unsigned int freq;
        int i;
 
-       if (!argc || argc > 2)
+       if (!argc || argc > 4)
                return 1;
 
-       if (argc == 2) {
-               for (i = 0; i < ARRAY_SIZE(htmap); i++) {
-                       if (strcasecmp(htmap[i].name, argv[1]) == 0) {
-                               htval = htmap[i].val;
-                               break;
-                       }
-               }
-               if (htval == NL80211_CHAN_NO_HT)
-                       return 1;
-       }
-
        if (!*argv[0])
                return 1;
        freq = strtoul(argv[0], &end, 10);
@@ -70,6 +117,20 @@ static int handle_freqchan(struct nl_msg *msg, bool chan,
                freq = ieee80211_channel_to_frequency(freq);
 
        NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
+
+       if (argc > 2) {
+               return handle_freqs(msg, argc - 1, argv + 1);
+       } else if (argc == 2) {
+               for (i = 0; i < ARRAY_SIZE(htmap); i++) {
+                       if (strcasecmp(htmap[i].name, argv[1]) == 0) {
+                               htval = htmap[i].val;
+                               break;
+                       }
+               }
+               if (htval == NL80211_CHAN_NO_HT)
+                       return handle_freqs(msg, argc - 1, argv + 1);
+       }
+
        NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, htval);
 
        return 0;
@@ -88,7 +149,8 @@ COMMAND(set, freq, "<freq> [HT20|HT40+|HT40-]",
        NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_freq,
        "Set frequency/channel the hardware is using, including HT\n"
        "configuration.");
-COMMAND(set, freq, "<freq> [HT20|HT40+|HT40-]",
+COMMAND(set, freq, "<freq> [HT20|HT40+|HT40-]\n"
+                  "<control freq> [20|40|80|80+80|160] [<center freq 1>] [<center freq 2>]",
        NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_freq, NULL);
 
 static int handle_chan(struct nl80211_state *state,