blob: b34f9db856d56a5d9b09b0e3daff6102d76308ab [file] [log] [blame]
Johannes Berg379f8392008-12-08 12:53:58 +01001#include <stdbool.h>
Johannes Berg0f55e0b2008-09-16 17:40:48 +02002#include <errno.h>
Johannes Berg0f55e0b2008-09-16 17:40:48 +02003#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
Johannes Bergf408e012008-09-18 19:32:11 +020011#include "nl80211.h"
Johannes Berg0f55e0b2008-09-16 17:40:48 +020012#include "iw.h"
13
Johannes Berg7c37a242009-04-08 13:13:28 +020014static int handle_name(struct nl80211_state *state,
15 struct nl_cb *cb,
Johannes Berg0f55e0b2008-09-16 17:40:48 +020016 struct nl_msg *msg,
17 int argc, char **argv)
18{
Johannes Berg0f55e0b2008-09-16 17:40:48 +020019 if (argc != 1)
Johannes Berg5e75fd02008-09-16 18:13:12 +020020 return 1;
Johannes Berg0f55e0b2008-09-16 17:40:48 +020021
22 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, *argv);
23
Johannes Berg70391cc2008-09-16 18:35:06 +020024 return 0;
Johannes Berg0f55e0b2008-09-16 17:40:48 +020025 nla_put_failure:
Johannes Berg70391cc2008-09-16 18:35:06 +020026 return -ENOBUFS;
Johannes Berg0f55e0b2008-09-16 17:40:48 +020027}
Johannes Bergcea8fa12009-05-05 15:05:10 +020028COMMAND(set, name, "<new name>", NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_name,
29 "Rename this wireless device.");
Johannes Bergb822cda2008-12-08 12:43:42 +010030
Johannes Berg379f8392008-12-08 12:53:58 +010031static int handle_freqchan(struct nl_msg *msg, bool chan,
32 int argc, char **argv)
Johannes Bergb822cda2008-12-08 12:43:42 +010033{
34 static const struct {
35 const char *name;
36 unsigned int val;
37 } htmap[] = {
Johannes Berg68632dc2008-12-12 22:40:45 +010038 { .name = "HT20", .val = NL80211_CHAN_HT20, },
39 { .name = "HT40+", .val = NL80211_CHAN_HT40PLUS, },
40 { .name = "HT40-", .val = NL80211_CHAN_HT40MINUS, },
Johannes Bergb822cda2008-12-08 12:43:42 +010041 };
Johannes Berg68632dc2008-12-12 22:40:45 +010042 unsigned int htval = NL80211_CHAN_NO_HT;
Johannes Bergb822cda2008-12-08 12:43:42 +010043 unsigned int freq;
44 int i;
45
46 if (!argc || argc > 2)
47 return 1;
48
49 if (argc == 2) {
Johannes Berg7d736012008-12-08 12:59:16 +010050 for (i = 0; i < ARRAY_SIZE(htmap); i++) {
Johannes Bergb822cda2008-12-08 12:43:42 +010051 if (strcasecmp(htmap[i].name, argv[1]) == 0) {
52 htval = htmap[i].val;
53 break;
54 }
55 }
Johannes Berg68632dc2008-12-12 22:40:45 +010056 if (htval == NL80211_CHAN_NO_HT)
Johannes Bergb822cda2008-12-08 12:43:42 +010057 return 1;
58 }
59
60 freq = strtoul(argv[0], NULL, 10);
Johannes Berg379f8392008-12-08 12:53:58 +010061 if (chan)
62 freq = ieee80211_channel_to_frequency(freq);
Johannes Bergb822cda2008-12-08 12:43:42 +010063
64 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
Johannes Berg68632dc2008-12-12 22:40:45 +010065 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, htval);
Johannes Bergb822cda2008-12-08 12:43:42 +010066
67 return 0;
68 nla_put_failure:
69 return -ENOBUFS;
70}
Johannes Berg379f8392008-12-08 12:53:58 +010071
Johannes Berg7c37a242009-04-08 13:13:28 +020072static int handle_freq(struct nl80211_state *state,
73 struct nl_cb *cb, struct nl_msg *msg,
Johannes Berg379f8392008-12-08 12:53:58 +010074 int argc, char **argv)
75{
76 return handle_freqchan(msg, false, argc, argv);
77}
Johannes Bergb822cda2008-12-08 12:43:42 +010078COMMAND(set, freq, "<freq> [HT20|HT40+|HT40-]",
Johannes Berg00c448b2009-05-05 15:04:19 +020079 NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_freq,
80 "Set frequency/channel the hardware is using, including HT\n"
81 "configuration.");
Johannes Bergb822cda2008-12-08 12:43:42 +010082COMMAND(set, freq, "<freq> [HT20|HT40+|HT40-]",
Johannes Berg01ae06f2009-05-05 14:48:16 +020083 NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_freq, NULL);
Johannes Berg379f8392008-12-08 12:53:58 +010084
Johannes Berg7c37a242009-04-08 13:13:28 +020085static int handle_chan(struct nl80211_state *state,
86 struct nl_cb *cb, struct nl_msg *msg,
Johannes Berg379f8392008-12-08 12:53:58 +010087 int argc, char **argv)
88{
89 return handle_freqchan(msg, true, argc, argv);
90}
91COMMAND(set, channel, "<channel> [HT20|HT40+|HT40-]",
Johannes Berg01ae06f2009-05-05 14:48:16 +020092 NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_chan, NULL);
Johannes Berg379f8392008-12-08 12:53:58 +010093COMMAND(set, channel, "<channel> [HT20|HT40+|HT40-]",
Johannes Berg01ae06f2009-05-05 14:48:16 +020094 NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_chan, NULL);
Johannes Berg625aa4a2009-08-11 11:26:42 +020095
96static int handle_fragmentation(struct nl80211_state *state,
97 struct nl_cb *cb, struct nl_msg *msg,
98 int argc, char **argv)
99{
100 unsigned int frag;
101
102 if (argc != 1)
103 return 1;
104
105 if (strcmp("off", argv[0]) == 0)
106 frag = -1;
107 else
108 frag = strtoul(argv[0], NULL, 10);
109
110 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, frag);
111
112 return 0;
113 nla_put_failure:
114 return -ENOBUFS;
115}
116COMMAND(set, frag, "<fragmentation threshold|off>",
117 NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_fragmentation,
118 "Set fragmentation threshold.");
119
120static int handle_rts(struct nl80211_state *state,
121 struct nl_cb *cb, struct nl_msg *msg,
122 int argc, char **argv)
123{
124 unsigned int rts;
125
126 if (argc != 1)
127 return 1;
128
129 if (strcmp("off", argv[0]) == 0)
130 rts = -1;
131 else
132 rts = strtoul(argv[0], NULL, 10);
133
134 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, rts);
135
136 return 0;
137 nla_put_failure:
138 return -ENOBUFS;
139}
140COMMAND(set, rts, "<rts threshold|off>",
141 NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_rts,
142 "Set rts threshold.");