4 #include <netlink/genl/genl.h>
5 #include <netlink/msg.h>
6 #include <netlink/attr.h>
11 static int set_power_save(struct nl80211_state
*state
,
14 int argc
, char **argv
,
17 enum nl80211_ps_state ps_state
;
20 printf("Invalid parameters!\n");
24 if (strcmp(argv
[0], "on") == 0)
25 ps_state
= NL80211_PS_ENABLED
;
26 else if (strcmp(argv
[0], "off") == 0)
27 ps_state
= NL80211_PS_DISABLED
;
29 printf("Invalid parameter: %s\n", argv
[0]);
33 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
, ps_state
);
41 COMMAND(set
, power_save
, "<on|off>",
42 NL80211_CMD_SET_POWER_SAVE
, 0, CIB_NETDEV
, set_power_save
,
43 "Set power save state to on or off.");
45 static int print_power_save_handler(struct nl_msg
*msg
, void *arg
)
47 struct nlattr
*attrs
[NL80211_ATTR_MAX
+ 1];
48 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
51 nla_parse(attrs
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
52 genlmsg_attrlen(gnlh
, 0), NULL
);
54 if (!attrs
[NL80211_ATTR_PS_STATE
])
57 switch (nla_get_u32(attrs
[NL80211_ATTR_PS_STATE
])) {
58 case NL80211_PS_ENABLED
:
61 case NL80211_PS_DISABLED
:
67 printf("Power save: %s\n", s
);
72 static int get_power_save(struct nl80211_state
*state
,
75 int argc
, char **argv
,
78 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
79 print_power_save_handler
, NULL
);
83 COMMAND(get
, power_save
, "<param>",
84 NL80211_CMD_GET_POWER_SAVE
, 0, CIB_NETDEV
, get_power_save
,
85 "Retrieve power save state.");