fbac49eb7a0e0eeb072896791568dd1636cf05d6
[openwrt/svn-archive/archive.git] / package / iw / patches / 401-antenna.patch
1 iw: Add antenna configuration commands
2
3 From: Bruno Randolf <br1@einfach.org>
4
5 Add command to set the antenna configuration (iw phyX set antenna ...) and
6 include antenna setting in wiphy information (iw phyX info).
7
8 iw phyX set antenna all | <bitmap> | <tx bitmap> <rx bitmap>
9
10 Signed-off-by: Bruno Randolf <br1@einfach.org>
11
12 v8: Simplfied option parser as requested.
13 ---
14 info.c | 7 +++++++
15 phy.c | 39 +++++++++++++++++++++++++++++++++++++++
16 2 files changed, 46 insertions(+), 0 deletions(-)
17
18 diff --git a/info.c b/info.c
19 index ce85514..75cadf0 100644
20 --- a/info.c
21 +++ b/info.c
22 @@ -168,6 +168,13 @@ static int print_phy_handler(struct nl_msg *msg, void *arg)
23 printf("\tCoverage class: %d (up to %dm)\n", coverage, 450 * coverage);
24 }
25
26 + if (tb_msg[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
27 + tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
28 + printf("\tAntenna: TX %#x RX %#x\n",
29 + nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_TX]),
30 + nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX]));
31 + }
32 +
33 if (tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES]) {
34 printf("\tSupported interface modes:\n");
35 nla_for_each_nested(nl_mode, tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES], rem_mode)
36 diff --git a/phy.c b/phy.c
37 index 7c6c7c8..e3bd4e8 100644
38 --- a/phy.c
39 +++ b/phy.c
40 @@ -307,3 +307,51 @@ COMMAND(set, txpower, "<auto|fixed|limit> [<tx power in mBm>]",
41 COMMAND(set, txpower, "<auto|fixed|limit> [<tx power in mBm>]",
42 NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_txpower,
43 "Specify transmit power level and setting type.");
44 +
45 +static int handle_antenna(struct nl80211_state *state,
46 + struct nl_cb *cb,
47 + struct nl_msg *msg,
48 + int argc, char **argv)
49 +{
50 + char *end;
51 + uint32_t tx_ant = 0, rx_ant = 0;
52 +
53 + if (argc == 1) {
54 + if (strcmp(argv[0], "all") == 0)
55 + tx_ant = rx_ant = 0xffffffff;
56 + else {
57 + tx_ant = rx_ant = strtoul(argv[0], &end, 0);
58 + if (*end)
59 + return 1;
60 + }
61 + }
62 + else if (argc == 2) {
63 + if (strcmp(argv[0], "all") == 0)
64 + tx_ant = 0xffffffff;
65 + else {
66 + tx_ant = strtoul(argv[0], &end, 0);
67 + if (*end)
68 + return 1;
69 + }
70 + if (strcmp(argv[1], "all") == 0)
71 + rx_ant = 0xffffffff;
72 + else {
73 + rx_ant = strtoul(argv[1], &end, 0);
74 + if (*end)
75 + return 1;
76 + }
77 + } else
78 + return 1;
79 +
80 + NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant);
81 + NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant);
82 +
83 + return 0;
84 +
85 + nla_put_failure:
86 + return -ENOBUFS;
87 +}
88 +COMMAND(set, antenna, "<bitmap> | all | <tx bitmap> <rx bitmap>",
89 + NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_antenna,
90 + "Set a bitmap of allowed antennas to use for TX and RX.\n"
91 + "The driver may reject antenna configurations it cannot support.");