4 #include <netlink/genl/genl.h>
5 #include <netlink/genl/family.h>
6 #include <netlink/genl/ctrl.h>
7 #include <netlink/msg.h>
8 #include <netlink/attr.h>
13 /* These enums need to be kept in sync with the kernel */
14 enum hwsim_testmode_attr
{
15 __HWSIM_TM_ATTR_INVALID
= 0,
16 HWSIM_TM_ATTR_CMD
= 1,
20 __HWSIM_TM_ATTR_AFTER_LAST
,
21 HWSIM_TM_ATTR_MAX
= __HWSIM_TM_ATTR_AFTER_LAST
- 1
24 enum hwsim_testmode_cmd
{
25 HWSIM_TM_CMD_SET_PS
= 0,
26 HWSIM_TM_CMD_GET_PS
= 1,
27 HWSIM_TM_CMD_STOP_QUEUES
= 2,
28 HWSIM_TM_CMD_WAKE_QUEUES
= 3,
34 static int print_hwsim_ps_handler(struct nl_msg
*msg
, void *arg
)
36 struct nlattr
*attrs
[NL80211_ATTR_MAX
+ 1];
37 struct nlattr
*tb
[HWSIM_TM_ATTR_MAX
+ 1];
38 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
40 nla_parse(attrs
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
41 genlmsg_attrlen(gnlh
, 0), NULL
);
43 if (!attrs
[NL80211_ATTR_TESTDATA
])
46 nla_parse(tb
, HWSIM_TM_ATTR_MAX
, nla_data(attrs
[NL80211_ATTR_TESTDATA
]),
47 nla_len(attrs
[NL80211_ATTR_TESTDATA
]), NULL
);
49 printf("HWSIM PS: %d\n", nla_get_u32(tb
[HWSIM_TM_ATTR_PS
]));
54 static int handle_hwsim_getps(struct nl80211_state
*state
,
55 struct nl_msg
*msg
, int argc
, char **argv
,
58 struct nlattr
*tmdata
;
60 tmdata
= nla_nest_start(msg
, NL80211_ATTR_TESTDATA
);
64 NLA_PUT_U32(msg
, HWSIM_TM_ATTR_CMD
, HWSIM_TM_CMD_GET_PS
);
66 nla_nest_end(msg
, tmdata
);
68 register_handler(print_hwsim_ps_handler
, NULL
);
73 COMMAND(hwsim
, getps
, "", NL80211_CMD_TESTMODE
, 0, CIB_PHY
, handle_hwsim_getps
, "");
75 static int handle_hwsim_setps(struct nl80211_state
*state
,
76 struct nl_msg
*msg
, int argc
, char **argv
,
79 struct nlattr
*tmdata
;
86 ps
= strtoul(argv
[0], &end
, 0);
90 tmdata
= nla_nest_start(msg
, NL80211_ATTR_TESTDATA
);
94 NLA_PUT_U32(msg
, HWSIM_TM_ATTR_CMD
, HWSIM_TM_CMD_SET_PS
);
95 NLA_PUT_U32(msg
, HWSIM_TM_ATTR_PS
, ps
);
97 nla_nest_end(msg
, tmdata
);
99 register_handler(print_hwsim_ps_handler
, NULL
);
104 COMMAND(hwsim
, setps
, "<value>", NL80211_CMD_TESTMODE
, 0, CIB_PHY
, handle_hwsim_setps
, "");
106 static int handle_hwsim_stop_queues(struct nl80211_state
*state
,
107 struct nl_msg
*msg
, int argc
, char **argv
,
110 struct nlattr
*tmdata
;
115 tmdata
= nla_nest_start(msg
, NL80211_ATTR_TESTDATA
);
117 goto nla_put_failure
;
119 NLA_PUT_U32(msg
, HWSIM_TM_ATTR_CMD
, HWSIM_TM_CMD_STOP_QUEUES
);
121 nla_nest_end(msg
, tmdata
);
126 COMMAND(hwsim
, stopqueues
, "", NL80211_CMD_TESTMODE
, 0, CIB_PHY
, handle_hwsim_stop_queues
, "");
128 static int handle_hwsim_wake_queues(struct nl80211_state
*state
,
129 struct nl_msg
*msg
, int argc
, char **argv
,
132 struct nlattr
*tmdata
;
137 tmdata
= nla_nest_start(msg
, NL80211_ATTR_TESTDATA
);
139 goto nla_put_failure
;
141 NLA_PUT_U32(msg
, HWSIM_TM_ATTR_CMD
, HWSIM_TM_CMD_WAKE_QUEUES
);
143 nla_nest_end(msg
, tmdata
);
148 COMMAND(hwsim
, wakequeues
, "", NL80211_CMD_TESTMODE
, 0, CIB_PHY
, handle_hwsim_wake_queues
, "");