From patchwork Mon Nov 7 14:59:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Berg X-Patchwork-Id: 9415357 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 EBBB260585 for ; Mon, 7 Nov 2016 15:00:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF2BF28C4A for ; Mon, 7 Nov 2016 15:00:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D41F528C4F; Mon, 7 Nov 2016 15:00:03 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 8052828C4A for ; Mon, 7 Nov 2016 15:00:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932334AbcKGPAB (ORCPT ); Mon, 7 Nov 2016 10:00:01 -0500 Received: from s3.sipsolutions.net ([5.9.151.49]:36818 "EHLO sipsolutions.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932290AbcKGO75 (ORCPT ); Mon, 7 Nov 2016 09:59:57 -0500 Received: by sipsolutions.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1c3lOt-00031L-6f; Mon, 07 Nov 2016 15:59:55 +0100 From: Benjamin Berg To: Johannes Berg Cc: linux-wireless@vger.kernel.org, sw@simonwunderlich.de, Benjamin Berg Subject: [PATCH 6/8] Add commands to send CSA Date: Mon, 7 Nov 2016 15:59:41 +0100 Message-Id: <20161107145943.16761-7-benjamin@sipsolutions.net> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161107145943.16761-1-benjamin@sipsolutions.net> References: <20161107145943.16761-1-benjamin@sipsolutions.net> 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 From: Benjamin Berg Add a new set of commands to send a CSA. Both the number of beacons and the flag to block TX can be given optionally. Signed-off-by: Simon Wunderlich Signed-off-by: Benjamin Berg --- interface.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ iw.h | 1 + 2 files changed, 73 insertions(+) diff --git a/interface.c b/interface.c index 57dd3c3..1c9ebfb 100644 --- a/interface.c +++ b/interface.c @@ -644,3 +644,75 @@ nla_put_failure: COMMAND(set, mcast_rate, "", NL80211_CMD_SET_MCAST_RATE, 0, CIB_NETDEV, set_mcast_rate, "Set the multicast bitrate."); + + +static int handle_chanfreq(struct nl80211_state *state, struct nl_msg *msg, + bool chan, int argc, char **argv, + enum id_input id) +{ + struct chandef chandef; + int res; + int parsed; + char *end; + + res = parse_freqchan(&chandef, chan, argc, argv, &parsed); + if (res) + return res; + + argc -= parsed; + argv += parsed; + + while (argc) { + unsigned int beacons = 10; + + if (strcmp(argv[0], "beacons") == 0) { + if (argc < 2) + return 1; + + beacons = strtol(argv[1], &end, 10); + if (*end) + return 1; + + argc -= 2; + argv += 2; + + NLA_PUT_U32(msg, NL80211_ATTR_CH_SWITCH_COUNT, beacons); + } else if (strcmp(argv[0], "block-tx") == 0) { + argc -= 1; + argv += 1; + + NLA_PUT_FLAG(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX); + } else { + return 1; + } + } + + return put_chandef(msg, &chandef); + + nla_put_failure: + return -ENOBUFS; +} + +static int handle_freq(struct nl80211_state *state, struct nl_msg *msg, + int argc, char **argv, + enum id_input id) +{ + return handle_chanfreq(state, msg, false, argc, argv, id); +} + +static int handle_chan(struct nl80211_state *state, struct nl_msg *msg, + int argc, char **argv, + enum id_input id) +{ + return handle_chanfreq(state, msg, true, argc, argv, id); +} + +SECTION(switch); +COMMAND(switch, freq, + " [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz] [beacons ] [block-tx]\n" + " [5|10|20|40|80|80+80|160] [ []] [beacons ] [block-tx]", + NL80211_CMD_CHANNEL_SWITCH, 0, CIB_NETDEV, handle_freq, + "Switch the operating channel by sending a channel switch announcement (CSA)."); +COMMAND(switch, channel, " [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz] [beacons ] [block-tx]", + NL80211_CMD_CHANNEL_SWITCH, 0, CIB_NETDEV, handle_chan, NULL); + diff --git a/iw.h b/iw.h index 7d56391..0857baf 100644 --- a/iw.h +++ b/iw.h @@ -202,6 +202,7 @@ int get_cf1(const struct chanmode *chanmode, unsigned long freq); "[randomise[=/]]" int parse_sched_scan(struct nl_msg *msg, int *argc, char ***argv); +DECLARE_SECTION(switch); DECLARE_SECTION(set); DECLARE_SECTION(get);