]> git.ipfire.org Git - thirdparty/iw.git/blob - hwsim.c
update nl80211.h
[thirdparty/iw.git] / hwsim.c
1 #include <net/if.h>
2 #include <errno.h>
3 #include <string.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 /* These enums need to be kept in sync with the kernel */
15 enum hwsim_testmode_attr {
16 __HWSIM_TM_ATTR_INVALID = 0,
17 HWSIM_TM_ATTR_CMD = 1,
18 HWSIM_TM_ATTR_PS = 2,
19
20 /* keep last */
21 __HWSIM_TM_ATTR_AFTER_LAST,
22 HWSIM_TM_ATTR_MAX = __HWSIM_TM_ATTR_AFTER_LAST - 1
23 };
24
25 enum hwsim_testmode_cmd {
26 HWSIM_TM_CMD_SET_PS = 0,
27 HWSIM_TM_CMD_GET_PS = 1,
28 HWSIM_TM_CMD_STOP_QUEUES = 2,
29 HWSIM_TM_CMD_WAKE_QUEUES = 3,
30 };
31
32
33 SECTION(hwsim);
34
35 static int print_hwsim_ps_handler(struct nl_msg *msg, void *arg)
36 {
37 struct nlattr *attrs[NL80211_ATTR_MAX + 1];
38 struct nlattr *tb[HWSIM_TM_ATTR_MAX + 1];
39 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
40
41 nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
42 genlmsg_attrlen(gnlh, 0), NULL);
43
44 if (!attrs[NL80211_ATTR_TESTDATA])
45 return NL_SKIP;
46
47 nla_parse(tb, HWSIM_TM_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]),
48 nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL);
49
50 printf("HWSIM PS: %d\n", nla_get_u32(tb[HWSIM_TM_ATTR_PS]));
51
52 return NL_SKIP;
53 }
54
55 static int handle_hwsim_getps(struct nl80211_state *state, struct nl_cb *cb,
56 struct nl_msg *msg, int argc, char **argv)
57 {
58 struct nlattr *tmdata;
59
60 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
61 if (!tmdata)
62 goto nla_put_failure;
63
64 NLA_PUT_U32(msg, HWSIM_TM_ATTR_CMD, HWSIM_TM_CMD_GET_PS);
65
66 nla_nest_end(msg, tmdata);
67
68 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM,
69 print_hwsim_ps_handler, NULL);
70 return 0;
71 nla_put_failure:
72 return -ENOBUFS;
73 }
74 COMMAND(hwsim, getps, "", NL80211_CMD_TESTMODE, 0, CIB_PHY, handle_hwsim_getps, "");
75
76 static int handle_hwsim_setps(struct nl80211_state *state, struct nl_cb *cb,
77 struct nl_msg *msg, int argc, char **argv)
78 {
79 struct nlattr *tmdata;
80 __u32 ps;
81 char *end;
82
83 if (argc != 1)
84 return 1;
85
86 ps = strtoul(argv[0], &end, 0);
87 if (*end)
88 return 1;
89
90 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
91 if (!tmdata)
92 goto nla_put_failure;
93
94 NLA_PUT_U32(msg, HWSIM_TM_ATTR_CMD, HWSIM_TM_CMD_SET_PS);
95 NLA_PUT_U32(msg, HWSIM_TM_ATTR_PS, ps);
96
97 nla_nest_end(msg, tmdata);
98
99 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM,
100 print_hwsim_ps_handler, NULL);
101 return 0;
102 nla_put_failure:
103 return -ENOBUFS;
104 }
105 COMMAND(hwsim, setps, "<value>", NL80211_CMD_TESTMODE, 0, CIB_PHY, handle_hwsim_setps, "");
106
107 static int handle_hwsim_stop_queues(struct nl80211_state *state, struct nl_cb *cb,
108 struct nl_msg *msg, int argc, char **argv)
109 {
110 struct nlattr *tmdata;
111
112 if (argc != 0)
113 return 1;
114
115 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
116 if (!tmdata)
117 goto nla_put_failure;
118
119 NLA_PUT_U32(msg, HWSIM_TM_ATTR_CMD, HWSIM_TM_CMD_STOP_QUEUES);
120
121 nla_nest_end(msg, tmdata);
122 return 0;
123 nla_put_failure:
124 return -ENOBUFS;
125 }
126 COMMAND(hwsim, stopqueues, "", NL80211_CMD_TESTMODE, 0, CIB_PHY, handle_hwsim_stop_queues, "");
127
128 static int handle_hwsim_wake_queues(struct nl80211_state *state, struct nl_cb *cb,
129 struct nl_msg *msg, int argc, char **argv)
130 {
131 struct nlattr *tmdata;
132
133 if (argc != 0)
134 return 1;
135
136 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
137 if (!tmdata)
138 goto nla_put_failure;
139
140 NLA_PUT_U32(msg, HWSIM_TM_ATTR_CMD, HWSIM_TM_CMD_WAKE_QUEUES);
141
142 nla_nest_end(msg, tmdata);
143 return 0;
144 nla_put_failure:
145 return -ENOBUFS;
146 }
147 COMMAND(hwsim, wakequeues, "", NL80211_CMD_TESTMODE, 0, CIB_PHY, handle_hwsim_wake_queues, "");