From patchwork Wed Nov 25 13:59:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 7699621 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 025A09F2EC for ; Wed, 25 Nov 2015 13:59:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 00425208E5 for ; Wed, 25 Nov 2015 13:59:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E3D2D20854 for ; Wed, 25 Nov 2015 13:59:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754298AbbKYN73 (ORCPT ); Wed, 25 Nov 2015 08:59:29 -0500 Received: from mail-wm0-f41.google.com ([74.125.82.41]:37456 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754292AbbKYN71 (ORCPT ); Wed, 25 Nov 2015 08:59:27 -0500 Received: by wmww144 with SMTP id w144so70468091wmw.0 for ; Wed, 25 Nov 2015 05:59:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=z/SnpLhVPcEfSaAe/snGkvkuLLGz/KBEb06hhaB7YOs=; b=paO7z5dPiWcWHKnlX9F2c1VyvWETCL9/aj90ONkhqwC4GTC5RMcPgkjk5HAQel3zBO 3lKttCnSUyfFm5AsbpSB6g333skdAz1CguMRWrIK0fiHFAtk0oSVmmWDbbSTdhHbv/+/ q9WIzQvNnNmYUeMmyrFF9W1L4tnL+hKGAQoB9Qut8s5YLsCa840HvdH33KwyaWxdTTTV 8msJwTLAfq5NKpnQ5b/KvrAFuOn78IsjHvy3fIs41KkOGaKgHLauqCwPrudtkiBkNfH2 ox/pIFU4PRrwb/THWW8DY9z5Og/+YqmaaETnwj2Hql9Ip6Nro5XG4ADaLiwVSWTv+6XC BGng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=z/SnpLhVPcEfSaAe/snGkvkuLLGz/KBEb06hhaB7YOs=; b=auYLeVfSBAuVLT2oP/UWNboswXWquT3wFQmyUnRIRGRVPflQdDcNofyIV4nPQP5sxY DoeKsZFyZWi6AfjCEPvZdNFkbunSEvmCwnG+HyxmmuPpYMeunf+Jd9wuiWzTKA/sdwbg 8kD/FifFgRu8Mg5mjB/pIQb9GmsKV0f6K1F5beYryR2B+OiBU8wlVShhlsmyE8wpSODM hGxZKGyDA1Nu5xN2A0WXYZdIPUAox7Z6mqFeVG90fZrcEMmZp40+KcrcSUXsTl2h7Qv0 BPwiauvs9YZ/68dTYAg0NURJU0w9SebaReQR3F37Gxx/m8BSdv69a1KmyXgFeZIRAeGK 13Vg== X-Gm-Message-State: ALoCoQn7/DzeRUoKWS4qWTjWRMBdpxZ+DZlTvkMztlfBXZGEL9kQFTIzS9oXRkkqxQconNgdFxhM X-Received: by 10.194.84.42 with SMTP id v10mr44042187wjy.116.1448459966399; Wed, 25 Nov 2015 05:59:26 -0800 (PST) Received: from sven-desktop.home.narfation.org (x4d05aec6.dyn.telefonica.de. [77.5.174.198]) by smtp.gmail.com with ESMTPSA id n127sm3652817wmf.12.2015.11.25.05.59.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Nov 2015 05:59:25 -0800 (PST) From: Sven Eckelmann To: Johannes Berg Cc: linux-wireless@vger.kernel.org, Julian Calaby , Sven Eckelmann Subject: [PATCH v3 1/4] iw: prepare get_cf1 for use in join_* functions Date: Wed, 25 Nov 2015 14:59:15 +0100 Message-Id: <1448459959-23641-1-git-send-email-sven@open-mesh.com> X-Mailer: git-send-email 2.6.2 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The chanmode structure and the function get_cf1 to calculate the center frequency one can be used by not only the ibss join code but also by the mesh and ocb join code. Signed-off-by: Sven Eckelmann --- v3: * split patch into two different patches (0001/0002) as request by Julian Calaby * change join_ocb to also use get_cf1 * move NOHT to the last entry in the mesh/ibss join usage texts as requested by Julian Calaby v2: * rebase from v4.3-ish version to current master ibss.c | 33 --------------------------------- iw.h | 9 +++++++++ mesh.c | 10 +++------- util.c | 26 ++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 40 deletions(-) diff --git a/ibss.c b/ibss.c index 024981a..a761794 100644 --- a/ibss.c +++ b/ibss.c @@ -16,39 +16,6 @@ SECTION(ibss); -struct chanmode { - const char *name; - unsigned int width; - int freq1_diff; - int chantype; /* for older kernel */ -}; - -static int get_cf1(const struct chanmode *chanmode, unsigned long freq) -{ - unsigned int cf1 = freq, j; - unsigned int vht80[] = { 5180, 5260, 5500, 5580, 5660, 5745 }; - - switch (chanmode->width) { - case NL80211_CHAN_WIDTH_80: - /* setup center_freq1 */ - for (j = 0; j < ARRAY_SIZE(vht80); j++) { - if (freq >= vht80[j] && freq < vht80[j] + 80) - break; - } - - if (j == ARRAY_SIZE(vht80)) - break; - - cf1 = vht80[j] + 30; - break; - default: - cf1 = freq + chanmode->freq1_diff; - break; - } - - return cf1; -} - static int join_ibss(struct nl80211_state *state, struct nl_msg *msg, int argc, char **argv, diff --git a/iw.h b/iw.h index 263e8b1..d91a33e 100644 --- a/iw.h +++ b/iw.h @@ -59,6 +59,13 @@ struct cmd { const struct cmd *parent; }; +struct chanmode { + const char *name; + unsigned int width; + int freq1_diff; + int chantype; /* for older kernel */ +}; + #define ARRAY_SIZE(ar) (sizeof(ar)/sizeof(ar[0])) #define DIV_ROUND_UP(x, y) (((x) + (y - 1)) / (y)) @@ -174,6 +181,8 @@ void print_ies(unsigned char *ie, int ielen, bool unknown, void parse_bitrate(struct nlattr *bitrate_attr, char *buf, int buflen); void iw_hexdump(const char *prefix, const __u8 *data, size_t len); +int get_cf1(const struct chanmode *chanmode, unsigned long freq); + #define SCHED_SCAN_OPTIONS "interval [delay ] " \ "[freqs +] [matches [ssid ]+]] [active [ssid ]+|passive] [randomise[=/]]" int parse_sched_scan(struct nl_msg *msg, int *argc, char ***argv); diff --git a/mesh.c b/mesh.c index f2415f3..593ab7a 100644 --- a/mesh.c +++ b/mesh.c @@ -448,12 +448,8 @@ static int join_mesh(struct nl80211_state *state, char *end, *value = NULL, *sptr = NULL; unsigned int i; unsigned long freq = 0; - static const struct { - const char *name; - unsigned int width; - int freq1_diff; - int chantype; /* for older kernel */ - } *chanmode_selected = NULL, chanmode[] = { + const struct chanmode *chanmode_selected = NULL; + static const struct chanmode chanmode[] = { { .name = "HT20", .width = NL80211_CHAN_WIDTH_20, .freq1_diff = 0, @@ -506,7 +502,7 @@ static int join_mesh(struct nl80211_state *state, NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, chanmode_selected->width); NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ1, - freq + chanmode_selected->freq1_diff); + get_cf1(chanmode_selected, freq)); if (chanmode_selected->chantype != -1) NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, diff --git a/util.c b/util.c index 55e1e26..da3be32 100644 --- a/util.c +++ b/util.c @@ -726,3 +726,29 @@ void iw_hexdump(const char *prefix, const __u8 *buf, size_t size) } printf("\n\n"); } + +int get_cf1(const struct chanmode *chanmode, unsigned long freq) +{ + unsigned int cf1 = freq, j; + unsigned int vht80[] = { 5180, 5260, 5500, 5580, 5660, 5745 }; + + switch (chanmode->width) { + case NL80211_CHAN_WIDTH_80: + /* setup center_freq1 */ + for (j = 0; j < ARRAY_SIZE(vht80); j++) { + if (freq >= vht80[j] && freq < vht80[j] + 80) + break; + } + + if (j == ARRAY_SIZE(vht80)) + break; + + cf1 = vht80[j] + 30; + break; + default: + cf1 = freq + chanmode->freq1_diff; + break; + } + + return cf1; +}