linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kalle Valo <kalle.valo@nokia.com>
To: linux-wireless@vger.kernel.org
Subject: [RFC PATCH 2/2] iw: add set/get power_save commands
Date: Tue, 16 Feb 2010 22:13:16 +0200	[thread overview]
Message-ID: <20100216201316.25291.18969.stgit@tikku> (raw)
In-Reply-To: <20100216201026.25148.40799.stgit@tikku>


---
 Makefile |    2 +
 ps.c     |   83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 1 deletions(-)
 create mode 100644 ps.c

diff --git a/Makefile b/Makefile
index bae1bfb..b0a4278 100644
--- a/Makefile
+++ b/Makefile
@@ -17,7 +17,7 @@ CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing
 OBJS = iw.o genl.o event.o info.o phy.o \
 	interface.o ibss.o station.o survey.o util.o \
 	mesh.o mpath.o scan.o reg.o version.o \
-	reason.o status.o connect.o link.o offch.o
+	reason.o status.o connect.o link.o offch.o ps.o
 OBJS += sections.o
 ALL = iw
 
diff --git a/ps.c b/ps.c
new file mode 100644
index 0000000..9b0614c
--- /dev/null
+++ b/ps.c
@@ -0,0 +1,83 @@
+#include <errno.h>
+#include <string.h>
+
+#include <netlink/genl/genl.h>
+#include <netlink/msg.h>
+#include <netlink/attr.h>
+
+#include "nl80211.h"
+#include "iw.h"
+
+static int set_power_save(struct nl80211_state *state,
+			  struct nl_cb *cb,
+			  struct nl_msg *msg,
+			  int argc, char **argv)
+{
+	enum nl80211_ps_state ps_state;
+
+	if (argc != 1) {
+		printf("Invalid parameters!\n");
+		return 2;
+	}
+
+	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;
+	}
+
+	NLA_PUT_U8(msg, NL80211_ATTR_PS_STATE, ps_state);
+
+	return 0;
+
+ nla_put_failure:
+	return -ENOBUFS;
+}
+
+COMMAND(set, power_save, "<on|off>",
+	NL80211_CMD_SET_POWER_SAVE, 0, CIB_NETDEV, set_power_save,
+	"Set power save state to on or off.");
+
+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;
+
+	nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
+		  genlmsg_attrlen(gnlh, 0), NULL);
+
+	if (!attrs[NL80211_ATTR_PS_STATE])
+		return NL_SKIP;
+
+	switch (nla_get_u8(attrs[NL80211_ATTR_PS_STATE])) {
+	case NL80211_PS_ENABLED:
+		s = "on";
+		break;
+	case NL80211_PS_DISABLED:
+	default:
+		s = "off";
+		break;
+	}
+
+	printf("Power save: %s\n", s);
+
+	return NL_SKIP;
+}
+
+static int get_power_save(struct nl80211_state *state,
+				   struct nl_cb *cb,
+				   struct nl_msg *msg,
+				   int argc, char **argv)
+{
+	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM,
+		  print_power_save_handler, NULL);
+	return 0;
+}
+
+COMMAND(get, power_save, "<param>",
+	NL80211_CMD_GET_POWER_SAVE, 0, CIB_NETDEV, get_power_save,
+	"Retrieve power save state.");


  parent reply	other threads:[~2010-02-16 20:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-16 20:10 [RFC PATCH] nl80211: add power save commands Kalle Valo
2010-02-16 20:13 ` [RFC PATCH 1/2] iw: update nl80211.h to include " Kalle Valo
2010-02-16 20:13 ` Kalle Valo [this message]
2010-02-16 20:19 ` [RFC PATCH] nl80211: add " Luis R. Rodriguez
2010-02-16 20:33   ` Kalle Valo
2010-02-17  7:34 ` Holger Schurig
2010-02-17  8:33   ` Johannes Berg
2010-02-17 13:21     ` Holger Schurig
2010-02-17 13:27       ` Johannes Berg
2010-02-17 13:36         ` Johannes Berg
2010-02-17 13:56           ` Holger Schurig
2010-02-17 14:44             ` Johannes Berg
2010-02-17  9:00   ` Kalle Valo
2010-02-17  8:47 ` Johannes Berg
2010-02-17  9:06   ` Kalle Valo

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=20100216201316.25291.18969.stgit@tikku \
    --to=kalle.valo@nokia.com \
    --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;
as well as URLs for NNTP newsgroup(s).