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
, struct nl_cb
*cb
,
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 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
70 print_hwsim_ps_handler
, NULL
);
75 COMMAND(hwsim
, getps
, "", NL80211_CMD_TESTMODE
, 0, CIB_PHY
, handle_hwsim_getps
, "");
77 static int handle_hwsim_setps(struct nl80211_state
*state
, struct nl_cb
*cb
,
78 struct nl_msg
*msg
, int argc
, char **argv
,
81 struct nlattr
*tmdata
;
88 ps
= strtoul(argv
[0], &end
, 0);
92 tmdata
= nla_nest_start(msg
, NL80211_ATTR_TESTDATA
);
96 NLA_PUT_U32(msg
, HWSIM_TM_ATTR_CMD
, HWSIM_TM_CMD_SET_PS
);
97 NLA_PUT_U32(msg
, HWSIM_TM_ATTR_PS
, ps
);
99 nla_nest_end(msg
, tmdata
);
101 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
102 print_hwsim_ps_handler
, NULL
);
107 COMMAND(hwsim
, setps
, "<value>", NL80211_CMD_TESTMODE
, 0, CIB_PHY
, handle_hwsim_setps
, "");
109 static int handle_hwsim_stop_queues(struct nl80211_state
*state
, struct nl_cb
*cb
,
110 struct nl_msg
*msg
, int argc
, char **argv
,
113 struct nlattr
*tmdata
;
118 tmdata
= nla_nest_start(msg
, NL80211_ATTR_TESTDATA
);
120 goto nla_put_failure
;
122 NLA_PUT_U32(msg
, HWSIM_TM_ATTR_CMD
, HWSIM_TM_CMD_STOP_QUEUES
);
124 nla_nest_end(msg
, tmdata
);
129 COMMAND(hwsim
, stopqueues
, "", NL80211_CMD_TESTMODE
, 0, CIB_PHY
, handle_hwsim_stop_queues
, "");
131 static int handle_hwsim_wake_queues(struct nl80211_state
*state
, struct nl_cb
*cb
,
132 struct nl_msg
*msg
, int argc
, char **argv
,
135 struct nlattr
*tmdata
;
140 tmdata
= nla_nest_start(msg
, NL80211_ATTR_TESTDATA
);
142 goto nla_put_failure
;
144 NLA_PUT_U32(msg
, HWSIM_TM_ATTR_CMD
, HWSIM_TM_CMD_WAKE_QUEUES
);
146 nla_nest_end(msg
, tmdata
);
151 COMMAND(hwsim
, wakequeues
, "", NL80211_CMD_TESTMODE
, 0, CIB_PHY
, handle_hwsim_wake_queues
, "");