]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
iw: Add support for setting transmit power level
authorJuuso Oikarinen <juuso.oikarinen@nokia.com>
Wed, 23 Jun 2010 09:12:57 +0000 (12:12 +0300)
committerJohannes Berg <johannes@sipsolutions.net>
Wed, 21 Jul 2010 08:14:30 +0000 (10:14 +0200)
Add a "set txpower" option to specify the current transmit power level. Modes
supported are automatic, fixed and limited, and the limit may be specified
in signed mBm units.

Signed-off-by: Juuso Oikarinen <juuso.oikarinen@nokia.com>
[Johannes: improve command line error checking, error reporting]
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
phy.c

diff --git a/phy.c b/phy.c
index 8f8d757473f73a36abd588763479f67301fac08d..1f54ba3aec2545de14c7d3fdd1cb4b1070445525 100644 (file)
--- a/phy.c
+++ b/phy.c
@@ -258,3 +258,51 @@ COMMAND(set, distance, "<distance>",
        NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_distance,
        "Set appropriate coverage class for given link distance in meters.\n"
        "Valid values: 0 - 114750");
+
+static int handle_txpower(struct nl80211_state *state,
+                         struct nl_cb *cb,
+                         struct nl_msg *msg,
+                         int argc, char **argv)
+{
+       enum nl80211_tx_power_setting type;
+       int mbm;
+
+       /* get the required args */
+       if (argc != 1 && argc != 2)
+               return 1;
+
+       if (!strcmp(argv[0], "auto"))
+               type = NL80211_TX_POWER_AUTOMATIC;
+       else if (!strcmp(argv[0], "fixed"))
+               type = NL80211_TX_POWER_FIXED;
+       else if (!strcmp(argv[0], "limit"))
+               type = NL80211_TX_POWER_LIMITED;
+       else {
+               printf("Invalid parameter: %s\n", argv[0]);
+               return 2;
+       }
+
+       NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_TX_POWER_SETTING, type);
+
+       if (type != NL80211_TX_POWER_AUTOMATIC) {
+               if (argc != 2) {
+                       printf("Missing TX power level argument.\n");
+                       return 2;
+               }
+
+               mbm = atoi(argv[1]);
+               NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, mbm);
+       } else if (argc != 1)
+               return 1;
+
+       return 0;
+
+ nla_put_failure:
+       return -ENOBUFS;
+}
+COMMAND(set, txpower, "<auto|fixed|limit> [<tx power in mBm>]",
+       NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_txpower,
+       "Specify transmit power level and setting type.");
+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.");