wpa_supplicant/tests/wpa_supplicant_standalone/runtest.sh
2023-07-10 13:45:54 +02:00

222 lines
5.1 KiB
Bash
Executable File

#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/wpa_supplicant/Sanity/wpa_supplicant_standalone
# Description: sanity test for wpa_supplicant
# Author: Davide Caratti <dcaratti@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2019 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="wpa_supplicant"
MACSTA="00:00:0a:bb:e1:1a"
IFACEAP="wlan0"
IFACESTA="wlan1"
open_ap() {
local SSID=${1:-notreallyassid}
cat >openap.conf <<-EOF
network={
frequency=2412
ssid="$SSID"
mode=2
key_mgmt=NONE
}
EOF
wpa_supplicant -ddd -Dnl80211 -i$IFACEAP -copenap.conf -B -fopenap.log -Pw1ap.pid
}
open_sta() {
local SSID=${1:-notreallyassid}
cat >opensta.conf <<-EOF
network={
ssid="$SSID"
key_mgmt=NONE
}
EOF
wpa_supplicant -ddd -Dnl80211 -i$IFACESTA -copensta.conf -B -fopensta.log -Pw1sta.pid
}
wpa2psk_ap() {
local SSID=${1:-notreallyassid}
cat >wpapskap.conf <<-EOF
network={
frequency=2437
ssid="$SSID"
mode=2
key_mgmt=WPA-PSK
pairwise=CCMP
group=CCMP
psk="hunter2?"
}
EOF
wpa_supplicant -ddd -Dnl80211 -i$IFACEAP -cwpapskap.conf -B -fwpapskap.log -Pw2ap.pid
}
wpa2psk_sta() {
local SSID=${1:-notreallyassid}
cat >wpapsksta.conf <<-EOF
network={
frequency=2437
ssid="$SSID"
proto=WPA
key_mgmt=WPA-PSK
pairwise=CCMP
group=CCMP
psk="hunter2?"
}
EOF
wpa_supplicant -ddd -Dnl80211 -i$IFACESTA -cwpapsksta.conf -B -fwpapsksta.log -Pw2sta.pid
}
kill_supplicants() {
local a=`cat w*.pid`
local iter=0
while [ ${#a} -gt 0 -a $iter -lt 10 ]; do
for a in $a; do
kill $a 1>/dev/null 2>&1
sleep 1
done
a=`cat w*.pid`
iter=$((iter+1))
done
ip link set dev $IFACEAP down
ip link set dev $IFACESTA down
if [ $iter -ge 10 -a ${#a} -gt 0 ]; then
return 1
else
return 0
fi
}
check_for_associated_sta()
{
local assoc_found=0 assoc_missed=0
ip link set dev $IFACEAP up
while sleep 2; do
if iw dev $IFACEAP station dump | grep -i $MACSTA ; then
assoc_found=$((assoc_found+1))
rlLog "found $MACSTA in $IFACEAP associations ($assoc_found)"
else
if [ $assoc_found -gt 0 ]; then
rlLog "association disappeared after $assoc_found cycles"
return 1
fi
rlLog "didn't find association ($assoc_missed)"
assoc_missed=$((assoc_missed+1))
fi
if [ $assoc_missed -gt 5 ]; then
rlLog "timeout waiting for $MACSTA in $IFACEAP station dump"
return 1
fi
if [ $assoc_found -gt 5 ]; then
return 0
fi
done
rlLog "sleep failed!"
return 1
}
check_for_running_aps()
{
local probe_ok=0 probe_missed=0
ip link set dev $IFACESTA up
while sleep 1; do
if iw dev $IFACESTA scan | grep "${1:-notreallyassid}"; then
probe_ok=$((probe_ok+1))
rlLog "$probe_ok probe received"
else
if [ $probe_ok -gt 0 ]; then
rlLog "probe failure after $probe_ok attempts"
return 1
fi
rlLog "missed probe response"
probe_missed=$((probe_missed+1))
fi
if [ $probe_missed -gt 5 ]; then
rlLog "timeout waiting for beacons"
return 1
fi
if [ $probe_ok -gt 5 ]; then
return 0
fi
done
rlLog "sleep failed!"
return 1
}
rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE
# avoid randomizing MAC for wlan0 and wlan1
rlRun "systemctl stop NetworkManager"
# allow scans
rlRun "systemctl stop wpa_supplicant"
# install required modules
rlRun "modprobe rfkill"
rlRun "modprobe mac80211_hwsim radio=2"
rlRun "rfkill unblock wifi"
rlRun "ip link set dev $IFACESTA address $MACSTA"
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "pushd $TmpDir"
rlPhaseEnd
rlPhaseStartTest
# cleartext wifi
rlRun "kill_supplicants"
rlRun "open_ap test_OPEN"
rlRun "check_for_running_aps test_OPEN"
rlRun "open_sta test_OPEN"
rlRun "check_for_associated_sta test_OPEN"
# WPA2 personal
rlRun "kill_supplicants"
rlRun "wpa2psk_ap test_WPAPSK"
rlRun "check_for_running_aps test_WPAPSK"
rlRun "wpa2psk_sta test_WPAPSK"
rlRun "check_for_associated_sta test_WPAPSK"
rlPhaseEnd
rlPhaseStartCleanup
rlRun kill_supplicants
rlRun "popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rlRun "modprobe -r mac80211_hwsim"
rlRun "systemctl restart wpa_supplicant"
rlRun "systemctl restart NetworkManager"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd