import logging
import binascii
import struct
+import tempfile
import wpaspy
import remotehost
import utils
return hapd_global.send_file(src, dst)
def acl_file(dev, apdev, conf):
- filename = os.path.join("/tmp", conf)
+ fd, filename = tempfile.mkstemp(dir='/tmp', prefix=conf + '-')
+ f = os.fdopen(fd, 'w')
if conf == 'hostapd.macaddr':
- with open(filename, 'w') as f:
- mac0 = dev[0].get_status_field("address")
- f.write(mac0 + '\n')
- f.write("02:00:00:00:00:12\n")
- f.write("02:00:00:00:00:34\n")
- f.write("-02:00:00:00:00:12\n")
- f.write("-02:00:00:00:00:34\n")
- f.write("01:01:01:01:01:01\n")
- f.write("03:01:01:01:01:03\n")
+ mac0 = dev[0].get_status_field("address")
+ f.write(mac0 + '\n')
+ f.write("02:00:00:00:00:12\n")
+ f.write("02:00:00:00:00:34\n")
+ f.write("-02:00:00:00:00:12\n")
+ f.write("-02:00:00:00:00:34\n")
+ f.write("01:01:01:01:01:01\n")
+ f.write("03:01:01:01:01:03\n")
elif conf == 'hostapd.accept':
- with open(filename, 'w') as f:
- mac0 = dev[0].get_status_field("address")
- mac1 = dev[1].get_status_field("address")
- f.write(mac0 + " 1\n")
- f.write(mac1 + " 2\n")
+ mac0 = dev[0].get_status_field("address")
+ mac1 = dev[1].get_status_field("address")
+ f.write(mac0 + " 1\n")
+ f.write(mac1 + " 2\n")
elif conf == 'hostapd.accept2':
- with open(filename, 'w') as f:
- mac0 = dev[0].get_status_field("address")
- mac1 = dev[1].get_status_field("address")
- mac2 = dev[2].get_status_field("address")
- f.write(mac0 + " 1\n")
- f.write(mac1 + " 2\n")
- f.write(mac2 + " 3\n")
+ mac0 = dev[0].get_status_field("address")
+ mac1 = dev[1].get_status_field("address")
+ mac2 = dev[2].get_status_field("address")
+ f.write(mac0 + " 1\n")
+ f.write(mac1 + " 2\n")
+ f.write(mac2 + " 3\n")
else:
+ f.close()
+ os.unlink(filename)
return conf
return filename
return bssid
def cfg_file(apdev, conf, ifname=None):
- # put cfg file in /tmp directory
- fname = os.path.join("/tmp", conf)
-
match = re.search(r'^bss-.+', conf)
if match:
- with open(fname, 'w') as f:
- idx = ''.join(filter(str.isdigit, conf.split('-')[-1]))
- if ifname is None:
- ifname = apdev['ifname']
- if idx != '1':
- ifname = ifname + '-' + idx
-
- f.write("driver=nl80211\n")
- f.write("ctrl_interface=/var/run/hostapd\n")
- f.write("hw_mode=g\n")
- f.write("channel=1\n")
- f.write("ieee80211n=1\n")
- if conf.startswith('bss-ht40-'):
- f.write("ht_capab=[HT40+]\n")
- f.write("interface=%s\n" % ifname)
-
- f.write("ssid=bss-%s\n" % idx)
- if conf == 'bss-2-dup.conf':
- bssid = apdev['bssid']
- else:
- bssid = bssid_inc(apdev, int(idx) - 1)
- f.write("bssid=%s\n" % bssid)
- else:
- return conf
+ # put cfg file in /tmp directory
+ fd, fname = tempfile.mkstemp(dir='/tmp', prefix=conf + '-')
+ f = os.fdopen(fd, 'w')
+ idx = ''.join(filter(str.isdigit, conf.split('-')[-1]))
+ if ifname is None:
+ ifname = apdev['ifname']
+ if idx != '1':
+ ifname = ifname + '-' + idx
+
+ f.write("driver=nl80211\n")
+ f.write("ctrl_interface=/var/run/hostapd\n")
+ f.write("hw_mode=g\n")
+ f.write("channel=1\n")
+ f.write("ieee80211n=1\n")
+ if conf.startswith('bss-ht40-'):
+ f.write("ht_capab=[HT40+]\n")
+ f.write("interface=%s\n" % ifname)
+
+ f.write("ssid=bss-%s\n" % idx)
+ if conf == 'bss-2-dup.conf':
+ bssid = apdev['bssid']
+ else:
+ bssid = bssid_inc(apdev, int(idx) - 1)
+ f.write("bssid=%s\n" % bssid)
+
+ return fname
- return fname
+ return conf
run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, conndev="brvlan1")
if "[WPA2-FT/PSK-CCMP]" not in dev[0].request("SCAN_RESULTS"):
raise Exception("Scan results missing RSN element info")
+ if filename.startswith('/tmp/'):
+ os.unlink(filename)
def test_ap_ft_vlan_disconnected(dev, apdev):
"""WPA2-PSK-FT AP with VLAN and local key generation"""
run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, conndev="brvlan1")
if "[WPA2-FT/PSK-CCMP]" not in dev[0].request("SCAN_RESULTS"):
raise Exception("Scan results missing RSN element info")
+ if filename.startswith('/tmp/'):
+ os.unlink(filename)
def test_ap_ft_vlan_2(dev, apdev):
"""WPA2-PSK-FT AP with VLAN and dest-AP does not have VLAN info locally"""
force_initial_conn_to_first_ap=True)
if "[WPA2-FT/PSK-CCMP]" not in dev[0].request("SCAN_RESULTS"):
raise Exception("Scan results missing RSN element info")
+ if filename.startswith('/tmp/'):
+ os.unlink(filename)
def test_ap_ft_many(dev, apdev):
"""WPA2-PSK-FT AP multiple times"""
run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, roams=50,
conndev="brvlan1")
+ if filename.startswith('/tmp/'):
+ os.unlink(filename)
def test_ap_ft_mixed(dev, apdev):
"""WPA2-PSK-FT mixed-mode AP"""
conndev="brvlan1")
check_mib(dev[0], [("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-4"),
("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-4")])
+ if filename.startswith('/tmp/'):
+ os.unlink(filename)
def test_ap_ft_over_ds_many(dev, apdev):
"""WPA2-PSK-FT AP over DS multiple times"""
run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
roams=50, conndev="brvlan1")
+ if filename.startswith('/tmp/'):
+ os.unlink(filename)
@remote_compatible
def test_ap_ft_over_ds_unknown_target(dev, apdev):
run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
conndev="brvlan1")
+ if filename.startswith('/tmp/'):
+ os.unlink(filename)
def start_ft_sae(dev, apdev, wpa_ptk_rekey=None, sae_pwe=None):
if "SAE" not in dev.get_capability("auth_alg"):
ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
if ev is not None:
raise Exception("Unexpected association")
+ if filename.startswith('/tmp/'):
+ os.unlink(filename)
def test_ap_acl_deny(dev, apdev):
"""MAC ACL deny list"""
ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
if ev is not None:
raise Exception("Unexpected association")
+ if filename.startswith('/tmp/'):
+ os.unlink(filename)
def test_ap_acl_mgmt(dev, apdev):
"""MAC ACL accept/deny management"""
hapd.request("DENY_ACL ADD_MAC " + dev[0].own_addr())
dev[0].wait_disconnected()
dev[0].request("DISCONNECT")
+ if filename.startswith('/tmp/'):
+ os.unlink(filename)
@remote_compatible
def test_ap_wds_sta(dev, apdev):
hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan1")
hwsim_utils.test_connectivity_iface(dev[1], hapd, "brvlan2")
hwsim_utils.test_connectivity(dev[2], hapd)
+ if filename.startswith('/tmp/'):
+ os.unlink(filename)
def test_ap_vlan_file_open(dev, apdev):
"""AP VLAN with open network and vlan_file mapping"""
hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan1")
hwsim_utils.test_connectivity_iface(dev[1], hapd, "brvlan2")
hwsim_utils.test_connectivity(dev[2], hapd)
+ if filename.startswith('/tmp/'):
+ os.unlink(filename)
def test_ap_vlan_file_open2(dev, apdev):
"""AP VLAN with open network and vlan_file mapping (2)"""
hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan1")
hwsim_utils.test_connectivity_iface(dev[1], hapd, "brvlan2")
hwsim_utils.test_connectivity_iface(dev[2], hapd, "hwsimbr3")
+ if filename.startswith('/tmp/'):
+ os.unlink(filename)
def test_ap_vlan_file_parsing(dev, apdev, params):
"""hostapd vlan_file/mac_file parsing"""
hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan1")
hwsim_utils.test_connectivity_iface(dev[1], hapd, "brvlan2")
hwsim_utils.test_connectivity(dev[2], hapd)
+ if filename.startswith('/tmp/'):
+ os.unlink(filename)
def test_ap_vlan_wpa2_radius(dev, apdev):
"""AP VLAN with WPA2-Enterprise and RADIUS attributes"""
hwsim_utils.test_connectivity_iface(dev[0], hapd, "test_br_vlan1")
hwsim_utils.test_connectivity_iface(dev[1], hapd, "test_br_vlan2")
hwsim_utils.test_connectivity(dev[2], hapd)
+ if filename.startswith('/tmp/'):
+ os.unlink(filename)
def test_ap_vlan_wpa2_radius_id_change(dev, apdev):
"""AP VLAN with WPA2-Enterprise and RADIUS attributes changing VLANID"""
hwsim_utils.test_connectivity_iface(dev[0], hapd, "brlo.1")
hwsim_utils.test_connectivity_iface(dev[1], hapd, "brlo.2")
hwsim_utils.test_connectivity(dev[2], hapd)
+ if filename.startswith('/tmp/'):
+ os.unlink(filename)
def ap_vlan_iface_cleanup_multibss_cleanup():
subprocess.call(['ifconfig', 'dummy0', 'down'],
dev[0].request("DISCONNECT")
dev[0].wait_disconnected()
+ if filename.startswith('/tmp/'):
+ os.unlink(filename)
finally:
subprocess.call(['ip', 'link', 'set', 'dev', 'brvlan1', 'down'])
dev[0].connect("test-vlan", psk="12345678", scan_freq="2412")
hapd.wait_sta()
hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan1")
+ if filename.startswith('/tmp/'):
+ os.unlink(filename)
def test_ap_vlan_psk(dev, apdev, params):
"""AP VLAN based on PSK/passphrase"""
import logging
logger = logging.getLogger()
+import os
from remotehost import remote_compatible
import hostapd
import hwsim_utils
ev = dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"], 1)
if ev is not None:
raise Exception("Unexpected disconnection")
+ if filename.startswith('/tmp/'):
+ os.unlink(filename)
def test_hapd_ctrl_set_accept_mac_file(dev, apdev):
"""hostapd and SET accept_mac_file ctrl_iface command"""
ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], 1)
if ev is not None:
raise Exception("Unexpected disconnection")
+ if filename.startswith('/tmp/'):
+ os.unlink(filename)
def test_hapd_ctrl_set_accept_mac_file_vlan(dev, apdev):
"""hostapd and SET accept_mac_file ctrl_iface command (VLAN ID)"""
raise Exception("Unexpected SET failure")
dev[1].wait_disconnected(timeout=15)
dev[0].wait_disconnected(timeout=15)
+ if filename.startswith('/tmp/'):
+ os.unlink(filename)
@remote_compatible
def test_hapd_ctrl_set_error_cases(dev, apdev):