]> git.ipfire.org Git - thirdparty/iw.git/blob - phy.c
add note to set channel/freq
[thirdparty/iw.git] / phy.c
1 #include <stdbool.h>
2 #include <errno.h>
3 #include <net/if.h>
4
5 #include <netlink/genl/genl.h>
6 #include <netlink/genl/family.h>
7 #include <netlink/genl/ctrl.h>
8 #include <netlink/msg.h>
9 #include <netlink/attr.h>
10
11 #include "nl80211.h"
12 #include "iw.h"
13
14 static int handle_name(struct nl80211_state *state,
15 struct nl_cb *cb,
16 struct nl_msg *msg,
17 int argc, char **argv)
18 {
19 if (argc != 1)
20 return 1;
21
22 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, *argv);
23
24 return 0;
25 nla_put_failure:
26 return -ENOBUFS;
27 }
28 COMMAND(set, name, "<new name>", NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_name, NULL);
29
30 static int handle_freqchan(struct nl_msg *msg, bool chan,
31 int argc, char **argv)
32 {
33 static const struct {
34 const char *name;
35 unsigned int val;
36 } htmap[] = {
37 { .name = "HT20", .val = NL80211_CHAN_HT20, },
38 { .name = "HT40+", .val = NL80211_CHAN_HT40PLUS, },
39 { .name = "HT40-", .val = NL80211_CHAN_HT40MINUS, },
40 };
41 unsigned int htval = NL80211_CHAN_NO_HT;
42 unsigned int freq;
43 int i;
44
45 if (!argc || argc > 2)
46 return 1;
47
48 if (argc == 2) {
49 for (i = 0; i < ARRAY_SIZE(htmap); i++) {
50 if (strcasecmp(htmap[i].name, argv[1]) == 0) {
51 htval = htmap[i].val;
52 break;
53 }
54 }
55 if (htval == NL80211_CHAN_NO_HT)
56 return 1;
57 }
58
59 freq = strtoul(argv[0], NULL, 10);
60 if (chan)
61 freq = ieee80211_channel_to_frequency(freq);
62
63 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
64 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, htval);
65
66 return 0;
67 nla_put_failure:
68 return -ENOBUFS;
69 }
70
71 static int handle_freq(struct nl80211_state *state,
72 struct nl_cb *cb, struct nl_msg *msg,
73 int argc, char **argv)
74 {
75 return handle_freqchan(msg, false, argc, argv);
76 }
77 COMMAND(set, freq, "<freq> [HT20|HT40+|HT40-]",
78 NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_freq,
79 "Set frequency/channel the hardware is using, including HT\n"
80 "configuration.");
81 COMMAND(set, freq, "<freq> [HT20|HT40+|HT40-]",
82 NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_freq, NULL);
83
84 static int handle_chan(struct nl80211_state *state,
85 struct nl_cb *cb, struct nl_msg *msg,
86 int argc, char **argv)
87 {
88 return handle_freqchan(msg, true, argc, argv);
89 }
90 COMMAND(set, channel, "<channel> [HT20|HT40+|HT40-]",
91 NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_chan, NULL);
92 COMMAND(set, channel, "<channel> [HT20|HT40+|HT40-]",
93 NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_chan, NULL);