2021-07-15 08:23:33

by Aloka Dixit

[permalink] [raw]
Subject: [PATCH v11 0/4] multiple bssid and EMA support in AP mode

This patchset adds support for multiple BSSID and
enhanced multi-BSSID advertisements for AP mode.
Individual patches describe the changes in this version.

John Crispin (4):
nl80211: MBSSID and EMA support in AP mode
mac80211: MBSSID support in interface handling
mac80211: MBSSID and EMA support in beacon handling
mac80211: channel switch for non-transmitting interfaces

include/net/cfg80211.h | 44 ++++++
include/net/mac80211.h | 93 +++++++++++++
include/uapi/linux/nl80211.h | 76 +++++++++-
net/mac80211/cfg.c | 170 +++++++++++++++++++++--
net/mac80211/ieee80211_i.h | 2 +
net/mac80211/iface.c | 29 +++-
net/mac80211/tx.c | 173 ++++++++++++++++++++---
net/wireless/nl80211.c | 261 +++++++++++++++++++++++++++++------
8 files changed, 772 insertions(+), 76 deletions(-)


base-commit: 5e437416ff66981d8154687cfdf7de50b1d82bfc
--
2.31.1


2021-07-15 08:23:33

by Aloka Dixit

[permalink] [raw]
Subject: [PATCH v11 4/4] mac80211: channel switch for non-transmitting interfaces

From: John Crispin <[email protected]>

Trigger ieee80211_csa_finish() on the non-transmitting interfaces
when channel switch concludes on the transmitting interface.

Signed-off-by: John Crispin <[email protected]>
Co-developed-by: Aloka Dixit <[email protected]>
Signed-off-by: Aloka Dixit <[email protected]>
---
v11: Reverted changes from v10.
v10: Used iflist_mtx instead of rcu_read_lock() as most other
accesses to sdata->local->interfaces do so.

net/mac80211/cfg.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index c95c5aacfbfa..6e1d525bf736 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -3244,8 +3244,19 @@ void ieee80211_csa_finish(struct ieee80211_vif *vif)
{
struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);

- ieee80211_queue_work(&sdata->local->hw,
- &sdata->csa_finalize_work);
+ if (vif->mbssid_tx_vif == vif) {
+ struct ieee80211_sub_if_data *child, *tmp;
+
+ list_for_each_entry_safe(child, tmp,
+ &sdata->local->interfaces, list)
+ if (child != sdata && child->vif.mbssid_tx_vif == vif &&
+ ieee80211_sdata_running(child)) {
+ ieee80211_queue_work(&child->local->hw,
+ &child->csa_finalize_work);
+ }
+ }
+
+ ieee80211_queue_work(&sdata->local->hw, &sdata->csa_finalize_work);
}
EXPORT_SYMBOL(ieee80211_csa_finish);

--
2.31.1

2021-07-15 08:23:33

by Aloka Dixit

[permalink] [raw]
Subject: [PATCH v11 2/4] mac80211: MBSSID support in interface handling

From: John Crispin <[email protected]>

Configure multiple BSSID and enhanced multi-BSSID advertisement (EMA)
parameters in mac80211 for AP mode.

For each interface, 'mbssid_tx_vif' points to the transmitting interface of
the MBSSID set. The pointer is set to NULL if MBSSID is disabled.

Function ieee80211_stop() is modified to always bring down all the
non-transmitting interfaces first and the transmitting interface last.

Signed-off-by: John Crispin <[email protected]>
Co-developed-by: Aloka Dixit <[email protected]>
Signed-off-by: Aloka Dixit <[email protected]>
---
v11: Moved dev_close() for non-transmitting interfaces
before locking wiphy->mtx.
Removed interface count, instead mac80211 passes pointer
'mbssid_tx_vif' to the driver for each interface.
Removed dev_close() calls from ieee80211_del_iface().
Removed IEEE80211_HW_SUPPORTS_MBSSID_AP and
IEEE80211_HW_SUPPORTS_EMA_AP.
Instead of new parameters in struct ieee80211_bss_conf,
reused the existing ones which were used for STA mode.

v10: Released wiphy->mtx before dev_close().
New flag for IEEE80211_HW_SUPPORTS_EMA_AP.
ieee80211_set_mbssid_options() returns int instead of void.

include/net/mac80211.h | 4 ++++
net/mac80211/cfg.c | 38 ++++++++++++++++++++++++++++++++++++++
net/mac80211/iface.c | 29 ++++++++++++++++++++++++++++-
3 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index d8a1d09a2141..a375b0c31062 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -1711,6 +1711,8 @@ enum ieee80211_offload_flags {
* protected by fq->lock.
* @offload_flags: 802.3 -> 802.11 enapsulation offload flags, see
* &enum ieee80211_offload_flags.
+ *
+ * @mbssid_tx_vif: Pointer to the transmitting interface if MBSSID is enabled.
*/
struct ieee80211_vif {
enum nl80211_iftype type;
@@ -1739,6 +1741,8 @@ struct ieee80211_vif {

bool txqs_stopped[IEEE80211_NUM_ACS];

+ struct ieee80211_vif *mbssid_tx_vif;
+
/* must be last */
u8 drv_priv[] __aligned(sizeof(void *));
};
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 84cc7733ea66..152cfa6bcf3a 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -111,6 +111,36 @@ static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata,
return 0;
}

+static int ieee80211_set_ap_mbssid_options(struct ieee80211_sub_if_data *sdata,
+ struct cfg80211_mbssid_config params)
+{
+ struct ieee80211_sub_if_data *tx_sdata;
+
+ sdata->vif.mbssid_tx_vif = NULL;
+ sdata->vif.bss_conf.bssid_index = 0;
+ sdata->vif.bss_conf.nontransmitted = false;
+ sdata->vif.bss_conf.ema_ap = false;
+
+ if (sdata->vif.type != NL80211_IFTYPE_AP || !params.tx_dev)
+ return -EINVAL;
+
+ tx_sdata = IEEE80211_WDEV_TO_SUB_IF(params.tx_dev);
+ if (!tx_sdata)
+ return -EINVAL;
+
+ if (tx_sdata == sdata) {
+ sdata->vif.mbssid_tx_vif = &sdata->vif;
+ } else {
+ sdata->vif.mbssid_tx_vif = &tx_sdata->vif;
+ sdata->vif.bss_conf.nontransmitted = true;
+ sdata->vif.bss_conf.bssid_index = params.index;
+ }
+ if (params.ema)
+ sdata->vif.bss_conf.ema_ap = true;
+
+ return 0;
+}
+
static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
const char *name,
unsigned char name_assign_type,
@@ -1078,6 +1108,14 @@ 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 &&
+ params->mbssid_config.tx_dev) {
+ err = ieee80211_set_ap_mbssid_options(sdata,
+ params->mbssid_config);
+ if (err)
+ return err;
+ }
+
mutex_lock(&local->mtx);
err = ieee80211_vif_use_channel(sdata, &params->chandef,
IEEE80211_CHANCTX_SHARED);
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index 1e5e9fc45523..7939827621ad 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -630,17 +630,44 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata, bool going_do
ieee80211_add_virtual_monitor(local);
}

+static void ieee80211_stop_mbssid(struct ieee80211_sub_if_data *sdata)
+{
+ struct ieee80211_sub_if_data *tx_sdata, *non_tx_sdata, *tmp_sdata;
+ struct ieee80211_vif *tx_vif = sdata->vif.mbssid_tx_vif;
+
+ tx_sdata = vif_to_sdata(tx_vif);
+ sdata->vif.mbssid_tx_vif = NULL;
+
+ list_for_each_entry_safe(non_tx_sdata, tmp_sdata,
+ &tx_sdata->local->interfaces, list) {
+ if (non_tx_sdata != sdata && non_tx_sdata != tx_sdata &&
+ non_tx_sdata->vif.mbssid_tx_vif == tx_vif &&
+ ieee80211_sdata_running(non_tx_sdata)) {
+ non_tx_sdata->vif.mbssid_tx_vif = NULL;
+ dev_close(non_tx_sdata->wdev.netdev);
+ }
+ }
+
+ if (sdata != tx_sdata && ieee80211_sdata_running(tx_sdata)) {
+ tx_sdata->vif.mbssid_tx_vif = NULL;
+ dev_close(tx_sdata->wdev.netdev);
+ }
+}
+
static int ieee80211_stop(struct net_device *dev)
{
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);

- /* close all dependent VLAN interfaces before locking wiphy */
+ /* close dependent VLAN and MBSSID interfaces before locking wiphy */
if (sdata->vif.type == NL80211_IFTYPE_AP) {
struct ieee80211_sub_if_data *vlan, *tmpsdata;

list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans,
u.vlan.list)
dev_close(vlan->dev);
+
+ if (sdata->vif.mbssid_tx_vif)
+ ieee80211_stop_mbssid(sdata);
}

wiphy_lock(sdata->local->hw.wiphy);
--
2.31.1

2021-07-15 08:23:41

by Aloka Dixit

[permalink] [raw]
Subject: [PATCH v11 3/4] mac80211: MBSSID and EMA support in beacon handling

From: John Crispin <[email protected]>

New fields added in struct beacon_data to store all MBSSID elements and
the index of the next element to be included in beacon template.

For a non-EMA AP, a single beacon template is generated with all elements.
For an EMA AP, multiple beacon templates are generated and each includes
a single MBSSID element. EMA profile periodicity equals the count of
elements.
This patch also generates and includes multiple BSSID configuration element
in each beacon template for both EMA/non-EMA AP when MBSSID is enabled.

New field added in struct ieee80211_mutable_offsets to store offset of the
first MBSSID element in beacons. Also the offset for channel switch
announcement (CSA) is modified to account for MBSSID length.

Depending on the hardware support and the usecase, drivers should use
following functions for beacon generation:
(1) ieee80211_beacon_get_template() - Existing function for legacy beacon
generation for non-MBSSID APs. No change in prototype.
(2) ieee80211_beacon_get_template_ema_next() - Generate the next EMA
beacon template using the 'ema_index' stored in beacon_data.
(3) ieee80211_beacon_get_template_ema_list() - Generate all EMA templates.
Drivers must call ieee80211_beacon_free_ema_list() to free the memory.

This commit also adds a missing free() for sdata->u.ap.next_beacon in
ieee80211_set_csa_beacon() and sets the pointer to NULL in case of error.

Signed-off-by: John Crispin <[email protected]>
Co-developed-by: Aloka Dixit <[email protected]>
Signed-off-by: Aloka Dixit <[email protected]>
---
v11: Removed addition of mbssid configuration element,
it should be added by userspace if EMA is enabled.

v10: Added the lock missing in v9 for ieee80211_beacon_get_tim()

include/net/mac80211.h | 89 +++++++++++++++++++
net/mac80211/cfg.c | 117 ++++++++++++++++++++++---
net/mac80211/ieee80211_i.h | 2 +
net/mac80211/tx.c | 173 ++++++++++++++++++++++++++++++++-----
4 files changed, 348 insertions(+), 33 deletions(-)

diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index a375b0c31062..5e65b4116a8d 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -4893,12 +4893,14 @@ 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.
+ * @mbssid_offset: position 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 mbssid_offset;
};

/**
@@ -4925,6 +4927,93 @@ 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
+ *
+ * When enhanced multi-BSSID advertisements (EMA) mode is enabled, the
+ * non-transmitting profiles from the multiple BSSID set are split into more
+ * than one multiple BSSID elements if required. Each EMA beacon includes only
+ * one element to reduce the total size. The number of beacons required to
+ * cover all profiles is called as the profile periodicity of the set.
+ *
+ * In MAC80211, the multiple BSSID elements passed by the application are
+ * stored in a array and the index of the next element (starting from 0) to be
+ * included in the beacon template is tracked through the member ema_index of
+ * struct beacon_data.
+ *
+ * @IEEE80211_BCN_EMA_NONE: Used when EMA is disabled. Only one beacon
+ * template will be generated which includes all multiple BSSID elements.
+ * @IEEE80211_BCN_EMA_NEXT: Used when EMA is enabled. Includes the next
+ * multiple BSSID element while generating the beacon template.
+ * @IEEE80211_BCN_EMA_BASE: Used when EMA is enabled. Beacon template includes
+ * the multiple MBSSID element at a specified index which should be set
+ * to a value more than or equal to IEEE80211_BCN_EMA_BASE.
+ */
+enum ieee80211_bcn_tmpl_ema {
+ IEEE80211_BCN_EMA_NONE = -2,
+ IEEE80211_BCN_EMA_NEXT = -1,
+ IEEE80211_BCN_EMA_BASE = 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 follows the same rules as ieee80211_beacon_get_template()
+ * but returns a beacon template which includes the next multiple BSSID
+ * element.
+ *
+ * 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 follows the same rules as ieee80211_beacon_get_template()
+ * but returns a linked list of all beacon templates required to cover all
+ * profiles in the multiple BSSID set. Each template includes only one multiple
+ * BSSID element.
+ *
+ * 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 152cfa6bcf3a..c95c5aacfbfa 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -964,14 +964,49 @@ static int ieee80211_set_ftm_responder_params(
return 0;
}

+static int ieee80211_get_mbssid_beacon_len(struct cfg80211_mbssid_elems *elems)
+{
+ int i, len = 0;
+
+ if (!elems)
+ return 0;
+
+ for (i = 0; i < elems->cnt; i++)
+ len += elems->elem[i].len;
+
+ return len;
+}
+
+static u8 *ieee80211_copy_mbssid_beacon(u8 *offset,
+ struct cfg80211_mbssid_elems *dest,
+ struct cfg80211_mbssid_elems *src)
+{
+ int i;
+
+ if (!dest || !src)
+ return offset;
+
+ dest->cnt = src->cnt;
+ for (i = 0; i < dest->cnt; i++) {
+ dest->elem[i].len = src->elem[i].len;
+ dest->elem[i].data = offset;
+ memcpy(dest->elem[i].data, src->elem[i].data,
+ dest->elem[i].len);
+ offset += dest->elem[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_mbssid_len = 0;
int size, err;
u32 changed = BSS_CHANGED_BEACON;
+ u8 *new_mbssid_offset;

old = sdata_dereference(sdata->u.ap.beacon, sdata);

@@ -993,12 +1028,27 @@ 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 elements? */
+ if (params->mbssid_ies)
+ new_mbssid_len = ieee80211_get_mbssid_beacon_len(params->mbssid_ies);
+ else if (old && old->mbssid_ies)
+ new_mbssid_len = ieee80211_get_mbssid_beacon_len(old->mbssid_ies);
+
+ size = sizeof(*new) + new_head_len + new_tail_len + new_mbssid_len;

new = kzalloc(size, GFP_KERNEL);
if (!new)
return -ENOMEM;

+ if (new_mbssid_len) {
+ new->mbssid_ies = kzalloc(sizeof(*params->mbssid_ies),
+ GFP_KERNEL);
+ if (!new->mbssid_ies) {
+ kfree(new);
+ return -ENOMEM;
+ }
+ }
+
/* start filling the new info now */

/*
@@ -1010,6 +1060,15 @@ 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 mbssid_ies */
+ new_mbssid_offset = new->tail + new_tail_len;
+ if (params->mbssid_ies)
+ ieee80211_copy_mbssid_beacon(new_mbssid_offset, new->mbssid_ies,
+ params->mbssid_ies);
+ else if (old && old->mbssid_ies)
+ ieee80211_copy_mbssid_beacon(new_mbssid_offset, new->mbssid_ies,
+ old->mbssid_ies);
+
if (csa) {
new->cntdwn_current_counter = csa->count;
memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_beacon,
@@ -1033,6 +1092,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->mbssid_ies);
kfree(new);
return err;
}
@@ -1048,6 +1108,7 @@ static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
params->civicloc_len);

if (err < 0) {
+ kfree(new->mbssid_ies);
kfree(new);
return err;
}
@@ -1057,9 +1118,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->mbssid_ies);
kfree_rcu(old, rcu_head);
-
+ }
return changed;
}

@@ -1219,8 +1281,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->mbssid_ies);
kfree_rcu(old, rcu_head);
+ }
RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
goto error;
}
@@ -1300,8 +1364,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->mbssid_ies);
+ 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)
@@ -1313,6 +1380,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->mbssid_ies);
kfree_rcu(old_beacon, rcu_head);
if (old_probe_resp)
kfree_rcu(old_probe_resp, rcu_head);
@@ -3096,13 +3164,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_mbssid_beacon_len(beacon->mbssid_ies);

new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
if (!new_beacon)
return NULL;

+ if (beacon->mbssid_ies) {
+ new_beacon->mbssid_ies = kzalloc(sizeof(*beacon->mbssid_ies),
+ GFP_KERNEL);
+ if (!new_beacon->mbssid_ies) {
+ 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;
@@ -3139,6 +3218,9 @@ cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
pos += beacon->probe_resp_len;
}
+ if (beacon->mbssid_ies && beacon->mbssid_ies->cnt)
+ pos = ieee80211_copy_mbssid_beacon(pos, new_beacon->mbssid_ies,
+ beacon->mbssid_ies);

/* might copy -1, meaning no changes requested */
new_beacon->ftm_responder = beacon->ftm_responder;
@@ -3176,8 +3258,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->mbssid_ies);
+ kfree(sdata->u.ap.next_beacon);
+ sdata->u.ap.next_beacon = NULL;
+ }

if (err < 0)
return err;
@@ -3332,8 +3417,14 @@ static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
if ((params->n_counter_offsets_beacon >
IEEE80211_MAX_CNTDWN_COUNTERS_NUM) ||
(params->n_counter_offsets_presp >
- IEEE80211_MAX_CNTDWN_COUNTERS_NUM))
+ IEEE80211_MAX_CNTDWN_COUNTERS_NUM)) {
+ if (sdata->u.ap.next_beacon) {
+ kfree(sdata->u.ap.next_beacon->mbssid_ies);
+ kfree(sdata->u.ap.next_beacon);
+ sdata->u.ap.next_beacon = NULL;
+ }
return -EINVAL;
+ }

csa.counter_offsets_beacon = params->counter_offsets_beacon;
csa.counter_offsets_presp = params->counter_offsets_presp;
@@ -3342,8 +3433,10 @@ static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
csa.count = params->count;

err = ieee80211_assign_beacon(sdata, &params->beacon_csa, &csa);
- if (err < 0) {
+ if (err < 0 && sdata->u.ap.next_beacon) {
+ kfree(sdata->u.ap.next_beacon->mbssid_ies);
kfree(sdata->u.ap.next_beacon);
+ sdata->u.ap.next_beacon = NULL;
return err;
}
*changed |= err;
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 22549b95d1aa..344fbbd8823a 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -250,6 +250,8 @@ struct beacon_data {
struct ieee80211_meshconf_ie *meshconf;
u16 cntdwn_counter_offsets[IEEE80211_MAX_CNTDWN_COUNTERS_NUM];
u8 cntdwn_current_counter;
+ struct cfg80211_mbssid_elems *mbssid_ies;
+ u16 ema_index;
struct rcu_head rcu_head;
};

diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index e96981144358..4f008d8b681d 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -4964,11 +4964,54 @@ static int ieee80211_beacon_protect(struct sk_buff *skb,
return 0;
}

+static int ieee80211_beacon_mbssid_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->mbssid_ies->cnt;
+ }
+
+ if (index != IEEE80211_BCN_EMA_NONE &&
+ index >= beacon->mbssid_ies->cnt)
+ return -1;
+
+ if (beacon->mbssid_ies->cnt) {
+ if (index >= IEEE80211_BCN_EMA_BASE) {
+ len = beacon->mbssid_ies->elem[index].len;
+ } else {
+ for (i = 0; i < beacon->mbssid_ies->cnt; i++)
+ len += beacon->mbssid_ies->elem[i].len;
+ }
+ }
+ return len;
+}
+
+static void ieee80211_beacon_add_mbssid(struct ieee80211_vif *vif,
+ struct sk_buff *skb,
+ struct cfg80211_mbssid_elems *elems,
+ int index)
+{
+ if (index >= IEEE80211_BCN_EMA_BASE) {
+ skb_put_data(skb, elems->elem[index].data,
+ elems->elem[index].len);
+ } else {
+ int i;
+
+ for (i = 0; i < elems->cnt; i++)
+ skb_put_data(skb, elems->elem[i].data,
+ elems->elem[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;
@@ -4980,13 +5023,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));
@@ -4996,6 +5037,8 @@ __ieee80211_beacon_get(struct ieee80211_hw *hw,

beacon = rcu_dereference(ap->beacon);
if (beacon) {
+ size_t mbssid_elems_len = 0;
+
if (beacon->cntdwn_counter_offsets[0]) {
if (!is_template)
ieee80211_beacon_update_cntdwn(vif);
@@ -5003,6 +5046,14 @@ __ieee80211_beacon_get(struct ieee80211_hw *hw,
ieee80211_set_beacon_cntdwn(sdata, beacon);
}

+ if (beacon->mbssid_ies) {
+ mbssid_elems_len =
+ ieee80211_beacon_mbssid_len(beacon,
+ ema_index);
+ if (mbssid_elems_len == -1)
+ return NULL;
+ }
+
/*
* headroom, head length,
* tail length and maximum TIM length
@@ -5010,9 +5061,10 @@ __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 +
+ mbssid_elems_len);
if (!skb)
- goto out;
+ return NULL;

skb_reserve(skb, local->tx_headroom);
skb_put_data(skb, beacon->head, beacon->head_len);
@@ -5028,21 +5080,32 @@ __ieee80211_beacon_get(struct ieee80211_hw *hw,
csa_off_base = skb->len;
}

+ if (mbssid_elems_len) {
+ ieee80211_beacon_add_mbssid(vif, skb,
+ beacon->mbssid_ies,
+ ema_index);
+ if (offs) {
+ offs->mbssid_offset = skb->len -
+ mbssid_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)
@@ -5054,7 +5117,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);

@@ -5066,7 +5129,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)
@@ -5089,7 +5152,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);
@@ -5102,7 +5165,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 */
@@ -5145,31 +5208,99 @@ __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 = NULL;
struct sk_buff *copy;
struct ieee80211_supported_band *sband;
int shift;

+ rcu_read_lock();
+ bcn = __ieee80211_beacon_get(hw, vif, &offs, false,
+ IEEE80211_BCN_EMA_NONE);
+ rcu_read_unlock();
if (!bcn)
return bcn;

--
2.31.1

2021-08-17 10:35:39

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH v11 0/4] multiple bssid and EMA support in AP mode

On Thu, 2021-07-15 at 00:07 -0700, Aloka Dixit wrote:
> This patchset adds support for multiple BSSID and
> enhanced multi-BSSID advertisements for AP mode.
> Individual patches describe the changes in this version.

How about adding the trivial advertisement to hwsim so we can have some
tests in hostapd?

johannes

2021-09-15 03:48:19

by Aloka Dixit

[permalink] [raw]
Subject: Re: [PATCH v11 0/4] multiple bssid and EMA support in AP mode

On 2021-08-17 03:35, Johannes Berg wrote:
> On Thu, 2021-07-15 at 00:07 -0700, Aloka Dixit wrote:
>> This patchset adds support for multiple BSSID and
>> enhanced multi-BSSID advertisements for AP mode.
>> Individual patches describe the changes in this version.
>
> How about adding the trivial advertisement to hwsim so we can have some
> tests in hostapd?
>
> johannes

Hi Johannes,
Yes, I plan to add hwsim advertisement separately once kernel
changes are accepted. Will also add hostapd testcases at the
same time.
Thanks.

2021-09-15 10:50:04

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH v11 0/4] multiple bssid and EMA support in AP mode

On Tue, 2021-09-14 at 20:47 -0700, Aloka Dixit wrote:
> On 2021-08-17 03:35, Johannes Berg wrote:
> > On Thu, 2021-07-15 at 00:07 -0700, Aloka Dixit wrote:
> > > This patchset adds support for multiple BSSID and
> > > enhanced multi-BSSID advertisements for AP mode.
> > > Individual patches describe the changes in this version.
> >
> > How about adding the trivial advertisement to hwsim so we can have some
> > tests in hostapd?
> >
> > johannes
>
> Hi Johannes,
> Yes, I plan to add hwsim advertisement separately once kernel
> changes are accepted. Will also add hostapd testcases at the
> same time.

OK, great! But adding it in hwsim is a kernel change, so why not just
send that patch together?

johannes

2021-09-15 18:50:03

by Aloka Dixit

[permalink] [raw]
Subject: Re: [PATCH v11 0/4] multiple bssid and EMA support in AP mode

On 2021-09-15 03:47, Johannes Berg wrote:
> On Tue, 2021-09-14 at 20:47 -0700, Aloka Dixit wrote:
>> On 2021-08-17 03:35, Johannes Berg wrote:
>> > On Thu, 2021-07-15 at 00:07 -0700, Aloka Dixit wrote:
>> > > This patchset adds support for multiple BSSID and
>> > > enhanced multi-BSSID advertisements for AP mode.
>> > > Individual patches describe the changes in this version.
>> >
>> > How about adding the trivial advertisement to hwsim so we can have some
>> > tests in hostapd?
>> >
>> > johannes
>>
>> Hi Johannes,
>> Yes, I plan to add hwsim advertisement separately once kernel
>> changes are accepted. Will also add hostapd testcases at the
>> same time.
>
> OK, great! But adding it in hwsim is a kernel change, so why not just
> send that patch together?
>
> johannes

Hi Johannes,

Trivial advertisement will not work because mac80211_hwsim_beacon_tx()
does not handle the EMA case which may have more than one beacons
transmitted.
It will need to be changed to use the newly added
ieee80211_beacon_get_template().

Hence I will add a separate change for HWSIM.

Thanks.