From patchwork Mon Jul 6 17:09:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Crispin X-Patchwork-Id: 1323799 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=phrozen.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=NSLxcEl5; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B0sXC1MhWz9sTH for ; Tue, 7 Jul 2020 03:10:34 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Tu5LSdFpsgAPo2BpU46dMOwMF6PJXPGwuFNtT7ClqHg=; b=NSLxcEl5iCSuvU/X/y4+wCJIO SXinZXASiJ02xObV9u7LtMVdi+xLWn54KVM88VknXj2CN9zt2sw0wRfPyTIbC3v9cSYVuRAYrL2BV /Cgx3YR4ygoxemdpQy9lgRwXp23zwIYjGDUHnbTb16ti1P8IeEEYgUY8F3tefZAUWSN9/6Kr0EQrG uDpx/p39jWB8Y5ADV2gfZttUeGiFSnYn8Y2MuB9pe0lFK5uSxt6oVymjXEr3bod89gg9WFfWANM2P gc2ak0fIk/hFpynaV8LnAQvW0vY03g44atRAWVTSy6YVcwIIg8xMyF9RNavN3gedmFjc2Pb1q4DxE OSLHJBipQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsUcZ-0007mr-CZ; Mon, 06 Jul 2020 17:09:35 +0000 Received: from nbd.name ([2a01:4f8:221:3d45::2]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsUcV-0007kK-Ob for hostap@lists.infradead.org; Mon, 06 Jul 2020 17:09:33 +0000 Received: from [134.101.131.141] (helo=bertha9.lan) by ds12 with esmtpa (Exim 4.89) (envelope-from ) id 1jsUcT-00017f-RW; Mon, 06 Jul 2020 19:09:29 +0200 From: John Crispin To: hostap@lists.infradead.org Subject: [PATCH V2 2/7] bss coloring: add support for handling collision events and triggering CCA Date: Mon, 6 Jul 2020 19:09:23 +0200 Message-Id: <20200706170928.1774626-3-john@phrozen.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200706170928.1774626-1-john@phrozen.org> References: <20200706170928.1774626-1-john@phrozen.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200706_130931_959014_500996EB X-CRM114-Status: GOOD ( 20.18 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Crispin Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add the core code for handling bss color collision events and triggering CCA inside the kernel. Signed-off-by: John Crispin --- src/ap/ap_drv_ops.h | 12 +++++ src/ap/hostapd.c | 89 ++++++++++++++++++++++++++++++++++++ src/ap/hostapd.h | 14 ++++++ src/common/ieee802_11_defs.h | 1 + src/drivers/driver.h | 31 +++++++++++++ 5 files changed, 147 insertions(+) diff --git a/src/ap/ap_drv_ops.h b/src/ap/ap_drv_ops.h index 651b77e9a..44e010f1e 100644 --- a/src/ap/ap_drv_ops.h +++ b/src/ap/ap_drv_ops.h @@ -299,6 +299,18 @@ static inline int hostapd_drv_switch_channel(struct hostapd_data *hapd, return hapd->driver->switch_channel(hapd->drv_priv, settings); } +#ifdef CONFIG_IEEE80211AX +static inline int hostapd_drv_switch_color(struct hostapd_data *hapd, + struct cca_settings *settings) +{ + if (hapd->driver == NULL || hapd->driver->switch_color == NULL || + hapd->drv_priv == NULL) + return -1; + + return hapd->driver->switch_color(hapd->drv_priv, settings); +} +#endif + static inline int hostapd_drv_status(struct hostapd_data *hapd, char *buf, size_t buflen) { diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c index 26e62d991..f569ddede 100644 --- a/src/ap/hostapd.c +++ b/src/ap/hostapd.c @@ -3661,6 +3661,95 @@ hostapd_switch_channel_fallback(struct hostapd_iface *iface, hostapd_enable_iface(iface); } + +#ifdef CONFIG_IEEE80211AX +void hostapd_cleanup_cca_params(struct hostapd_data *hapd) +{ + hapd->cca_count = 0; + hapd->cca_color = 0; + hapd->cca_c_off_beacon = 0; + hapd->cca_c_off_proberesp = 0; + hapd->cca_in_progress = 0; +} + + +static int hostapd_fill_cca_settings(struct hostapd_data *hapd, + struct cca_settings *settings) +{ + struct hostapd_iface *iface = hapd->iface; + u8 old_color; + int ret; + + + if (!iface || hapd->conf->he_op.he_bss_color_disabled) + return -1; + + old_color = hapd->conf->he_op.he_bss_color; + hapd->conf->he_op.he_bss_color = hapd->cca_color; + ret = hostapd_build_beacon_data(hapd, &settings->beacon_after); + hapd->conf->he_op.he_bss_color = old_color; + + settings->cca_count = hapd->cca_count; + settings->cca_color = hapd->cca_color, + hapd->cca_in_progress = 1; + + ret = hostapd_build_beacon_data(hapd, &settings->beacon_cca); + if (ret) { + free_beacon_data(&settings->beacon_after); + return ret; + } + + settings->counter_offset_beacon = hapd->cca_c_off_beacon; + settings->counter_offset_presp = hapd->cca_c_off_proberesp; + + return 0; +} + + +void +hostapd_switch_color(struct hostapd_data *hapd, u64 bitmap) +{ + struct cca_settings settings; + int i, r, ret; + + if (hapd->cca_in_progress) + return; + + r = os_random() % HE_OPERATION_BSS_COLOR_MAX; + for (i = 0; i < HE_OPERATION_BSS_COLOR_MAX; i++) { + if ((bitmap & (1 << r)) == 0) + break; + r = (r + 1) % HE_OPERATION_BSS_COLOR_MAX; + } + if (i == HE_OPERATION_BSS_COLOR_MAX) { + /* there are no free colors so turn bss coloring off */ + wpa_printf(MSG_INFO, "no free colors left, turning of BSS coloring"); + hapd->conf->he_op.he_bss_color_disabled = 1; + hapd->conf->he_op.he_bss_color = 1; + ieee802_11_set_beacon(hapd); + return; + } + + hostapd_cleanup_cca_params(hapd); + hapd->cca_color = r; + hapd->cca_count = 10; + + if (hostapd_fill_cca_settings(hapd, &settings)) { + hostapd_cleanup_cca_params(hapd); + return; + } + + ret = hostapd_drv_switch_color(hapd, &settings); + free_beacon_data(&settings.beacon_cca); + free_beacon_data(&settings.beacon_after); + + if (ret) { + hostapd_cleanup_cca_params(hapd); + return; + } +} +#endif + #endif /* NEED_AP_MLME */ diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h index 44d2c6068..ae16a30bf 100644 --- a/src/ap/hostapd.h +++ b/src/ap/hostapd.h @@ -292,6 +292,14 @@ struct hostapd_data { unsigned int cs_c_off_ecsa_beacon; unsigned int cs_c_off_ecsa_proberesp; +#ifdef CONFIG_IEEE80211AX + int cca_in_progress; + u8 cca_count; + u8 cca_color; + unsigned int cca_c_off_beacon; + unsigned int cca_c_off_proberesp; +#endif + #ifdef CONFIG_P2P struct p2p_data *p2p; struct p2p_group *p2p_group; @@ -636,6 +644,12 @@ void hostapd_periodic_iface(struct hostapd_iface *iface); int hostapd_owe_trans_get_info(struct hostapd_data *hapd); void hostapd_ocv_check_csa_sa_query(void *eloop_ctx, void *timeout_ctx); + +#ifdef CONFIG_IEEE80211AX +void hostapd_switch_color(struct hostapd_data *hapd, u64 bitmap); +void hostapd_cleanup_cca_params(struct hostapd_data *hapd); +#endif + /* utils.c */ int hostapd_register_probereq_cb(struct hostapd_data *hapd, int (*cb)(void *ctx, const u8 *sa, diff --git a/src/common/ieee802_11_defs.h b/src/common/ieee802_11_defs.h index 7d1287763..f1fdc8796 100644 --- a/src/common/ieee802_11_defs.h +++ b/src/common/ieee802_11_defs.h @@ -2265,6 +2265,7 @@ struct ieee80211_spatial_reuse { #define HE_OPERATION_BSS_COLOR_PARTIAL ((u32) BIT(30)) #define HE_OPERATION_BSS_COLOR_DISABLED ((u32) BIT(31)) #define HE_OPERATION_BSS_COLOR_OFFSET 24 +#define HE_OPERATION_BSS_COLOR_MAX 64 /* Spatial Reuse defines */ #define SPATIAL_REUSE_SRP_DISALLOWED BIT(0) diff --git a/src/drivers/driver.h b/src/drivers/driver.h index cfeb94781..487f2faee 100644 --- a/src/drivers/driver.h +++ b/src/drivers/driver.h @@ -2308,6 +2308,26 @@ struct csa_settings { u16 counter_offset_presp[2]; }; +/** + * struct cca_settings - Settings for color switch command + * @cca_count: Count in Beacon frames (TBTT) to perform the switch + * @cca_color: The new color that we are switching to + * @beacon_cca: Beacon/probe resp/asooc resp info for color switch period + * @beacon_after: Next beacon/probe resp/asooc resp info + * @counter_offset_beacon: Offset to the count field in beacon's tail + * @counter_offset_presp: Offset to the count field in probe resp. + */ +struct cca_settings { + u8 cca_count; + u8 cca_color; + + struct beacon_data beacon_cca; + struct beacon_data beacon_after; + + u16 counter_offset_beacon; + u16 counter_offset_presp; +}; + /* TDLS peer capabilities for send_tdls_mgmt() */ enum tdls_peer_capability { TDLS_PEER_HT = BIT(0), @@ -3879,6 +3899,17 @@ struct wpa_driver_ops { */ int (*switch_channel)(void *priv, struct csa_settings *settings); + /** + * switch_color - Announce color switch and migrate the BSS to the + * given color + * @priv: Private driver interface data + * @settings: Settings for CCA period and new color + * Returns: 0 on success, -1 on failure + * + * This function is used to move the BSS to its new color. + */ + int (*switch_color)(void *priv, struct cca_settings *settings); + /** * add_tx_ts - Add traffic stream * @priv: Private driver interface data