tests: Verify dynamic wpa_supplicant interface addition/removal

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2013-12-30 23:08:25 +02:00
parent d52747c99e
commit 9489637b42
6 changed files with 87 additions and 15 deletions

View file

@ -33,6 +33,13 @@ def reset_devs(dev, apdev):
logger.info("Failed to reset device " + d.ifname) logger.info("Failed to reset device " + d.ifname)
print str(e) print str(e)
ok = False ok = False
try:
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
wpas.interface_remove("wlan5")
except Exception, e:
pass
try: try:
hapd = HostapdGlobal() hapd = HostapdGlobal()
hapd.remove('wlan3-3') 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("Failed to issue TEST-STOP after {} for {}".format(name, d.ifname))
logger.info(e) logger.info(e)
result = "FAIL" 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: if args.no_reset:
print "Leaving devices in current state" print "Leaving devices in current state"
else: else:
@ -325,7 +339,6 @@ def main():
for i in range(0, 3): for i in range(0, 3):
rename_log(args.logdir, 'log' + str(i), name, dev[i]) rename_log(args.logdir, 'log' + str(i), name, dev[i])
try: try:
hapd = HostapdGlobal() hapd = HostapdGlobal()
except Exception, e: except Exception, e:

View file

@ -58,13 +58,15 @@ else
fi fi
$DIR/stop.sh $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 ifconfig hwsim0 up
sudo $WLANTEST -i hwsim0 -n $LOGDIR/hwsim0.pcapng -c -dt -L $LOGDIR/hwsim0 & sudo $WLANTEST -i hwsim0 -n $LOGDIR/hwsim0.pcapng -c -dt -L $LOGDIR/hwsim0 &
for i in 0 1 2; do 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 \ 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 & -ddKt$TRACE -f $LOGDIR/log$i &
done 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 & sudo $VALGRIND_HAPD $HAPD -ddKt$TRACE -g /var/run/hostapd-global -G $GROUP -ddKt -f $LOGDIR/hostapd &
sleep 1 sleep 1

View file

@ -56,15 +56,17 @@ for i in `pidof valgrind.bin`; do
fi fi
done 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 count=0
if [ -e $i ]; then 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" echo "Waiting for ctrl_iface $i to disappear"
sleep 1 sleep 1
fi
if [ -e $i ]; then if [ -e $i ]; then
echo "Control interface file $i exists - remove it" echo "Control interface file $i exists - remove it"
sudo rm $i sudo rm $i
fi fi
fi
done done
if grep -q mac80211_hwsim /proc/modules 2>/dev/null ; then if grep -q mac80211_hwsim /proc/modules 2>/dev/null ; then

View 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")

View file

@ -105,7 +105,7 @@ kvm \
-fsdev local,security_model=none,id=fsdev-logs,path="$LOGDIR",writeout=immediate \ -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 \ -device virtio-9p-pci,id=fs-logs,fsdev=fsdev-logs,mount_tag=logshare \
-monitor null -serial stdio -serial file:$LOGDIR/console \ -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 if [ $CODECOV = "yes" ]; then
mv $LOGDIR/alt-wpa_supplicant /tmp/logs mv $LOGDIR/alt-wpa_supplicant /tmp/logs

View file

@ -17,12 +17,12 @@ logger = logging.getLogger()
wpas_ctrl = '/var/run/wpa_supplicant' wpas_ctrl = '/var/run/wpa_supplicant'
class WpaSupplicant: class WpaSupplicant:
def __init__(self, ifname, global_iface=None): def __init__(self, ifname=None, global_iface=None):
self.ifname = ifname
self.group_ifname = None self.group_ifname = None
self.ctrl = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname)) if ifname:
self.mon = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname)) self.set_ifname(ifname)
self.mon.attach() else:
self.ifname = None
self.global_iface = global_iface self.global_iface = global_iface
if global_iface: if global_iface:
@ -30,6 +30,34 @@ class WpaSupplicant:
self.global_mon = wpaspy.Ctrl(global_iface) self.global_mon = wpaspy.Ctrl(global_iface)
self.global_mon.attach() 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): def request(self, cmd):
logger.debug(self.ifname + ": CTRL: " + cmd) logger.debug(self.ifname + ": CTRL: " + cmd)
return self.ctrl.request(cmd) return self.ctrl.request(cmd)
@ -38,7 +66,8 @@ class WpaSupplicant:
if self.global_iface is None: if self.global_iface is None:
self.request(cmd) self.request(cmd)
else: 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) return self.global_ctrl.request(cmd)
def group_request(self, cmd): def group_request(self, cmd):