[PATCH 2/2] tests: Add scan privacy testing coverage

Andrei Otcheretianski andrei.otcheretianski at intel.com
Wed Nov 25 05:49:40 PST 2026


From: Ilan Peer <ilan.peer at intel.com>

- Add a scan privacy test that verifies that the probe
  request only includes the allowed elements.
- Extend EPPKE tests that use 'preassoc_mac_addr=1' to
  also set 'scan_privacy=1'.

Signed-off-by: Ilan Peer <ilan.peer at intel.com>
---
 tests/hwsim/test_eppke.py |  8 ++++++
 tests/hwsim/test_scan.py  | 55 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)

diff --git a/tests/hwsim/test_eppke.py b/tests/hwsim/test_eppke.py
index 3bb6011f6b..3b9aff1599 100644
--- a/tests/hwsim/test_eppke.py
+++ b/tests/hwsim/test_eppke.py
@@ -234,6 +234,7 @@ def test_eppke_ap_with_base_akm_sae_ext_non_mld_client_pmksa_cached(dev, apdev):
         dev[0].set("pasn_groups", "")
         dev[0].set("sae_pwe", "1")
         dev[0].set("preassoc_mac_addr", "1")
+        dev[0].set("scan_privacy", "1")
         dev[0].set("rand_addr_lifetime", "0")
         dev[0].connect(ssid, sae_password=passphrase, scan_freq="2412",
                        key_mgmt="SAE-EXT-KEY EPPKE", ieee80211w="2",
@@ -267,6 +268,7 @@ def test_eppke_ap_with_base_akm_sae_ext_non_mld_client_pmksa_cached(dev, apdev):
     finally:
         dev[0].set("pasn_groups", "")
         dev[0].set("preassoc_mac_addr", "0")
+        dev[0].set("scan_privacy", "0")
         dev[0].set("rand_addr_lifetime", "60")
         dev[0].set("sae_pwe", "0")
 
@@ -292,6 +294,7 @@ def test_eppke_mld_ap_with_base_akm_sae_ext_non_mld_client_pmksa_cached(dev, apd
             dev[0].set("pasn_groups", "")
             dev[0].set("sae_pwe", "1")
             dev[0].set("preassoc_mac_addr", "1")
+            dev[0].set("scan_privacy", "1")
             dev[0].set("rand_addr_lifetime", "0")
             dev[0].connect(ssid, sae_password=passphrase, scan_freq="2412",
                            key_mgmt="SAE-EXT-KEY EPPKE", ieee80211w="2",
@@ -345,6 +348,7 @@ def test_eppke_mld_ap_with_base_akm_sae_ext_non_mld_client_pmksa_cached(dev, apd
         finally:
             dev[0].set("pasn_groups", "")
             dev[0].set("preassoc_mac_addr", "0")
+            dev[0].set("scan_privacy", "0")
             dev[0].set("rand_addr_lifetime", "60")
             dev[0].set("sae_pwe", "0")
 
@@ -371,6 +375,7 @@ def run_eppke_mld_one_link_pmksa_cached(dev, apdev, key_mgmt):
         wpas.set("pasn_groups", "")
         wpas.set("sae_pwe", "1")
         wpas.set("preassoc_mac_addr", "1")
+        wpas.set("scan_privacy", "1")
         wpas.set("rand_addr_lifetime", "0")
         try:
             wpas.connect(ssid, sae_password=passphrase, scan_freq="2412",
@@ -404,6 +409,7 @@ def run_eppke_mld_one_link_pmksa_cached(dev, apdev, key_mgmt):
                 hwsim_utils.test_connectivity(wpas, hapd0)
         finally:
             wpas.set("preassoc_mac_addr", "0")
+            wpas.set("scan_privacy", "0")
             wpas.set("rand_addr_lifetime", "60")
             wpas.set("sae_pwe", "0")
 
@@ -437,6 +443,7 @@ def run_eppke_mld_two_links_pmksa_cached(dev, apdev, key_mgmt):
         wpas.set("pasn_groups", "")
         wpas.set("sae_pwe", "1")
         wpas.set("preassoc_mac_addr", "1")
+        wpas.set("scan_privacy", "1")
         wpas.set("rand_addr_lifetime", "0")
         try:
             wpas.connect(ssid, sae_password=passphrase, scan_freq="2412 2437",
@@ -470,6 +477,7 @@ def run_eppke_mld_two_links_pmksa_cached(dev, apdev, key_mgmt):
                 hwsim_utils.test_connectivity(wpas, hapd0)
         finally:
             wpas.set("preassoc_mac_addr", "0")
+            wpas.set("scan_privacy", "0")
             wpas.set("rand_addr_lifetime", "60")
             wpas.set("sae_pwe", "0")
 
diff --git a/tests/hwsim/test_scan.py b/tests/hwsim/test_scan.py
index 6255259d21..2ef6112f71 100644
--- a/tests/hwsim/test_scan.py
+++ b/tests/hwsim/test_scan.py
@@ -2094,6 +2094,61 @@ def test_scan_short_ssid_list(dev, apdev):
     if not found:
         raise Exception("AP not found in scan results")
 
+WLAN_FC_STYPE_PROBE_REQ = 4
+WLAN_EID_SSID = 0
+WLAN_EID_SUPP_RATES = 1
+WLAN_EID_DS_PARAMS = 3
+
+def test_scan_privacy(dev, apdev):
+    """Scan with scan_privacy=1 minimizes probe request content"""
+    if dev[0].get_driver_status_field('capa.mac_addr_rand_scan_supported') != '1':
+        raise HwsimSkip("Driver does not support random MAC address for scanning")
+
+    hapd = hostapd.add_ap(apdev[0], {"ssid": "test-scan",
+                                     "beacon_int": "1000"})
+    hapd.set("ext_mgmt_frame_handling", "1")
+
+    hapd.dump_monitor()
+    try:
+        if "OK" not in dev[0].request("SET scan_privacy 1"):
+            raise Exception("SET scan_privacy failed")
+
+        if "OK" not in dev[0].request("MAC_RAND_SCAN all enable=1"):
+            raise Exception("MAC_RAND_SCAN failed")
+
+        if "OK" not in dev[0].request("SCAN TYPE=ONLY freq=2412,2417,2422"):
+            raise Exception("SCAN failed")
+
+        ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
+        if ev is None:
+            raise Exception("Scan did not complete")
+
+        # Collect probe requests and verify IE content
+        found = False
+        for i in range(30):
+            msg = hapd.mgmt_rx(timeout=1)
+            if msg is None:
+                break
+            if msg['subtype'] != WLAN_FC_STYPE_PROBE_REQ:
+                continue
+            found = True
+            ie = parse_ie(binascii.hexlify(msg['payload']).decode())
+            allowed_ids = {WLAN_EID_SSID, WLAN_EID_SUPP_RATES,
+                           WLAN_EID_DS_PARAMS}
+
+            unexpected = set(ie.keys()) - allowed_ids
+            if unexpected:
+                raise Exception("Probe Request contains unexpected IEs: " +
+                                str(unexpected))
+
+        if not found:
+            raise Exception("No Probe Request frames seen")
+    finally:
+        dev[0].request("MAC_RAND_SCAN all enable=0")
+        dev[0].request("SET scan_privacy 0")
+        hapd.set("ext_mgmt_frame_handling", "0")
+        dev[0].flush_scan_cache()
+
 def test_scan_freq_network(dev, apdev):
     """Scanning channels based on network profiles"""
     hostapd.add_ap(apdev[0], {"ssid": "test-scan"})
-- 
2.56.1




More information about the Hostap mailing list