import hostapd
import hwsim_utils
from utils import alloc_fail
+from wpasupplicant import WpaSupplicant
def test_ap_open(dev, apdev):
"""AP with open mode (no security) configuration"""
if ev is not None:
raise Exception("Unexpected dev[2] connectin")
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")
import hostapd
from utils import HwsimSkip
import hwsim_utils
+from wpasupplicant import WpaSupplicant
def check_mib(dev, vals):
mib = dev.get_mib()
raise Exception("WEP key accepted to WPA2 network")
except Exception:
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")
self.ctrl = 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:
groups = subprocess.check_output(["id"])
group = "admin" if "(admin)" in groups else "adm"
cmd = "INTERFACE_ADD " + ifname + "\t" + config + "\t" + driver + "\tDIR=/var/run/wpa_supplicant GROUP=" + group
if 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):
raise Exception("Failed to add a dynamic wpa_supplicant interface")
self.set_ifname(ifname)