From 816e3df9720ecefe50a739455aef26ffb5c7b8f3 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sat, 27 Sep 2014 19:12:32 +0300 Subject: [PATCH] tests: Random MAC address use Signed-off-by: Jouni Malinen --- tests/hwsim/test_ap_hs20.py | 35 +++++++++++++++++++++ tests/hwsim/test_sta_dynamic.py | 55 +++++++++++++++++++++++++++++++++ tests/hwsim/wpasupplicant.py | 2 +- 3 files changed, 91 insertions(+), 1 deletion(-) diff --git a/tests/hwsim/test_ap_hs20.py b/tests/hwsim/test_ap_hs20.py index 65ad1c2bc..f5744195e 100644 --- a/tests/hwsim/test_ap_hs20.py +++ b/tests/hwsim/test_ap_hs20.py @@ -2070,3 +2070,38 @@ def test_ap_hs20_external_selection(dev, apdev): scan_freq="2412", update_identifier="54321") if dev[0].get_status_field("hs20") != "2": raise Exception("Unexpected hs20 indication") + +def test_ap_hs20_random_mac_addr(dev, apdev): + """Hotspot 2.0 connection with random MAC address""" + bssid = apdev[0]['bssid'] + params = hs20_ap_params() + params['hessid'] = bssid + params['disable_dgaf'] = '1' + hapd = hostapd.add_ap(apdev[0]['ifname'], params) + + wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') + wpas.interface_add("wlan5") + addr = wpas.p2p_interface_addr() + wpas.request("SET mac_addr 1") + wpas.request("SET preassoc_mac_addr 1") + wpas.request("SET rand_addr_lifetime 60") + wpas.hs20_enable() + id = wpas.add_cred_values({ 'realm': "example.com", + 'username': "hs20-test", + 'password': "password", + 'ca_cert': "auth_serv/ca.pem", + 'domain': "example.com", + 'update_identifier': "1234" }) + interworking_select(wpas, bssid, "home", freq="2412") + interworking_connect(wpas, bssid, "TTLS") + check_sp_type(wpas, "home") + addr1 = wpas.get_driver_status_field("addr") + if addr == addr1: + raise Exception("Did not use random MAC address") + + sta = hapd.get_sta(addr) + if sta['addr'] != "FAIL": + raise Exception("Unexpected STA association with permanent address") + sta = hapd.get_sta(addr1) + if sta['addr'] != addr1: + raise Exception("STA association with random address not found") diff --git a/tests/hwsim/test_sta_dynamic.py b/tests/hwsim/test_sta_dynamic.py index 727bc70e3..1bbdc83a3 100644 --- a/tests/hwsim/test_sta_dynamic.py +++ b/tests/hwsim/test_sta_dynamic.py @@ -108,3 +108,58 @@ def test_sta_dynamic_down_up(dev, apdev): if ev is None: raise Exception("Reconnection not reported") hwsim_utils.test_connectivity(wpas.ifname, apdev[0]['ifname']) + +def test_sta_dynamic_random_mac_addr(dev, apdev): + """Dynamically added wpa_supplicant interface and random MAC address""" + params = hostapd.wpa2_params(ssid="sta-dynamic", passphrase="12345678") + hapd = hostapd.add_ap(apdev[0]['ifname'], params) + + wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') + wpas.interface_add("wlan5") + addr0 = wpas.get_driver_status_field("addr") + wpas.request("SET preassoc_mac_addr 1") + wpas.request("SET rand_addr_lifetime 0") + + id = wpas.connect("sta-dynamic", psk="12345678", mac_addr="1", + scan_freq="2412") + addr1 = wpas.get_driver_status_field("addr") + + if addr0 == addr1: + raise Exception("Random MAC address not used") + + sta = hapd.get_sta(addr0) + if sta['addr'] != "FAIL": + raise Exception("Unexpected STA association with permanent address") + sta = hapd.get_sta(addr1) + if sta['addr'] != addr1: + raise Exception("STA association with random address not found") + + wpas.request("DISCONNECT") + wpas.connect_network(id) + addr2 = wpas.get_driver_status_field("addr") + if addr1 != addr2: + raise Exception("Random MAC address changed unexpectedly") + + wpas.remove_network(id) + id = wpas.connect("sta-dynamic", psk="12345678", mac_addr="1", + scan_freq="2412") + addr2 = wpas.get_driver_status_field("addr") + if addr1 == addr2: + raise Exception("Random MAC address did not change") + +def test_sta_dynamic_random_mac_addr_scan(dev, apdev): + """Dynamically added wpa_supplicant interface and random MAC address for scan""" + params = hostapd.wpa2_params(ssid="sta-dynamic", passphrase="12345678") + hapd = hostapd.add_ap(apdev[0]['ifname'], params) + + wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') + wpas.interface_add("wlan5") + addr0 = wpas.get_driver_status_field("addr") + wpas.request("SET preassoc_mac_addr 1") + wpas.request("SET rand_addr_lifetime 0") + + id = wpas.connect("sta-dynamic", psk="12345678", scan_freq="2412") + addr1 = wpas.get_driver_status_field("addr") + + if addr0 != addr1: + raise Exception("Random MAC address used unexpectedly") diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py index 8ab071164..fcb99f169 100644 --- a/tests/hwsim/wpasupplicant.py +++ b/tests/hwsim/wpasupplicant.py @@ -668,7 +668,7 @@ class WpaSupplicant: "wpa_ptk_rekey", "disable_ht", "disable_vht", "bssid", "disable_max_amsdu", "ampdu_factor", "ampdu_density", "disable_ht40", "disable_sgi", "disable_ldpc", - "ht40_intolerant", "update_identifier" ] + "ht40_intolerant", "update_identifier", "mac_addr" ] for field in not_quoted: if field in kwargs and kwargs[field]: self.set_network(id, field, kwargs[field])