tests: Random MAC address use

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2014-09-27 19:12:32 +03:00
parent c267753ba2
commit 816e3df972
3 changed files with 91 additions and 1 deletions

View File

@ -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")

View File

@ -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")

View File

@ -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])