]>
Commit | Line | Data |
---|---|---|
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 | ||
11 | static int set_power_save(struct nl80211_state *state, | |
12 | struct nl_cb *cb, | |
13 | struct nl_msg *msg, | |
14 | int argc, char **argv) | |
15 | { | |
16 | enum nl80211_ps_state ps_state; | |
17 | ||
18 | if (argc != 1) { | |
19 | printf("Invalid parameters!\n"); | |
20 | return 2; | |
21 | } | |
22 | ||
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; | |
27 | else { | |
28 | printf("Invalid parameter: %s\n", argv[0]); | |
29 | return 2; | |
30 | } | |
31 | ||
32 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); | |
33 | ||
34 | return 0; | |
35 | ||
36 | nla_put_failure: | |
37 | return -ENOBUFS; | |
38 | } | |
39 | ||
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."); | |
43 | ||
44 | static int print_power_save_handler(struct nl_msg *msg, void *arg) | |
45 | { | |
46 | struct nlattr *attrs[NL80211_ATTR_MAX + 1]; | |
47 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
48 | const char *s; | |
49 | ||
50 | nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
51 | genlmsg_attrlen(gnlh, 0), NULL); | |
52 | ||
53 | if (!attrs[NL80211_ATTR_PS_STATE]) | |
54 | return NL_SKIP; | |
55 | ||
56 | switch (nla_get_u32(attrs[NL80211_ATTR_PS_STATE])) { | |
57 | case NL80211_PS_ENABLED: | |
58 | s = "on"; | |
59 | break; | |
60 | case NL80211_PS_DISABLED: | |
61 | default: | |
62 | s = "off"; | |
63 | break; | |
64 | } | |
65 | ||
66 | printf("Power save: %s\n", s); | |
67 | ||
68 | return NL_SKIP; | |
69 | } | |
70 | ||
71 | static int get_power_save(struct nl80211_state *state, | |
72 | struct nl_cb *cb, | |
73 | struct nl_msg *msg, | |
74 | int argc, char **argv) | |
75 | { | |
76 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, | |
77 | print_power_save_handler, NULL); | |
78 | return 0; | |
79 | } | |
80 | ||
81 | COMMAND(get, power_save, "<param>", | |
82 | NL80211_CMD_GET_POWER_SAVE, 0, CIB_NETDEV, get_power_save, | |
83 | "Retrieve power save state."); |