diff mbox series

[v2,3/4] wifi: mac80211_hwsim: Add support for randomizing auth and deauth frames TA

Message ID 20220919121155.3069765-3-quic_vjakkam@quicinc.com (mailing list archive)
State Changes Requested
Delegated to: Johannes Berg
Headers show
Series [v2,1/4] wifi: nl80211: Add support for randomizing TA of auth and deauth frames | expand

Commit Message

Veerendranath Jakkam Sept. 19, 2022, 12:11 p.m. UTC
Add changes to support randomizing transmit address of the
authentication and deauthentication frames and support sending ACK to
frames with receive address as configured random MAC address.

Signed-off-by: Veerendranath Jakkam <quic_vjakkam@quicinc.com>
---
 drivers/net/wireless/mac80211_hwsim.c | 33 ++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index df51b5b1f171..4473cbf28725 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -720,6 +720,9 @@  struct mac80211_hwsim_data {
 	int rx_rssi;
 
 	struct mac80211_hwsim_link_data link_data[IEEE80211_MLD_MAX_NUM_LINKS];
+
+	/* Ack the frames with RA as configured random address */
+	u8 random_addr[ETH_ALEN];
 };
 
 static const struct rhashtable_params hwsim_rht_params = {
@@ -1232,6 +1235,10 @@  static bool mac80211_hwsim_addr_match(struct mac80211_hwsim_data *data,
 	if (data->scanning && memcmp(addr, data->scan_addr, ETH_ALEN) == 0)
 		return true;
 
+	if (!is_zero_ether_addr(data->random_addr) &&
+	    ether_addr_equal(addr, data->random_addr))
+		return true;
+
 	memcpy(md.addr, addr, ETH_ALEN);
 
 	ieee80211_iterate_active_interfaces_atomic(data->hw,
@@ -3102,6 +3109,27 @@  static int mac80211_hwsim_change_sta_links(struct ieee80211_hw *hw,
 	return 0;
 }
 
+static void mac80211_hwsim_config_random_mac(struct ieee80211_hw *hw,
+					     const u8 *addr)
+{
+	struct mac80211_hwsim_data *hwsim = hw->priv;
+
+	mutex_lock(&hwsim->mutex);
+
+	if (!is_zero_ether_addr(addr)) {
+		if (!is_zero_ether_addr(hwsim->random_addr))
+			mac80211_hwsim_config_mac_nl(hw, hwsim->random_addr,
+						     false);
+		ether_addr_copy(hwsim->random_addr, addr);
+		mac80211_hwsim_config_mac_nl(hw, hwsim->random_addr, true);
+	} else {
+		mac80211_hwsim_config_mac_nl(hw, hwsim->random_addr, false);
+		eth_zero_addr(hwsim->random_addr);
+	}
+
+	mutex_unlock(&hwsim->mutex);
+}
+
 #define HWSIM_COMMON_OPS					\
 	.tx = mac80211_hwsim_tx,				\
 	.start = mac80211_hwsim_start,				\
@@ -3123,7 +3151,8 @@  static int mac80211_hwsim_change_sta_links(struct ieee80211_hw *hw,
 	.flush = mac80211_hwsim_flush,				\
 	.get_et_sset_count = mac80211_hwsim_get_et_sset_count,	\
 	.get_et_stats = mac80211_hwsim_get_et_stats,		\
-	.get_et_strings = mac80211_hwsim_get_et_strings,
+	.get_et_strings = mac80211_hwsim_get_et_strings,	\
+	.config_random_mac = mac80211_hwsim_config_random_mac,
 
 #define HWSIM_NON_MLO_OPS					\
 	.sta_add = mac80211_hwsim_sta_add,			\
@@ -4439,6 +4468,8 @@  static int mac80211_hwsim_new_radio(struct genl_info *info,
 			      NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS);
 	wiphy_ext_feature_set(hw->wiphy,
 			      NL80211_EXT_FEATURE_BEACON_RATE_LEGACY);
+	wiphy_ext_feature_set(hw->wiphy,
+			      NL80211_EXT_FEATURE_AUTH_AND_DEAUTH_RANDOM_TA);
 
 	hw->wiphy->interface_modes = param->iftypes;