2013-03-27 07:57:48 -04:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
2013-03-29 11:19:47 -04:00
|
|
|
# TDLS tests
|
2013-03-27 07:57:48 -04:00
|
|
|
# Copyright (c) 2013, Jouni Malinen <j@w1.fi>
|
|
|
|
#
|
|
|
|
# This software may be distributed under the terms of the BSD license.
|
|
|
|
# See README for more details.
|
|
|
|
|
|
|
|
import time
|
|
|
|
import logging
|
2013-10-31 06:46:42 -04:00
|
|
|
logger = logging.getLogger()
|
2013-03-27 07:57:48 -04:00
|
|
|
|
|
|
|
import hwsim_utils
|
2013-03-29 12:37:03 -04:00
|
|
|
from hostapd import HostapdGlobal
|
|
|
|
from hostapd import Hostapd
|
2013-03-29 14:33:25 -04:00
|
|
|
import hostapd
|
2013-03-30 07:47:22 -04:00
|
|
|
from wlantest import Wlantest
|
2013-03-29 12:37:03 -04:00
|
|
|
|
|
|
|
def start_ap_wpa2_psk(ifname):
|
2013-03-29 14:33:25 -04:00
|
|
|
params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678")
|
|
|
|
hostapd.add_ap(ifname, params)
|
2013-03-29 13:15:43 -04:00
|
|
|
|
2013-03-29 14:41:33 -04:00
|
|
|
def connectivity(dev, ap_ifname):
|
2013-03-29 12:51:48 -04:00
|
|
|
hwsim_utils.test_connectivity_sta(dev[0], dev[1])
|
2013-03-30 04:31:18 -04:00
|
|
|
hwsim_utils.test_connectivity(dev[0].ifname, ap_ifname)
|
|
|
|
hwsim_utils.test_connectivity(dev[1].ifname, ap_ifname)
|
2013-03-29 12:51:48 -04:00
|
|
|
|
2013-03-31 09:16:37 -04:00
|
|
|
def connect_2sta(dev, ssid, ap_ifname):
|
2013-03-29 14:41:33 -04:00
|
|
|
dev[0].connect(ssid, psk="12345678")
|
|
|
|
dev[1].connect(ssid, psk="12345678")
|
2013-03-30 04:31:18 -04:00
|
|
|
connectivity(dev, ap_ifname)
|
2013-03-29 14:41:33 -04:00
|
|
|
|
2013-03-31 09:16:37 -04:00
|
|
|
def connect_2sta_wpa2_psk(dev, ap_ifname):
|
|
|
|
connect_2sta(dev, "test-wpa2-psk", ap_ifname)
|
2013-03-29 12:51:48 -04:00
|
|
|
|
2013-03-31 09:16:37 -04:00
|
|
|
def connect_2sta_wpa_psk(dev, ap_ifname):
|
|
|
|
connect_2sta(dev, "test-wpa-psk", ap_ifname)
|
2013-03-29 12:51:48 -04:00
|
|
|
|
2013-03-31 09:16:37 -04:00
|
|
|
def connect_2sta_wpa_psk_mixed(dev, ap_ifname):
|
2013-03-29 14:41:33 -04:00
|
|
|
dev[0].connect("test-wpa-mixed-psk", psk="12345678", proto="WPA")
|
|
|
|
dev[1].connect("test-wpa-mixed-psk", psk="12345678", proto="WPA2")
|
2013-03-30 04:31:18 -04:00
|
|
|
connectivity(dev, ap_ifname)
|
2013-03-29 13:15:43 -04:00
|
|
|
|
2013-03-31 09:16:37 -04:00
|
|
|
def connect_2sta_wep(dev, ap_ifname):
|
2013-03-29 14:41:33 -04:00
|
|
|
dev[0].connect("test-wep", key_mgmt="NONE", wep_key0='"hello"')
|
|
|
|
dev[1].connect("test-wep", key_mgmt="NONE", wep_key0='"hello"')
|
2013-03-30 04:31:18 -04:00
|
|
|
connectivity(dev, ap_ifname)
|
2013-03-29 13:15:43 -04:00
|
|
|
|
2013-03-31 09:16:37 -04:00
|
|
|
def connect_2sta_open(dev, ap_ifname):
|
2013-03-29 14:41:33 -04:00
|
|
|
dev[0].connect("test-open", key_mgmt="NONE")
|
|
|
|
dev[1].connect("test-open", key_mgmt="NONE")
|
2013-03-30 04:31:18 -04:00
|
|
|
connectivity(dev, ap_ifname)
|
2013-03-27 07:57:48 -04:00
|
|
|
|
|
|
|
def wlantest_setup():
|
2013-03-30 07:47:22 -04:00
|
|
|
wt = Wlantest()
|
|
|
|
wt.flush()
|
|
|
|
wt.add_passphrase("12345678")
|
|
|
|
wt.add_wepkey("68656c6c6f")
|
2013-03-27 07:57:48 -04:00
|
|
|
|
2013-03-27 10:05:52 -04:00
|
|
|
def wlantest_tdls_packet_counters(bssid, addr0, addr1):
|
2013-03-30 07:47:22 -04:00
|
|
|
wt = Wlantest()
|
|
|
|
dl = wt.get_tdls_counter("valid_direct_link", bssid, addr0, addr1)
|
|
|
|
inv_dl = wt.get_tdls_counter("invalid_direct_link", bssid, addr0, addr1)
|
|
|
|
ap = wt.get_tdls_counter("valid_ap_path", bssid, addr0, addr1)
|
|
|
|
inv_ap = wt.get_tdls_counter("invalid_ap_path", bssid, addr0, addr1)
|
2013-03-27 10:05:52 -04:00
|
|
|
return [dl,inv_dl,ap,inv_ap]
|
|
|
|
|
|
|
|
def tdls_check_dl(sta0, sta1, bssid, addr0, addr1):
|
2013-03-30 07:47:22 -04:00
|
|
|
wt = Wlantest()
|
|
|
|
wt.tdls_clear(bssid, addr0, addr1)
|
2013-03-27 10:05:52 -04:00
|
|
|
hwsim_utils.test_connectivity_sta(sta0, sta1)
|
|
|
|
[dl,inv_dl,ap,inv_ap] = wlantest_tdls_packet_counters(bssid, addr0, addr1)
|
|
|
|
if dl == 0:
|
|
|
|
raise Exception("No valid frames through direct link")
|
|
|
|
if inv_dl > 0:
|
|
|
|
raise Exception("Invalid frames through direct link")
|
|
|
|
if ap > 0:
|
|
|
|
raise Exception("Unexpected frames through AP path")
|
|
|
|
if inv_ap > 0:
|
|
|
|
raise Exception("Invalid frames through AP path")
|
|
|
|
|
|
|
|
def tdls_check_ap(sta0, sta1, bssid, addr0, addr1):
|
2013-03-30 07:47:22 -04:00
|
|
|
wt = Wlantest()
|
|
|
|
wt.tdls_clear(bssid, addr0, addr1);
|
2013-03-27 10:05:52 -04:00
|
|
|
hwsim_utils.test_connectivity_sta(sta0, sta1)
|
|
|
|
[dl,inv_dl,ap,inv_ap] = wlantest_tdls_packet_counters(bssid, addr0, addr1)
|
|
|
|
if dl > 0:
|
|
|
|
raise Exception("Unexpected frames through direct link")
|
|
|
|
if inv_dl > 0:
|
|
|
|
raise Exception("Invalid frames through direct link")
|
|
|
|
if ap == 0:
|
|
|
|
raise Exception("No valid frames through AP path")
|
|
|
|
if inv_ap > 0:
|
|
|
|
raise Exception("Invalid frames through AP path")
|
|
|
|
|
2013-07-31 06:38:34 -04:00
|
|
|
def check_connectivity(sta0, sta1, ap):
|
|
|
|
hwsim_utils.test_connectivity_sta(sta0, sta1)
|
|
|
|
hwsim_utils.test_connectivity(sta0.ifname, ap['ifname'])
|
|
|
|
hwsim_utils.test_connectivity(sta1.ifname, ap['ifname'])
|
|
|
|
|
2013-07-31 06:27:41 -04:00
|
|
|
def setup_tdls(sta0, sta1, ap, reverse=False, expect_fail=False):
|
2013-03-27 07:57:48 -04:00
|
|
|
logger.info("Setup TDLS")
|
2013-07-31 06:38:34 -04:00
|
|
|
check_connectivity(sta0, sta1, ap)
|
2013-07-31 06:27:41 -04:00
|
|
|
bssid = ap['bssid']
|
2013-03-27 07:57:48 -04:00
|
|
|
addr0 = sta0.p2p_interface_addr()
|
|
|
|
addr1 = sta1.p2p_interface_addr()
|
2013-03-30 07:47:22 -04:00
|
|
|
wt = Wlantest()
|
|
|
|
wt.tdls_clear(bssid, addr0, addr1);
|
|
|
|
wt.tdls_clear(bssid, addr1, addr0);
|
2013-03-27 07:57:48 -04:00
|
|
|
sta0.tdls_setup(addr1)
|
|
|
|
time.sleep(1)
|
2013-03-27 10:40:49 -04:00
|
|
|
if expect_fail:
|
|
|
|
tdls_check_ap(sta0, sta1, bssid, addr0, addr1)
|
|
|
|
return
|
2013-03-27 07:57:48 -04:00
|
|
|
if reverse:
|
|
|
|
addr1 = sta0.p2p_interface_addr()
|
|
|
|
addr0 = sta1.p2p_interface_addr()
|
2013-03-30 07:47:22 -04:00
|
|
|
conf = wt.get_tdls_counter("setup_conf_ok", bssid, addr0, addr1);
|
2013-03-27 07:57:48 -04:00
|
|
|
if conf == 0:
|
|
|
|
raise Exception("No TDLS Setup Confirm (success) seen")
|
2013-03-27 10:05:52 -04:00
|
|
|
tdls_check_dl(sta0, sta1, bssid, addr0, addr1)
|
2013-07-31 06:38:34 -04:00
|
|
|
check_connectivity(sta0, sta1, ap)
|
2013-03-27 07:57:48 -04:00
|
|
|
|
2013-07-31 06:27:41 -04:00
|
|
|
def teardown_tdls(sta0, sta1, ap):
|
2013-03-27 07:57:48 -04:00
|
|
|
logger.info("Teardown TDLS")
|
2013-07-31 06:38:34 -04:00
|
|
|
check_connectivity(sta0, sta1, ap)
|
2013-07-31 06:27:41 -04:00
|
|
|
bssid = ap['bssid']
|
2013-03-27 07:57:48 -04:00
|
|
|
addr0 = sta0.p2p_interface_addr()
|
|
|
|
addr1 = sta1.p2p_interface_addr()
|
|
|
|
sta0.tdls_teardown(addr1)
|
|
|
|
time.sleep(1)
|
2013-03-30 07:47:22 -04:00
|
|
|
wt = Wlantest()
|
|
|
|
teardown = wt.get_tdls_counter("teardown", bssid, addr0, addr1);
|
2013-03-27 07:57:48 -04:00
|
|
|
if teardown == 0:
|
|
|
|
raise Exception("No TDLS Setup Teardown seen")
|
2013-03-27 10:05:52 -04:00
|
|
|
tdls_check_ap(sta0, sta1, bssid, addr0, addr1)
|
2013-07-31 06:38:34 -04:00
|
|
|
check_connectivity(sta0, sta1, ap)
|
2013-03-27 07:57:48 -04:00
|
|
|
|
2013-03-31 09:16:37 -04:00
|
|
|
def test_ap_wpa2_tdls(dev, apdev):
|
2013-03-27 07:57:48 -04:00
|
|
|
"""WPA2-PSK AP and two stations using TDLS"""
|
2013-03-31 09:16:37 -04:00
|
|
|
start_ap_wpa2_psk(apdev[0]['ifname'])
|
2013-03-27 07:57:48 -04:00
|
|
|
wlantest_setup()
|
2013-03-31 09:16:37 -04:00
|
|
|
connect_2sta_wpa2_psk(dev, apdev[0]['ifname'])
|
2013-07-31 06:27:41 -04:00
|
|
|
setup_tdls(dev[0], dev[1], apdev[0])
|
|
|
|
teardown_tdls(dev[0], dev[1], apdev[0])
|
|
|
|
setup_tdls(dev[1], dev[0], apdev[0])
|
|
|
|
#teardown_tdls(dev[0], dev[1], apdev[0])
|
2013-03-27 07:57:48 -04:00
|
|
|
|
2013-03-31 09:16:37 -04:00
|
|
|
def test_ap_wpa2_tdls_concurrent_init(dev, apdev):
|
2013-03-27 07:57:48 -04:00
|
|
|
"""Concurrent TDLS setup initiation"""
|
2013-03-31 09:16:37 -04:00
|
|
|
start_ap_wpa2_psk(apdev[0]['ifname'])
|
2013-03-27 07:57:48 -04:00
|
|
|
wlantest_setup()
|
2013-03-31 09:16:37 -04:00
|
|
|
connect_2sta_wpa2_psk(dev, apdev[0]['ifname'])
|
2013-03-27 07:57:48 -04:00
|
|
|
dev[0].request("SET tdls_testing 0x80")
|
2013-07-31 06:27:41 -04:00
|
|
|
setup_tdls(dev[1], dev[0], apdev[0], reverse=True)
|
2013-03-27 07:57:48 -04:00
|
|
|
|
2013-03-31 09:16:37 -04:00
|
|
|
def test_ap_wpa2_tdls_concurrent_init2(dev, apdev):
|
2013-03-27 07:57:48 -04:00
|
|
|
"""Concurrent TDLS setup initiation (reverse)"""
|
2013-03-31 09:16:37 -04:00
|
|
|
start_ap_wpa2_psk(apdev[0]['ifname'])
|
2013-03-27 07:57:48 -04:00
|
|
|
wlantest_setup()
|
2013-03-31 09:16:37 -04:00
|
|
|
connect_2sta_wpa2_psk(dev, apdev[0]['ifname'])
|
2013-03-27 07:57:48 -04:00
|
|
|
dev[1].request("SET tdls_testing 0x80")
|
2013-07-31 06:27:41 -04:00
|
|
|
setup_tdls(dev[0], dev[1], apdev[0])
|
2013-03-27 07:57:48 -04:00
|
|
|
|
2013-03-31 09:16:37 -04:00
|
|
|
def test_ap_wpa2_tdls_decline_resp(dev, apdev):
|
2013-03-27 10:40:49 -04:00
|
|
|
"""Decline TDLS Setup Response"""
|
2013-03-31 09:16:37 -04:00
|
|
|
start_ap_wpa2_psk(apdev[0]['ifname'])
|
2013-03-27 10:40:49 -04:00
|
|
|
wlantest_setup()
|
2013-03-31 09:16:37 -04:00
|
|
|
connect_2sta_wpa2_psk(dev, apdev[0]['ifname'])
|
2013-03-27 10:40:49 -04:00
|
|
|
dev[1].request("SET tdls_testing 0x200")
|
2013-07-31 06:27:41 -04:00
|
|
|
setup_tdls(dev[1], dev[0], apdev[0], expect_fail=True)
|
2013-03-27 10:40:49 -04:00
|
|
|
|
2013-03-31 09:16:37 -04:00
|
|
|
def test_ap_wpa2_tdls_long_lifetime(dev, apdev):
|
2013-03-27 10:40:49 -04:00
|
|
|
"""TDLS with long TPK lifetime"""
|
2013-03-31 09:16:37 -04:00
|
|
|
start_ap_wpa2_psk(apdev[0]['ifname'])
|
2013-03-27 10:40:49 -04:00
|
|
|
wlantest_setup()
|
2013-03-31 09:16:37 -04:00
|
|
|
connect_2sta_wpa2_psk(dev, apdev[0]['ifname'])
|
2013-03-27 10:40:49 -04:00
|
|
|
dev[1].request("SET tdls_testing 0x40")
|
2013-07-31 06:27:41 -04:00
|
|
|
setup_tdls(dev[1], dev[0], apdev[0])
|
2013-03-27 10:40:49 -04:00
|
|
|
|
2013-03-31 09:16:37 -04:00
|
|
|
def test_ap_wpa2_tdls_long_frame(dev, apdev):
|
2013-03-27 10:40:49 -04:00
|
|
|
"""TDLS with long setup/teardown frames"""
|
2013-03-31 09:16:37 -04:00
|
|
|
start_ap_wpa2_psk(apdev[0]['ifname'])
|
2013-03-27 10:40:49 -04:00
|
|
|
wlantest_setup()
|
2013-03-31 09:16:37 -04:00
|
|
|
connect_2sta_wpa2_psk(dev, apdev[0]['ifname'])
|
2013-03-27 10:40:49 -04:00
|
|
|
dev[0].request("SET tdls_testing 0x1")
|
|
|
|
dev[1].request("SET tdls_testing 0x1")
|
2013-07-31 06:27:41 -04:00
|
|
|
setup_tdls(dev[1], dev[0], apdev[0])
|
|
|
|
teardown_tdls(dev[1], dev[0], apdev[0])
|
|
|
|
setup_tdls(dev[0], dev[1], apdev[0])
|
2013-03-27 10:40:49 -04:00
|
|
|
|
2013-03-31 09:16:37 -04:00
|
|
|
def test_ap_wpa2_tdls_reneg(dev, apdev):
|
2013-03-27 10:40:49 -04:00
|
|
|
"""Renegotiate TDLS link"""
|
2013-03-31 09:16:37 -04:00
|
|
|
start_ap_wpa2_psk(apdev[0]['ifname'])
|
2013-03-27 10:40:49 -04:00
|
|
|
wlantest_setup()
|
2013-03-31 09:16:37 -04:00
|
|
|
connect_2sta_wpa2_psk(dev, apdev[0]['ifname'])
|
2013-07-31 06:27:41 -04:00
|
|
|
setup_tdls(dev[1], dev[0], apdev[0])
|
|
|
|
setup_tdls(dev[0], dev[1], apdev[0])
|
2013-03-27 10:40:49 -04:00
|
|
|
|
2013-03-31 09:16:37 -04:00
|
|
|
def test_ap_wpa2_tdls_wrong_lifetime_resp(dev, apdev):
|
2013-03-27 10:40:49 -04:00
|
|
|
"""Incorrect TPK lifetime in TDLS Setup Response"""
|
2013-03-31 09:16:37 -04:00
|
|
|
start_ap_wpa2_psk(apdev[0]['ifname'])
|
2013-03-27 10:40:49 -04:00
|
|
|
wlantest_setup()
|
2013-03-31 09:16:37 -04:00
|
|
|
connect_2sta_wpa2_psk(dev, apdev[0]['ifname'])
|
2013-03-27 10:40:49 -04:00
|
|
|
dev[1].request("SET tdls_testing 0x10")
|
2013-07-31 06:27:41 -04:00
|
|
|
setup_tdls(dev[0], dev[1], apdev[0], expect_fail=True)
|
2013-03-27 10:40:49 -04:00
|
|
|
|
2013-03-31 09:16:37 -04:00
|
|
|
def test_ap_wpa2_tdls_diff_rsnie(dev, apdev):
|
2013-03-27 10:40:49 -04:00
|
|
|
"""TDLS with different RSN IEs"""
|
2013-03-31 09:16:37 -04:00
|
|
|
start_ap_wpa2_psk(apdev[0]['ifname'])
|
2013-03-27 10:40:49 -04:00
|
|
|
wlantest_setup()
|
2013-03-31 09:16:37 -04:00
|
|
|
connect_2sta_wpa2_psk(dev, apdev[0]['ifname'])
|
2013-03-27 10:40:49 -04:00
|
|
|
dev[1].request("SET tdls_testing 0x2")
|
2013-07-31 06:27:41 -04:00
|
|
|
setup_tdls(dev[1], dev[0], apdev[0])
|
|
|
|
teardown_tdls(dev[1], dev[0], apdev[0])
|
2013-03-27 10:40:49 -04:00
|
|
|
|
2013-03-31 09:16:37 -04:00
|
|
|
def test_ap_wpa_tdls(dev, apdev):
|
2013-03-29 12:51:48 -04:00
|
|
|
"""WPA-PSK AP and two stations using TDLS"""
|
2013-03-31 09:16:37 -04:00
|
|
|
hostapd.add_ap(apdev[0]['ifname'],
|
|
|
|
hostapd.wpa_params(ssid="test-wpa-psk",
|
|
|
|
passphrase="12345678"))
|
2013-03-29 12:51:48 -04:00
|
|
|
wlantest_setup()
|
2013-03-31 09:16:37 -04:00
|
|
|
connect_2sta_wpa_psk(dev, apdev[0]['ifname'])
|
2013-07-31 06:27:41 -04:00
|
|
|
setup_tdls(dev[0], dev[1], apdev[0])
|
|
|
|
teardown_tdls(dev[0], dev[1], apdev[0])
|
|
|
|
setup_tdls(dev[1], dev[0], apdev[0])
|
2013-03-29 12:51:48 -04:00
|
|
|
|
2013-03-31 09:16:37 -04:00
|
|
|
def test_ap_wpa_mixed_tdls(dev, apdev):
|
2013-03-29 12:51:48 -04:00
|
|
|
"""WPA+WPA2-PSK AP and two stations using TDLS"""
|
2013-03-31 09:16:37 -04:00
|
|
|
hostapd.add_ap(apdev[0]['ifname'],
|
|
|
|
hostapd.wpa_mixed_params(ssid="test-wpa-mixed-psk",
|
|
|
|
passphrase="12345678"))
|
2013-03-29 12:51:48 -04:00
|
|
|
wlantest_setup()
|
2013-03-31 09:16:37 -04:00
|
|
|
connect_2sta_wpa_psk_mixed(dev, apdev[0]['ifname'])
|
2013-07-31 06:27:41 -04:00
|
|
|
setup_tdls(dev[0], dev[1], apdev[0])
|
|
|
|
teardown_tdls(dev[0], dev[1], apdev[0])
|
|
|
|
setup_tdls(dev[1], dev[0], apdev[0])
|
2013-03-29 12:51:48 -04:00
|
|
|
|
2013-03-31 09:16:37 -04:00
|
|
|
def test_ap_wep_tdls(dev, apdev):
|
2013-03-29 13:15:43 -04:00
|
|
|
"""WEP AP and two stations using TDLS"""
|
2013-03-31 09:16:37 -04:00
|
|
|
hostapd.add_ap(apdev[0]['ifname'],
|
|
|
|
{ "ssid": "test-wep", "wep_key0": '"hello"' })
|
2013-03-29 13:15:43 -04:00
|
|
|
wlantest_setup()
|
2013-03-31 09:16:37 -04:00
|
|
|
connect_2sta_wep(dev, apdev[0]['ifname'])
|
2013-07-31 06:27:41 -04:00
|
|
|
setup_tdls(dev[0], dev[1], apdev[0])
|
|
|
|
teardown_tdls(dev[0], dev[1], apdev[0])
|
|
|
|
setup_tdls(dev[1], dev[0], apdev[0])
|
2013-03-29 13:15:43 -04:00
|
|
|
|
2013-03-31 09:16:37 -04:00
|
|
|
def test_ap_open_tdls(dev, apdev):
|
2013-03-29 13:15:43 -04:00
|
|
|
"""Open AP and two stations using TDLS"""
|
2013-03-31 09:16:37 -04:00
|
|
|
hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" })
|
2013-03-29 13:15:43 -04:00
|
|
|
wlantest_setup()
|
2013-03-31 09:16:37 -04:00
|
|
|
connect_2sta_open(dev, apdev[0]['ifname'])
|
2013-07-31 06:27:41 -04:00
|
|
|
setup_tdls(dev[0], dev[1], apdev[0])
|
|
|
|
teardown_tdls(dev[0], dev[1], apdev[0])
|
|
|
|
setup_tdls(dev[1], dev[0], apdev[0])
|