From: Ilan Peer Instant Communication requires user space to track the NAN beacons, so let it register for Rx of beacons on a NAN interface. Add support for passing beacon on NAN Device interface when instant communication is enabled. Add a helper function to identify NAN beacons, based on the BSSID and the beacon frame content. Skip NAN beacons so they would not be used to update the BSS table. Assisted-by: GitHubCopilot:claude-opus-5 Signed-off-by: Ilan Peer Signed-off-by: Miri Korenblit --- include/linux/ieee80211-nan.h | 26 ++++++++++++++++++++++++++ net/mac80211/main.c | 7 ++++++- net/mac80211/rx.c | 11 ++++++++++- net/mac80211/scan.c | 4 ++++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/include/linux/ieee80211-nan.h b/include/linux/ieee80211-nan.h index 455033955e54..b332a94671ba 100644 --- a/include/linux/ieee80211-nan.h +++ b/include/linux/ieee80211-nan.h @@ -74,4 +74,30 @@ struct ieee80211_nan_anchor_master_info { _attr = (const struct ieee80211_nan_attr *) \ (_attr->data + le16_to_cpu(_attr->length))) +static inline bool ieee80211_is_nan_beacon(const struct ieee80211_mgmt *mgmt, + size_t len) +{ + const struct element *elem; + + /* The NAN IE is at least 6 octets */ + if (len < offsetofend(struct ieee80211_mgmt, u.beacon) + 6) + return false; + + if (!ieee80211_is_beacon(mgmt->frame_control)) + return false; + + /* NAN Cluster IDs range from 50-6F-9A-01-00-00 to 50-6F-9A-01-FF-FF */ + if (get_unaligned_be32(mgmt->bssid) != ((WLAN_OUI_WFA << 8) | 0x01)) + return false; + + elem = (const struct element *)mgmt->u.beacon.variable; + if (elem->id != WLAN_EID_VENDOR_SPECIFIC || + elem->datalen < 4 || + get_unaligned_be32(elem->data) != + (WLAN_OUI_WFA << 8 | WLAN_OUI_TYPE_WFA_NAN)) + return false; + + return true; +} + #endif /* LINUX_IEEE80211_NAN_H */ diff --git a/net/mac80211/main.c b/net/mac80211/main.c index 7816395681fa..b889d2a7ef75 100644 --- a/net/mac80211/main.c +++ b/net/mac80211/main.c @@ -745,8 +745,13 @@ ieee80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = { }, [NL80211_IFTYPE_NAN] = { .tx = 0xffff, + /* + * Beacon Rx registration is needed to let user space handle + * service discovery when Instant Communication is enabled. + */ .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | - BIT(IEEE80211_STYPE_AUTH >> 4), + BIT(IEEE80211_STYPE_AUTH >> 4) | + BIT(IEEE80211_STYPE_BEACON >> 4), }, [NL80211_IFTYPE_NAN_DATA] = { .tx = 0xffff, diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index b3990b7a7299..8dde57a9112f 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -4536,7 +4536,10 @@ static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx) struct ieee80211_hdr *hdr = (void *)skb->data; struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type); + bool nan_beacon = ieee80211_is_nan_beacon((struct ieee80211_mgmt *)hdr, + skb->len); bool multicast; + static const u8 nan_network_id[ETH_ALEN] __aligned(2) = { 0x51, 0x6F, 0x9A, 0x01, 0x00, 0x00 }; @@ -4545,6 +4548,9 @@ static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx) return sdata->vif.type == NL80211_IFTYPE_STATION && bssid; multicast = is_multicast_ether_addr(hdr->addr1); + /* Only a NAN interface may handle NAN beacons */ + if (nan_beacon && sdata->vif.type != NL80211_IFTYPE_NAN) + return false; switch (sdata->vif.type) { case NL80211_IFTYPE_STATION: @@ -4681,7 +4687,8 @@ static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx) * Accept only frames that are addressed to the NAN cluster * (based on the Cluster ID). From these frames, accept only * - public action frames, - * - authentication frames to the local address, and + * - authentication frames to the local address, + * - NAN beacons, when Instant Communication is enabled, and * - robust management frames except disassoc. */ if (!ether_addr_equal(sdata->u.nan.conf.cluster_id, hdr->addr3)) @@ -4691,6 +4698,8 @@ static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx) if (ieee80211_is_auth(hdr->frame_control) && ether_addr_equal(sdata->vif.addr, hdr->addr1)) return true; + if (nan_beacon) + return sdata->u.nan.conf.instant_comm; if (!ieee80211_is_disassoc(hdr->frame_control) && ieee80211_is_robust_mgmt_frame(skb)) return true; diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c index a4bca412e577..fc8d090bfd7c 100644 --- a/net/mac80211/scan.c +++ b/net/mac80211/scan.c @@ -353,6 +353,10 @@ void ieee80211_scan_rx(struct ieee80211_local *local, struct sk_buff *skb) if (!ieee80211_is_s1g_beacon(mgmt->frame_control) && !is_broadcast_ether_addr(mgmt->da)) return; + + /* NAN beacons are not a BSS, don't add to the BSS table */ + if (ieee80211_is_nan_beacon(mgmt, skb->len)) + return; } /* Do not update the BSS table in case of only monitor interfaces */ -- 2.34.1