diff --git a/tests/hwsim/ap-wpa2-psk.conf b/tests/hwsim/ap-wpa2-psk.conf deleted file mode 100644 index dcf7d5f26..000000000 --- a/tests/hwsim/ap-wpa2-psk.conf +++ /dev/null @@ -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 diff --git a/tests/hwsim/hostapd.py b/tests/hwsim/hostapd.py new file mode 100644 index 000000000..eb0d13f6b --- /dev/null +++ b/tests/hwsim/hostapd.py @@ -0,0 +1,72 @@ +#!/usr/bin/python +# +# Python class for controlling hostapd +# Copyright (c) 2013, Jouni Malinen +# +# 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) diff --git a/tests/hwsim/run-ap-tests.py b/tests/hwsim/run-ap-tests.py index 96f823e75..4554accad 100755 --- a/tests/hwsim/run-ap-tests.py +++ b/tests/hwsim/run-ap-tests.py @@ -1,6 +1,6 @@ #!/usr/bin/python # -# AP WPA2-PSK tests +# AP tests # Copyright (c) 2013, Jouni Malinen # # This software may be distributed under the terms of the BSD license. @@ -14,6 +14,14 @@ import time import logging 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(): idx = 1 @@ -34,6 +42,7 @@ def main(): dev0 = WpaSupplicant('wlan0') dev1 = WpaSupplicant('wlan1') dev = [ dev0, dev1 ] + hapd_ifaces = [ 'wlan2', 'wlan3' ] for d in dev: if not d.ping(): @@ -58,8 +67,7 @@ def main(): #if test_filter not in t.__name__: if test_filter != t.__name__: continue - for d in dev: - d.reset() + reset_devs(dev, hapd_ifaces) print "START " + t.__name__ if t.__doc__: print "Test: " + t.__doc__ @@ -77,8 +85,7 @@ def main(): d.request("NOTE TEST-STOP " + t.__name__) if not test_filter: - for d in dev: - d.reset() + reset_devs(dev, hapd_ifaces) print "passed tests: " + str(passed) print "failed tests: " + str(failed) diff --git a/tests/hwsim/start-ap.sh b/tests/hwsim/start-ap.sh index c5be87f8b..5d327da8a 100755 --- a/tests/hwsim/start-ap.sh +++ b/tests/hwsim/start-ap.sh @@ -6,12 +6,12 @@ HAPD=$DIR/../../hostapd/hostapd WLANTEST=$DIR/../../wlantest/wlantest $DIR/stop-wifi.sh -sudo modprobe mac80211_hwsim radios=3 +sudo modprobe mac80211_hwsim radios=4 mkdir -p $DIR/logs DATE=`date +%s` sudo ifconfig hwsim0 up 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 -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 diff --git a/tests/hwsim/test_ap_tdls.py b/tests/hwsim/test_ap_tdls.py index 44e687cc8..d02875b45 100644 --- a/tests/hwsim/test_ap_tdls.py +++ b/tests/hwsim/test_ap_tdls.py @@ -12,6 +12,20 @@ import logging logger = logging.getLogger(__name__) 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): logger.info("Connect STA " + sta.ifname + " to AP") @@ -109,6 +123,7 @@ def teardown_tdls(sta0, sta1, bssid): def test_ap_wpa2_tdls(dev): """WPA2-PSK AP and two stations using TDLS""" + start_ap_wpa2_psk(ap_ifname) bssid = "02:00:00:00:02:00" wlantest_setup() connect_2sta(dev) @@ -119,6 +134,7 @@ def test_ap_wpa2_tdls(dev): def test_ap_wpa2_tdls_concurrent_init(dev): """Concurrent TDLS setup initiation""" + start_ap_wpa2_psk(ap_ifname) bssid = "02:00:00:00:02:00" wlantest_setup() connect_2sta(dev) @@ -127,6 +143,7 @@ def test_ap_wpa2_tdls_concurrent_init(dev): def test_ap_wpa2_tdls_concurrent_init2(dev): """Concurrent TDLS setup initiation (reverse)""" + start_ap_wpa2_psk(ap_ifname) bssid = "02:00:00:00:02:00" wlantest_setup() connect_2sta(dev) @@ -135,6 +152,7 @@ def test_ap_wpa2_tdls_concurrent_init2(dev): def test_ap_wpa2_tdls_decline_resp(dev): """Decline TDLS Setup Response""" + start_ap_wpa2_psk(ap_ifname) bssid = "02:00:00:00:02:00" wlantest_setup() connect_2sta(dev) @@ -143,6 +161,7 @@ def test_ap_wpa2_tdls_decline_resp(dev): def test_ap_wpa2_tdls_long_lifetime(dev): """TDLS with long TPK lifetime""" + start_ap_wpa2_psk(ap_ifname) bssid = "02:00:00:00:02:00" wlantest_setup() connect_2sta(dev) @@ -151,6 +170,7 @@ def test_ap_wpa2_tdls_long_lifetime(dev): def test_ap_wpa2_tdls_long_frame(dev): """TDLS with long setup/teardown frames""" + start_ap_wpa2_psk(ap_ifname) bssid = "02:00:00:00:02:00" wlantest_setup() connect_2sta(dev) @@ -162,6 +182,7 @@ def test_ap_wpa2_tdls_long_frame(dev): def test_ap_wpa2_tdls_reneg(dev): """Renegotiate TDLS link""" + start_ap_wpa2_psk(ap_ifname) bssid = "02:00:00:00:02:00" wlantest_setup() connect_2sta(dev) @@ -170,6 +191,7 @@ def test_ap_wpa2_tdls_reneg(dev): def test_ap_wpa2_tdls_wrong_lifetime_resp(dev): """Incorrect TPK lifetime in TDLS Setup Response""" + start_ap_wpa2_psk(ap_ifname) bssid = "02:00:00:00:02:00" wlantest_setup() connect_2sta(dev) @@ -178,6 +200,7 @@ def test_ap_wpa2_tdls_wrong_lifetime_resp(dev): def test_ap_wpa2_tdls_diff_rsnie(dev): """TDLS with different RSN IEs""" + start_ap_wpa2_psk(ap_ifname) bssid = "02:00:00:00:02:00" wlantest_setup() connect_2sta(dev)