From patchwork Fri Oct 27 21:43:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Peter_Gro=C3=9Fe?= X-Patchwork-Id: 10030693 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 F34276034B for ; Fri, 27 Oct 2017 21:49:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0F8328FE3 for ; Fri, 27 Oct 2017 21:49:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3C0128FE7; Fri, 27 Oct 2017 21:49:51 +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 D3BFC28FE3 for ; Fri, 27 Oct 2017 21:49:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932532AbdJ0Vtt (ORCPT ); Fri, 27 Oct 2017 17:49:49 -0400 Received: from james.theweblords.de ([217.11.55.87]:41605 "EHLO james.theweblords.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932190AbdJ0Vts (ORCPT ); Fri, 27 Oct 2017 17:49:48 -0400 X-Greylist: delayed 395 seconds by postgrey-1.27 at vger.kernel.org; Fri, 27 Oct 2017 17:49:47 EDT Received: (qmail 32570 invoked by uid 210); 27 Oct 2017 21:43:06 -0000 X-Qmail-Scanner-Diagnostics: from wl-r3-120.rz.tu-ilmenau.de (petronios@theweblords.de@wl-r3-120.rz.tu-ilmenau.de) by james (envelope-from , uid 201) with qmail-scanner-2.10st (mhr: 1.0. spamassassin: 3.4.1. perlscan: 2.10st. Clear:RC:1(141.24.16.120):. Processed in 0.041157 secs); 27 Oct 2017 21:43:06 -0000 Received: from wl-r3-120.rz.tu-ilmenau.de (HELO localhost.localdomain) (petronios@theweblords.de@141.24.16.120) by james.theweblords.de with ESMTPA; 27 Oct 2017 21:43:06 -0000 From: =?UTF-8?q?Peter=20Gro=C3=9Fe?= To: Johannes Berg Cc: linux-wireless@vger.kernel.org Subject: [PATCH 1/1] ocb: Use common freqchan helper for setting the operating channel Date: Fri, 27 Oct 2017 23:43:02 +0200 Message-Id: <20171027214302.4059-1-pegro@friiks.de> X-Mailer: git-send-email 2.13.6 MIME-Version: 1.0 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 Simplify code by using the helper which has been introduced earlier. Signed-off-by: Peter Große --- 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,