]> git.ipfire.org Git - thirdparty/iw.git/blame - ps.c
info: macro-ify ext_feat_print()
[thirdparty/iw.git] / ps.c
CommitLineData
cf40ef37
KV
1#include <errno.h>
2#include <string.h>
3
4#include <netlink/genl/genl.h>
5#include <netlink/msg.h>
6#include <netlink/attr.h>
7
8#include "nl80211.h"
9#include "iw.h"
10
11static int set_power_save(struct nl80211_state *state,
cf40ef37 12 struct nl_msg *msg,
05514f95
JB
13 int argc, char **argv,
14 enum id_input id)
cf40ef37
KV
15{
16 enum nl80211_ps_state ps_state;
17
86a9801f
OO
18 if (argc != 1)
19 return 1;
cf40ef37
KV
20
21 if (strcmp(argv[0], "on") == 0)
22 ps_state = NL80211_PS_ENABLED;
23 else if (strcmp(argv[0], "off") == 0)
24 ps_state = NL80211_PS_DISABLED;
25 else {
26 printf("Invalid parameter: %s\n", argv[0]);
27 return 2;
28 }
29
30 NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state);
31
32 return 0;
33
34 nla_put_failure:
35 return -ENOBUFS;
36}
37
38COMMAND(set, power_save, "<on|off>",
39 NL80211_CMD_SET_POWER_SAVE, 0, CIB_NETDEV, set_power_save,
40 "Set power save state to on or off.");
41
42static int print_power_save_handler(struct nl_msg *msg, void *arg)
43{
44 struct nlattr *attrs[NL80211_ATTR_MAX + 1];
45 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
46 const char *s;
47
48 nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
49 genlmsg_attrlen(gnlh, 0), NULL);
50
51 if (!attrs[NL80211_ATTR_PS_STATE])
52 return NL_SKIP;
53
54 switch (nla_get_u32(attrs[NL80211_ATTR_PS_STATE])) {
55 case NL80211_PS_ENABLED:
56 s = "on";
57 break;
58 case NL80211_PS_DISABLED:
59 default:
60 s = "off";
61 break;
62 }
63
64 printf("Power save: %s\n", s);
65
66 return NL_SKIP;
67}
68
69static int get_power_save(struct nl80211_state *state,
34b23014
JB
70 struct nl_msg *msg,
71 int argc, char **argv,
72 enum id_input id)
cf40ef37 73{
34b23014 74 register_handler(print_power_save_handler, NULL);
cf40ef37
KV
75 return 0;
76}
77
78COMMAND(get, power_save, "<param>",
79 NL80211_CMD_GET_POWER_SAVE, 0, CIB_NETDEV, get_power_save,
80 "Retrieve power save state.");