summaryrefslogtreecommitdiff
path: root/package/iw/patches/401-antenna.patch
blob: fbac49eb7a0e0eeb072896791568dd1636cf05d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
iw: Add antenna configuration commands

From: Bruno Randolf <br1@einfach.org>

Add command to set the antenna configuration (iw phyX set antenna ...) and
include antenna setting in wiphy information (iw phyX info).

iw phyX set antenna all | <bitmap> | <tx bitmap> <rx bitmap>

Signed-off-by: Bruno Randolf <br1@einfach.org>

v8:  Simplfied option parser as requested.
---
 info.c |    7 +++++++
 phy.c  |   39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/info.c b/info.c
index ce85514..75cadf0 100644
--- a/info.c
+++ b/info.c
@@ -168,6 +168,13 @@ static int print_phy_handler(struct nl_msg *msg, void *arg)
 		printf("\tCoverage class: %d (up to %dm)\n", coverage, 450 * coverage);
 	}
 
+	if (tb_msg[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
+	    tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
+		printf("\tAntenna: TX %#x RX %#x\n",
+		       nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_TX]),
+		       nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX]));
+	}
+
 	if (tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES]) {
 		printf("\tSupported interface modes:\n");
 		nla_for_each_nested(nl_mode, tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES], rem_mode)
diff --git a/phy.c b/phy.c
index 7c6c7c8..e3bd4e8 100644
--- a/phy.c
+++ b/phy.c
@@ -307,3 +307,51 @@ COMMAND(set, txpower, "<auto|fixed|limit> [<tx power in mBm>]",
 COMMAND(set, txpower, "<auto|fixed|limit> [<tx power in mBm>]",
 	NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_txpower,
 	"Specify transmit power level and setting type.");
+
+static int handle_antenna(struct nl80211_state *state,
+			  struct nl_cb *cb,
+			  struct nl_msg *msg,
+			  int argc, char **argv)
+{
+	char *end;
+	uint32_t tx_ant = 0, rx_ant = 0;
+
+	if (argc == 1) {
+		if (strcmp(argv[0], "all") == 0)
+			tx_ant = rx_ant = 0xffffffff;
+		else {
+			tx_ant = rx_ant = strtoul(argv[0], &end, 0);
+			if (*end)
+				return 1;
+		}
+	}
+	else if (argc == 2) {
+		if (strcmp(argv[0], "all") == 0)
+			tx_ant = 0xffffffff;
+		else {
+			tx_ant = strtoul(argv[0], &end, 0);
+			if (*end)
+				return 1;
+		}
+		if (strcmp(argv[1], "all") == 0)
+			rx_ant = 0xffffffff;
+		else {
+			rx_ant = strtoul(argv[1], &end, 0);
+			if (*end)
+				return 1;
+		}
+	} else
+		return 1;
+
+	NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant);
+	NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant);
+
+	return 0;
+
+ nla_put_failure:
+	return -ENOBUFS;
+}
+COMMAND(set, antenna, "<bitmap> | all | <tx bitmap> <rx bitmap>",
+	NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_antenna,
+	"Set a bitmap of allowed antennas to use for TX and RX.\n"
+	"The driver may reject antenna configurations it cannot support.");