]> git.ipfire.org Git - thirdparty/iw.git/blame - phy.c
use C99 initialiser for cmd struct
[thirdparty/iw.git] / phy.c
CommitLineData
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
14static 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
JB
27}
28COMMAND(set, name, "<new name>", NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_name);
b822cda9 29
379f8397
JB
30static int handle_freqchan(struct nl_msg *msg, bool chan,
31 int argc, char **argv)
b822cda9
JB
32{
33 static const struct {
34 const char *name;
35 unsigned int val;
36 } htmap[] = {
68632dc7
JB
37 { .name = "HT20", .val = NL80211_CHAN_HT20, },
38 { .name = "HT40+", .val = NL80211_CHAN_HT40PLUS, },
39 { .name = "HT40-", .val = NL80211_CHAN_HT40MINUS, },
b822cda9 40 };
68632dc7 41 unsigned int htval = NL80211_CHAN_NO_HT;
b822cda9
JB
42 unsigned int freq;
43 int i;
44
45 if (!argc || argc > 2)
46 return 1;
47
48 if (argc == 2) {
7d736016 49 for (i = 0; i < ARRAY_SIZE(htmap); i++) {
b822cda9
JB
50 if (strcasecmp(htmap[i].name, argv[1]) == 0) {
51 htval = htmap[i].val;
52 break;
53 }
54 }
68632dc7 55 if (htval == NL80211_CHAN_NO_HT)
b822cda9
JB
56 return 1;
57 }
58
59 freq = strtoul(argv[0], NULL, 10);
379f8397
JB
60 if (chan)
61 freq = ieee80211_channel_to_frequency(freq);
b822cda9
JB
62
63 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
68632dc7 64 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, htval);
b822cda9
JB
65
66 return 0;
67 nla_put_failure:
68 return -ENOBUFS;
69}
379f8397 70
7c37a24d
JB
71static int handle_freq(struct nl80211_state *state,
72 struct nl_cb *cb, struct nl_msg *msg,
379f8397
JB
73 int argc, char **argv)
74{
75 return handle_freqchan(msg, false, argc, argv);
76}
b822cda9
JB
77COMMAND(set, freq, "<freq> [HT20|HT40+|HT40-]",
78 NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_freq);
79COMMAND(set, freq, "<freq> [HT20|HT40+|HT40-]",
80 NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_freq);
379f8397 81
7c37a24d
JB
82static int handle_chan(struct nl80211_state *state,
83 struct nl_cb *cb, struct nl_msg *msg,
379f8397
JB
84 int argc, char **argv)
85{
86 return handle_freqchan(msg, true, argc, argv);
87}
88COMMAND(set, channel, "<channel> [HT20|HT40+|HT40-]",
89 NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_chan);
90COMMAND(set, channel, "<channel> [HT20|HT40+|HT40-]",
91 NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_chan);