From patchwork Mon Oct 8 12:28:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Shvedov X-Patchwork-Id: 980546 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=wimarksystems.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="lUbSmkkw"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="Wua9iXwD"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42TKpW69jGz9s8r for ; Mon, 8 Oct 2018 23:45:39 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=/zBO4h0E9ca4UZH8i4aNkHLyRvGo1AfHEvse6+V99FY=; b=lUbSmkkwtamC+Jh9r01BDmdQk3 5ZLdDOpYJuzVU7P5NDlhNIw1Z62VqOr0ypVlSaPkZNu1Ap91kDESF7Xn67cc8FoVY+iholol5FghC SLA/2t8HYJMUU37KNJ+7mOSHXVNleW4StZ1mTLI4xUGjaDnX7ghvYA21ZwpXZMMtOOqZxfLD6dXTW 0+le/C1yqwGKx5xJgOaigWrpbinAJgLC7qQv4qmjYM0ipN3KXAWdCjksxzlQpTTuepwVoFVvQgS4w WwSKZGYBn0rTdoci4ch9y6eO0PSG/cMN/FLXpSWsqlLT7BO0chEW8/FRUIomjfDiZ32lzOocTWR97 C5BlbhIA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9Uul-0000Jr-6b; Mon, 08 Oct 2018 12:45:35 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9Uu8-0007B5-N1 for openwrt-devel@bombadil.infradead.org; Mon, 08 Oct 2018 12:44:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=eDQ3/sVMhFiI8mJ6mPPwHnznpWbQ2lzVVLEyKgHUd0M=; b=Wua9iXwDE5ZGYfun3wwijrFnHd GkG4ppbTIysfLtvVVBHPCXsIBUgexqXvs8aZPvKsY7/JjGO8w5nrSah7JUEC7tbsAoqCO5XDX6mvL veLBxDMD0waCs6n9JiK+dx31VE3P2X5ezEPLCbdW8FJQmGhAVZuZXSUUhEhWWnEMO87yWX223ZRw4 ps3+11x2vb6R3YgtgREN/j/3ixILwFw82nkoG8U5nwKB4w9o3UsK1r/h3Oz8cn9XEKB9mLi+HEqvs LhzcOMSDjrhvJT09jUKph+ARuOKPjIvhfmiiXiLPtDXfNNdmrFF7/S1C8WOQSO2IlKfsLDXsrbaD9 MORBLWIA==; Received: from forward101o.mail.yandex.net ([37.140.190.181]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9UeN-0002gP-7s for openwrt-devel@lists.openwrt.org; Mon, 08 Oct 2018 12:28:41 +0000 Received: from mxback4j.mail.yandex.net (mxback4j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10d]) by forward101o.mail.yandex.net (Yandex) with ESMTP id 6943A1345435 for ; Mon, 8 Oct 2018 15:28:23 +0300 (MSK) Received: from smtp1p.mail.yandex.net (smtp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:6]) by mxback4j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id RD1b97DLDV-SNLCSTu8; Mon, 08 Oct 2018 15:28:23 +0300 Received: by smtp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id vvLubVtQwM-SMV8gGB5; Mon, 08 Oct 2018 15:28:22 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) From: Yury Shvedov To: openwrt-devel@lists.openwrt.org Date: Mon, 8 Oct 2018 15:28:18 +0300 Message-Id: <20181008122821.29237-2-yshvedov@wimarksystems.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008122821.29237-1-yshvedov@wimarksystems.com> References: <20181008122821.29237-1-yshvedov@wimarksystems.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181008_132839_418995_E6CF6DB8 X-CRM114-Status: GOOD ( 13.10 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.1 on casper.infradead.org summary: Content analysis details: (-0.7 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [37.140.190.181 listed in list.dnswl.org] Subject: [OpenWrt-Devel] [PATCH 2/5] hostapd: add ubus switch_chan method to ifaces X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org switch_chan method now could be called directly by hostapd_iface object. Signed-off-by: Yury Shvedov --- .../services/hostapd/src/src/ap/ubus.c | 145 +++++++++++------- 1 file changed, 86 insertions(+), 59 deletions(-) diff --git a/package/network/services/hostapd/src/src/ap/ubus.c b/package/network/services/hostapd/src/src/ap/ubus.c index a393451af2..6d12126a1a 100644 --- a/package/network/services/hostapd/src/src/ap/ubus.c +++ b/package/network/services/hostapd/src/src/ap/ubus.c @@ -145,9 +145,88 @@ hostapd_iface_get_bss(struct ubus_context *ctx, struct ubus_object *obj, return 0; } + +#ifdef NEED_AP_MLME +enum { + CSA_FREQ, + CSA_BCN_COUNT, + CSA_CENTER_FREQ1, + CSA_CENTER_FREQ2, + CSA_BANDWIDTH, + CSA_SEC_CHANNEL_OFFSET, + CSA_HT, + CSA_VHT, + CSA_BLOCK_TX, + __CSA_MAX +}; + +static const struct blobmsg_policy csa_policy[__CSA_MAX] = { + [CSA_FREQ] = { "freq", BLOBMSG_TYPE_INT32 }, + [CSA_BCN_COUNT] = { "bcn_count", BLOBMSG_TYPE_INT32 }, + [CSA_CENTER_FREQ1] = { "center_freq1", BLOBMSG_TYPE_INT32 }, + [CSA_CENTER_FREQ2] = { "center_freq2", BLOBMSG_TYPE_INT32 }, + [CSA_BANDWIDTH] = { "bandwidth", BLOBMSG_TYPE_INT32 }, + [CSA_SEC_CHANNEL_OFFSET] = { "sec_channel_offset", BLOBMSG_TYPE_INT32 }, + [CSA_HT] = { "ht", BLOBMSG_TYPE_BOOL }, + [CSA_VHT] = { "vht", BLOBMSG_TYPE_BOOL }, + [CSA_BLOCK_TX] = { "block_tx", BLOBMSG_TYPE_BOOL }, +}; + +static int +hostapd_switch_chan(struct hostapd_data *hapd, struct blob_attr *msg) +{ + struct blob_attr *tb[__CSA_MAX]; + struct csa_settings css; + + blobmsg_parse(csa_policy, __CSA_MAX, tb, blob_data(msg), blob_len(msg)); + + if (!tb[CSA_FREQ]) + return UBUS_STATUS_INVALID_ARGUMENT; + + memset(&css, 0, sizeof(css)); + css.freq_params.freq = blobmsg_get_u32(tb[CSA_FREQ]); + +#define SET_CSA_SETTING(name, field, type) \ + do { \ + if (tb[name]) \ + css.field = blobmsg_get_ ## type(tb[name]); \ + } while(0) + + SET_CSA_SETTING(CSA_BCN_COUNT, cs_count, u32); + SET_CSA_SETTING(CSA_CENTER_FREQ1, freq_params.center_freq1, u32); + SET_CSA_SETTING(CSA_CENTER_FREQ2, freq_params.center_freq2, u32); + SET_CSA_SETTING(CSA_BANDWIDTH, freq_params.bandwidth, u32); + SET_CSA_SETTING(CSA_SEC_CHANNEL_OFFSET, freq_params.sec_channel_offset, u32); + SET_CSA_SETTING(CSA_HT, freq_params.ht_enabled, bool); + SET_CSA_SETTING(CSA_VHT, freq_params.vht_enabled, bool); + SET_CSA_SETTING(CSA_BLOCK_TX, block_tx, bool); + + + if (hostapd_switch_channel(hapd, &css) != 0) + return UBUS_STATUS_NOT_SUPPORTED; + return UBUS_STATUS_OK; +#undef SET_CSA_SETTING +} + +static int +hostapd_iface_switch_chan(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct hostapd_iface *iface = container_of(obj, struct hostapd_iface, + ubus.obj); + if (iface && iface->bss[0]) + return hostapd_switch_chan(iface->bss[0], msg); + return UBUS_STATUS_INVALID_ARGUMENT; +} +#endif + static const struct ubus_method iface_methods[] = { UBUS_METHOD_NOARG("get_state", hostapd_iface_get_state), UBUS_METHOD_NOARG("get_bss", hostapd_iface_get_bss), +#ifdef NEED_AP_MLME + UBUS_METHOD("switch_chan", hostapd_iface_switch_chan, csa_policy), +#endif }; static struct ubus_object_type iface_object_type = UBUS_OBJECT_TYPE("hostapd_iface", iface_methods); @@ -472,69 +551,17 @@ hostapd_bss_update_beacon(struct ubus_context *ctx, struct ubus_object *obj, return 0; } -enum { - CSA_FREQ, - CSA_BCN_COUNT, - CSA_CENTER_FREQ1, - CSA_CENTER_FREQ2, - CSA_BANDWIDTH, - CSA_SEC_CHANNEL_OFFSET, - CSA_HT, - CSA_VHT, - CSA_BLOCK_TX, - __CSA_MAX -}; - -static const struct blobmsg_policy csa_policy[__CSA_MAX] = { - [CSA_FREQ] = { "freq", BLOBMSG_TYPE_INT32 }, - [CSA_BCN_COUNT] = { "bcn_count", BLOBMSG_TYPE_INT32 }, - [CSA_CENTER_FREQ1] = { "center_freq1", BLOBMSG_TYPE_INT32 }, - [CSA_CENTER_FREQ2] = { "center_freq2", BLOBMSG_TYPE_INT32 }, - [CSA_BANDWIDTH] = { "bandwidth", BLOBMSG_TYPE_INT32 }, - [CSA_SEC_CHANNEL_OFFSET] = { "sec_channel_offset", BLOBMSG_TYPE_INT32 }, - [CSA_HT] = { "ht", BLOBMSG_TYPE_BOOL }, - [CSA_VHT] = { "vht", BLOBMSG_TYPE_BOOL }, - [CSA_BLOCK_TX] = { "block_tx", BLOBMSG_TYPE_BOOL }, -}; #ifdef NEED_AP_MLME static int -hostapd_switch_chan(struct ubus_context *ctx, struct ubus_object *obj, - struct ubus_request_data *req, const char *method, - struct blob_attr *msg) +hostapd_bss_switch_chan(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) { - struct blob_attr *tb[__CSA_MAX]; struct hostapd_data *hapd = get_hapd_from_object(obj); - struct csa_settings css; - - blobmsg_parse(csa_policy, __CSA_MAX, tb, blob_data(msg), blob_len(msg)); - - if (!tb[CSA_FREQ]) - return UBUS_STATUS_INVALID_ARGUMENT; - - memset(&css, 0, sizeof(css)); - css.freq_params.freq = blobmsg_get_u32(tb[CSA_FREQ]); - -#define SET_CSA_SETTING(name, field, type) \ - do { \ - if (tb[name]) \ - css.field = blobmsg_get_ ## type(tb[name]); \ - } while(0) - - SET_CSA_SETTING(CSA_BCN_COUNT, cs_count, u32); - SET_CSA_SETTING(CSA_CENTER_FREQ1, freq_params.center_freq1, u32); - SET_CSA_SETTING(CSA_CENTER_FREQ2, freq_params.center_freq2, u32); - SET_CSA_SETTING(CSA_BANDWIDTH, freq_params.bandwidth, u32); - SET_CSA_SETTING(CSA_SEC_CHANNEL_OFFSET, freq_params.sec_channel_offset, u32); - SET_CSA_SETTING(CSA_HT, freq_params.ht_enabled, bool); - SET_CSA_SETTING(CSA_VHT, freq_params.vht_enabled, bool); - SET_CSA_SETTING(CSA_BLOCK_TX, block_tx, bool); - - - if (hostapd_switch_channel(hapd, &css) != 0) - return UBUS_STATUS_NOT_SUPPORTED; - return UBUS_STATUS_OK; -#undef SET_CSA_SETTING + if (hapd) + return hostapd_switch_chan(hapd, msg); + return UBUS_STATUS_INVALID_ARGUMENT; } #endif @@ -1050,7 +1077,7 @@ static const struct ubus_method bss_methods[] = { UBUS_METHOD_NOARG("update_beacon", hostapd_bss_update_beacon), UBUS_METHOD_NOARG("get_features", hostapd_bss_get_features), #ifdef NEED_AP_MLME - UBUS_METHOD("switch_chan", hostapd_switch_chan, csa_policy), + UBUS_METHOD("switch_chan", hostapd_bss_switch_chan, csa_policy), #endif UBUS_METHOD("set_vendor_elements", hostapd_vendor_elements, ve_policy), UBUS_METHOD("notify_response", hostapd_notify_response, notify_policy),