From: Stanislaw Gruszka <sgruszka@redhat.com>
To: linux-wireless@vger.kernel.org
Cc: Johannes Berg <johannes@sipsolutions.net>
Subject: [PATCH 2/2] iw: allow to configure dynamic power save timeout
Date: Tue, 30 Sep 2014 15:20:35 +0200 [thread overview]
Message-ID: <1412083235-8560-2-git-send-email-sgruszka@redhat.com> (raw)
In-Reply-To: <1412083235-8560-1-git-send-email-sgruszka@redhat.com>
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
ps.c | 38 +++++++++++++++++++++++++++++---------
1 file changed, 29 insertions(+), 9 deletions(-)
diff --git a/ps.c b/ps.c
index 4c8e2d1..83ee9d5 100644
--- a/ps.c
+++ b/ps.c
@@ -15,19 +15,29 @@ static int set_power_save(struct nl80211_state *state,
enum id_input id)
{
enum nl80211_ps_state ps_state;
+ int timeout;
+ char *endp;
- if (argc != 1) {
- printf("Invalid parameters!\n");
- return 2;
- }
+ if (argc != 1 && argc != 3)
+ goto invalid_parameters;
if (strcmp(argv[0], "on") == 0)
ps_state = NL80211_PS_ENABLED;
else if (strcmp(argv[0], "off") == 0)
ps_state = NL80211_PS_DISABLED;
- else {
- printf("Invalid parameter: %s\n", argv[0]);
- return 2;
+ else
+ goto invalid_parameters;
+
+ if (argc == 3) {
+ if (ps_state != NL80211_PS_ENABLED)
+ goto invalid_parameters;
+ if (strcmp(argv[1], "timeout") != 0)
+ goto invalid_parameters;
+ timeout = (int) strtol(argv[2], &endp, 10);
+ if (endp == argv[2] || (timeout <= 0 && timeout != -1))
+ goto invalid_parameters;
+
+ NLA_PUT_U32(msg, NL80211_ATTR_PS_TIMEOUT, timeout);
}
NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state);
@@ -36,9 +46,13 @@ static int set_power_save(struct nl80211_state *state,
nla_put_failure:
return -ENOBUFS;
+
+ invalid_parameters:
+ printf("Invalid parameters!\n");
+ return 2;
}
-COMMAND(set, power_save, "<on|off>",
+COMMAND(set, power_save, "<on [timeout <value>] | off>",
NL80211_CMD_SET_POWER_SAVE, 0, CIB_NETDEV, set_power_save,
"Set power save state to on or off.");
@@ -47,6 +61,7 @@ static int print_power_save_handler(struct nl_msg *msg, void *arg)
struct nlattr *attrs[NL80211_ATTR_MAX + 1];
struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
const char *s;
+ int timeout = -1;
nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
genlmsg_attrlen(gnlh, 0), NULL);
@@ -57,6 +72,8 @@ static int print_power_save_handler(struct nl_msg *msg, void *arg)
switch (nla_get_u32(attrs[NL80211_ATTR_PS_STATE])) {
case NL80211_PS_ENABLED:
s = "on";
+ if (attrs[NL80211_ATTR_PS_TIMEOUT])
+ timeout = nla_get_u32(attrs[NL80211_ATTR_PS_TIMEOUT]);
break;
case NL80211_PS_DISABLED:
default:
@@ -64,7 +81,10 @@ static int print_power_save_handler(struct nl_msg *msg, void *arg)
break;
}
- printf("Power save: %s\n", s);
+ if (timeout > 0)
+ printf("Power save: on, timeout %d ms\n", timeout);
+ else
+ printf("Power save: %s\n", s);
return NL_SKIP;
}
--
1.8.3.1
prev parent reply other threads:[~2014-09-30 13:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-30 13:20 [PATCH 1/2] iw: update nl80211.h Stanislaw Gruszka
2014-09-30 13:20 ` Stanislaw Gruszka [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1412083235-8560-2-git-send-email-sgruszka@redhat.com \
--to=sgruszka@redhat.com \
--cc=johannes@sipsolutions.net \
--cc=linux-wireless@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox