From: Ilan Peer <ilan.peer@intel.com>
To: johannes@sipsolutions.net
Cc: linux-wireless@vger.kernel.org, Ilan Peer <ilan.peer@intel.com>
Subject: [PATCH v3 10/11] wifi: mac80211_hwsim: nan: Handle more of the NAN configuration
Date: Mon, 5 Oct 2026 11:44:57 +0300 [thread overview]
Message-ID: <20261005084458.3666739-11-ilan.peer@intel.com> (raw)
In-Reply-To: <20261005084458.3666739-1-ilan.peer@intel.com>
- Use the discovery beacon interval configured by user space instead of
always using hardcoded 100 TUs.
- Append the NAN attributes set by user space to the locally generated
ones in the discovery beacons.
Assisted-by: GitHubCopilot:claude-opus-5
Signed-off-by: Ilan Peer <ilan.peer@intel.com>
---
.../net/wireless/virtual/mac80211_hwsim_nan.c | 69 +++++++++++++++++--
.../net/wireless/virtual/mac80211_hwsim_nan.h | 5 ++
2 files changed, 69 insertions(+), 5 deletions(-)
diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_nan.c b/drivers/net/wireless/virtual/mac80211_hwsim_nan.c
index 2b30933ef2f9..e7815eb95c55 100644
--- a/drivers/net/wireless/virtual/mac80211_hwsim_nan.c
+++ b/drivers/net/wireless/virtual/mac80211_hwsim_nan.c
@@ -36,6 +36,9 @@ static_assert(DW0_TSF_MASK + 1 == 8192 * 1024);
/* Size of the NAN vendor element carrying the mandatory attributes */
#define NAN_BEACON_ELEM_LEN 27
+/* Space left in the NAN vendor element for the configured attributes */
+#define NAN_BEACON_EXTRA_ATTRS_LEN (255 - (NAN_BEACON_ELEM_LEN - 2))
+
/* Quiet time at the end of each slot where TX is suppressed */
#define NAN_CHAN_SWITCH_TIME_US 256
@@ -704,16 +707,27 @@ mac80211_hwsim_nan_tx_beacon(struct mac80211_hwsim_data *data,
struct sk_buff *skb;
/*
- * TODO: Should the configured vendor elements or NAN attributes be
- * included in some of these beacons?
+ * TODO: Should the configured vendor elements be included in some of
+ * these beacons?
*/
+ /* Allocate maximal size for NAN IE */
+ if (is_discovery)
+ alloc_size += NAN_BEACON_EXTRA_ATTRS_LEN;
+
skb = alloc_skb(alloc_size, GFP_ATOMIC);
if (!skb)
return;
spin_lock(&data->nan.state_lock);
+ /*
+ * The attributes configured by user space are appended to the
+ * mandatory ones.
+ */
+ if (is_discovery)
+ nan_ie.len += data->nan.extra_nan_attrs_len;
+
skb_reserve(skb, IEEE80211_TX_STATUS_HEADROOM);
mgmt = skb_put(skb, offsetofend(struct ieee80211_mgmt, u.beacon));
@@ -724,7 +738,9 @@ mac80211_hwsim_nan_tx_beacon(struct mac80211_hwsim_data *data,
mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
IEEE80211_STYPE_BEACON);
- mgmt->u.beacon.beacon_int = cpu_to_le16(is_discovery ? 100 : DWST_TU);
+ mgmt->u.beacon.beacon_int =
+ cpu_to_le16(is_discovery ? data->nan.discovery_beacon_interval :
+ DWST_TU);
mgmt->u.beacon.capab_info =
cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME |
WLAN_CAPABILITY_SHORT_PREAMBLE);
@@ -755,6 +771,10 @@ mac80211_hwsim_nan_tx_beacon(struct mac80211_hwsim_data *data,
skb_put_data(skb, &data->nan.current_ami,
sizeof(data->nan.current_ami));
+ if (is_discovery && data->nan.extra_nan_attrs_len)
+ skb_put_data(skb, data->nan.extra_nan_attrs,
+ data->nan.extra_nan_attrs_len);
+
spin_unlock(&data->nan.state_lock);
mac80211_hwsim_tx_frame(data->hw, skb, channel);
@@ -884,10 +904,11 @@ mac80211_hwsim_nan_discovery_beacon_timer(struct hrtimer *timer)
tsf_now = mac80211_hwsim_get_tsf(data->hw, data->nan.device_vif);
/* Wrap value to be after the next TBTT */
- tbtt = tsf_now + ieee80211_tu_to_usec(100);
+ tbtt = tsf_now + ieee80211_tu_to_usec(data->nan.discovery_beacon_interval);
/* Round TBTT down to the correct time */
- div_u64_rem(tbtt, ieee80211_tu_to_usec(100), &remainder);
+ div_u64_rem(tbtt, ieee80211_tu_to_usec(data->nan.discovery_beacon_interval),
+ &remainder);
tbtt = tbtt - remainder;
hrtimer_set_expires(&data->nan.discovery_beacon_timer,
@@ -911,8 +932,37 @@ mac80211_hwsim_nan_sched_update_work(struct wiphy *wiphy,
static int mac80211_hwsim_nan_set_config(struct mac80211_hwsim_data *data,
struct cfg80211_nan_conf *conf)
{
+ const u8 *extra_nan_attrs = NULL;
+ const u8 *old;
+
+ if (conf->extra_nan_attrs_len > NAN_BEACON_EXTRA_ATTRS_LEN)
+ return -EINVAL;
+
+ if (conf->extra_nan_attrs_len) {
+ extra_nan_attrs = kmemdup(conf->extra_nan_attrs,
+ conf->extra_nan_attrs_len,
+ GFP_KERNEL);
+ if (!extra_nan_attrs)
+ return -ENOMEM;
+ }
+
data->nan.notify_dw = conf->enable_dw_notification;
+ scoped_guard(spinlock_bh, &data->nan.state_lock) {
+ /*
+ * Fall back to the device default if user space did not
+ * configure it
+ */
+ data->nan.discovery_beacon_interval =
+ conf->discovery_beacon_interval ? : 100;
+
+ old = data->nan.extra_nan_attrs;
+ data->nan.extra_nan_attrs = extra_nan_attrs;
+ data->nan.extra_nan_attrs_len = conf->extra_nan_attrs_len;
+ }
+
+ kfree(old);
+
return 0;
}
@@ -968,6 +1018,7 @@ int mac80211_hwsim_nan_stop(struct ieee80211_hw *hw,
struct ieee80211_vif *vif)
{
struct mac80211_hwsim_data *data = hw->priv;
+ const u8 *old;
if (vif->type != NL80211_IFTYPE_NAN || !data->nan.device_vif ||
data->nan.device_vif != vif)
@@ -979,6 +1030,14 @@ int mac80211_hwsim_nan_stop(struct ieee80211_hw *hw,
wiphy_delayed_work_cancel(hw->wiphy, &data->nan.sched_update_work);
data->nan.device_vif = NULL;
+ scoped_guard(spinlock_bh, &data->nan.state_lock) {
+ old = data->nan.extra_nan_attrs;
+ data->nan.extra_nan_attrs = NULL;
+ data->nan.extra_nan_attrs_len = 0;
+ }
+
+ kfree(old);
+
return 0;
}
diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_nan.h b/drivers/net/wireless/virtual/mac80211_hwsim_nan.h
index 2801a1d8dcf0..e73634e479e8 100644
--- a/drivers/net/wireless/virtual/mac80211_hwsim_nan.h
+++ b/drivers/net/wireless/virtual/mac80211_hwsim_nan.h
@@ -32,6 +32,9 @@ struct mac80211_hwsim_nan_data {
/* Later members are protected by this lock */
spinlock_t state_lock;
+ const u8 *extra_nan_attrs;
+ u16 extra_nan_attrs_len;
+
u8 master_pref;
u8 random_factor;
@@ -53,6 +56,8 @@ struct mac80211_hwsim_nan_data {
bool tsf_adjusted;
bool tsf_discontinuity;
+ u8 discovery_beacon_interval;
+
/*
* Local schedule - stores channel definition for each 16TU slot.
* Derived from NMI vif->cfg.nan_schedule. chan == NULL means not
--
2.55.0
next prev parent reply other threads:[~2026-10-04 14:30 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-05 8:44 [PATCH v3 00/11] wifi: cfg80211/mac80211: add NAN Instant Communication support Ilan Peer
2026-10-05 8:44 ` [PATCH v3 01/11] wifi: cfg80211: nan: add " Ilan Peer
2026-10-05 8:44 ` [PATCH v3 02/11] wifi: mac80211: nan: Update NAN configuration copy Ilan Peer
2026-10-05 8:44 ` [PATCH v3 03/11] wifi: cfg80211: nan: check Rx registration for NAN beacons Ilan Peer
2026-10-05 8:44 ` [PATCH v3 04/11] wifi: cfg80211: do not use NAN beacons to update the BSS table Ilan Peer
2026-10-05 8:44 ` [PATCH v3 05/11] wifi: mac80211: nan: allow Rx registration for NAN beacons Ilan Peer
2026-10-05 8:44 ` [PATCH v3 06/11] wifi: mac80211: accept NAN beacons only when IC is enabled Ilan Peer
2026-10-05 8:44 ` [PATCH v3 07/11] wifi: ieee80211: add NAN service ID list attribute definitions Ilan Peer
2026-10-05 8:44 ` [PATCH v3 08/11] wifi: mac80211_hwsim: nan: use ieee80211_is_nan_beacon() helper Ilan Peer
2026-10-05 8:44 ` [PATCH v3 09/11] wifi: mac80211_hwsim: nan: prepare for more configurable NAN settings Ilan Peer
2026-10-05 8:44 ` Ilan Peer [this message]
2026-10-05 8:44 ` [PATCH v3 11/11] wifi: mac80211_hwsim: add NAN Instant Communication support Ilan Peer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261005084458.3666739-11-ilan.peer@intel.com \
--to=ilan.peer@intel.com \
--cc=johannes@sipsolutions.net \
--cc=linux-wireless@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox