]>
Commit | Line | Data |
---|---|---|
379f8397 | 1 | #include <stdbool.h> |
0f55e0b8 | 2 | #include <errno.h> |
0f55e0b8 JB |
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 | ||
f408e01b | 11 | #include "nl80211.h" |
0f55e0b8 JB |
12 | #include "iw.h" |
13 | ||
7c37a24d JB |
14 | static int handle_name(struct nl80211_state *state, |
15 | struct nl_cb *cb, | |
0f55e0b8 JB |
16 | struct nl_msg *msg, |
17 | int argc, char **argv) | |
18 | { | |
0f55e0b8 | 19 | if (argc != 1) |
5e75fd04 | 20 | return 1; |
0f55e0b8 JB |
21 | |
22 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, *argv); | |
23 | ||
70391ccf | 24 | return 0; |
0f55e0b8 | 25 | nla_put_failure: |
70391ccf | 26 | return -ENOBUFS; |
0f55e0b8 | 27 | } |
cea8fa1c JB |
28 | COMMAND(set, name, "<new name>", NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_name, |
29 | "Rename this wireless device."); | |
b822cda9 | 30 | |
379f8397 JB |
31 | static int handle_freqchan(struct nl_msg *msg, bool chan, |
32 | int argc, char **argv) | |
b822cda9 JB |
33 | { |
34 | static const struct { | |
35 | const char *name; | |
36 | unsigned int val; | |
37 | } htmap[] = { | |
68632dc7 JB |
38 | { .name = "HT20", .val = NL80211_CHAN_HT20, }, |
39 | { .name = "HT40+", .val = NL80211_CHAN_HT40PLUS, }, | |
40 | { .name = "HT40-", .val = NL80211_CHAN_HT40MINUS, }, | |
b822cda9 | 41 | }; |
68632dc7 | 42 | unsigned int htval = NL80211_CHAN_NO_HT; |
b822cda9 JB |
43 | unsigned int freq; |
44 | int i; | |
45 | ||
46 | if (!argc || argc > 2) | |
47 | return 1; | |
48 | ||
49 | if (argc == 2) { | |
7d736016 | 50 | for (i = 0; i < ARRAY_SIZE(htmap); i++) { |
b822cda9 JB |
51 | if (strcasecmp(htmap[i].name, argv[1]) == 0) { |
52 | htval = htmap[i].val; | |
53 | break; | |
54 | } | |
55 | } | |
68632dc7 | 56 | if (htval == NL80211_CHAN_NO_HT) |
b822cda9 JB |
57 | return 1; |
58 | } | |
59 | ||
60 | freq = strtoul(argv[0], NULL, 10); | |
379f8397 JB |
61 | if (chan) |
62 | freq = ieee80211_channel_to_frequency(freq); | |
b822cda9 JB |
63 | |
64 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); | |
68632dc7 | 65 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, htval); |
b822cda9 JB |
66 | |
67 | return 0; | |
68 | nla_put_failure: | |
69 | return -ENOBUFS; | |
70 | } | |
379f8397 | 71 | |
7c37a24d JB |
72 | static int handle_freq(struct nl80211_state *state, |
73 | struct nl_cb *cb, struct nl_msg *msg, | |
379f8397 JB |
74 | int argc, char **argv) |
75 | { | |
76 | return handle_freqchan(msg, false, argc, argv); | |
77 | } | |
b822cda9 | 78 | COMMAND(set, freq, "<freq> [HT20|HT40+|HT40-]", |
00c448b2 JB |
79 | NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_freq, |
80 | "Set frequency/channel the hardware is using, including HT\n" | |
81 | "configuration."); | |
b822cda9 | 82 | COMMAND(set, freq, "<freq> [HT20|HT40+|HT40-]", |
01ae06f9 | 83 | NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_freq, NULL); |
379f8397 | 84 | |
7c37a24d JB |
85 | static int handle_chan(struct nl80211_state *state, |
86 | struct nl_cb *cb, struct nl_msg *msg, | |
379f8397 JB |
87 | int argc, char **argv) |
88 | { | |
89 | return handle_freqchan(msg, true, argc, argv); | |
90 | } | |
91 | COMMAND(set, channel, "<channel> [HT20|HT40+|HT40-]", | |
01ae06f9 | 92 | NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_chan, NULL); |
379f8397 | 93 | COMMAND(set, channel, "<channel> [HT20|HT40+|HT40-]", |
01ae06f9 | 94 | NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_chan, NULL); |