tests: Configure hostapd dynamically during the tests
This makes it more convenient to change hostapd parameters between the test cases. Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
9f46d57f2b
commit
b8cd4c542f
5 changed files with 109 additions and 22 deletions
|
@ -1,15 +0,0 @@
|
||||||
driver=nl80211
|
|
||||||
interface=wlan2
|
|
||||||
|
|
||||||
hw_mode=g
|
|
||||||
channel=1
|
|
||||||
ieee80211n=1
|
|
||||||
|
|
||||||
ctrl_interface=/var/run/hostapd
|
|
||||||
ctrl_interface_group=admin
|
|
||||||
|
|
||||||
ssid=test-wpa2-psk
|
|
||||||
wpa=2
|
|
||||||
wpa_key_mgmt=WPA-PSK
|
|
||||||
wpa_pairwise=CCMP
|
|
||||||
wpa_passphrase=12345678
|
|
72
tests/hwsim/hostapd.py
Normal file
72
tests/hwsim/hostapd.py
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
#
|
||||||
|
# Python class for controlling hostapd
|
||||||
|
# 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 os
|
||||||
|
import time
|
||||||
|
import logging
|
||||||
|
import wpaspy
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
hapd_ctrl = '/var/run/hostapd'
|
||||||
|
hapd_global = 'hostapd-global'
|
||||||
|
|
||||||
|
class HostapdGlobal:
|
||||||
|
def __init__(self):
|
||||||
|
self.ctrl = wpaspy.Ctrl(hapd_global)
|
||||||
|
|
||||||
|
def add(self, ifname):
|
||||||
|
res = self.ctrl.request("ADD " + ifname + " " + hapd_ctrl)
|
||||||
|
if not "OK" in res:
|
||||||
|
raise Exception("Could not add hostapd interface " + ifname)
|
||||||
|
|
||||||
|
def remove(self, ifname):
|
||||||
|
self.ctrl.request("REMOVE " + ifname)
|
||||||
|
|
||||||
|
|
||||||
|
class Hostapd:
|
||||||
|
def __init__(self, ifname):
|
||||||
|
self.ifname = ifname
|
||||||
|
self.ctrl = wpaspy.Ctrl(os.path.join(hapd_ctrl, ifname))
|
||||||
|
|
||||||
|
def request(self, cmd):
|
||||||
|
logger.debug(self.ifname + ": CTRL: " + cmd)
|
||||||
|
return self.ctrl.request(cmd)
|
||||||
|
|
||||||
|
def ping(self):
|
||||||
|
return "PONG" in self.request("PING")
|
||||||
|
|
||||||
|
def set(self, field, value):
|
||||||
|
logger.debug(self.ifname + ": SET " + field + "=" + value)
|
||||||
|
if not "OK" in self.request("SET " + field + " " + value):
|
||||||
|
raise Exception("Failed to set hostapd parameter " + field)
|
||||||
|
|
||||||
|
def set_defaults(self):
|
||||||
|
self.set("driver", "nl80211")
|
||||||
|
self.set("hw_mode", "g")
|
||||||
|
self.set("channel", "1")
|
||||||
|
self.set("ieee80211n", "1")
|
||||||
|
|
||||||
|
def set_open(self, ssid):
|
||||||
|
self.set_defaults()
|
||||||
|
self.set("ssid", ssid)
|
||||||
|
|
||||||
|
def set_wpa2_psk(self, ssid, passphrase):
|
||||||
|
self.set_defaults()
|
||||||
|
self.set("ssid", ssid)
|
||||||
|
self.set("wpa_passphrase", passphrase)
|
||||||
|
self.set("wpa", "2")
|
||||||
|
self.set("wpa_key_mgmt", "WPA-PSK")
|
||||||
|
self.set("rsn_pairwise", "CCMP")
|
||||||
|
|
||||||
|
def enable(self):
|
||||||
|
if not "OK" in self.ctrl.request("ENABLE"):
|
||||||
|
raise Exception("Failed to enable hostapd interface " + self.ifname)
|
||||||
|
|
||||||
|
def disable(self):
|
||||||
|
if not "OK" in self.ctrl.request("ENABLE"):
|
||||||
|
raise Exception("Failed to disable hostapd interface " + self.ifname)
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
#
|
#
|
||||||
# AP WPA2-PSK tests
|
# AP tests
|
||||||
# Copyright (c) 2013, Jouni Malinen <j@w1.fi>
|
# Copyright (c) 2013, Jouni Malinen <j@w1.fi>
|
||||||
#
|
#
|
||||||
# This software may be distributed under the terms of the BSD license.
|
# This software may be distributed under the terms of the BSD license.
|
||||||
|
@ -14,6 +14,14 @@ import time
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from wpasupplicant import WpaSupplicant
|
from wpasupplicant import WpaSupplicant
|
||||||
|
from hostapd import HostapdGlobal
|
||||||
|
|
||||||
|
def reset_devs(dev, hapd_ifaces):
|
||||||
|
for d in dev:
|
||||||
|
d.reset()
|
||||||
|
hapd = HostapdGlobal()
|
||||||
|
for h in hapd_ifaces:
|
||||||
|
hapd.remove(h)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
idx = 1
|
idx = 1
|
||||||
|
@ -34,6 +42,7 @@ def main():
|
||||||
dev0 = WpaSupplicant('wlan0')
|
dev0 = WpaSupplicant('wlan0')
|
||||||
dev1 = WpaSupplicant('wlan1')
|
dev1 = WpaSupplicant('wlan1')
|
||||||
dev = [ dev0, dev1 ]
|
dev = [ dev0, dev1 ]
|
||||||
|
hapd_ifaces = [ 'wlan2', 'wlan3' ]
|
||||||
|
|
||||||
for d in dev:
|
for d in dev:
|
||||||
if not d.ping():
|
if not d.ping():
|
||||||
|
@ -58,8 +67,7 @@ def main():
|
||||||
#if test_filter not in t.__name__:
|
#if test_filter not in t.__name__:
|
||||||
if test_filter != t.__name__:
|
if test_filter != t.__name__:
|
||||||
continue
|
continue
|
||||||
for d in dev:
|
reset_devs(dev, hapd_ifaces)
|
||||||
d.reset()
|
|
||||||
print "START " + t.__name__
|
print "START " + t.__name__
|
||||||
if t.__doc__:
|
if t.__doc__:
|
||||||
print "Test: " + t.__doc__
|
print "Test: " + t.__doc__
|
||||||
|
@ -77,8 +85,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:
|
||||||
for d in dev:
|
reset_devs(dev, hapd_ifaces)
|
||||||
d.reset()
|
|
||||||
|
|
||||||
print "passed tests: " + str(passed)
|
print "passed tests: " + str(passed)
|
||||||
print "failed tests: " + str(failed)
|
print "failed tests: " + str(failed)
|
||||||
|
|
|
@ -6,12 +6,12 @@ HAPD=$DIR/../../hostapd/hostapd
|
||||||
WLANTEST=$DIR/../../wlantest/wlantest
|
WLANTEST=$DIR/../../wlantest/wlantest
|
||||||
|
|
||||||
$DIR/stop-wifi.sh
|
$DIR/stop-wifi.sh
|
||||||
sudo modprobe mac80211_hwsim radios=3
|
sudo modprobe mac80211_hwsim radios=4
|
||||||
mkdir -p $DIR/logs
|
mkdir -p $DIR/logs
|
||||||
DATE=`date +%s`
|
DATE=`date +%s`
|
||||||
sudo ifconfig hwsim0 up
|
sudo ifconfig hwsim0 up
|
||||||
sudo $WLANTEST -i hwsim0 -c -d > $DIR/logs/$DATE-hwsim0 &
|
sudo $WLANTEST -i hwsim0 -c -d > $DIR/logs/$DATE-hwsim0 &
|
||||||
sudo $WPAS -Dnl80211 -iwlan0 -c $DIR/p2p0.conf -ddKt > $DIR/logs/$DATE-log0 &
|
sudo $WPAS -Dnl80211 -iwlan0 -c $DIR/p2p0.conf -ddKt > $DIR/logs/$DATE-log0 &
|
||||||
sudo $WPAS -Dnl80211 -iwlan1 -c $DIR/p2p1.conf -ddKt > $DIR/logs/$DATE-log1 &
|
sudo $WPAS -Dnl80211 -iwlan1 -c $DIR/p2p1.conf -ddKt > $DIR/logs/$DATE-log1 &
|
||||||
sudo $HAPD -ddKt $DIR/ap-wpa2-psk.conf -ddKt > $DIR/logs/$DATE-log2 &
|
sudo $HAPD -ddKt -g $DIR/hostapd-global -G admin -ddKt > $DIR/logs/$DATE-hostapd &
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
|
@ -12,6 +12,20 @@ import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
import hwsim_utils
|
import hwsim_utils
|
||||||
|
from hostapd import HostapdGlobal
|
||||||
|
from hostapd import Hostapd
|
||||||
|
|
||||||
|
ap_ifname = 'wlan2'
|
||||||
|
|
||||||
|
def start_ap_wpa2_psk(ifname):
|
||||||
|
logger.info("Starting WPA2-PSK AP " + ifname)
|
||||||
|
hapd_global = HostapdGlobal()
|
||||||
|
hapd_global.add(ifname)
|
||||||
|
hapd = Hostapd(ifname)
|
||||||
|
if not hapd.ping():
|
||||||
|
raise Exception("Could not ping hostapd")
|
||||||
|
hapd.set_wpa2_psk("test-wpa2-psk", "12345678")
|
||||||
|
hapd.enable()
|
||||||
|
|
||||||
def connect_sta(sta):
|
def connect_sta(sta):
|
||||||
logger.info("Connect STA " + sta.ifname + " to AP")
|
logger.info("Connect STA " + sta.ifname + " to AP")
|
||||||
|
@ -109,6 +123,7 @@ def teardown_tdls(sta0, sta1, bssid):
|
||||||
|
|
||||||
def test_ap_wpa2_tdls(dev):
|
def test_ap_wpa2_tdls(dev):
|
||||||
"""WPA2-PSK AP and two stations using TDLS"""
|
"""WPA2-PSK AP and two stations using TDLS"""
|
||||||
|
start_ap_wpa2_psk(ap_ifname)
|
||||||
bssid = "02:00:00:00:02:00"
|
bssid = "02:00:00:00:02:00"
|
||||||
wlantest_setup()
|
wlantest_setup()
|
||||||
connect_2sta(dev)
|
connect_2sta(dev)
|
||||||
|
@ -119,6 +134,7 @@ def test_ap_wpa2_tdls(dev):
|
||||||
|
|
||||||
def test_ap_wpa2_tdls_concurrent_init(dev):
|
def test_ap_wpa2_tdls_concurrent_init(dev):
|
||||||
"""Concurrent TDLS setup initiation"""
|
"""Concurrent TDLS setup initiation"""
|
||||||
|
start_ap_wpa2_psk(ap_ifname)
|
||||||
bssid = "02:00:00:00:02:00"
|
bssid = "02:00:00:00:02:00"
|
||||||
wlantest_setup()
|
wlantest_setup()
|
||||||
connect_2sta(dev)
|
connect_2sta(dev)
|
||||||
|
@ -127,6 +143,7 @@ def test_ap_wpa2_tdls_concurrent_init(dev):
|
||||||
|
|
||||||
def test_ap_wpa2_tdls_concurrent_init2(dev):
|
def test_ap_wpa2_tdls_concurrent_init2(dev):
|
||||||
"""Concurrent TDLS setup initiation (reverse)"""
|
"""Concurrent TDLS setup initiation (reverse)"""
|
||||||
|
start_ap_wpa2_psk(ap_ifname)
|
||||||
bssid = "02:00:00:00:02:00"
|
bssid = "02:00:00:00:02:00"
|
||||||
wlantest_setup()
|
wlantest_setup()
|
||||||
connect_2sta(dev)
|
connect_2sta(dev)
|
||||||
|
@ -135,6 +152,7 @@ def test_ap_wpa2_tdls_concurrent_init2(dev):
|
||||||
|
|
||||||
def test_ap_wpa2_tdls_decline_resp(dev):
|
def test_ap_wpa2_tdls_decline_resp(dev):
|
||||||
"""Decline TDLS Setup Response"""
|
"""Decline TDLS Setup Response"""
|
||||||
|
start_ap_wpa2_psk(ap_ifname)
|
||||||
bssid = "02:00:00:00:02:00"
|
bssid = "02:00:00:00:02:00"
|
||||||
wlantest_setup()
|
wlantest_setup()
|
||||||
connect_2sta(dev)
|
connect_2sta(dev)
|
||||||
|
@ -143,6 +161,7 @@ def test_ap_wpa2_tdls_decline_resp(dev):
|
||||||
|
|
||||||
def test_ap_wpa2_tdls_long_lifetime(dev):
|
def test_ap_wpa2_tdls_long_lifetime(dev):
|
||||||
"""TDLS with long TPK lifetime"""
|
"""TDLS with long TPK lifetime"""
|
||||||
|
start_ap_wpa2_psk(ap_ifname)
|
||||||
bssid = "02:00:00:00:02:00"
|
bssid = "02:00:00:00:02:00"
|
||||||
wlantest_setup()
|
wlantest_setup()
|
||||||
connect_2sta(dev)
|
connect_2sta(dev)
|
||||||
|
@ -151,6 +170,7 @@ def test_ap_wpa2_tdls_long_lifetime(dev):
|
||||||
|
|
||||||
def test_ap_wpa2_tdls_long_frame(dev):
|
def test_ap_wpa2_tdls_long_frame(dev):
|
||||||
"""TDLS with long setup/teardown frames"""
|
"""TDLS with long setup/teardown frames"""
|
||||||
|
start_ap_wpa2_psk(ap_ifname)
|
||||||
bssid = "02:00:00:00:02:00"
|
bssid = "02:00:00:00:02:00"
|
||||||
wlantest_setup()
|
wlantest_setup()
|
||||||
connect_2sta(dev)
|
connect_2sta(dev)
|
||||||
|
@ -162,6 +182,7 @@ def test_ap_wpa2_tdls_long_frame(dev):
|
||||||
|
|
||||||
def test_ap_wpa2_tdls_reneg(dev):
|
def test_ap_wpa2_tdls_reneg(dev):
|
||||||
"""Renegotiate TDLS link"""
|
"""Renegotiate TDLS link"""
|
||||||
|
start_ap_wpa2_psk(ap_ifname)
|
||||||
bssid = "02:00:00:00:02:00"
|
bssid = "02:00:00:00:02:00"
|
||||||
wlantest_setup()
|
wlantest_setup()
|
||||||
connect_2sta(dev)
|
connect_2sta(dev)
|
||||||
|
@ -170,6 +191,7 @@ def test_ap_wpa2_tdls_reneg(dev):
|
||||||
|
|
||||||
def test_ap_wpa2_tdls_wrong_lifetime_resp(dev):
|
def test_ap_wpa2_tdls_wrong_lifetime_resp(dev):
|
||||||
"""Incorrect TPK lifetime in TDLS Setup Response"""
|
"""Incorrect TPK lifetime in TDLS Setup Response"""
|
||||||
|
start_ap_wpa2_psk(ap_ifname)
|
||||||
bssid = "02:00:00:00:02:00"
|
bssid = "02:00:00:00:02:00"
|
||||||
wlantest_setup()
|
wlantest_setup()
|
||||||
connect_2sta(dev)
|
connect_2sta(dev)
|
||||||
|
@ -178,6 +200,7 @@ def test_ap_wpa2_tdls_wrong_lifetime_resp(dev):
|
||||||
|
|
||||||
def test_ap_wpa2_tdls_diff_rsnie(dev):
|
def test_ap_wpa2_tdls_diff_rsnie(dev):
|
||||||
"""TDLS with different RSN IEs"""
|
"""TDLS with different RSN IEs"""
|
||||||
|
start_ap_wpa2_psk(ap_ifname)
|
||||||
bssid = "02:00:00:00:02:00"
|
bssid = "02:00:00:00:02:00"
|
||||||
wlantest_setup()
|
wlantest_setup()
|
||||||
connect_2sta(dev)
|
connect_2sta(dev)
|
||||||
|
|
Loading…
Reference in a new issue