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
)
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 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
69 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
, struct nl_cb
*cb
,
77 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 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
100 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
, struct nl_cb
*cb
,
108 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
, struct nl_cb
*cb
,
129 struct nl_msg
*msg
, int argc
, char **argv
)
131 struct nlattr
*tmdata
;
136 tmdata
= nla_nest_start(msg
, NL80211_ATTR_TESTDATA
);
138 goto nla_put_failure
;
140 NLA_PUT_U32(msg
, HWSIM_TM_ATTR_CMD
, HWSIM_TM_CMD_WAKE_QUEUES
);
142 nla_nest_end(msg
, tmdata
);
147 COMMAND(hwsim
, wakequeues
, "", NL80211_CMD_TESTMODE
, 0, CIB_PHY
, handle_hwsim_wake_queues
, "");