In preparation for handling more of the NAN configuration setting, do some refactoring and cleanup: - Extract mac80211_hwsim_nan_set_config() and call it both when NAN is started and when the configuration changes. - Add NAN_BEACON_ELEM_LEN instead of the hardcoded 27. Assisted-by: GitHubCopilot:claude-opus-5 Signed-off-by: Ilan Peer --- .../net/wireless/virtual/mac80211_hwsim_nan.c | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/virtual/mac80211_hwsim_nan.c b/drivers/net/wireless/virtual/mac80211_hwsim_nan.c index fab6bd9e3cfb..2b30933ef2f9 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim_nan.c +++ b/drivers/net/wireless/virtual/mac80211_hwsim_nan.c @@ -33,6 +33,9 @@ static_assert(DW0_TSF_MASK + 1 == 8192 * 1024); #define NAN_RSSI_CLOSE (-60) #define NAN_RSSI_MIDDLE (-75) +/* Size of the NAN vendor element carrying the mandatory attributes */ +#define NAN_BEACON_ELEM_LEN 27 + /* Quiet time at the end of each slot where TX is suppressed */ #define NAN_CHAN_SWITCH_TIME_US 256 @@ -685,7 +688,7 @@ mac80211_hwsim_nan_tx_beacon(struct mac80211_hwsim_data *data, { struct ieee80211_vendor_ie nan_ie = { .element_id = WLAN_EID_VENDOR_SPECIFIC, - .len = 27 - 2, + .len = NAN_BEACON_ELEM_LEN - 2, .oui = { u32_get_bits(WLAN_OUI_WFA, 0xff0000), u32_get_bits(WLAN_OUI_WFA, 0xff00), u32_get_bits(WLAN_OUI_WFA, 0xff) }, @@ -694,7 +697,7 @@ mac80211_hwsim_nan_tx_beacon(struct mac80211_hwsim_data *data, size_t alloc_size = IEEE80211_TX_STATUS_HEADROOM + offsetofend(struct ieee80211_mgmt, u.beacon) + - 27 /* size of NAN vendor element */; + NAN_BEACON_ELEM_LEN; struct ieee80211_nan_master_indication master_indication; struct ieee80211_nan_attr nan_attr; struct ieee80211_mgmt *mgmt; @@ -905,11 +908,20 @@ mac80211_hwsim_nan_sched_update_work(struct wiphy *wiphy, ieee80211_nan_sched_update_done(data->nan.device_vif); } +static int mac80211_hwsim_nan_set_config(struct mac80211_hwsim_data *data, + struct cfg80211_nan_conf *conf) +{ + data->nan.notify_dw = conf->enable_dw_notification; + + return 0; +} + int mac80211_hwsim_nan_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct cfg80211_nan_conf *conf) { struct mac80211_hwsim_data *data = hw->priv; + int err; if (vif->type != NL80211_IFTYPE_NAN) return -EINVAL; @@ -917,6 +929,10 @@ int mac80211_hwsim_nan_start(struct ieee80211_hw *hw, if (data->nan.device_vif) return -EALREADY; + err = mac80211_hwsim_nan_set_config(data, conf); + if (err) + return err; + /* set this before starting the timer, as preemption might occur */ data->nan.device_vif = vif; data->nan.bands = conf->bands; @@ -945,8 +961,6 @@ int mac80211_hwsim_nan_start(struct ieee80211_hw *hw, ether_addr_copy(data->nan.cluster_id, conf->cluster_id); - data->nan.notify_dw = conf->enable_dw_notification; - return 0; } @@ -983,13 +997,17 @@ int mac80211_hwsim_nan_change_config(struct ieee80211_hw *hw, wiphy_debug(hw->wiphy, "nan_config_changed: changes=0x%x\n", changes); + if (changes & CFG80211_NAN_CONF_CHANGED_CONFIG) { + int err = mac80211_hwsim_nan_set_config(data, conf); + + if (err) + return err; + } + /* Handle only the changes we care about for simulation purposes */ if (changes & CFG80211_NAN_CONF_CHANGED_BANDS) data->nan.bands = conf->bands; - if (changes & CFG80211_NAN_CONF_CHANGED_CONFIG) - data->nan.notify_dw = conf->enable_dw_notification; - if (changes & CFG80211_NAN_CONF_CHANGED_PREF) { scoped_guard(spinlock_bh, &data->nan.state_lock) data->nan.master_pref = conf->master_pref; -- 2.55.0