From patchwork Wed Mar 10 18:26:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aloka Dixit X-Patchwork-Id: 397168 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A621EC43381 for ; Wed, 10 Mar 2021 18:27:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64D4764FB6 for ; Wed, 10 Mar 2021 18:27:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233257AbhCJS0q (ORCPT ); Wed, 10 Mar 2021 13:26:46 -0500 Received: from z11.mailgun.us ([104.130.96.11]:55982 "EHLO z11.mailgun.us" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232824AbhCJS02 (ORCPT ); Wed, 10 Mar 2021 13:26:28 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1615400788; h=Content-Transfer-Encoding: MIME-Version: References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=Gh5h1OwMER/3kogGkKj3JAznQ2dPzVJxHnyYWva/A08=; b=Z4UdEiHlQPeqquc1HIWhiCQrgxWHeUhRZ4qZQHpinzTU/i3gf7z0Xn6R8nqCQonHndD0gWnL y/eIc5U3RoPSEa5BEP8mcjL0o1SRaX7/z9nom6bsrKU+uXBuFDOd/uhd938vwgz6t+3RIWXF ucxmOd4Ufafao1Ons1Me69Fk5vc= X-Mailgun-Sending-Ip: 104.130.96.11 X-Mailgun-Sid: WyI3YTAwOSIsICJsaW51eC13aXJlbGVzc0B2Z2VyLmtlcm5lbC5vcmciLCAiYmU5ZTRhIl0= Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n01.prod.us-east-1.postgun.com with SMTP id 60490f49b86af9bf23d769d9 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Wed, 10 Mar 2021 18:26:16 GMT Sender: alokad=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 51892C43461; Wed, 10 Mar 2021 18:26:16 +0000 (UTC) Received: from alokad-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: alokad) by smtp.codeaurora.org (Postfix) with ESMTPSA id 9D1E0C433C6; Wed, 10 Mar 2021 18:26:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 9D1E0C433C6 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=alokad@codeaurora.org From: Aloka Dixit To: johannes@sipsolutions.net Cc: linux-wireless@vger.kernel.org, John Crispin , Aloka Dixit Subject: [PATCH v9 2/4] mac80211: add multiple bssid support to interface handling Date: Wed, 10 Mar 2021 10:26:02 -0800 Message-Id: <20210310182604.8858-3-alokad@codeaurora.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20210310182604.8858-1-alokad@codeaurora.org> References: <20210310182604.8858-1-alokad@codeaurora.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: John Crispin Add a new helper ieee80211_set_multiple_bssid_options() takes propagating the cfg80211 data down the stack. The patch also makes sure that all members of the bss set will get closed when either of them is shutdown. Signed-off-by: John Crispin Co-developed-by: Aloka Dixit Signed-off-by: Aloka Dixit --- include/net/mac80211.h | 30 +++++++++++++++++++++++- net/mac80211/cfg.c | 53 ++++++++++++++++++++++++++++++++++++++++++ net/mac80211/debugfs.c | 1 + net/mac80211/iface.c | 6 +++++ 4 files changed, 89 insertions(+), 1 deletion(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index 2d1d629e5d14..b9f51515c2e8 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -631,6 +631,7 @@ struct ieee80211_fils_discovery { * @s1g: BSS is S1G BSS (affects Association Request format). * @beacon_tx_rate: The configured beacon transmit rate that needs to be passed * to driver when rate control is offloaded to firmware. + * @multiple_bssid: the multiple bssid settings of the AP. */ struct ieee80211_bss_conf { const u8 *bssid; @@ -700,6 +701,7 @@ struct ieee80211_bss_conf { u32 unsol_bcast_probe_resp_interval; bool s1g; struct cfg80211_bitrate_mask beacon_tx_rate; + struct cfg80211_multiple_bssid multiple_bssid; }; /** @@ -1663,6 +1665,19 @@ enum ieee80211_offload_flags { IEEE80211_OFFLOAD_DECAP_ENABLED = BIT(2), }; +/** + * enum ieee80211_vif_multiple_bssid_flags - virtual interface multiple bssid flags + * + * @IEEE80211_VIF_MBSS_TRANSMITTING: this BSS is transmitting beacons + * @IEEE80211_VIF_MBSS_NON_TRANSMITTING: this BSS is not transmitting beacons + * @IEEE80211_VIF_MBSS_EMA_BEACON: beacons should be send out in EMA mode + */ +enum ieee80211_vif_multiple_bssid_flags { + IEEE80211_VIF_MBSS_TRANSMITTING = BIT(1), + IEEE80211_VIF_MBSS_NON_TRANSMITTING = BIT(2), + IEEE80211_VIF_MBSS_EMA_BEACON = BIT(3), +}; + /** * struct ieee80211_vif - per-interface data * @@ -1709,6 +1724,11 @@ enum ieee80211_offload_flags { * protected by fq->lock. * @offload_flags: 802.3 -> 802.11 enapsulation offload flags, see * &enum ieee80211_offload_flags. + * + * @multiple_bssid: Multiple BSSID configurations. + * @multiple_bssid.parent: Interface index of the transmitted BSS. + * @multiple_bssid.flags: multiple bssid flags, see + * enum ieee80211_vif_multiple_bssid_flags. */ struct ieee80211_vif { enum nl80211_iftype type; @@ -1737,6 +1757,11 @@ struct ieee80211_vif { bool txqs_stopped[IEEE80211_NUM_ACS]; + struct { + struct ieee80211_vif *parent; + u32 flags; + } multiple_bssid; + /* must be last */ u8 drv_priv[] __aligned(sizeof(void *)); }; @@ -2384,7 +2409,7 @@ struct ieee80211_txq { * @IEEE80211_HW_TX_STATUS_NO_AMPDU_LEN: Driver does not report accurate A-MPDU * length in tx status information * - * @IEEE80211_HW_SUPPORTS_MULTI_BSSID: Hardware supports multi BSSID + * @IEEE80211_HW_SUPPORTS_MULTI_BSSID: Hardware supports multi BSSID in STA mode * * @IEEE80211_HW_SUPPORTS_ONLY_HE_MULTI_BSSID: Hardware supports multi BSSID * only for HE APs. Applies if @IEEE80211_HW_SUPPORTS_MULTI_BSSID is set. @@ -2399,6 +2424,8 @@ struct ieee80211_txq { * @IEEE80211_HW_SUPPORTS_RX_DECAP_OFFLOAD: Hardware supports rx decapsulation * offload * + * @IEEE80211_HW_SUPPORTS_MULTI_BSSID_AP: Hardware supports multi BSSID in + * AP mode * @NUM_IEEE80211_HW_FLAGS: number of hardware flags, used for sizing arrays */ enum ieee80211_hw_flags { @@ -2453,6 +2480,7 @@ enum ieee80211_hw_flags { IEEE80211_HW_AMPDU_KEYBORDER_SUPPORT, IEEE80211_HW_SUPPORTS_TX_ENCAP_OFFLOAD, IEEE80211_HW_SUPPORTS_RX_DECAP_OFFLOAD, + IEEE80211_HW_SUPPORTS_MULTI_BSSID_AP, /* keep last, obviously */ NUM_IEEE80211_HW_FLAGS diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index c4c70e30ad7f..91e659a43f67 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -111,6 +111,39 @@ static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata, return 0; } +static void ieee80211_set_multiple_bssid_options(struct ieee80211_sub_if_data *sdata, + struct cfg80211_ap_settings *params) +{ + struct ieee80211_local *local = sdata->local; + struct wiphy *wiphy = local->hw.wiphy; + struct net_device *parent; + struct ieee80211_sub_if_data *psdata; + + if (!ieee80211_hw_check(&local->hw, SUPPORTS_MULTI_BSSID_AP)) + return; + + if (!params->multiple_bssid.count) + return; + + if (params->multiple_bssid.parent) { + parent = __dev_get_by_index(wiphy_net(wiphy), + params->multiple_bssid.parent); + if (!parent || !parent->ieee80211_ptr) + return; + psdata = IEEE80211_WDEV_TO_SUB_IF(parent->ieee80211_ptr); + if (psdata->vif.multiple_bssid.parent) + return; + sdata->vif.multiple_bssid.parent = &psdata->vif; + sdata->vif.multiple_bssid.flags |= IEEE80211_VIF_MBSS_NON_TRANSMITTING; + } else { + sdata->vif.multiple_bssid.flags |= IEEE80211_VIF_MBSS_TRANSMITTING; + } + + if (params->multiple_bssid.ema) + sdata->vif.multiple_bssid.flags |= IEEE80211_VIF_MBSS_EMA_BEACON; + sdata->vif.bss_conf.multiple_bssid = params->multiple_bssid; +} + static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy, const char *name, unsigned char name_assign_type, @@ -141,6 +174,23 @@ static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy, static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev) { + struct ieee80211_sub_if_data *sdata; + + sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); + if (sdata && sdata->vif.type == NL80211_IFTYPE_AP) { + if (sdata->vif.multiple_bssid.flags & IEEE80211_VIF_MBSS_TRANSMITTING) { + struct ieee80211_sub_if_data *child; + + rcu_read_lock(); + list_for_each_entry_rcu(child, &sdata->local->interfaces, list) + if (child->vif.multiple_bssid.parent == &sdata->vif) + dev_close(child->wdev.netdev); + rcu_read_unlock(); + } else { + sdata->vif.multiple_bssid.parent = NULL; + } + } + ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev)); return 0; @@ -1078,6 +1128,9 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev, changed |= BSS_CHANGED_HE_BSS_COLOR; } + if (sdata->vif.type == NL80211_IFTYPE_AP) + ieee80211_set_multiple_bssid_options(sdata, params); + mutex_lock(&local->mtx); err = ieee80211_vif_use_channel(sdata, ¶ms->chandef, IEEE80211_CHANCTX_SHARED); diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c index 5296898875ff..249b8f4e6a54 100644 --- a/net/mac80211/debugfs.c +++ b/net/mac80211/debugfs.c @@ -456,6 +456,7 @@ static const char *hw_flag_names[] = { FLAG(AMPDU_KEYBORDER_SUPPORT), FLAG(SUPPORTS_TX_ENCAP_OFFLOAD), FLAG(SUPPORTS_RX_DECAP_OFFLOAD), + FLAG(SUPPORTS_MULTI_BSSID_AP), #undef FLAG }; diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c index b80c9b016b2b..6bb48bf87aca 100644 --- a/net/mac80211/iface.c +++ b/net/mac80211/iface.c @@ -376,6 +376,12 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata, bool going_do bool cancel_scan; struct cfg80211_nan_func *func; + /* make sure the parent is already down */ + if (sdata->vif.type == NL80211_IFTYPE_AP && + sdata->vif.multiple_bssid.parent && + ieee80211_sdata_running(vif_to_sdata(sdata->vif.multiple_bssid.parent))) + dev_close(vif_to_sdata(sdata->vif.multiple_bssid.parent)->wdev.netdev); + clear_bit(SDATA_STATE_RUNNING, &sdata->state); cancel_scan = rcu_access_pointer(local->scan_sdata) == sdata; From patchwork Wed Mar 10 18:26:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aloka Dixit X-Patchwork-Id: 397167 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B01F5C4332B for ; Wed, 10 Mar 2021 18:27:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 819D464FB9 for ; Wed, 10 Mar 2021 18:27:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231402AbhCJS0p (ORCPT ); Wed, 10 Mar 2021 13:26:45 -0500 Received: from m42-2.mailgun.net ([69.72.42.2]:27273 "EHLO m42-2.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232734AbhCJS00 (ORCPT ); Wed, 10 Mar 2021 13:26:26 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1615400786; h=Content-Transfer-Encoding: MIME-Version: References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=/oeD4X3oXPN9rYza/vgcgWPVWwomndIU2IeW4VhF7U4=; b=BAI9M5/NgsJmFmmzkCLaK4zBeRueqwCuM4jTSOxNv/jTSuXzEuLry1pTKu1RVEtlrx9BiY1H d2Ms+HJJpxnr4v1YfyxHRGeuEaQ0XcBcRjyh5eeWISGlP5sRe8DAwb9ErGPmJHmtCUdGe270 FrgqG4OxVUChz2C2KBUGrrKaBKY= X-Mailgun-Sending-Ip: 69.72.42.2 X-Mailgun-Sid: WyI3YTAwOSIsICJsaW51eC13aXJlbGVzc0B2Z2VyLmtlcm5lbC5vcmciLCAiYmU5ZTRhIl0= Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n03.prod.us-east-1.postgun.com with SMTP id 60490f4ab86af9bf23d76f89 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Wed, 10 Mar 2021 18:26:18 GMT Sender: alokad=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 75EB7C433ED; Wed, 10 Mar 2021 18:26:17 +0000 (UTC) Received: from alokad-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: alokad) by smtp.codeaurora.org (Postfix) with ESMTPSA id B0757C43463; Wed, 10 Mar 2021 18:26:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org B0757C43463 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=alokad@codeaurora.org From: Aloka Dixit To: johannes@sipsolutions.net Cc: linux-wireless@vger.kernel.org, John Crispin , Aloka Dixit Subject: [PATCH v9 3/4] mac80211: add multiple bssid/EMA support to beacon handling Date: Wed, 10 Mar 2021 10:26:03 -0800 Message-Id: <20210310182604.8858-4-alokad@codeaurora.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20210310182604.8858-1-alokad@codeaurora.org> References: <20210310182604.8858-1-alokad@codeaurora.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: John Crispin With beacon_data now holding the additional information about the multiple bssid elements, we need to honour these in the various beacon handling code paths. Extend ieee80211_beacon_get_template() to allow generation of multiple bssid/EMA beacons. The API provides support for HW that can offload the EMA beaconing aswell as HW that will require periodic updates of the beacon template upon completion events. In case the HW can do full EMA offload, functions are provided that allow the driver to get a list of the periodicity number of beacons and their matching mutable offsets. Signed-off-by: John Crispin Co-developed-by: Aloka Dixit Signed-off-by: Aloka Dixit --- include/net/mac80211.h | 86 +++++++++++++++++ net/mac80211/cfg.c | 114 +++++++++++++++++++--- net/mac80211/ieee80211_i.h | 2 + net/mac80211/tx.c | 189 ++++++++++++++++++++++++++++++++----- 4 files changed, 359 insertions(+), 32 deletions(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index b9f51515c2e8..fc456262b335 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -4889,12 +4889,17 @@ void ieee80211_report_low_ack(struct ieee80211_sta *sta, u32 num_packets); * @cntdwn_counter_offs: array of IEEE80211_MAX_CNTDWN_COUNTERS_NUM offsets * to countdown counters. This array can contain zero values which * should be ignored. + * @multiple_bssid_offset: position of the multiple bssid element + * @multiple_bssid_length: size of the multiple bssid element */ struct ieee80211_mutable_offsets { u16 tim_offset; u16 tim_length; u16 cntdwn_counter_offs[IEEE80211_MAX_CNTDWN_COUNTERS_NUM]; + + u16 multiple_bssid_offset; + u16 multiple_bssid_length; }; /** @@ -4921,6 +4926,87 @@ ieee80211_beacon_get_template(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_mutable_offsets *offs); +/** + * enum ieee80211_bcn_tmpl_ema - EMA beacon generation type + * @IEEE80211_BCN_EMA_NONE: don't generate an EMA beacon. + * @IEEE80211_BCN_EMA_NEXT: generate the next periodicity beacon. + * @IEEE80211_BCN_EMA_INDEX: generate beacon by periodicity index + * if the value is >= this enum value. + */ +enum ieee80211_bcn_tmpl_ema { + IEEE80211_BCN_EMA_NONE = -2, + IEEE80211_BCN_EMA_NEXT = -1, + IEEE80211_BCN_EMA_INDEX = 0, +}; + +/** + * ieee80211_beacon_get_template_ema_next - EMA beacon template generation + * function for drivers using the sw offload path. + * @hw: pointer obtained from ieee80211_alloc_hw(). + * @vif: &struct ieee80211_vif pointer from the add_interface callback. + * @offs: &struct ieee80211_mutable_offsets pointer to struct that will + * receive the offsets that may be updated by the driver. + * + * This function differs from ieee80211_beacon_get_template in the sense that + * it generates EMA VAP templates. When we use multiple_bssid, the beacons can + * get very large costing a lot of airtime. To work around this, we iterate + * over the multiple bssid elements and only send one inside the beacon for + * 1..n. Calling this function will auto-increment the periodicity counter. + * + * This function needs to follow the same rules as ieee80211_beacon_get_template + * + * Return: The beacon template. %NULL on error. + */ +struct sk_buff *ieee80211_beacon_get_template_ema_next(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, + struct ieee80211_mutable_offsets *offs); + +/** + * struct ieee80211_ema_bcn_list - list entry of an EMA beacon + * @list: the list pointer. + * @skb: the skb containing this specific beacon + * @offs: &struct ieee80211_mutable_offsets pointer to struct that will + * receive the offsets that may be updated by the driver. + */ +struct ieee80211_ema_bcn_list { + struct list_head list; + struct sk_buff *skb; + struct ieee80211_mutable_offsets offs; +}; + +/** + * ieee80211_beacon_get_template_ema_list - EMA beacon template generation + * function for drivers using the hw offload. + * @hw: pointer obtained from ieee80211_alloc_hw(). + * @vif: &struct ieee80211_vif pointer from the add_interface callback. + * @head: linked list head that will get populated with + * &struct ieee80211_ema_bcn_list pointers. + * + * This function differs from ieee80211_beacon_get_template in the sense that + * it generates EMA VAP templates. When we use multiple_bssid, the beacons can + * get very large costing a lot of airtime. To work around this, we iterate + * over the multiple bssid elements and only send one inside the beacon for + * 1..n. This function will populate a linked list that the driver can pass + * to the HW. + * + * This function needs to follow the same rules as ieee80211_beacon_get_template + * + * Return: The nuber of entries in the list or 0 on error. + */ + +int ieee80211_beacon_get_template_ema_list(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, + struct list_head *head); + +/** + * ieee80211_beacon_free_ema_list - free an EMA beacon template list + * @head: linked list head containing &struct ieee80211_ema_bcn_list pointers. + * + * This function will free a list previously acquired by calling + * ieee80211_beacon_get_template_ema_list() + */ +void ieee80211_beacon_free_ema_list(struct list_head *head); + /** * ieee80211_beacon_get_tim - beacon generation function * @hw: pointer obtained from ieee80211_alloc_hw(). diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index 91e659a43f67..e72c0a4a26c3 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -984,14 +984,49 @@ static int ieee80211_set_ftm_responder_params( return 0; } +static int ieee80211_get_multiple_bssid_beacon_len(struct cfg80211_multiple_bssid_data *data) +{ + int i, len = 0; + + if (!data) + return 0; + + for (i = 0; i < data->cnt; i++) + len += data->elems[i].len; + + return len; +} + +static u8 *ieee80211_copy_multiple_bssid_beacon(u8 *offset, + struct cfg80211_multiple_bssid_data *dest, + struct cfg80211_multiple_bssid_data *src) +{ + int i; + + if (!dest || !src) + return offset; + + dest->cnt = src->cnt; + for (i = 0; i < dest->cnt; i++) { + dest->elems[i].len = src->elems[i].len; + dest->elems[i].data = offset; + memcpy(dest->elems[i].data, src->elems[i].data, + dest->elems[i].len); + offset += dest->elems[i].len; + } + + return offset; +} + static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, struct cfg80211_beacon_data *params, const struct ieee80211_csa_settings *csa) { struct beacon_data *new, *old; - int new_head_len, new_tail_len; + int new_head_len, new_tail_len, new_multiple_bssid_len = 0; int size, err; u32 changed = BSS_CHANGED_BEACON; + u8 *new_multiple_bssid_offset; old = sdata_dereference(sdata->u.ap.beacon, sdata); @@ -1013,12 +1048,30 @@ static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, else new_tail_len = old->tail_len; - size = sizeof(*new) + new_head_len + new_tail_len; + /* new or old multiple_bssid? */ + if (params->multiple_bssid) + new_multiple_bssid_len = + ieee80211_get_multiple_bssid_beacon_len(params->multiple_bssid); + else if (old && old->multiple_bssid) + new_multiple_bssid_len = + ieee80211_get_multiple_bssid_beacon_len(old->multiple_bssid); + + size = sizeof(*new) + new_head_len + new_tail_len + + new_multiple_bssid_len; new = kzalloc(size, GFP_KERNEL); if (!new) return -ENOMEM; + if (new_multiple_bssid_len) { + new->multiple_bssid = kzalloc(sizeof(*params->multiple_bssid), + GFP_KERNEL); + if (!new->multiple_bssid) { + kfree(new); + return -ENOMEM; + } + } + /* start filling the new info now */ /* @@ -1030,6 +1083,17 @@ static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, new->head_len = new_head_len; new->tail_len = new_tail_len; + /* copy in optional multiple_bssid_ies */ + new_multiple_bssid_offset = new->tail + new_tail_len; + if (params->multiple_bssid) + ieee80211_copy_multiple_bssid_beacon(new_multiple_bssid_offset, + new->multiple_bssid, + params->multiple_bssid); + else if (old && old->multiple_bssid) + ieee80211_copy_multiple_bssid_beacon(new_multiple_bssid_offset, + new->multiple_bssid, + old->multiple_bssid); + if (csa) { new->cntdwn_current_counter = csa->count; memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_beacon, @@ -1053,6 +1117,7 @@ static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, err = ieee80211_set_probe_resp(sdata, params->probe_resp, params->probe_resp_len, csa); if (err < 0) { + kfree(new->multiple_bssid); kfree(new); return err; } @@ -1068,6 +1133,7 @@ static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, params->civicloc_len); if (err < 0) { + kfree(new->multiple_bssid); kfree(new); return err; } @@ -1077,9 +1143,10 @@ static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, rcu_assign_pointer(sdata->u.ap.beacon, new); - if (old) + if (old) { + kfree(old->multiple_bssid); kfree_rcu(old, rcu_head); - + } return changed; } @@ -1234,8 +1301,10 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev, if (err) { old = sdata_dereference(sdata->u.ap.beacon, sdata); - if (old) + if (old) { + kfree(old->multiple_bssid); kfree_rcu(old, rcu_head); + } RCU_INIT_POINTER(sdata->u.ap.beacon, NULL); goto error; } @@ -1315,8 +1384,11 @@ static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev) mutex_unlock(&local->mtx); - kfree(sdata->u.ap.next_beacon); - sdata->u.ap.next_beacon = NULL; + if (sdata->u.ap.next_beacon) { + kfree(sdata->u.ap.next_beacon->multiple_bssid); + kfree(sdata->u.ap.next_beacon); + sdata->u.ap.next_beacon = NULL; + } /* turn off carrier for this interface and dependent VLANs */ list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) @@ -1328,6 +1400,7 @@ static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev) RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL); RCU_INIT_POINTER(sdata->u.ap.fils_discovery, NULL); RCU_INIT_POINTER(sdata->u.ap.unsol_bcast_probe_resp, NULL); + kfree(old_beacon->multiple_bssid); kfree_rcu(old_beacon, rcu_head); if (old_probe_resp) kfree_rcu(old_probe_resp, rcu_head); @@ -3084,13 +3157,24 @@ cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon) len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len + beacon->proberesp_ies_len + beacon->assocresp_ies_len + - beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len; + beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len + + ieee80211_get_multiple_bssid_beacon_len(beacon->multiple_bssid); new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL); if (!new_beacon) return NULL; + if (beacon->multiple_bssid) { + new_beacon->multiple_bssid = kzalloc(sizeof(*beacon->multiple_bssid), + GFP_KERNEL); + if (!new_beacon->multiple_bssid) { + kfree(new_beacon); + return NULL; + } + } + pos = (u8 *)(new_beacon + 1); + if (beacon->head_len) { new_beacon->head_len = beacon->head_len; new_beacon->head = pos; @@ -3127,6 +3211,10 @@ cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon) memcpy(pos, beacon->probe_resp, beacon->probe_resp_len); pos += beacon->probe_resp_len; } + if (beacon->multiple_bssid && beacon->multiple_bssid->cnt) + pos = ieee80211_copy_multiple_bssid_beacon(pos, + new_beacon->multiple_bssid, + beacon->multiple_bssid); /* might copy -1, meaning no changes requested */ new_beacon->ftm_responder = beacon->ftm_responder; @@ -3164,8 +3252,11 @@ static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata, case NL80211_IFTYPE_AP: err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon, NULL); - kfree(sdata->u.ap.next_beacon); - sdata->u.ap.next_beacon = NULL; + if (sdata->u.ap.next_beacon) { + kfree(sdata->u.ap.next_beacon->multiple_bssid); + kfree(sdata->u.ap.next_beacon); + sdata->u.ap.next_beacon = NULL; + } if (err < 0) return err; @@ -3330,7 +3421,8 @@ static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata, csa.count = params->count; err = ieee80211_assign_beacon(sdata, ¶ms->beacon_csa, &csa); - if (err < 0) { + if (err < 0 && sdata->u.ap.next_beacon) { + kfree(sdata->u.ap.next_beacon->multiple_bssid); kfree(sdata->u.ap.next_beacon); return err; } diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index ecda126a7026..d30d53cfec1a 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -261,6 +261,8 @@ struct beacon_data { struct ieee80211_meshconf_ie *meshconf; u16 cntdwn_counter_offsets[IEEE80211_MAX_CNTDWN_COUNTERS_NUM]; u8 cntdwn_current_counter; + struct cfg80211_multiple_bssid_data *multiple_bssid; + u16 ema_index; struct rcu_head rcu_head; }; diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 5d06de61047a..5cdf977e7289 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -4724,11 +4724,71 @@ static int ieee80211_beacon_protect(struct sk_buff *skb, return 0; } +static int ieee80211_beacon_multiple_bssid_len(struct beacon_data *beacon, + int index) +{ + int len = 0, i; + + if (index == IEEE80211_BCN_EMA_NEXT) { + index = beacon->ema_index; + beacon->ema_index++; + beacon->ema_index %= beacon->multiple_bssid->cnt; + } + + if (index != IEEE80211_BCN_EMA_NONE && + index >= beacon->multiple_bssid->cnt) + return -1; + + if (beacon->multiple_bssid->cnt) { + if (index >= IEEE80211_BCN_EMA_INDEX) { + len = beacon->multiple_bssid->elems[index].len; + } else { + for (i = 0; i < beacon->multiple_bssid->cnt; i++) + len += beacon->multiple_bssid->elems[i].len; + } + } + return len; +} + +static void +ieee80211_beacon_add_multiple_bssid_config(struct ieee80211_vif *vif, + struct sk_buff *skb, + struct cfg80211_multiple_bssid_data *config) +{ + u8 *pos = skb_put(skb, 5); + + *pos++ = WLAN_EID_EXTENSION; + *pos++ = 3; + *pos++ = WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION; + *pos++ = vif->bss_conf.multiple_bssid.count; + *pos++ = config->cnt; +} + +static void +ieee80211_beacon_add_multiple_bssid(struct ieee80211_vif *vif, + struct sk_buff *skb, + struct cfg80211_multiple_bssid_data *config, + int index) +{ + if (index >= IEEE80211_BCN_EMA_INDEX) { + ieee80211_beacon_add_multiple_bssid_config(vif, skb, config); + skb_put_data(skb, config->elems[index].data, + config->elems[index].len); + } else { + int i; + + for (i = 0; i < config->cnt; i++) + skb_put_data(skb, config->elems[i].data, + config->elems[i].len); + } +} + static struct sk_buff * __ieee80211_beacon_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_mutable_offsets *offs, - bool is_template) + bool is_template, + int ema_index) { struct ieee80211_local *local = hw_to_local(hw); struct beacon_data *beacon = NULL; @@ -4740,13 +4800,11 @@ __ieee80211_beacon_get(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *chanctx_conf; int csa_off_base = 0; - rcu_read_lock(); - sdata = vif_to_sdata(vif); chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); if (!ieee80211_sdata_running(sdata) || !chanctx_conf) - goto out; + return NULL; if (offs) memset(offs, 0, sizeof(*offs)); @@ -4756,6 +4814,9 @@ __ieee80211_beacon_get(struct ieee80211_hw *hw, beacon = rcu_dereference(ap->beacon); if (beacon) { + int multiple_bssid_elems_len = 0; + int multiple_bssid_config_len = 5; + if (beacon->cntdwn_counter_offsets[0]) { if (!is_template) ieee80211_beacon_update_cntdwn(vif); @@ -4763,6 +4824,14 @@ __ieee80211_beacon_get(struct ieee80211_hw *hw, ieee80211_set_beacon_cntdwn(sdata, beacon); } + if (beacon->multiple_bssid) { + multiple_bssid_elems_len = + ieee80211_beacon_multiple_bssid_len(beacon, + ema_index); + if (multiple_bssid_elems_len == -1) + return NULL; + } + /* * headroom, head length, * tail length and maximum TIM length @@ -4770,9 +4839,11 @@ __ieee80211_beacon_get(struct ieee80211_hw *hw, skb = dev_alloc_skb(local->tx_headroom + beacon->head_len + beacon->tail_len + 256 + - local->hw.extra_beacon_tailroom); + local->hw.extra_beacon_tailroom + + multiple_bssid_config_len + + multiple_bssid_elems_len); if (!skb) - goto out; + return NULL; skb_reserve(skb, local->tx_headroom); skb_put_data(skb, beacon->head, beacon->head_len); @@ -4788,21 +4859,32 @@ __ieee80211_beacon_get(struct ieee80211_hw *hw, csa_off_base = skb->len; } + if (multiple_bssid_elems_len) { + ieee80211_beacon_add_multiple_bssid(vif, skb, + beacon->multiple_bssid, + ema_index); + if (offs) { + offs->multiple_bssid_offset = skb->len - + multiple_bssid_elems_len; + csa_off_base = skb->len; + } + } + if (beacon->tail) skb_put_data(skb, beacon->tail, beacon->tail_len); if (ieee80211_beacon_protect(skb, local, sdata) < 0) - goto out; + return NULL; } else - goto out; + return NULL; } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; struct ieee80211_hdr *hdr; beacon = rcu_dereference(ifibss->presp); if (!beacon) - goto out; + return NULL; if (beacon->cntdwn_counter_offsets[0]) { if (!is_template) @@ -4814,7 +4896,7 @@ __ieee80211_beacon_get(struct ieee80211_hw *hw, skb = dev_alloc_skb(local->tx_headroom + beacon->head_len + local->hw.extra_beacon_tailroom); if (!skb) - goto out; + return NULL; skb_reserve(skb, local->tx_headroom); skb_put_data(skb, beacon->head, beacon->head_len); @@ -4826,7 +4908,7 @@ __ieee80211_beacon_get(struct ieee80211_hw *hw, beacon = rcu_dereference(ifmsh->beacon); if (!beacon) - goto out; + return NULL; if (beacon->cntdwn_counter_offsets[0]) { if (!is_template) @@ -4849,7 +4931,7 @@ __ieee80211_beacon_get(struct ieee80211_hw *hw, beacon->tail_len + local->hw.extra_beacon_tailroom); if (!skb) - goto out; + return NULL; skb_reserve(skb, local->tx_headroom); skb_put_data(skb, beacon->head, beacon->head_len); ieee80211_beacon_add_tim(sdata, &ifmsh->ps, skb, is_template); @@ -4862,7 +4944,7 @@ __ieee80211_beacon_get(struct ieee80211_hw *hw, skb_put_data(skb, beacon->tail, beacon->tail_len); } else { WARN_ON(1); - goto out; + return NULL; } /* CSA offsets */ @@ -4905,27 +4987,92 @@ __ieee80211_beacon_get(struct ieee80211_hw *hw, info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT | IEEE80211_TX_CTL_ASSIGN_SEQ | IEEE80211_TX_CTL_FIRST_FRAGMENT; - out: - rcu_read_unlock(); return skb; } -struct sk_buff * -ieee80211_beacon_get_template(struct ieee80211_hw *hw, - struct ieee80211_vif *vif, - struct ieee80211_mutable_offsets *offs) +struct sk_buff *ieee80211_beacon_get_template(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, + struct ieee80211_mutable_offsets *offs) { - return __ieee80211_beacon_get(hw, vif, offs, true); + struct sk_buff *bcn; + + rcu_read_lock(); + bcn = __ieee80211_beacon_get(hw, vif, offs, true, + IEEE80211_BCN_EMA_NONE); + rcu_read_unlock(); + + return bcn; } EXPORT_SYMBOL(ieee80211_beacon_get_template); +struct sk_buff *ieee80211_beacon_get_template_ema_next(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, + struct ieee80211_mutable_offsets *offs) +{ + struct sk_buff *bcn; + + rcu_read_lock(); + bcn = __ieee80211_beacon_get(hw, vif, offs, true, + IEEE80211_BCN_EMA_NEXT); + rcu_read_unlock(); + + return bcn; +} +EXPORT_SYMBOL(ieee80211_beacon_get_template_ema_next); + +void ieee80211_beacon_free_ema_list(struct list_head *head) +{ + struct ieee80211_ema_bcn_list *ema, *tmp; + + list_for_each_entry_safe(ema, tmp, head, list) { + kfree_skb(ema->skb); + kfree(ema); + } +} +EXPORT_SYMBOL(ieee80211_beacon_free_ema_list); + +int +ieee80211_beacon_get_template_ema_list(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, + struct list_head *head) +{ + int cnt = 0; + + rcu_read_lock(); + while (true) { + struct ieee80211_ema_bcn_list *ema; + + ema = kmalloc(sizeof(*ema), GFP_KERNEL); + if (!ema) { + ieee80211_beacon_free_ema_list(head); + cnt = 0; + goto out; + } + + ema->skb = __ieee80211_beacon_get(hw, vif, &ema->offs, true, + cnt); + if (!ema->skb) { + kfree(ema); + break; + } + list_add_tail(&ema->list, head); + cnt++; + } +out: + rcu_read_unlock(); + + return cnt; +} +EXPORT_SYMBOL(ieee80211_beacon_get_template_ema_list); + struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 *tim_offset, u16 *tim_length) { struct ieee80211_mutable_offsets offs = {}; - struct sk_buff *bcn = __ieee80211_beacon_get(hw, vif, &offs, false); + struct sk_buff *bcn = __ieee80211_beacon_get(hw, vif, &offs, false, + IEEE80211_BCN_EMA_NONE); struct sk_buff *copy; struct ieee80211_supported_band *sband; int shift;