]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
show channels and allow setting frequency by channel
authorJohannes Berg <johannes@sipsolutions.net>
Mon, 8 Dec 2008 11:53:58 +0000 (12:53 +0100)
committerJohannes Berg <johannes@sipsolutions.net>
Mon, 8 Dec 2008 11:53:58 +0000 (12:53 +0100)
info.c
iw.h
phy.c
util.c

diff --git a/info.c b/info.c
index 7e2467ff88e59e15823a369732c69d5af67b01ef..cbc3086df148aac1668ab837f9e88cd56a61d96d 100644 (file)
--- a/info.c
+++ b/info.c
@@ -138,11 +138,13 @@ static int print_phy_handler(struct nl_msg *msg, void *arg)
                printf("\t\tFrequencies:\n");
 
                nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
+                       uint32_t freq;
                        nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq),
                                  nla_len(nl_freq), freq_policy);
                        if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
                                continue;
-                       printf("\t\t\t* %d MHz", nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]));
+                       freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
+                       printf("\t\t\t* %d MHz [%d]", freq, ieee80211_frequency_to_channel(freq));
 
                        if (tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] &&
                            !tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
diff --git a/iw.h b/iw.h
index a69bd3098c72aabd917b82cdc8f0deb60b37c6c7..3967368ef05422e8de7012cfbd122cb43523f094 100644 (file)
--- a/iw.h
+++ b/iw.h
@@ -57,6 +57,8 @@ int mac_addr_a2n(unsigned char *mac_addr, char *arg);
 int mac_addr_n2a(char *mac_addr, unsigned char *arg);
 
 const char *iftype_name(enum nl80211_iftype iftype);
+int ieee80211_channel_to_frequency(int chan);
+int ieee80211_frequency_to_channel(int freq);
 
 int nl_get_multicast_id(struct nl_handle *handle, const char *family, const char *group);
 
diff --git a/phy.c b/phy.c
index 98de1fc5ce3fe1149c0ff1368bc9325ae801f6e8..45d4e78fefd28b95aed3954bc0df6a60c2ffa62d 100644 (file)
--- a/phy.c
+++ b/phy.c
@@ -1,3 +1,4 @@
+#include <stdbool.h>
 #include <errno.h>
 #include <net/if.h>
 
@@ -25,8 +26,8 @@ static int handle_name(struct nl_cb *cb,
 }
 COMMAND(set, name, "<new name>", NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_name);
 
-static int handle_freq(struct nl_cb *cb, struct nl_msg *msg,
-                      int argc, char **argv)
+static int handle_freqchan(struct nl_msg *msg, bool chan,
+                          int argc, char **argv)
 {
        static const struct {
                const char *name;
@@ -55,6 +56,8 @@ static int handle_freq(struct nl_cb *cb, struct nl_msg *msg,
        }
 
        freq = strtoul(argv[0], NULL, 10);
+       if (chan)
+               freq = ieee80211_channel_to_frequency(freq);
 
        NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
        NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_SEC_CHAN_OFFSET, htval);
@@ -63,7 +66,23 @@ static int handle_freq(struct nl_cb *cb, struct nl_msg *msg,
  nla_put_failure:
        return -ENOBUFS;
 }
+
+static int handle_freq(struct nl_cb *cb, struct nl_msg *msg,
+                      int argc, char **argv)
+{
+       return handle_freqchan(msg, false, argc, argv);
+}
 COMMAND(set, freq, "<freq> [HT20|HT40+|HT40-]",
        NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_freq);
 COMMAND(set, freq, "<freq> [HT20|HT40+|HT40-]",
        NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_freq);
+
+static int handle_chan(struct nl_cb *cb, struct nl_msg *msg,
+                      int argc, char **argv)
+{
+       return handle_freqchan(msg, true, argc, argv);
+}
+COMMAND(set, channel, "<channel> [HT20|HT40+|HT40-]",
+       NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_chan);
+COMMAND(set, channel, "<channel> [HT20|HT40+|HT40-]",
+       NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_chan);
diff --git a/util.c b/util.c
index 4d1c1a69a844beaed2bd964378294066cd0f9e95..40a9568c02486fe65102f5de8df51df0c0764a7e 100644 (file)
--- a/util.c
+++ b/util.c
@@ -65,3 +65,27 @@ const char *iftype_name(enum nl80211_iftype iftype)
        sprintf(modebuf, "Unknown mode (%d)", iftype);
        return modebuf;
 }
+
+int ieee80211_channel_to_frequency(int chan)
+{
+       if (chan < 14)
+               return 2407 + chan * 5;
+
+       if (chan == 14)
+               return 2484;
+
+       /* FIXME: dot11ChannelStartingFactor (802.11-2007 17.3.8.3.2) */
+       return (chan + 1000) * 5;
+}
+
+int ieee80211_frequency_to_channel(int freq)
+{
+       if (freq == 2484)
+               return 14;
+
+       if (freq < 2484)
+               return (freq - 2407) / 5;
+
+       /* FIXME: dot11ChannelStartingFactor (802.11-2007 17.3.8.3.2) */
+       return freq/5 - 1000;
+}