From: Bruno Randolf <br1@einfach.org>
To: johannes@sipsolutions.net, linville@tuxdriver.com
Cc: linux-wireless@vger.kernel.org, holgerschurig@gmail.com
Subject: [PATCH 3/3] iw: Add antenna set/get
Date: Wed, 12 May 2010 17:27:51 +0900 [thread overview]
Message-ID: <20100512082751.26746.43302.stgit@tt-desk> (raw)
In-Reply-To: <20100512082516.26746.19520.stgit@tt-desk>
Add commands to set and get the antenna configuration. The antenna
configuration is defined as a bitmap of 8 antennas. When multiple antennas are
selected the driver may use diversity. Also the driver may reject antenna
configurations it cannot support.
Signed-off-by: Bruno Randolf <br1@einfach.org>
---
Makefile | 2 +
antenna.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
util.c | 2 +
3 files changed, 91 insertions(+), 1 deletions(-)
create mode 100644 antenna.c
diff --git a/Makefile b/Makefile
index d303f45..e526cda 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 ps.o cqm.o
+ reason.o status.o connect.o link.o offch.o ps.o cqm.o antenna.o
OBJS += sections.o
ALL = iw
diff --git a/antenna.c b/antenna.c
new file mode 100644
index 0000000..5869aa6
--- /dev/null
+++ b/antenna.c
@@ -0,0 +1,88 @@
+#include <net/if.h>
+#include <errno.h>
+#include <string.h>
+
+#include <netlink/genl/genl.h>
+#include <netlink/genl/family.h>
+#include <netlink/genl/ctrl.h>
+#include <netlink/msg.h>
+#include <netlink/attr.h>
+
+#include "nl80211.h"
+#include "iw.h"
+
+SECTION(antenna);
+
+static int set_antenna(struct nl80211_state *state,
+ struct nl_cb *cb,
+ struct nl_msg *msg,
+ int argc, char **argv)
+{
+ char *end;
+ uint8_t tx_ant = 0, rx_ant = 0;
+
+ if (argc == 1)
+ tx_ant = rx_ant = strtoul(argv[0], &end, 10);
+ else if (argc == 4)
+ {
+ while (argc) {
+ if (strcmp(*argv, "tx") == 0 ||
+ strcmp(*argv, "rx") == 0) {
+ if (strcmp(*argv, "tx") == 0)
+ tx_ant = strtoul(argv[1], &end, 10);
+ else
+ rx_ant = strtoul(argv[1], &end, 10);
+ argv = argv + 2;
+ argc = argc - 2;
+ }
+ }
+ }
+
+ if (*end || !tx_ant || !rx_ant)
+ return 1;
+
+ NLA_PUT_U8(msg, NL80211_ATTR_ANTENNA_TX, tx_ant);
+ NLA_PUT_U8(msg, NL80211_ATTR_ANTENNA_RX, rx_ant);
+ return 0;
+
+ nla_put_failure:
+ return -ENOBUFS;
+}
+
+COMMAND(antenna, set, "<bitmap> | tx <bitmap> rx <bitmap>",
+ NL80211_CMD_SET_ANTENNA, 0, CIB_PHY, set_antenna,
+ "Set a bitmap of allowed antennas to use for TX and RX.\n"
+ "The driver may reject antenna configurations it cannot support.");
+
+
+static int print_antenna_handler(struct nl_msg *msg, void *arg)
+{
+ struct nlattr *attrs[NL80211_ATTR_MAX + 1];
+ struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
+ uint8_t tx_ant, rx_ant;
+
+ nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
+ genlmsg_attrlen(gnlh, 0), NULL);
+
+ if (!attrs[NL80211_ATTR_ANTENNA_TX] || !attrs[NL80211_ATTR_ANTENNA_RX])
+ return NL_SKIP;
+
+ tx_ant = nla_get_u8(attrs[NL80211_ATTR_ANTENNA_TX]);
+ rx_ant = nla_get_u8(attrs[NL80211_ATTR_ANTENNA_RX]);
+
+ printf("Antenna configuration: tx %d rx %d\n", tx_ant, rx_ant);
+
+ return NL_SKIP;
+}
+
+static int get_antenna(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_antenna_handler, NULL);
+ return 0;
+}
+
+COMMAND(antenna, get, NULL, NL80211_CMD_GET_ANTENNA, 0, CIB_PHY, get_antenna,
+ "Retrieve antenna configuration.");
diff --git a/util.c b/util.c
index 0c6d978..7d971ac 100644
--- a/util.c
+++ b/util.c
@@ -166,6 +166,8 @@ static const char *commands[NL80211_CMD_MAX + 1] = {
[NL80211_CMD_REGISTER_ACTION] = "register_action",
[NL80211_CMD_ACTION] = "action",
[NL80211_CMD_SET_CHANNEL] = "set_channel",
+ [NL80211_CMD_SET_ANTENNA] = "antenna_set",
+ [NL80211_CMD_GET_ANTENNA] = "antenna_get",
};
static char cmdbuf[100];
prev parent reply other threads:[~2010-05-12 8:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-12 8:27 [PATCH 0/3] iw antenna command Bruno Randolf
2010-05-12 8:27 ` [PATCH 1/3] iw: add channel command name Bruno Randolf
2010-05-12 8:27 ` [PATCH 2/3] iw: sync nl80211.h with wireless-testing Bruno Randolf
2010-05-12 8:27 ` Bruno Randolf [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=20100512082751.26746.43302.stgit@tt-desk \
--to=br1@einfach.org \
--cc=holgerschurig@gmail.com \
--cc=johannes@sipsolutions.net \
--cc=linux-wireless@vger.kernel.org \
--cc=linville@tuxdriver.com \
/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