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>
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,
21 __HWSIM_TM_ATTR_AFTER_LAST
,
22 HWSIM_TM_ATTR_MAX
= __HWSIM_TM_ATTR_AFTER_LAST
- 1
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,
35 static int print_hwsim_ps_handler(struct nl_msg
*msg
, void *arg
)
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
));
41 nla_parse(attrs
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
42 genlmsg_attrlen(gnlh
, 0), NULL
);
44 if (!attrs
[NL80211_ATTR_TESTDATA
])
47 nla_parse(tb
, HWSIM_TM_ATTR_MAX
, nla_data(attrs
[NL80211_ATTR_TESTDATA
]),
48 nla_len(attrs
[NL80211_ATTR_TESTDATA
]), NULL
);
50 printf("HWSIM PS: %d\n", nla_get_u32(tb
[HWSIM_TM_ATTR_PS
]));
55 static int handle_hwsim_getps(struct nl80211_state
*state
,
56 struct nl_msg
*msg
, int argc
, char **argv
,
59 struct nlattr
*tmdata
;
61 tmdata
= nla_nest_start(msg
, NL80211_ATTR_TESTDATA
);
65 NLA_PUT_U32(msg
, HWSIM_TM_ATTR_CMD
, HWSIM_TM_CMD_GET_PS
);
67 nla_nest_end(msg
, tmdata
);
69 register_handler(print_hwsim_ps_handler
, NULL
);
74 COMMAND(hwsim
, getps
, "", NL80211_CMD_TESTMODE
, 0, CIB_PHY
, handle_hwsim_getps
, "");
76 static int handle_hwsim_setps(struct nl80211_state
*state
,
77 struct nl_msg
*msg
, int argc
, char **argv
,
80 struct nlattr
*tmdata
;
87 ps
= strtoul(argv
[0], &end
, 0);
91 tmdata
= nla_nest_start(msg
, NL80211_ATTR_TESTDATA
);
95 NLA_PUT_U32(msg
, HWSIM_TM_ATTR_CMD
, HWSIM_TM_CMD_SET_PS
);
96 NLA_PUT_U32(msg
, HWSIM_TM_ATTR_PS
, ps
);
98 nla_nest_end(msg
, tmdata
);
100 register_handler(print_hwsim_ps_handler
, NULL
);
105 COMMAND(hwsim
, setps
, "<value>", NL80211_CMD_TESTMODE
, 0, CIB_PHY
, handle_hwsim_setps
, "");
107 static int handle_hwsim_stop_queues(struct nl80211_state
*state
,
108 struct nl_msg
*msg
, int argc
, char **argv
,
111 struct nlattr
*tmdata
;
116 tmdata
= nla_nest_start(msg
, NL80211_ATTR_TESTDATA
);
118 goto nla_put_failure
;
120 NLA_PUT_U32(msg
, HWSIM_TM_ATTR_CMD
, HWSIM_TM_CMD_STOP_QUEUES
);
122 nla_nest_end(msg
, tmdata
);
127 COMMAND(hwsim
, stopqueues
, "", NL80211_CMD_TESTMODE
, 0, CIB_PHY
, handle_hwsim_stop_queues
, "");
129 static int handle_hwsim_wake_queues(struct nl80211_state
*state
,
130 struct nl_msg
*msg
, int argc
, char **argv
,
133 struct nlattr
*tmdata
;
138 tmdata
= nla_nest_start(msg
, NL80211_ATTR_TESTDATA
);
140 goto nla_put_failure
;
142 NLA_PUT_U32(msg
, HWSIM_TM_ATTR_CMD
, HWSIM_TM_CMD_WAKE_QUEUES
);
144 nla_nest_end(msg
, tmdata
);
149 COMMAND(hwsim
, wakequeues
, "", NL80211_CMD_TESTMODE
, 0, CIB_PHY
, handle_hwsim_wake_queues
, "");