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
)
16 enum nl80211_ps_state ps_state
;
19 printf("Invalid parameters!\n");
23 if (strcmp(argv
[0], "on") == 0)
24 ps_state
= NL80211_PS_ENABLED
;
25 else if (strcmp(argv
[0], "off") == 0)
26 ps_state
= NL80211_PS_DISABLED
;
28 printf("Invalid parameter: %s\n", argv
[0]);
32 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
, ps_state
);
40 COMMAND(set
, power_save
, "<on|off>",
41 NL80211_CMD_SET_POWER_SAVE
, 0, CIB_NETDEV
, set_power_save
,
42 "Set power save state to on or off.");
44 static int print_power_save_handler(struct nl_msg
*msg
, void *arg
)
46 struct nlattr
*attrs
[NL80211_ATTR_MAX
+ 1];
47 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
50 nla_parse(attrs
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
51 genlmsg_attrlen(gnlh
, 0), NULL
);
53 if (!attrs
[NL80211_ATTR_PS_STATE
])
56 switch (nla_get_u32(attrs
[NL80211_ATTR_PS_STATE
])) {
57 case NL80211_PS_ENABLED
:
60 case NL80211_PS_DISABLED
:
66 printf("Power save: %s\n", s
);
71 static int get_power_save(struct nl80211_state
*state
,
74 int argc
, char **argv
)
76 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
77 print_power_save_handler
, NULL
);
81 COMMAND(get
, power_save
, "<param>",
82 NL80211_CMD_GET_POWER_SAVE
, 0, CIB_NETDEV
, get_power_save
,
83 "Retrieve power save state.");