diff mbox series

[2/5] mac80211_hwsim: Random MAC address for a Management frame exchange

Message ID 20200425155713.25687-2-jouni@codeaurora.org (mailing list archive)
State Changes Requested
Delegated to: Johannes Berg
Headers show
Series [1/5] mac80211: Random MAC address for a Management frame exchange | expand

Commit Message

Jouni Malinen April 25, 2020, 3:57 p.m. UTC
Allow a temporary random MAC address to be used for a Management frame
exchange. This can be used to test pre-association GAS/ANQP exchanges
with random addresses.

Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
---
 drivers/net/wireless/mac80211_hwsim.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index 05e8203aa6d9..a05e9c778f21 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -535,6 +535,7 @@  struct mac80211_hwsim_data {
 		unsigned long next_start, start, end;
 	} survey_data[ARRAY_SIZE(hwsim_channels_2ghz) +
 		      ARRAY_SIZE(hwsim_channels_5ghz)];
+	u8 mgmt_tx_rand_addr[ETH_ALEN];
 
 	struct ieee80211_channel *channel;
 	u64 beacon_int	/* beacon interval in us */;
@@ -1006,7 +1007,9 @@  static bool mac80211_hwsim_addr_match(struct mac80211_hwsim_data *data,
 		.ret = false,
 	};
 
-	if (data->scanning && memcmp(addr, data->scan_addr, ETH_ALEN) == 0)
+	if ((data->scanning && ether_addr_equal(addr, data->scan_addr)) ||
+	    (is_valid_ether_addr(data->mgmt_tx_rand_addr) &&
+	     ether_addr_equal(addr, data->mgmt_tx_rand_addr)))
 		return true;
 
 	memcpy(md.addr, addr, ETH_ALEN);
@@ -1507,6 +1510,12 @@  static void mac80211_hwsim_tx(struct ieee80211_hw *hw,
 		return;
 	}
 
+	if (txi->control.vif &&
+	    !ether_addr_equal(hdr->addr2, txi->control.vif->addr))
+		memcpy(data->mgmt_tx_rand_addr, hdr->addr2, ETH_ALEN);
+	else
+		eth_zero_addr(data->mgmt_tx_rand_addr);
+
 	if (txi->control.vif)
 		hwsim_check_magic(txi->control.vif);
 	if (control->sta)
@@ -3060,6 +3069,7 @@  static int mac80211_hwsim_new_radio(struct genl_info *info,
 			       NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
 	wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
 	wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_BEACON_PROTECTION);
+	wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_MGMT_TX_RANDOM_TA);
 
 	hw->wiphy->interface_modes = param->iftypes;