tests: Verify dynamic wpa_supplicant interface addition/removal
Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
d52747c99e
commit
9489637b42
6 changed files with 87 additions and 15 deletions
|
@ -33,6 +33,13 @@ def reset_devs(dev, apdev):
|
|||
logger.info("Failed to reset device " + d.ifname)
|
||||
print str(e)
|
||||
ok = False
|
||||
|
||||
try:
|
||||
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
||||
wpas.interface_remove("wlan5")
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
try:
|
||||
hapd = HostapdGlobal()
|
||||
hapd.remove('wlan3-3')
|
||||
|
@ -318,6 +325,13 @@ def main():
|
|||
logger.info("Failed to issue TEST-STOP after {} for {}".format(name, d.ifname))
|
||||
logger.info(e)
|
||||
result = "FAIL"
|
||||
try:
|
||||
wpas = WpaSupplicant("wlan5", "/tmp/wpas-wlan5")
|
||||
rename_log(args.logdir, 'log5', name, wpas)
|
||||
if not args.no_reset:
|
||||
wpas.remove_ifname()
|
||||
except Exception, e:
|
||||
pass
|
||||
if args.no_reset:
|
||||
print "Leaving devices in current state"
|
||||
else:
|
||||
|
@ -325,7 +339,6 @@ def main():
|
|||
|
||||
for i in range(0, 3):
|
||||
rename_log(args.logdir, 'log' + str(i), name, dev[i])
|
||||
|
||||
try:
|
||||
hapd = HostapdGlobal()
|
||||
except Exception, e:
|
||||
|
|
|
@ -58,13 +58,15 @@ else
|
|||
fi
|
||||
|
||||
$DIR/stop.sh
|
||||
test -f /proc/modules && sudo modprobe mac80211_hwsim radios=5
|
||||
test -f /proc/modules && sudo modprobe mac80211_hwsim radios=6
|
||||
sudo ifconfig hwsim0 up
|
||||
sudo $WLANTEST -i hwsim0 -n $LOGDIR/hwsim0.pcapng -c -dt -L $LOGDIR/hwsim0 &
|
||||
for i in 0 1 2; do
|
||||
sudo $(printf -- "$VALGRIND_WPAS" $i) $WPAS -g /tmp/wpas-wlan$i -G$GROUP -Dnl80211 -iwlan$i -c $LOGDIR/p2p$i.conf \
|
||||
-ddKt$TRACE -f $LOGDIR/log$i &
|
||||
done
|
||||
sudo $(printf -- "$VALGRIND_WPAS" 5) $WPAS -g /tmp/wpas-wlan5 -G$GROUP \
|
||||
-ddKt$TRACE -f $LOGDIR/log5 &
|
||||
sudo $VALGRIND_HAPD $HAPD -ddKt$TRACE -g /var/run/hostapd-global -G $GROUP -ddKt -f $LOGDIR/hostapd &
|
||||
|
||||
sleep 1
|
||||
|
|
|
@ -56,14 +56,16 @@ for i in `pidof valgrind.bin`; do
|
|||
fi
|
||||
done
|
||||
|
||||
for i in /tmp/wpas-wlan0 /tmp/wpas-wlan1 /tmp/wpas-wlan2 /var/run/hostapd-global /tmp/hlr_auc_gw.sock /tmp/wpa_ctrl_* /tmp/eap_sim_db_*; do
|
||||
if [ -e $i ]; then
|
||||
count=0
|
||||
for i in /tmp/wpas-wlan0 /tmp/wpas-wlan1 /tmp/wpas-wlan2 /tmp/wpas-wlan5 /var/run/hostapd-global /tmp/hlr_auc_gw.sock /tmp/wpa_ctrl_* /tmp/eap_sim_db_*; do
|
||||
count=$(($count + 1))
|
||||
if [ $count -lt 7 -a -e $i ]; then
|
||||
echo "Waiting for ctrl_iface $i to disappear"
|
||||
sleep 1
|
||||
if [ -e $i ]; then
|
||||
echo "Control interface file $i exists - remove it"
|
||||
sudo rm $i
|
||||
fi
|
||||
fi
|
||||
if [ -e $i ]; then
|
||||
echo "Control interface file $i exists - remove it"
|
||||
sudo rm $i
|
||||
fi
|
||||
done
|
||||
|
||||
|
|
26
tests/hwsim/test_sta_dynamic.py
Normal file
26
tests/hwsim/test_sta_dynamic.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/python
|
||||
#
|
||||
# Dynamic wpa_supplicant interface
|
||||
# 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 logging
|
||||
logger = logging.getLogger()
|
||||
import time
|
||||
|
||||
import hwsim_utils
|
||||
import hostapd
|
||||
from wpasupplicant import WpaSupplicant
|
||||
|
||||
def test_sta_dynamic(dev, apdev):
|
||||
"""Dynamically added wpa_supplicant interface"""
|
||||
params = hostapd.wpa2_params(ssid="sta-dynamic", passphrase="12345678")
|
||||
hostapd.add_ap(apdev[0]['ifname'], params)
|
||||
|
||||
logger.info("Create a dynamic wpa_supplicant interface and connect")
|
||||
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
||||
wpas.interface_add("wlan5")
|
||||
|
||||
wpas.connect("sta-dynamic", psk="12345678", scan_freq="2412")
|
|
@ -105,7 +105,7 @@ kvm \
|
|||
-fsdev local,security_model=none,id=fsdev-logs,path="$LOGDIR",writeout=immediate \
|
||||
-device virtio-9p-pci,id=fs-logs,fsdev=fsdev-logs,mount_tag=logshare \
|
||||
-monitor null -serial stdio -serial file:$LOGDIR/console \
|
||||
-append "mac80211_hwsim.channels=$CHANNELS mac80211_hwsim.radios=5 init=$CMD testdir=$TESTDIR console=$KVMOUT root=/dev/root rootflags=trans=virtio,version=9p2000.u ro rootfstype=9p EPATH=$EPATH ARGS=$*"
|
||||
-append "mac80211_hwsim.channels=$CHANNELS mac80211_hwsim.radios=6 init=$CMD testdir=$TESTDIR console=$KVMOUT root=/dev/root rootflags=trans=virtio,version=9p2000.u ro rootfstype=9p EPATH=$EPATH ARGS=$*"
|
||||
|
||||
if [ $CODECOV = "yes" ]; then
|
||||
mv $LOGDIR/alt-wpa_supplicant /tmp/logs
|
||||
|
|
|
@ -17,12 +17,12 @@ logger = logging.getLogger()
|
|||
wpas_ctrl = '/var/run/wpa_supplicant'
|
||||
|
||||
class WpaSupplicant:
|
||||
def __init__(self, ifname, global_iface=None):
|
||||
self.ifname = ifname
|
||||
def __init__(self, ifname=None, global_iface=None):
|
||||
self.group_ifname = None
|
||||
self.ctrl = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
|
||||
self.mon = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
|
||||
self.mon.attach()
|
||||
if ifname:
|
||||
self.set_ifname(ifname)
|
||||
else:
|
||||
self.ifname = None
|
||||
|
||||
self.global_iface = global_iface
|
||||
if global_iface:
|
||||
|
@ -30,6 +30,34 @@ class WpaSupplicant:
|
|||
self.global_mon = wpaspy.Ctrl(global_iface)
|
||||
self.global_mon.attach()
|
||||
|
||||
def set_ifname(self, ifname):
|
||||
self.ifname = ifname
|
||||
self.ctrl = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
|
||||
self.mon = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
|
||||
self.mon.attach()
|
||||
|
||||
def remove_ifname(self):
|
||||
if self.ifname:
|
||||
self.mon.detach()
|
||||
self.mon = None
|
||||
self.ctrl = None
|
||||
self.ifname = None
|
||||
|
||||
def interface_add(self, ifname, driver="nl80211"):
|
||||
try:
|
||||
groups = subprocess.check_output(["id"])
|
||||
group = "admin" if "(admin)" in groups else "adm"
|
||||
except Exception, e:
|
||||
group = "admin"
|
||||
cmd = "INTERFACE_ADD " + ifname + "\t\t" + driver + "\tDIR=/var/run/wpa_supplicant GROUP=" + group
|
||||
if "FAIL" in self.global_request(cmd):
|
||||
raise Exception("Failed to add a dynamic wpa_supplicant interface")
|
||||
self.set_ifname(ifname)
|
||||
|
||||
def interface_remove(self, ifname):
|
||||
self.remove_ifname()
|
||||
self.global_request("INTERFACE_REMOVE " + ifname)
|
||||
|
||||
def request(self, cmd):
|
||||
logger.debug(self.ifname + ": CTRL: " + cmd)
|
||||
return self.ctrl.request(cmd)
|
||||
|
@ -38,7 +66,8 @@ class WpaSupplicant:
|
|||
if self.global_iface is None:
|
||||
self.request(cmd)
|
||||
else:
|
||||
logger.debug(self.ifname + ": CTRL: " + cmd)
|
||||
ifname = self.ifname or self.global_iface
|
||||
logger.debug(ifname + ": CTRL: " + cmd)
|
||||
return self.global_ctrl.request(cmd)
|
||||
|
||||
def group_request(self, cmd):
|
||||
|
|
Loading…
Reference in a new issue