]> git.ipfire.org Git - thirdparty/iw.git/blame - phy.c
print unknown events
[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
70391ccf 14static int handle_name(struct nl_cb *cb,
0f55e0b8
JB
15 struct nl_msg *msg,
16 int argc, char **argv)
17{
0f55e0b8 18 if (argc != 1)
5e75fd04 19 return 1;
0f55e0b8
JB
20
21 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, *argv);
22
70391ccf 23 return 0;
0f55e0b8 24 nla_put_failure:
70391ccf 25 return -ENOBUFS;
0f55e0b8
JB
26}
27COMMAND(set, name, "<new name>", NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_name);
b822cda9 28
379f8397
JB
29static int handle_freqchan(struct nl_msg *msg, bool chan,
30 int argc, char **argv)
b822cda9
JB
31{
32 static const struct {
33 const char *name;
34 unsigned int val;
35 } htmap[] = {
36 { .name = "HT20", .val = NL80211_SEC_CHAN_DISABLED, },
37 { .name = "HT40+", .val = NL80211_SEC_CHAN_ABOVE, },
38 { .name = "HT40-", .val = NL80211_SEC_CHAN_BELOW, },
39 };
40 unsigned int htval = NL80211_SEC_CHAN_NO_HT;
41 unsigned int freq;
42 int i;
43
44 if (!argc || argc > 2)
45 return 1;
46
47 if (argc == 2) {
7d736016 48 for (i = 0; i < ARRAY_SIZE(htmap); i++) {
b822cda9
JB
49 if (strcasecmp(htmap[i].name, argv[1]) == 0) {
50 htval = htmap[i].val;
51 break;
52 }
53 }
54 if (htval == NL80211_SEC_CHAN_NO_HT)
55 return 1;
56 }
57
58 freq = strtoul(argv[0], NULL, 10);
379f8397
JB
59 if (chan)
60 freq = ieee80211_channel_to_frequency(freq);
b822cda9
JB
61
62 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
63 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_SEC_CHAN_OFFSET, htval);
64
65 return 0;
66 nla_put_failure:
67 return -ENOBUFS;
68}
379f8397
JB
69
70static int handle_freq(struct nl_cb *cb, struct nl_msg *msg,
71 int argc, char **argv)
72{
73 return handle_freqchan(msg, false, argc, argv);
74}
b822cda9
JB
75COMMAND(set, freq, "<freq> [HT20|HT40+|HT40-]",
76 NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_freq);
77COMMAND(set, freq, "<freq> [HT20|HT40+|HT40-]",
78 NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_freq);
379f8397
JB
79
80static int handle_chan(struct nl_cb *cb, struct nl_msg *msg,
81 int argc, char **argv)
82{
83 return handle_freqchan(msg, true, argc, argv);
84}
85COMMAND(set, channel, "<channel> [HT20|HT40+|HT40-]",
86 NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_chan);
87COMMAND(set, channel, "<channel> [HT20|HT40+|HT40-]",
88 NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_chan);