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