From 7ee7b046a995d1977a178fe9a688a2007cd4ce3f Mon Sep 17 00:00:00 2001 From: Vinayak Yadawad Date: Fri, 8 Dec 2023 21:50:23 +0530 Subject: [PATCH] nl80211: Use attribute NL80211_ATTR_BSSID to scan for specific BSSID With changes to optimize scan for specific BSSID, there arises a scenario where in nl80211_trigger_scan() is called with a scan randomization enabled. A combination of NL80211_ATTR_MAC for BSSID and scan randomization, which uses NL80211_ATTR_MAC for a different purpose, results in invalid error for the scan request. To fix the issue use attribute NL80211_ATTR_BSSID instead of NL80211_ATTR_MAC. NL80211_ATTR_BSSID was introduced in kernel commit 2fa436b3a2a7 ("nl80211: Use different attrs for BSSID and random MAC addr in scan req") in 2016. Prior to that, only NL80211_ATTR_MAC could be used for specifying the target BSSID. For backwards compatibility, add the NL80211_ATTR_MAC attribute as well when not using a random MAC address. Signed-off-by: Vinayak Yadawad --- src/drivers/driver_nl80211_scan.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/drivers/driver_nl80211_scan.c b/src/drivers/driver_nl80211_scan.c index 736db6406..530d50c7f 100644 --- a/src/drivers/driver_nl80211_scan.c +++ b/src/drivers/driver_nl80211_scan.c @@ -385,7 +385,15 @@ int wpa_driver_nl80211_scan(struct i802_bss *bss, if (params->bssid) { wpa_printf(MSG_DEBUG, "nl80211: Scan for a specific BSSID: " MACSTR, MAC2STR(params->bssid)); - if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) + if (nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid)) + goto fail; + /* NL80211_ATTR_MAC was used for this purpose initially and the + * NL80211_ATTR_BSSID was added in 2016 when MAC address + * randomization was added. For compatibility with older kernel + * versions, add the NL80211_ATTR_MAC attribute as well when + * the conflicting functionality is not in use. */ + if (!params->mac_addr_rand && + nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) goto fail; }