[PATCH] scan: disable MAC randomization during provisioning

Benjamin Berg benjamin at sipsolutions.net
Wed May 20 07:31:16 PDT 2026


From: Benjamin Berg <benjamin.berg at intel.com>

If the GO has already been started and we are just trying to find its
beacon, then we should not randomize the MAC address. Doing so would
conflict with the GO possibly having a MAC filter installed and
ignoring the probe requests (wpa_supplicant does this).

So, do not enable address randomization if in P2P provisioning.

Also move the wpa_state check into wpa_setup_mac_addr_rand_params so
that all the checks are in the same location.

Note that other P2P scans bypass the main wpa_supplicant scanning
facilities and avoid MAC randomization that way.

Signed-off-by: Benjamin Berg <benjamin.berg at intel.com>
---
 wpa_supplicant/scan.c | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c
index b705058565..e5edeac8ce 100644
--- a/wpa_supplicant/scan.c
+++ b/wpa_supplicant/scan.c
@@ -81,11 +81,20 @@ static int wpas_wps_in_use(struct wpa_supplicant *wpa_s,
 #endif /* CONFIG_WPS */
 
 
-static int wpa_setup_mac_addr_rand_params(struct wpa_driver_scan_params *params,
+static int wpa_setup_mac_addr_rand_params(struct wpa_supplicant *wpa_s,
+					  struct wpa_driver_scan_params *params,
 					  const u8 *mac_addr)
 {
 	u8 *tmp;
 
+	/* If we are connected, there is no point in randomization */
+	if (wpa_s && wpa_s->wpa_state > WPA_SCANNING)
+		return 0;
+
+	/* The P2P GO might ignore our probe requests otherwise */
+	if (wpa_s && wpa_s->p2p_in_provisioning)
+		return 0;
+
 	if (params->mac_addr) {
 		params->mac_addr_mask = NULL;
 		os_free(params->mac_addr);
@@ -198,9 +207,9 @@ static void wpas_trigger_scan_cb(struct wpa_radio_work *work, int deinit)
 		return;
 	}
 
-	if ((wpa_s->mac_addr_rand_enable & MAC_ADDR_RAND_SCAN) &&
-	    wpa_s->wpa_state <= WPA_SCANNING)
-		wpa_setup_mac_addr_rand_params(params, wpa_s->mac_addr_scan);
+	if (wpa_s->mac_addr_rand_enable & MAC_ADDR_RAND_SCAN)
+		wpa_setup_mac_addr_rand_params(wpa_s, params,
+					       wpa_s->mac_addr_scan);
 
 	if (wpas_update_random_addr_disassoc(wpa_s) < 0) {
 		wpa_msg(wpa_s, MSG_INFO,
@@ -1459,9 +1468,9 @@ ssid_list_set:
 	}
 #endif /* CONFIG_P2P */
 
-	if ((wpa_s->mac_addr_rand_enable & MAC_ADDR_RAND_SCAN) &&
-	    wpa_s->wpa_state <= WPA_SCANNING)
-		wpa_setup_mac_addr_rand_params(&params, wpa_s->mac_addr_scan);
+	if (wpa_s->mac_addr_rand_enable & MAC_ADDR_RAND_SCAN)
+		wpa_setup_mac_addr_rand_params(wpa_s, &params,
+					       wpa_s->mac_addr_scan);
 
 	if (!is_zero_ether_addr(wpa_s->next_scan_bssid)) {
 		struct wpa_bss *bss;
@@ -1935,9 +1944,8 @@ scan:
 
 	wpa_setband_scan_freqs(wpa_s, scan_params);
 
-	if ((wpa_s->mac_addr_rand_enable & MAC_ADDR_RAND_SCHED_SCAN) &&
-	    wpa_s->wpa_state <= WPA_SCANNING)
-		wpa_setup_mac_addr_rand_params(&params,
+	if (wpa_s->mac_addr_rand_enable & MAC_ADDR_RAND_SCHED_SCAN)
+		wpa_setup_mac_addr_rand_params(wpa_s, &params,
 					       wpa_s->mac_addr_sched_scan);
 
 	wpa_scan_set_relative_rssi_params(wpa_s, scan_params);
@@ -3853,7 +3861,7 @@ wpa_scan_clone_params(const struct wpa_driver_scan_params *src)
 	}
 
 	if (src->mac_addr_rand &&
-	    wpa_setup_mac_addr_rand_params(params, src->mac_addr))
+	    wpa_setup_mac_addr_rand_params(NULL, params, src->mac_addr))
 		goto failed;
 
 	if (src->bssid) {
@@ -4043,9 +4051,9 @@ int wpas_start_pno(struct wpa_supplicant *wpa_s)
 		params.freqs = wpa_s->manual_sched_scan_freqs;
 	}
 
-	if ((wpa_s->mac_addr_rand_enable & MAC_ADDR_RAND_PNO) &&
-	    wpa_s->wpa_state <= WPA_SCANNING)
-		wpa_setup_mac_addr_rand_params(&params, wpa_s->mac_addr_pno);
+	if (wpa_s->mac_addr_rand_enable & MAC_ADDR_RAND_PNO)
+		wpa_setup_mac_addr_rand_params(wpa_s, &params,
+					       wpa_s->mac_addr_pno);
 
 	wpa_scan_set_relative_rssi_params(wpa_s, &params);
 
-- 
2.54.0




More information about the Hostap mailing list