From patchwork Tue Jun 14 17:46:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashok Raj Nagarajan X-Patchwork-Id: 9176363 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 D84F960868 for ; Tue, 14 Jun 2016 17:46:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE7B42656B for ; Tue, 14 Jun 2016 17:46:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C36792823D; Tue, 14 Jun 2016 17:46:44 +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 3796028047 for ; Tue, 14 Jun 2016 17:46:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752914AbcFNRqm (ORCPT ); Tue, 14 Jun 2016 13:46:42 -0400 Received: from wolverine02.qualcomm.com ([199.106.114.251]:11926 "EHLO wolverine02.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752860AbcFNRqk (ORCPT ); Tue, 14 Jun 2016 13:46:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=qti.qualcomm.com; i=@qti.qualcomm.com; q=dns/txt; s=qcdkim; t=1465926400; x=1497462400; h=from:to:cc:subject:date:message-id:mime-version; bh=RHryKwlwCKMmzGm8w2KE7g9gY1rDe01bwoQbCeRrQcQ=; b=Ye0EOkNF45Qyf1BD/zDmgjQbjvR036+BOY7pFomK24bo1UTKgFaBB7j8 jH9MjgAjQv2NpbwRpfbS/K7fSMNDvGC51K5xiXEM9/aBksqtfKL9zbMMm XItCIKG0HEFJNWQzGNNLvmS1zohNCTYtbGarrFjsgHg75ofhSacaSo1hZ I=; X-IronPort-AV: E=Sophos;i="5.26,471,1459839600"; d="scan'208";a="295641789" Received: from unknown (HELO Ironmsg03-L.qualcomm.com) ([10.53.140.110]) by wolverine02.qualcomm.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 14 Jun 2016 10:46:39 -0700 X-IronPort-AV: E=McAfee;i="5700,7163,8196"; a="1166566729" Received: from nasanexm02d.na.qualcomm.com ([10.85.0.44]) by Ironmsg03-L.qualcomm.com with ESMTP/TLS/RC4-SHA; 14 Jun 2016 10:46:39 -0700 Received: from aphydexm01f.ap.qualcomm.com (10.252.127.15) by NASANEXM02D.na.qualcomm.com (10.85.0.44) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Tue, 14 Jun 2016 10:46:38 -0700 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; Tue, 14 Jun 2016 23:16:29 +0530 Received: by qcmail1.qualcomm.com (sSMTP sendmail emulation); Tue, 14 Jun 2016 23:16:04 +0530 From: Ashok Raj Nagarajan To: CC: , , , Ashok Raj Nagarajan Subject: [PATCH] iw: Add support for controlling tx power for per station Date: Tue, 14 Jun 2016 23:16:00 +0530 Message-ID: <1465926360-6561-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: NASANEXM01C.na.qualcomm.com (10.85.0.83) 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 --- 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,