Currently, we store in nan.conf the cluster id that was configured from upper layer to be used when the device opens a cluster. But after we joined a cluster, the configured cluster id is no longer relevant. Particularly, in reconfig we will give the driver the (possibly) wrong cluster id. Add an API to be called by the driver when joined a cluster in which the cluster id will be updated. Use the locally stored cluster id instead of cfg80211's copy. Ignore cluster id updates from cfg80211 if we already have one configured. Adjust the drivers that use the cfg80211 API (cfg80211_nan_cluster_joined) directly, otherwise we break functionality (i.e. accept frame check won't evaluate to true). Signed-off-by: Miri Korenblit --- include/net/mac80211.h | 14 ++++++++++++++ net/mac80211/cfg.c | 19 +++++++++++++++++++ net/mac80211/rx.c | 4 ++-- net/mac80211/tx.c | 2 +- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index 02318a4be0e1..0d1b1d726b9c 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -7891,6 +7891,20 @@ void ieee80211_nan_func_match(struct ieee80211_vif *vif, */ void ieee80211_nan_sched_update_done(struct ieee80211_vif *vif); +/** + * ieee80211_nan_cluster_joined - notify about NAN cluster join. + * + * This function is used to notify mac80211 about NAN cluster join. + * + * @vif: &struct ieee80211_vif pointer from the add_interface callback. + * @cluster_id: the cluster ID that was joined + * @new_cluster: true if this is a new cluster + * @gfp: allocation flags + */ +void ieee80211_nan_cluster_joined(struct ieee80211_vif *vif, + const u8 *cluster_id, bool new_cluster, + gfp_t gfp); + /** * ieee80211_calc_rx_airtime - calculate estimated transmission airtime for RX. * diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index 00261bd6674b..c71af8878562 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -5215,6 +5215,25 @@ void ieee80211_nan_func_match(struct ieee80211_vif *vif, } EXPORT_SYMBOL(ieee80211_nan_func_match); +void ieee80211_nan_cluster_joined(struct ieee80211_vif *vif, + const u8 *cluster_id, bool new_cluster, + gfp_t gfp) +{ + struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); + + if (WARN_ON(vif->type != NL80211_IFTYPE_NAN)) + return; + + if (WARN_ON(!sdata->u.nan.started)) + return; + + ether_addr_copy(sdata->u.nan.conf.cluster_id, cluster_id); + + cfg80211_nan_cluster_joined(ieee80211_vif_to_wdev(vif), cluster_id, + new_cluster, gfp); +} +EXPORT_SYMBOL(ieee80211_nan_cluster_joined); + static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy, struct net_device *dev, const bool enabled) diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index 3e5d1c47a5b0..82ea7404f3da 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -4629,7 +4629,7 @@ static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx) * action frames or authentication frames that are addressed to * the local NAN interface. */ - return memcmp(sdata->wdev.u.nan.cluster_id, + return memcmp(sdata->u.nan.conf.cluster_id, hdr->addr3, ETH_ALEN) == 0 && (ieee80211_is_public_action(hdr, skb->len) || (ieee80211_is_auth(hdr->frame_control) && @@ -4646,7 +4646,7 @@ static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx) if (!nmi) return false; - if (!ether_addr_equal(nmi->wdev.u.nan.cluster_id, + if (!ether_addr_equal(nmi->u.nan.conf.cluster_id, hdr->addr3)) return false; diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 8e4876d1c544..1702f816419b 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -2854,7 +2854,7 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, ret = -ENOTCONN; goto free; } - memcpy(hdr.addr3, nmi->wdev.u.nan.cluster_id, ETH_ALEN); + memcpy(hdr.addr3, nmi->u.nan.conf.cluster_id, ETH_ALEN); hdrlen = 24; break; } -- 2.34.1