tests: wpa_supplicant and station interface in a bridge
Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
e6dd8196e5
commit
a1512a0cc7
3 changed files with 76 additions and 1 deletions
|
@ -13,6 +13,7 @@ import time
|
||||||
import hostapd
|
import hostapd
|
||||||
import hwsim_utils
|
import hwsim_utils
|
||||||
from utils import alloc_fail
|
from utils import alloc_fail
|
||||||
|
from wpasupplicant import WpaSupplicant
|
||||||
|
|
||||||
def test_ap_open(dev, apdev):
|
def test_ap_open(dev, apdev):
|
||||||
"""AP with open mode (no security) configuration"""
|
"""AP with open mode (no security) configuration"""
|
||||||
|
@ -240,3 +241,41 @@ def test_bssid_black_white_list(dev, apdev):
|
||||||
if ev is not None:
|
if ev is not None:
|
||||||
raise Exception("Unexpected dev[2] connectin")
|
raise Exception("Unexpected dev[2] connectin")
|
||||||
dev[2].request("REMOVE_NETWORK all")
|
dev[2].request("REMOVE_NETWORK all")
|
||||||
|
|
||||||
|
def test_ap_open_wpas_in_bridge(dev, apdev):
|
||||||
|
"""Open mode AP and wpas interface in a bridge"""
|
||||||
|
br_ifname='sta-br0'
|
||||||
|
ifname='wlan5'
|
||||||
|
try:
|
||||||
|
_test_ap_open_wpas_in_bridge(dev, apdev)
|
||||||
|
finally:
|
||||||
|
subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'down'])
|
||||||
|
subprocess.call(['brctl', 'delif', br_ifname, ifname])
|
||||||
|
subprocess.call(['brctl', 'delbr', br_ifname])
|
||||||
|
subprocess.call(['iw', ifname, 'set', '4addr', 'on'])
|
||||||
|
|
||||||
|
def _test_ap_open_wpas_in_bridge(dev, apdev):
|
||||||
|
hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
|
||||||
|
|
||||||
|
br_ifname='sta-br0'
|
||||||
|
ifname='wlan5'
|
||||||
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
||||||
|
# First, try a failure case of adding an interface
|
||||||
|
try:
|
||||||
|
wpas.interface_add(ifname, br_ifname=br_ifname)
|
||||||
|
raise Exception("Interface addition succeeded unexpectedly")
|
||||||
|
except Exception, e:
|
||||||
|
if "Failed to add" in str(e):
|
||||||
|
logger.info("Ignore expected interface_add failure due to missing bridge interface: " + str(e))
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
|
# Next, add the bridge interface and add the interface again
|
||||||
|
subprocess.call(['brctl', 'addbr', br_ifname])
|
||||||
|
subprocess.call(['brctl', 'setfd', br_ifname, '0'])
|
||||||
|
subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'up'])
|
||||||
|
subprocess.call(['iw', ifname, 'set', '4addr', 'on'])
|
||||||
|
subprocess.check_call(['brctl', 'addif', br_ifname, ifname])
|
||||||
|
wpas.interface_add(ifname, br_ifname=br_ifname)
|
||||||
|
|
||||||
|
wpas.connect("open", key_mgmt="NONE", scan_freq="2412")
|
||||||
|
|
|
@ -18,6 +18,7 @@ import time
|
||||||
import hostapd
|
import hostapd
|
||||||
from utils import HwsimSkip
|
from utils import HwsimSkip
|
||||||
import hwsim_utils
|
import hwsim_utils
|
||||||
|
from wpasupplicant import WpaSupplicant
|
||||||
|
|
||||||
def check_mib(dev, vals):
|
def check_mib(dev, vals):
|
||||||
mib = dev.get_mib()
|
mib = dev.get_mib()
|
||||||
|
@ -987,3 +988,33 @@ def test_ap_wpa2_psk_wep(dev, apdev):
|
||||||
raise Exception("WEP key accepted to WPA2 network")
|
raise Exception("WEP key accepted to WPA2 network")
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def test_ap_wpa2_psk_wpas_in_bridge(dev, apdev):
|
||||||
|
"""WPA2-PSK AP and wpas interface in a bridge"""
|
||||||
|
br_ifname='sta-br0'
|
||||||
|
ifname='wlan5'
|
||||||
|
try:
|
||||||
|
_test_ap_wpa2_psk_wpas_in_bridge(dev, apdev)
|
||||||
|
finally:
|
||||||
|
subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'down'])
|
||||||
|
subprocess.call(['brctl', 'delif', br_ifname, ifname])
|
||||||
|
subprocess.call(['brctl', 'delbr', br_ifname])
|
||||||
|
subprocess.call(['iw', ifname, 'set', '4addr', 'on'])
|
||||||
|
|
||||||
|
def _test_ap_wpa2_psk_wpas_in_bridge(dev, apdev):
|
||||||
|
ssid = "test-wpa2-psk"
|
||||||
|
passphrase = 'qwertyuiop'
|
||||||
|
params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
|
||||||
|
hapd = hostapd.add_ap(apdev[0]['ifname'], params)
|
||||||
|
|
||||||
|
br_ifname='sta-br0'
|
||||||
|
ifname='wlan5'
|
||||||
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
||||||
|
subprocess.call(['brctl', 'addbr', br_ifname])
|
||||||
|
subprocess.call(['brctl', 'setfd', br_ifname, '0'])
|
||||||
|
subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'up'])
|
||||||
|
subprocess.call(['iw', ifname, 'set', '4addr', 'on'])
|
||||||
|
subprocess.check_call(['brctl', 'addif', br_ifname, ifname])
|
||||||
|
wpas.interface_add(ifname, br_ifname=br_ifname)
|
||||||
|
|
||||||
|
wpas.connect(ssid, psk=passphrase, scan_freq="2412")
|
||||||
|
|
|
@ -53,7 +53,8 @@ class WpaSupplicant:
|
||||||
self.ctrl = None
|
self.ctrl = None
|
||||||
self.ifname = None
|
self.ifname = None
|
||||||
|
|
||||||
def interface_add(self, ifname, config="", driver="nl80211", drv_params=None):
|
def interface_add(self, ifname, config="", driver="nl80211",
|
||||||
|
drv_params=None, br_ifname=None):
|
||||||
try:
|
try:
|
||||||
groups = subprocess.check_output(["id"])
|
groups = subprocess.check_output(["id"])
|
||||||
group = "admin" if "(admin)" in groups else "adm"
|
group = "admin" if "(admin)" in groups else "adm"
|
||||||
|
@ -62,6 +63,10 @@ class WpaSupplicant:
|
||||||
cmd = "INTERFACE_ADD " + ifname + "\t" + config + "\t" + driver + "\tDIR=/var/run/wpa_supplicant GROUP=" + group
|
cmd = "INTERFACE_ADD " + ifname + "\t" + config + "\t" + driver + "\tDIR=/var/run/wpa_supplicant GROUP=" + group
|
||||||
if drv_params:
|
if drv_params:
|
||||||
cmd = cmd + '\t' + drv_params
|
cmd = cmd + '\t' + drv_params
|
||||||
|
if br_ifname:
|
||||||
|
if not drv_params:
|
||||||
|
cmd += '\t'
|
||||||
|
cmd += '\t' + br_ifname
|
||||||
if "FAIL" in self.global_request(cmd):
|
if "FAIL" in self.global_request(cmd):
|
||||||
raise Exception("Failed to add a dynamic wpa_supplicant interface")
|
raise Exception("Failed to add a dynamic wpa_supplicant interface")
|
||||||
self.set_ifname(ifname)
|
self.set_ifname(ifname)
|
||||||
|
|
Loading…
Reference in a new issue