tests: Pass AP devices to test cases

This removes hardcoded assumptions about AP interfaces from test_*.py.

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2013-03-31 16:16:37 +03:00
parent 302b7a1b09
commit ae3ad3284a
5 changed files with 177 additions and 168 deletions

View file

@ -16,12 +16,12 @@ import logging
from wpasupplicant import WpaSupplicant from wpasupplicant import WpaSupplicant
from hostapd import HostapdGlobal from hostapd import HostapdGlobal
def reset_devs(dev, hapd_ifaces): def reset_devs(dev, apdev):
for d in dev: for d in dev:
d.reset() d.reset()
hapd = HostapdGlobal() hapd = HostapdGlobal()
for h in hapd_ifaces: for ap in apdev:
hapd.remove(h) hapd.remove(ap['ifname'])
def main(): def main():
idx = 1 idx = 1
@ -42,7 +42,9 @@ def main():
dev0 = WpaSupplicant('wlan0') dev0 = WpaSupplicant('wlan0')
dev1 = WpaSupplicant('wlan1') dev1 = WpaSupplicant('wlan1')
dev = [ dev0, dev1 ] dev = [ dev0, dev1 ]
hapd_ifaces = [ 'wlan2', 'wlan3' ] apdev = [ ]
apdev.append({"ifname": 'wlan2', "bssid": "02:00:00:00:02:00"})
apdev.append({"ifname": 'wlan3', "bssid": "02:00:00:00:03:00"})
for d in dev: for d in dev:
if not d.ping(): if not d.ping():
@ -50,6 +52,8 @@ def main():
return return
d.reset() d.reset()
print "DEV: " + d.ifname + ": " + d.p2p_dev_addr() print "DEV: " + d.ifname + ": " + d.p2p_dev_addr()
for ap in apdev:
print "APDEV: " + ap['ifname']
tests = [] tests = []
for t in os.listdir("."): for t in os.listdir("."):
@ -69,14 +73,17 @@ def main():
if test_filter: if test_filter:
if test_filter != t.__name__: if test_filter != t.__name__:
continue continue
reset_devs(dev, hapd_ifaces) reset_devs(dev, apdev)
print "START " + t.__name__ print "START " + t.__name__
if t.__doc__: if t.__doc__:
print "Test: " + t.__doc__ print "Test: " + t.__doc__
for d in dev: for d in dev:
d.request("NOTE TEST-START " + t.__name__) d.request("NOTE TEST-START " + t.__name__)
try: try:
t(dev) if t.func_code.co_argcount > 1:
t(dev, apdev)
else:
t(dev)
passed.append(t.__name__) passed.append(t.__name__)
print "PASS " + t.__name__ print "PASS " + t.__name__
except Exception, e: except Exception, e:
@ -87,7 +94,7 @@ def main():
d.request("NOTE TEST-STOP " + t.__name__) d.request("NOTE TEST-STOP " + t.__name__)
if not test_filter: if not test_filter:
reset_devs(dev, hapd_ifaces) reset_devs(dev, apdev)
print "passed tests: " + str(passed) print "passed tests: " + str(passed)
print "failed tests: " + str(failed) print "failed tests: " + str(failed)

View file

@ -15,10 +15,7 @@ import hwsim_utils
import hostapd import hostapd
from wlantest import Wlantest from wlantest import Wlantest
ap_ifname = 'wlan2' def test_ap_pmf_required(dev, apdev):
bssid = "02:00:00:00:02:00"
def test_ap_pmf_required(dev):
"""WPA2-PSK AP with PMF required""" """WPA2-PSK AP with PMF required"""
ssid = "test-pmf-required" ssid = "test-pmf-required"
wt = Wlantest() wt = Wlantest()
@ -27,26 +24,28 @@ def test_ap_pmf_required(dev):
params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678") params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
params["wpa_key_mgmt"] = "WPA-PSK-SHA256"; params["wpa_key_mgmt"] = "WPA-PSK-SHA256";
params["ieee80211w"] = "2"; params["ieee80211w"] = "2";
hostapd.add_ap(ap_ifname, params) hostapd.add_ap(apdev[0]['ifname'], params)
dev[0].connect(ssid, psk="12345678", ieee80211w="1", key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2") dev[0].connect(ssid, psk="12345678", ieee80211w="1",
hwsim_utils.test_connectivity(dev[0].ifname, ap_ifname) key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2")
dev[1].connect(ssid, psk="12345678", ieee80211w="2", key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2") hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
hwsim_utils.test_connectivity(dev[1].ifname, ap_ifname) dev[1].connect(ssid, psk="12345678", ieee80211w="2",
hapd = hostapd.Hostapd(ap_ifname) key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2")
hwsim_utils.test_connectivity(dev[1].ifname, apdev[0]['ifname'])
hapd = hostapd.Hostapd(apdev[0]['ifname'])
hapd.request("SA_QUERY " + dev[0].p2p_interface_addr()) hapd.request("SA_QUERY " + dev[0].p2p_interface_addr())
hapd.request("SA_QUERY " + dev[1].p2p_interface_addr()) hapd.request("SA_QUERY " + dev[1].p2p_interface_addr())
wt.require_ap_pmf_mandatory(bssid) wt.require_ap_pmf_mandatory(apdev[0]['bssid'])
wt.require_sta_pmf(bssid, dev[0].p2p_interface_addr()) wt.require_sta_pmf(apdev[0]['bssid'], dev[0].p2p_interface_addr())
wt.require_sta_pmf_mandatory(bssid, dev[1].p2p_interface_addr()) wt.require_sta_pmf_mandatory(apdev[0]['bssid'], dev[1].p2p_interface_addr())
time.sleep(0.1) time.sleep(0.1)
if wt.get_sta_counter("valid_saqueryresp_tx", bssid, if wt.get_sta_counter("valid_saqueryresp_tx", apdev[0]['bssid'],
dev[0].p2p_interface_addr()) < 1: dev[0].p2p_interface_addr()) < 1:
raise Exception("STA did not reply to SA Query") raise Exception("STA did not reply to SA Query")
if wt.get_sta_counter("valid_saqueryresp_tx", bssid, if wt.get_sta_counter("valid_saqueryresp_tx", apdev[0]['bssid'],
dev[1].p2p_interface_addr()) < 1: dev[1].p2p_interface_addr()) < 1:
raise Exception("STA did not reply to SA Query") raise Exception("STA did not reply to SA Query")
def test_ap_pmf_optional(dev): def test_ap_pmf_optional(dev, apdev):
"""WPA2-PSK AP with PMF optional""" """WPA2-PSK AP with PMF optional"""
ssid = "test-pmf-optional" ssid = "test-pmf-optional"
wt = Wlantest() wt = Wlantest()
@ -55,16 +54,18 @@ def test_ap_pmf_optional(dev):
params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678") params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
params["wpa_key_mgmt"] = "WPA-PSK"; params["wpa_key_mgmt"] = "WPA-PSK";
params["ieee80211w"] = "1"; params["ieee80211w"] = "1";
hostapd.add_ap(ap_ifname, params) hostapd.add_ap(apdev[0]['ifname'], params)
dev[0].connect(ssid, psk="12345678", ieee80211w="1", key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2") dev[0].connect(ssid, psk="12345678", ieee80211w="1",
hwsim_utils.test_connectivity(dev[0].ifname, ap_ifname) key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2")
dev[1].connect(ssid, psk="12345678", ieee80211w="2", key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2") hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
hwsim_utils.test_connectivity(dev[1].ifname, ap_ifname) dev[1].connect(ssid, psk="12345678", ieee80211w="2",
wt.require_ap_pmf_optional(bssid) key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2")
wt.require_sta_pmf(bssid, dev[0].p2p_interface_addr()) hwsim_utils.test_connectivity(dev[1].ifname, apdev[0]['ifname'])
wt.require_sta_pmf_mandatory(bssid, dev[1].p2p_interface_addr()) wt.require_ap_pmf_optional(apdev[0]['bssid'])
wt.require_sta_pmf(apdev[0]['bssid'], dev[0].p2p_interface_addr())
wt.require_sta_pmf_mandatory(apdev[0]['bssid'], dev[1].p2p_interface_addr())
def test_ap_pmf_optional_2akm(dev): def test_ap_pmf_optional_2akm(dev, apdev):
"""WPA2-PSK AP with PMF optional (2 AKMs)""" """WPA2-PSK AP with PMF optional (2 AKMs)"""
ssid = "test-pmf-optional-2akm" ssid = "test-pmf-optional-2akm"
wt = Wlantest() wt = Wlantest()
@ -73,31 +74,37 @@ def test_ap_pmf_optional_2akm(dev):
params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678") params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
params["wpa_key_mgmt"] = "WPA-PSK WPA-PSK-SHA256"; params["wpa_key_mgmt"] = "WPA-PSK WPA-PSK-SHA256";
params["ieee80211w"] = "1"; params["ieee80211w"] = "1";
hostapd.add_ap(ap_ifname, params) hostapd.add_ap(apdev[0]['ifname'], params)
dev[0].connect(ssid, psk="12345678", ieee80211w="1", key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2") dev[0].connect(ssid, psk="12345678", ieee80211w="1",
hwsim_utils.test_connectivity(dev[0].ifname, ap_ifname) key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2")
dev[1].connect(ssid, psk="12345678", ieee80211w="2", key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2") hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
hwsim_utils.test_connectivity(dev[1].ifname, ap_ifname) dev[1].connect(ssid, psk="12345678", ieee80211w="2",
wt.require_ap_pmf_optional(bssid) key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2")
wt.require_sta_pmf(bssid, dev[0].p2p_interface_addr()) hwsim_utils.test_connectivity(dev[1].ifname, apdev[0]['ifname'])
wt.require_sta_key_mgmt(bssid, dev[0].p2p_interface_addr(), "PSK-SHA256") wt.require_ap_pmf_optional(apdev[0]['bssid'])
wt.require_sta_pmf_mandatory(bssid, dev[1].p2p_interface_addr()) wt.require_sta_pmf(apdev[0]['bssid'], dev[0].p2p_interface_addr())
wt.require_sta_key_mgmt(bssid, dev[1].p2p_interface_addr(), "PSK-SHA256") wt.require_sta_key_mgmt(apdev[0]['bssid'], dev[0].p2p_interface_addr(),
"PSK-SHA256")
wt.require_sta_pmf_mandatory(apdev[0]['bssid'], dev[1].p2p_interface_addr())
wt.require_sta_key_mgmt(apdev[0]['bssid'], dev[1].p2p_interface_addr(),
"PSK-SHA256")
def test_ap_pmf_negative(dev): def test_ap_pmf_negative(dev, apdev):
"""WPA2-PSK AP without PMF (negative test)""" """WPA2-PSK AP without PMF (negative test)"""
ssid = "test-pmf-negative" ssid = "test-pmf-negative"
wt = Wlantest() wt = Wlantest()
wt.flush() wt.flush()
wt.add_passphrase("12345678") wt.add_passphrase("12345678")
params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678") params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
hostapd.add_ap(ap_ifname, params) hostapd.add_ap(apdev[0]['ifname'], params)
dev[0].connect(ssid, psk="12345678", ieee80211w="1", key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2") dev[0].connect(ssid, psk="12345678", ieee80211w="1",
hwsim_utils.test_connectivity(dev[0].ifname, ap_ifname) key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2")
hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
try: try:
dev[1].connect(ssid, psk="12345678", ieee80211w="2", key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2") dev[1].connect(ssid, psk="12345678", ieee80211w="2",
hwsim_utils.test_connectivity(dev[1].ifname, ap_ifname) key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2")
hwsim_utils.test_connectivity(dev[1].ifname, apdev[0]['ifname'])
raise Exception("PMF required STA connected to no PMF AP") raise Exception("PMF required STA connected to no PMF AP")
except Exception, e: except Exception, e:
logger.debug("Ignore expected exception: " + str(e)) logger.debug("Ignore expected exception: " + str(e))
wt.require_ap_no_pmf(bssid) wt.require_ap_no_pmf(apdev[0]['bssid'])

View file

@ -14,32 +14,27 @@ logger = logging.getLogger(__name__)
import hwsim_utils import hwsim_utils
import hostapd import hostapd
ap_ifname = 'wlan2' def test_ap_roam_open(dev, apdev):
bssid = "02:00:00:00:02:00"
ap2_ifname = 'wlan3'
bssid2 = "02:00:00:00:03:00"
def test_ap_roam_open(dev):
"""Roam between two open APs""" """Roam between two open APs"""
hostapd.add_ap(ap_ifname, { "ssid": "test-open" }) hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" })
dev[0].connect("test-open", key_mgmt="NONE") dev[0].connect("test-open", key_mgmt="NONE")
hwsim_utils.test_connectivity(dev[0].ifname, ap_ifname) hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
hostapd.add_ap(ap2_ifname, { "ssid": "test-open" }) hostapd.add_ap(apdev[1]['ifname'], { "ssid": "test-open" })
dev[0].scan(type="ONLY") dev[0].scan(type="ONLY")
dev[0].roam(bssid2) dev[0].roam(apdev[1]['bssid'])
hwsim_utils.test_connectivity(dev[0].ifname, ap2_ifname) hwsim_utils.test_connectivity(dev[0].ifname, apdev[1]['ifname'])
dev[0].roam(bssid) dev[0].roam(apdev[0]['bssid'])
hwsim_utils.test_connectivity(dev[0].ifname, ap_ifname) hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
def test_ap_roam_wpa2_psk(dev): def test_ap_roam_wpa2_psk(dev, apdev):
"""Roam between two WPA2-PSK APs""" """Roam between two WPA2-PSK APs"""
params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678") params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678")
hostapd.add_ap(ap_ifname, params) hostapd.add_ap(apdev[0]['ifname'], params)
dev[0].connect("test-wpa2-psk", psk="12345678") dev[0].connect("test-wpa2-psk", psk="12345678")
hwsim_utils.test_connectivity(dev[0].ifname, ap_ifname) hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
hostapd.add_ap(ap2_ifname, params) hostapd.add_ap(apdev[1]['ifname'], params)
dev[0].scan(type="ONLY") dev[0].scan(type="ONLY")
dev[0].roam(bssid2) dev[0].roam(apdev[1]['bssid'])
hwsim_utils.test_connectivity(dev[0].ifname, ap2_ifname) hwsim_utils.test_connectivity(dev[0].ifname, apdev[1]['ifname'])
dev[0].roam(bssid) dev[0].roam(apdev[0]['bssid'])
hwsim_utils.test_connectivity(dev[0].ifname, ap_ifname) hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])

View file

@ -16,8 +16,6 @@ from hostapd import Hostapd
import hostapd import hostapd
from wlantest import Wlantest from wlantest import Wlantest
ap_ifname = 'wlan2'
def start_ap_wpa2_psk(ifname): def start_ap_wpa2_psk(ifname):
params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678") params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678")
hostapd.add_ap(ifname, params) hostapd.add_ap(ifname, params)
@ -27,28 +25,28 @@ def connectivity(dev, ap_ifname):
hwsim_utils.test_connectivity(dev[0].ifname, ap_ifname) hwsim_utils.test_connectivity(dev[0].ifname, ap_ifname)
hwsim_utils.test_connectivity(dev[1].ifname, ap_ifname) hwsim_utils.test_connectivity(dev[1].ifname, ap_ifname)
def connect_2sta(dev, ssid): def connect_2sta(dev, ssid, ap_ifname):
dev[0].connect(ssid, psk="12345678") dev[0].connect(ssid, psk="12345678")
dev[1].connect(ssid, psk="12345678") dev[1].connect(ssid, psk="12345678")
connectivity(dev, ap_ifname) connectivity(dev, ap_ifname)
def connect_2sta_wpa2_psk(dev): def connect_2sta_wpa2_psk(dev, ap_ifname):
connect_2sta(dev, "test-wpa2-psk") connect_2sta(dev, "test-wpa2-psk", ap_ifname)
def connect_2sta_wpa_psk(dev): def connect_2sta_wpa_psk(dev, ap_ifname):
connect_2sta(dev, "test-wpa-psk") connect_2sta(dev, "test-wpa-psk", ap_ifname)
def connect_2sta_wpa_psk_mixed(dev): def connect_2sta_wpa_psk_mixed(dev, ap_ifname):
dev[0].connect("test-wpa-mixed-psk", psk="12345678", proto="WPA") dev[0].connect("test-wpa-mixed-psk", psk="12345678", proto="WPA")
dev[1].connect("test-wpa-mixed-psk", psk="12345678", proto="WPA2") dev[1].connect("test-wpa-mixed-psk", psk="12345678", proto="WPA2")
connectivity(dev, ap_ifname) connectivity(dev, ap_ifname)
def connect_2sta_wep(dev): def connect_2sta_wep(dev, ap_ifname):
dev[0].connect("test-wep", key_mgmt="NONE", wep_key0='"hello"') dev[0].connect("test-wep", key_mgmt="NONE", wep_key0='"hello"')
dev[1].connect("test-wep", key_mgmt="NONE", wep_key0='"hello"') dev[1].connect("test-wep", key_mgmt="NONE", wep_key0='"hello"')
connectivity(dev, ap_ifname) connectivity(dev, ap_ifname)
def connect_2sta_open(dev): def connect_2sta_open(dev, ap_ifname):
dev[0].connect("test-open", key_mgmt="NONE") dev[0].connect("test-open", key_mgmt="NONE")
dev[1].connect("test-open", key_mgmt="NONE") dev[1].connect("test-open", key_mgmt="NONE")
connectivity(dev, ap_ifname) connectivity(dev, ap_ifname)
@ -127,129 +125,134 @@ def teardown_tdls(sta0, sta1, bssid):
raise Exception("No TDLS Setup Teardown seen") raise Exception("No TDLS Setup Teardown seen")
tdls_check_ap(sta0, sta1, bssid, addr0, addr1) tdls_check_ap(sta0, sta1, bssid, addr0, addr1)
def test_ap_wpa2_tdls(dev): def test_ap_wpa2_tdls(dev, apdev):
"""WPA2-PSK AP and two stations using TDLS""" """WPA2-PSK AP and two stations using TDLS"""
start_ap_wpa2_psk(ap_ifname) start_ap_wpa2_psk(apdev[0]['ifname'])
bssid = "02:00:00:00:02:00" bssid = apdev[0]['bssid']
wlantest_setup() wlantest_setup()
connect_2sta_wpa2_psk(dev) connect_2sta_wpa2_psk(dev, apdev[0]['ifname'])
setup_tdls(dev[0], dev[1], bssid) setup_tdls(dev[0], dev[1], bssid)
teardown_tdls(dev[0], dev[1], bssid) teardown_tdls(dev[0], dev[1], bssid)
setup_tdls(dev[1], dev[0], bssid) setup_tdls(dev[1], dev[0], bssid)
#teardown_tdls(dev[0], dev[1], bssid) #teardown_tdls(dev[0], dev[1], bssid)
def test_ap_wpa2_tdls_concurrent_init(dev): def test_ap_wpa2_tdls_concurrent_init(dev, apdev):
"""Concurrent TDLS setup initiation""" """Concurrent TDLS setup initiation"""
start_ap_wpa2_psk(ap_ifname) start_ap_wpa2_psk(apdev[0]['ifname'])
bssid = "02:00:00:00:02:00" bssid = apdev[0]['bssid']
wlantest_setup() wlantest_setup()
connect_2sta_wpa2_psk(dev) connect_2sta_wpa2_psk(dev, apdev[0]['ifname'])
dev[0].request("SET tdls_testing 0x80") dev[0].request("SET tdls_testing 0x80")
setup_tdls(dev[1], dev[0], bssid, reverse=True) setup_tdls(dev[1], dev[0], bssid, reverse=True)
def test_ap_wpa2_tdls_concurrent_init2(dev): def test_ap_wpa2_tdls_concurrent_init2(dev, apdev):
"""Concurrent TDLS setup initiation (reverse)""" """Concurrent TDLS setup initiation (reverse)"""
start_ap_wpa2_psk(ap_ifname) start_ap_wpa2_psk(apdev[0]['ifname'])
bssid = "02:00:00:00:02:00" bssid = apdev[0]['bssid']
wlantest_setup() wlantest_setup()
connect_2sta_wpa2_psk(dev) connect_2sta_wpa2_psk(dev, apdev[0]['ifname'])
dev[1].request("SET tdls_testing 0x80") dev[1].request("SET tdls_testing 0x80")
setup_tdls(dev[0], dev[1], bssid) setup_tdls(dev[0], dev[1], bssid)
def test_ap_wpa2_tdls_decline_resp(dev): def test_ap_wpa2_tdls_decline_resp(dev, apdev):
"""Decline TDLS Setup Response""" """Decline TDLS Setup Response"""
start_ap_wpa2_psk(ap_ifname) start_ap_wpa2_psk(apdev[0]['ifname'])
bssid = "02:00:00:00:02:00" bssid = apdev[0]['bssid']
wlantest_setup() wlantest_setup()
connect_2sta_wpa2_psk(dev) connect_2sta_wpa2_psk(dev, apdev[0]['ifname'])
dev[1].request("SET tdls_testing 0x200") dev[1].request("SET tdls_testing 0x200")
setup_tdls(dev[1], dev[0], bssid, expect_fail=True) setup_tdls(dev[1], dev[0], bssid, expect_fail=True)
def test_ap_wpa2_tdls_long_lifetime(dev): def test_ap_wpa2_tdls_long_lifetime(dev, apdev):
"""TDLS with long TPK lifetime""" """TDLS with long TPK lifetime"""
start_ap_wpa2_psk(ap_ifname) start_ap_wpa2_psk(apdev[0]['ifname'])
bssid = "02:00:00:00:02:00" bssid = apdev[0]['bssid']
wlantest_setup() wlantest_setup()
connect_2sta_wpa2_psk(dev) connect_2sta_wpa2_psk(dev, apdev[0]['ifname'])
dev[1].request("SET tdls_testing 0x40") dev[1].request("SET tdls_testing 0x40")
setup_tdls(dev[1], dev[0], bssid) setup_tdls(dev[1], dev[0], bssid)
def test_ap_wpa2_tdls_long_frame(dev): def test_ap_wpa2_tdls_long_frame(dev, apdev):
"""TDLS with long setup/teardown frames""" """TDLS with long setup/teardown frames"""
start_ap_wpa2_psk(ap_ifname) start_ap_wpa2_psk(apdev[0]['ifname'])
bssid = "02:00:00:00:02:00" bssid = apdev[0]['bssid']
wlantest_setup() wlantest_setup()
connect_2sta_wpa2_psk(dev) connect_2sta_wpa2_psk(dev, apdev[0]['ifname'])
dev[0].request("SET tdls_testing 0x1") dev[0].request("SET tdls_testing 0x1")
dev[1].request("SET tdls_testing 0x1") dev[1].request("SET tdls_testing 0x1")
setup_tdls(dev[1], dev[0], bssid) setup_tdls(dev[1], dev[0], bssid)
teardown_tdls(dev[1], dev[0], bssid) teardown_tdls(dev[1], dev[0], bssid)
setup_tdls(dev[0], dev[1], bssid) setup_tdls(dev[0], dev[1], bssid)
def test_ap_wpa2_tdls_reneg(dev): def test_ap_wpa2_tdls_reneg(dev, apdev):
"""Renegotiate TDLS link""" """Renegotiate TDLS link"""
start_ap_wpa2_psk(ap_ifname) start_ap_wpa2_psk(apdev[0]['ifname'])
bssid = "02:00:00:00:02:00" bssid = apdev[0]['bssid']
wlantest_setup() wlantest_setup()
connect_2sta_wpa2_psk(dev) connect_2sta_wpa2_psk(dev, apdev[0]['ifname'])
setup_tdls(dev[1], dev[0], bssid) setup_tdls(dev[1], dev[0], bssid)
setup_tdls(dev[0], dev[1], bssid) setup_tdls(dev[0], dev[1], bssid)
def test_ap_wpa2_tdls_wrong_lifetime_resp(dev): def test_ap_wpa2_tdls_wrong_lifetime_resp(dev, apdev):
"""Incorrect TPK lifetime in TDLS Setup Response""" """Incorrect TPK lifetime in TDLS Setup Response"""
start_ap_wpa2_psk(ap_ifname) start_ap_wpa2_psk(apdev[0]['ifname'])
bssid = "02:00:00:00:02:00" bssid = apdev[0]['bssid']
wlantest_setup() wlantest_setup()
connect_2sta_wpa2_psk(dev) connect_2sta_wpa2_psk(dev, apdev[0]['ifname'])
dev[1].request("SET tdls_testing 0x10") dev[1].request("SET tdls_testing 0x10")
setup_tdls(dev[0], dev[1], bssid, expect_fail=True) setup_tdls(dev[0], dev[1], bssid, expect_fail=True)
def test_ap_wpa2_tdls_diff_rsnie(dev): def test_ap_wpa2_tdls_diff_rsnie(dev, apdev):
"""TDLS with different RSN IEs""" """TDLS with different RSN IEs"""
start_ap_wpa2_psk(ap_ifname) start_ap_wpa2_psk(apdev[0]['ifname'])
bssid = "02:00:00:00:02:00" bssid = apdev[0]['bssid']
wlantest_setup() wlantest_setup()
connect_2sta_wpa2_psk(dev) connect_2sta_wpa2_psk(dev, apdev[0]['ifname'])
dev[1].request("SET tdls_testing 0x2") dev[1].request("SET tdls_testing 0x2")
setup_tdls(dev[1], dev[0], bssid) setup_tdls(dev[1], dev[0], bssid)
teardown_tdls(dev[1], dev[0], bssid) teardown_tdls(dev[1], dev[0], bssid)
def test_ap_wpa_tdls(dev): def test_ap_wpa_tdls(dev, apdev):
"""WPA-PSK AP and two stations using TDLS""" """WPA-PSK AP and two stations using TDLS"""
hostapd.add_ap(ap_ifname, hostapd.wpa_params(ssid="test-wpa-psk", passphrase="12345678")) hostapd.add_ap(apdev[0]['ifname'],
bssid = "02:00:00:00:02:00" hostapd.wpa_params(ssid="test-wpa-psk",
passphrase="12345678"))
bssid = apdev[0]['bssid']
wlantest_setup() wlantest_setup()
connect_2sta_wpa_psk(dev) connect_2sta_wpa_psk(dev, apdev[0]['ifname'])
setup_tdls(dev[0], dev[1], bssid) setup_tdls(dev[0], dev[1], bssid)
teardown_tdls(dev[0], dev[1], bssid) teardown_tdls(dev[0], dev[1], bssid)
setup_tdls(dev[1], dev[0], bssid) setup_tdls(dev[1], dev[0], bssid)
def test_ap_wpa_mixed_tdls(dev): def test_ap_wpa_mixed_tdls(dev, apdev):
"""WPA+WPA2-PSK AP and two stations using TDLS""" """WPA+WPA2-PSK AP and two stations using TDLS"""
hostapd.add_ap(ap_ifname, hostapd.wpa_mixed_params(ssid="test-wpa-mixed-psk", passphrase="12345678")) hostapd.add_ap(apdev[0]['ifname'],
bssid = "02:00:00:00:02:00" hostapd.wpa_mixed_params(ssid="test-wpa-mixed-psk",
passphrase="12345678"))
bssid = apdev[0]['bssid']
wlantest_setup() wlantest_setup()
connect_2sta_wpa_psk_mixed(dev) connect_2sta_wpa_psk_mixed(dev, apdev[0]['ifname'])
setup_tdls(dev[0], dev[1], bssid) setup_tdls(dev[0], dev[1], bssid)
teardown_tdls(dev[0], dev[1], bssid) teardown_tdls(dev[0], dev[1], bssid)
setup_tdls(dev[1], dev[0], bssid) setup_tdls(dev[1], dev[0], bssid)
def test_ap_wep_tdls(dev): def test_ap_wep_tdls(dev, apdev):
"""WEP AP and two stations using TDLS""" """WEP AP and two stations using TDLS"""
hostapd.add_ap(ap_ifname, { "ssid": "test-wep", "wep_key0": '"hello"' }) hostapd.add_ap(apdev[0]['ifname'],
bssid = "02:00:00:00:02:00" { "ssid": "test-wep", "wep_key0": '"hello"' })
bssid = apdev[0]['bssid']
wlantest_setup() wlantest_setup()
connect_2sta_wep(dev) connect_2sta_wep(dev, apdev[0]['ifname'])
setup_tdls(dev[0], dev[1], bssid) setup_tdls(dev[0], dev[1], bssid)
teardown_tdls(dev[0], dev[1], bssid) teardown_tdls(dev[0], dev[1], bssid)
setup_tdls(dev[1], dev[0], bssid) setup_tdls(dev[1], dev[0], bssid)
def test_ap_open_tdls(dev): def test_ap_open_tdls(dev, apdev):
"""Open AP and two stations using TDLS""" """Open AP and two stations using TDLS"""
hostapd.add_ap(ap_ifname, { "ssid": "test-open" }) hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" })
bssid = "02:00:00:00:02:00" bssid = apdev[0]['bssid']
wlantest_setup() wlantest_setup()
connect_2sta_open(dev) connect_2sta_open(dev, apdev[0]['ifname'])
setup_tdls(dev[0], dev[1], bssid) setup_tdls(dev[0], dev[1], bssid)
teardown_tdls(dev[0], dev[1], bssid) teardown_tdls(dev[0], dev[1], bssid)
setup_tdls(dev[1], dev[0], bssid) setup_tdls(dev[1], dev[0], bssid)

View file

@ -14,17 +14,12 @@ logger = logging.getLogger(__name__)
import hwsim_utils import hwsim_utils
import hostapd import hostapd
ap_ifname = 'wlan2' def test_ap_wps_init(dev, apdev):
bssid = "02:00:00:00:02:00"
ap2_ifname = 'wlan3'
bssid2 = "02:00:00:00:03:00"
def test_ap_wps_init(dev):
"""Initial AP configuration with first WPS Enrollee""" """Initial AP configuration with first WPS Enrollee"""
ssid = "test-wps" ssid = "test-wps"
hostapd.add_ap(ap_ifname, hostapd.add_ap(apdev[0]['ifname'],
{ "ssid": ssid, "eap_server": "1", "wps_state": "1" }) { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
hapd = hostapd.Hostapd(ap_ifname) hapd = hostapd.Hostapd(apdev[0]['ifname'])
logger.info("WPS provisioning step") logger.info("WPS provisioning step")
hapd.request("WPS_PBC") hapd.request("WPS_PBC")
dev[0].dump_monitor() dev[0].dump_monitor()
@ -33,7 +28,7 @@ def test_ap_wps_init(dev):
if ev is None: if ev is None:
raise Exception("Association with the AP timed out") raise Exception("Association with the AP timed out")
status = dev[0].get_status() status = dev[0].get_status()
if status['wpa_state'] != 'COMPLETED' or status['bssid'] != bssid: if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
raise Exception("Not fully connected") raise Exception("Not fully connected")
if status['ssid'] != ssid: if status['ssid'] != ssid:
raise Exception("Unexpected SSID") raise Exception("Unexpected SSID")
@ -42,14 +37,14 @@ def test_ap_wps_init(dev):
if status['key_mgmt'] != 'WPA2-PSK': if status['key_mgmt'] != 'WPA2-PSK':
raise Exception("Unexpected key_mgmt") raise Exception("Unexpected key_mgmt")
def test_ap_wps_conf(dev): def test_ap_wps_conf(dev, apdev):
"""WPS PBC provisioning with configured AP""" """WPS PBC provisioning with configured AP"""
ssid = "test-wps-conf" ssid = "test-wps-conf"
hostapd.add_ap(ap_ifname, hostapd.add_ap(apdev[0]['ifname'],
{ "ssid": ssid, "eap_server": "1", "wps_state": "2", { "ssid": ssid, "eap_server": "1", "wps_state": "2",
"wpa_passphrase": "12345678", "wpa": "2", "wpa_passphrase": "12345678", "wpa": "2",
"wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
hapd = hostapd.Hostapd(ap_ifname) hapd = hostapd.Hostapd(apdev[0]['ifname'])
logger.info("WPS provisioning step") logger.info("WPS provisioning step")
hapd.request("WPS_PBC") hapd.request("WPS_PBC")
dev[0].dump_monitor() dev[0].dump_monitor()
@ -58,8 +53,10 @@ def test_ap_wps_conf(dev):
if ev is None: if ev is None:
raise Exception("Association with the AP timed out") raise Exception("Association with the AP timed out")
status = dev[0].get_status() status = dev[0].get_status()
if status['wpa_state'] != 'COMPLETED' or status['bssid'] != bssid: if status['wpa_state'] != 'COMPLETED':
raise Exception("Not fully connected") raise Exception("Not fully connected")
if status['bssid'] != apdev[0]['bssid']:
raise Exception("Unexpected BSSID")
if status['ssid'] != ssid: if status['ssid'] != ssid:
raise Exception("Unexpected SSID") raise Exception("Unexpected SSID")
if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP': if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
@ -67,14 +64,14 @@ def test_ap_wps_conf(dev):
if status['key_mgmt'] != 'WPA2-PSK': if status['key_mgmt'] != 'WPA2-PSK':
raise Exception("Unexpected key_mgmt") raise Exception("Unexpected key_mgmt")
def test_ap_wps_conf_pin(dev): def test_ap_wps_conf_pin(dev, apdev):
"""WPS PIN provisioning with configured AP""" """WPS PIN provisioning with configured AP"""
ssid = "test-wps-conf-pin" ssid = "test-wps-conf-pin"
hostapd.add_ap(ap_ifname, hostapd.add_ap(apdev[0]['ifname'],
{ "ssid": ssid, "eap_server": "1", "wps_state": "2", { "ssid": ssid, "eap_server": "1", "wps_state": "2",
"wpa_passphrase": "12345678", "wpa": "2", "wpa_passphrase": "12345678", "wpa": "2",
"wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
hapd = hostapd.Hostapd(ap_ifname) hapd = hostapd.Hostapd(apdev[0]['ifname'])
logger.info("WPS provisioning step") logger.info("WPS provisioning step")
pin = dev[0].wps_read_pin() pin = dev[0].wps_read_pin()
hapd.request("WPS_PIN any " + pin) hapd.request("WPS_PIN any " + pin)
@ -84,7 +81,7 @@ def test_ap_wps_conf_pin(dev):
if ev is None: if ev is None:
raise Exception("Association with the AP timed out") raise Exception("Association with the AP timed out")
status = dev[0].get_status() status = dev[0].get_status()
if status['wpa_state'] != 'COMPLETED' or status['bssid'] != bssid: if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
raise Exception("Not fully connected") raise Exception("Not fully connected")
if status['ssid'] != ssid: if status['ssid'] != ssid:
raise Exception("Unexpected SSID") raise Exception("Unexpected SSID")
@ -93,11 +90,11 @@ def test_ap_wps_conf_pin(dev):
if status['key_mgmt'] != 'WPA2-PSK': if status['key_mgmt'] != 'WPA2-PSK':
raise Exception("Unexpected key_mgmt") raise Exception("Unexpected key_mgmt")
def test_ap_wps_reg_connect(dev): def test_ap_wps_reg_connect(dev, apdev):
"""WPS registrar using AP PIN to connect""" """WPS registrar using AP PIN to connect"""
ssid = "test-wps-conf-ap-pin" ssid = "test-wps-conf-ap-pin"
appin = "12345670" appin = "12345670"
hostapd.add_ap(ap_ifname, hostapd.add_ap(apdev[0]['ifname'],
{ "ssid": ssid, "eap_server": "1", "wps_state": "2", { "ssid": ssid, "eap_server": "1", "wps_state": "2",
"wpa_passphrase": "12345678", "wpa": "2", "wpa_passphrase": "12345678", "wpa": "2",
"wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
@ -105,12 +102,12 @@ def test_ap_wps_reg_connect(dev):
logger.info("WPS provisioning step") logger.info("WPS provisioning step")
dev[0].request("BSS_FLUSH") dev[0].request("BSS_FLUSH")
dev[0].dump_monitor() dev[0].dump_monitor()
dev[0].request("WPS_REG " + bssid + " " + appin) dev[0].request("WPS_REG " + apdev[0]['bssid'] + " " + appin)
ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15) ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
if ev is None: if ev is None:
raise Exception("Association with the AP timed out") raise Exception("Association with the AP timed out")
status = dev[0].get_status() status = dev[0].get_status()
if status['wpa_state'] != 'COMPLETED' or status['bssid'] != bssid: if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
raise Exception("Not fully connected") raise Exception("Not fully connected")
if status['ssid'] != ssid: if status['ssid'] != ssid:
raise Exception("Unexpected SSID") raise Exception("Unexpected SSID")
@ -119,11 +116,11 @@ def test_ap_wps_reg_connect(dev):
if status['key_mgmt'] != 'WPA2-PSK': if status['key_mgmt'] != 'WPA2-PSK':
raise Exception("Unexpected key_mgmt") raise Exception("Unexpected key_mgmt")
def test_ap_wps_reg_config(dev): def test_ap_wps_reg_config(dev, apdev):
"""WPS registrar configuring and AP using AP PIN""" """WPS registrar configuring and AP using AP PIN"""
ssid = "test-wps-init-ap-pin" ssid = "test-wps-init-ap-pin"
appin = "12345670" appin = "12345670"
hostapd.add_ap(ap_ifname, hostapd.add_ap(apdev[0]['ifname'],
{ "ssid": ssid, "eap_server": "1", "wps_state": "2", { "ssid": ssid, "eap_server": "1", "wps_state": "2",
"ap_pin": appin}) "ap_pin": appin})
logger.info("WPS configuration step") logger.info("WPS configuration step")
@ -131,12 +128,12 @@ def test_ap_wps_reg_config(dev):
dev[0].dump_monitor() dev[0].dump_monitor()
new_ssid = "wps-new-ssid" new_ssid = "wps-new-ssid"
new_passphrase = "1234567890" new_passphrase = "1234567890"
dev[0].request("WPS_REG " + bssid + " " + appin + " " + new_ssid.encode("hex") + " WPA2PSK CCMP " + new_passphrase.encode("hex")) dev[0].request("WPS_REG " + apdev[0]['bssid'] + " " + appin + " " + new_ssid.encode("hex") + " WPA2PSK CCMP " + new_passphrase.encode("hex"))
ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15) ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
if ev is None: if ev is None:
raise Exception("Association with the AP timed out") raise Exception("Association with the AP timed out")
status = dev[0].get_status() status = dev[0].get_status()
if status['wpa_state'] != 'COMPLETED' or status['bssid'] != bssid: if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
raise Exception("Not fully connected") raise Exception("Not fully connected")
if status['ssid'] != new_ssid: if status['ssid'] != new_ssid:
raise Exception("Unexpected SSID") raise Exception("Unexpected SSID")
@ -145,21 +142,21 @@ def test_ap_wps_reg_config(dev):
if status['key_mgmt'] != 'WPA2-PSK': if status['key_mgmt'] != 'WPA2-PSK':
raise Exception("Unexpected key_mgmt") raise Exception("Unexpected key_mgmt")
def test_ap_wps_pbc_overlap_2ap(dev): def test_ap_wps_pbc_overlap_2ap(dev, apdev):
"""WPS PBC session overlap with two active APs""" """WPS PBC session overlap with two active APs"""
hostapd.add_ap(ap_ifname, hostapd.add_ap(apdev[0]['ifname'],
{ "ssid": "wps1", "eap_server": "1", "wps_state": "2", { "ssid": "wps1", "eap_server": "1", "wps_state": "2",
"wpa_passphrase": "12345678", "wpa": "2", "wpa_passphrase": "12345678", "wpa": "2",
"wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
"wps_independent": "1"}) "wps_independent": "1"})
hostapd.add_ap(ap2_ifname, hostapd.add_ap(apdev[1]['ifname'],
{ "ssid": "wps2", "eap_server": "1", "wps_state": "2", { "ssid": "wps2", "eap_server": "1", "wps_state": "2",
"wpa_passphrase": "123456789", "wpa": "2", "wpa_passphrase": "123456789", "wpa": "2",
"wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
"wps_independent": "1"}) "wps_independent": "1"})
hapd = hostapd.Hostapd(ap_ifname) hapd = hostapd.Hostapd(apdev[0]['ifname'])
hapd.request("WPS_PBC") hapd.request("WPS_PBC")
hapd2 = hostapd.Hostapd(ap2_ifname) hapd2 = hostapd.Hostapd(apdev[1]['ifname'])
hapd2.request("WPS_PBC") hapd2.request("WPS_PBC")
logger.info("WPS provisioning step") logger.info("WPS provisioning step")
dev[0].dump_monitor() dev[0].dump_monitor()
@ -168,14 +165,14 @@ def test_ap_wps_pbc_overlap_2ap(dev):
if ev is None: if ev is None:
raise Exception("PBC session overlap not detected") raise Exception("PBC session overlap not detected")
def test_ap_wps_pbc_overlap_2sta(dev): def test_ap_wps_pbc_overlap_2sta(dev, apdev):
"""WPS PBC session overlap with two active STAs""" """WPS PBC session overlap with two active STAs"""
ssid = "test-wps-pbc-overlap" ssid = "test-wps-pbc-overlap"
hostapd.add_ap(ap_ifname, hostapd.add_ap(apdev[0]['ifname'],
{ "ssid": ssid, "eap_server": "1", "wps_state": "2", { "ssid": ssid, "eap_server": "1", "wps_state": "2",
"wpa_passphrase": "12345678", "wpa": "2", "wpa_passphrase": "12345678", "wpa": "2",
"wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
hapd = hostapd.Hostapd(ap_ifname) hapd = hostapd.Hostapd(apdev[0]['ifname'])
logger.info("WPS provisioning step") logger.info("WPS provisioning step")
hapd.request("WPS_PBC") hapd.request("WPS_PBC")
dev[0].request("BSS_FLUSH") dev[0].request("BSS_FLUSH")