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])
+#include <stdbool.h>
#include <errno.h>
#include <net/if.h>
}
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;
}
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);
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);
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;
+}