blob: 124bf75ccc1dde26e4c4a9fedd3ac2897c9afaf6 [file] [log] [blame]
Kalle Valocf40ef32010-02-17 18:05:54 +02001#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,
Kalle Valocf40ef32010-02-17 18:05:54 +020012 struct nl_msg *msg,
Johannes Berg05514f92012-07-19 11:50:50 +020013 int argc, char **argv,
14 enum id_input id)
Kalle Valocf40ef32010-02-17 18:05:54 +020015{
16 enum nl80211_ps_state ps_state;
17
Sunil Ravi44e0e582022-03-05 11:09:09 -080018 if (argc != 1)
19 return 1;
Kalle Valocf40ef32010-02-17 18:05:54 +020020
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,
Sunil Ravi44e0e582022-03-05 11:09:09 -080070 struct nl_msg *msg,
71 int argc, char **argv,
72 enum id_input id)
Kalle Valocf40ef32010-02-17 18:05:54 +020073{
Sunil Ravi44e0e582022-03-05 11:09:09 -080074 register_handler(print_power_save_handler, NULL);
Kalle Valocf40ef32010-02-17 18:05:54 +020075 return 0;
76}
77
Sunil Ravi44e0e582022-03-05 11:09:09 -080078COMMAND(get, power_save, "",
Kalle Valocf40ef32010-02-17 18:05:54 +020079 NL80211_CMD_GET_POWER_SAVE, 0, CIB_NETDEV, get_power_save,
80 "Retrieve power save state.");