Return-path: Received: from james.theweblords.de ([217.11.55.87]:56259 "EHLO james.theweblords.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752714AbdLMM7V (ORCPT ); Wed, 13 Dec 2017 07:59:21 -0500 From: =?UTF-8?q?Peter=20Gro=C3=9Fe?= To: Johannes Berg Cc: linux-wireless@vger.kernel.org Subject: [PATCH] ocb: Use common freqchan helper for setting the operating channel Date: Wed, 13 Dec 2017 13:58:40 +0100 Message-Id: <20171213125840.1036-1-pegro@friiks.de> (sfid-20171213_135927_318860_CA260086) In-Reply-To: <1512991065.26976.70.camel@sipsolutions.net> References: <1512991065.26976.70.camel@sipsolutions.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-wireless-owner@vger.kernel.org List-ID: Simplify code by using the helper which has been introduced earlier. Signed-off-by: Peter Große --- Mh, the patch is against the full tree of iw, not the kernel, so there is no net/wireless/ path. But yeah, whitespace got mangled. Regards Peter ocb.c | 50 ++++++++------------------------------------------ 1 file changed, 8 insertions(+), 42 deletions(-) diff --git a/ocb.c b/ocb.c index bcf0474..dfdaf59 100644 --- a/ocb.c +++ b/ocb.c @@ -10,56 +10,22 @@ static int join_ocb(struct nl80211_state *state, struct nl_msg *msg, int argc, char **argv, enum id_input id) { - unsigned long freq; - char *end; - unsigned int i; - const struct chanmode *chanmode_selected = NULL; - static const struct chanmode chanmode[] = { - { .name = "5MHz", - .width = NL80211_CHAN_WIDTH_5, - .freq1_diff = 0, - .chantype = -1 }, - { .name = "10MHz", - .width = NL80211_CHAN_WIDTH_10, - .freq1_diff = 0, - .chantype = -1 }, - }; + struct chandef chandef; + int err, parsed; if (argc < 2) return 1; - /* freq */ - freq = strtoul(argv[0], &end, 10); - if (*end != '\0') - return 1; - - NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); - argv++; - argc--; + err = parse_freqchan(&chandef, false, argc, argv, &parsed); - /* channel width */ - for (i = 0; i < ARRAY_SIZE(chanmode); i++) { - if (strcasecmp(chanmode[i].name, argv[0]) == 0) { - chanmode_selected = &chanmode[i]; - break; - } - } - if (chanmode_selected) { - NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, - chanmode_selected->width); - NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ1, - get_cf1(chanmode_selected, freq)); + if (err) + return err; - argv++; - argc--; - } else { - return 1; - } + put_chandef(msg, &chandef); + if (err) + return err; return 0; - -nla_put_failure: - return -ENOBUFS; } COMMAND(ocb, join, " <5MHz|10MHz>", NL80211_CMD_JOIN_OCB, 0, CIB_NETDEV, join_ocb, -- 2.13.6