From patchwork Mon Oct 8 12:45:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Shvedov X-Patchwork-Id: 980548 X-Patchwork-Delegate: ynezz@true.cz 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="i3EYJM0d"; 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 42TKrD6n23z9sBk for ; Mon, 8 Oct 2018 23:47:08 +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=i3EYJM0dQK00gkjzwvfjAROkfP MxGuWyHgrOTygnsUaMC72uAGrig0oLQvgfCo+ylHqieuK02q6w5kh+JrEh5YP4Oq8znBYQhKzcz34 eCzDoVA1gW6DR9aF2TC1oov/D2DcFUK6qss9EV8I3Xu7oSJV85MyZhtuI5SevmXYJg3nYEZbHmtMg yiOIilLnslXJWZ/358Z13AFNEFT/llcM5FDZ8JZDXxHg8U4276jxZkeC3XEDZb/neOoe05qB9aW1u hoZKsYv+nKfrFjchWDhwZTVQFd9dLogIq+/uJiMMhgRx+wNa2C7HVietjYvLrK6whJl7ei3s0960u TKDnPCHw==; 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 1g9Uw6-0000vq-Ir; Mon, 08 Oct 2018 12:46:58 +0000 Received: from forward103o.mail.yandex.net ([2a02:6b8:0:1a2d::606]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9Uut-0000Is-AM for openwrt-devel@lists.openwrt.org; Mon, 08 Oct 2018 12:46:13 +0000 Received: from mxback12j.mail.yandex.net (mxback12j.mail.yandex.net [IPv6:2a02:6b8:0:1619::87]) by forward103o.mail.yandex.net (Yandex) with ESMTP id DC686588551D for ; Mon, 8 Oct 2018 15:45:22 +0300 (MSK) Received: from smtp2o.mail.yandex.net (smtp2o.mail.yandex.net [2a02:6b8:0:1a2d::26]) by mxback12j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 2u7RYHJswB-jMMqr9PX; Mon, 08 Oct 2018 15:45:22 +0300 Received: by smtp2o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id wSOATOpRjx-jL1eDcaD; Mon, 08 Oct 2018 15:45:21 +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:45:17 +0300 Message-Id: <20181008124520.30040-2-yshvedov@wimarksystems.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008124520.30040-1-yshvedov@wimarksystems.com> References: <20181008122821.29237-4-yshvedov@wimarksystems.com> <20181008124520.30040-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_054543_763200_CC61C23F X-CRM114-Status: GOOD ( 10.47 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a02:6b8:0:1a2d:0:0:0:606 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),