From patchwork Wed Feb 8 12:01:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashok Raj Nagarajan X-Patchwork-Id: 9562421 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 96F4B60434 for ; Wed, 8 Feb 2017 12:10:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 893A2283EC for ; Wed, 8 Feb 2017 12:10:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E444284D4; Wed, 8 Feb 2017 12:10:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14B5A283EC for ; Wed, 8 Feb 2017 12:10:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753669AbdBHMKP (ORCPT ); Wed, 8 Feb 2017 07:10:15 -0500 Received: from wolverine02.qualcomm.com ([199.106.114.251]:41217 "EHLO wolverine02.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751886AbdBHMKN (ORCPT ); Wed, 8 Feb 2017 07:10:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=qti.qualcomm.com; i=@qti.qualcomm.com; q=dns/txt; s=qcdkim; t=1486555813; x=1518091813; h=from:to:cc:subject:date:message-id:mime-version; bh=3k97QToKDLj8K8kk9IvMwoHbiO2ThTjHJqoEuqwfUYo=; b=YM8zorfLl1WXIjANoxIiWftzjCkcZJINtsF+LX27OWtr/MdN3DWiSfOG /TySbXdnL7W/CnhHPlJ/IL3oUwKrsCGl3H2Rsq/Jv4f34YYbigarKtSR5 0kcyX0B5z2XK41VQv4GYAHZvoUUf/NDStxN4LhfdHvJBGAMEmeomW+5Mx g=; X-IronPort-AV: E=Sophos;i="5.33,346,1477983600"; d="scan'208";a="356570230" Received: from unknown (HELO Ironmsg03-L.qualcomm.com) ([10.53.140.110]) by wolverine02.qualcomm.com with ESMTP; 08 Feb 2017 04:06:35 -0800 X-IronPort-AV: E=McAfee;i="5800,7501,8432"; a="1309627056" Received: from nasanexm02a.na.qualcomm.com ([10.85.0.41]) by Ironmsg03-L.qualcomm.com with ESMTP/TLS/RC4-SHA; 08 Feb 2017 04:06:35 -0800 Received: from aphydexm01f.ap.qualcomm.com (10.252.127.15) by nasanexm02a.na.qualcomm.com (10.85.0.41) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Wed, 8 Feb 2017 04:06:33 -0800 Received: from qcmail1.qualcomm.com (10.80.80.8) by aphydexm01f.ap.qualcomm.com (10.252.127.15) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Wed, 8 Feb 2017 17:36:25 +0530 Received: by qcmail1.qualcomm.com (sSMTP sendmail emulation); Wed, 08 Feb 2017 17:31:19 +0530 From: Ashok Raj Nagarajan To: CC: , , , Ashok Raj Nagarajan Subject: [PATCH v3] iw: Add support for controlling tx power for per station Date: Wed, 8 Feb 2017 17:31:17 +0530 Message-ID: <1486555277-25258-1-git-send-email-arnagara@qti.qualcomm.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanexm01a.na.qualcomm.com (10.85.0.81) To aphydexm01f.ap.qualcomm.com (10.252.127.15) Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch allows userspace to set transmit power, in mBm units, to a station associated to the AP. To set a limit tx power of 2000 mBm: iw wlan0 station set txpwr limit 2000 To revert the user defined tx power for a station: iw wlan0 station set txpwr auto Signed-off-by: Ashok Raj Nagarajan --- v3: - rebased station.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/station.c b/station.c index f3e3da8..8364593 100644 --- a/station.c +++ b/station.c @@ -569,6 +569,7 @@ COMMAND(station, del, " [subtype ] [reason-code ]", static const struct cmd *station_set_plink; static const struct cmd *station_set_vlan; static const struct cmd *station_set_mesh_power_mode; +static const struct cmd *station_set_txpwr; static const struct cmd *select_station_cmd(int argc, char **argv) { @@ -580,6 +581,8 @@ static const struct cmd *select_station_cmd(int argc, char **argv) return station_set_vlan; if (strcmp(argv[1], "mesh_power_mode") == 0) return station_set_mesh_power_mode; + if (strcmp(argv[1], "txpwr") == 0) + return station_set_txpwr; return NULL; } @@ -731,6 +734,72 @@ COMMAND_ALIAS(station, set, " mesh_power_mode " "Set link-specific mesh power mode for this station", select_station_cmd, station_set_mesh_power_mode); +static int handle_station_set_txpwr(struct nl80211_state *state, + struct nl_msg *msg, + int argc, char **argv, + enum id_input id) +{ + enum nl80211_tx_power_setting type; + unsigned char mac_addr[ETH_ALEN]; + unsigned int sta_txpwr = 0; + char *err = NULL; + + if (argc != 3 && argc != 4) + return 1; + + if (mac_addr_a2n(mac_addr, argv[0])) { + fprintf(stderr, "invalid mac address\n"); + return 2; + } + + NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); + argc--; + argv++; + + if (strcmp("txpwr", argv[0]) != 0) + return 1; + argc--; + argv++; + + if (!strcmp(argv[0], "auto")) + type = NL80211_TX_POWER_AUTOMATIC; + 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_STA_TX_POWER_SETTING, type); + + if (type != NL80211_TX_POWER_AUTOMATIC) { + if (argc != 2) { + printf("Missing TX power level argument.\n"); + return 2; + } + + argc--; + argv++; + + sta_txpwr = strtoul(argv[0], &err, 0); + NLA_PUT_U32(msg, NL80211_ATTR_STA_TX_POWER, sta_txpwr); + } + + argc--; + argv++; + + if (argc) + return 1; + + return 0; + nla_put_failure: + return -ENOBUFS; +} +COMMAND_ALIAS(station, set, " txpwr []", + NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_txpwr, + "Set Tx power for this station.", + select_station_cmd, station_set_txpwr); + static int handle_station_dump(struct nl80211_state *state, struct nl_msg *msg, int argc, char **argv,