blob: b7fa3685a92a48e1743fa2bc0d80dd438502227e [file] [log] [blame]
#!/bin/sh
# Test script for /bin/wifi
mydir=$(dirname "$0")
cd "$mydir"
. ../etc/wvtest.sh
PATH=$PATH:.
hostapd_running() {
pgrep -f '^hostapd .* /tmp/hostapd.conf.wlan.*'
}
# conman isn't present on all devices. QUIET=1 makes stop return 0 if conman
# isn't found.
QUIET=1 stop conman
# Stop returns 1 on failure and 143 on success.
WVPASSNE 1 $?
stop waveguide
WVPASSNE 1 $?
WVSTART "wifi basics"
WVPASS runnable wifi
WVPASS wifi stop -P
WVFAIL hostapd_running
WVPASS wifi restore
WVFAIL hostapd_running
rm -f /tmp/*.wlan* /tmp/*.wcli* /tmp/*.opts.2.4 /tmp/*.opts.5
WVPASS wifi set -b2.4 -e NONE
WVPASS hostapd_running
export WIFI_PSK=whatever
WVPASS wifi set -b2.4 -P
WVPASS hostapd_running
WVSTART "Save the autochannel settings and pick a good channel"
WVPASSEQ NONDFS-2.4-20 \
"$(cat /tmp/autotype.wlan*)-$(cat /tmp/band.wlan*)-$(cat /tmp/width.wlan*)"
chan1=$(cat /tmp/autochan.wlan*)
WVPASS [ "$chan1" -gt 0 ]
WVPASS [ "$chan1" -lt 12 ]
WVSTART "hostapd doesn't restart if settings are unchanged"
pid1=$(WVPASS hostapd_running)
WVPASS wifi set -b2.4
WVPASSEQ "$pid1" "$(hostapd_running)"
WVSTART "autochannel cache"
WVPASS wifi stop -b2.4
WVPASS wifi set -b2.4
chan2=$(cat /tmp/autochan.wlan*)
WVPASSEQ "$chan1" "$chan2"
pid2=$(WVPASS hostapd_running)
WVPASSNE "$pid1" "$pid2"
WVSTART "manual channel selection"
chanfile=$(ls /tmp/autochan.wlan*)
WVPASS [ -e "$chanfile" ]
WVPASS wifi set -b2.4 -c11
WVFAIL [ -e "$chanfile" ]
WVSTART "autochannel 2.4GHz only has one choice with -w40"
WVPASS wifi set -b2.4 -w40
WVPASSEQ 1 "$(cat /tmp/autochan.wlan*)"
WVSTART "multi-radio settings"
WVPASS wifi set -b5 -P
WVPASS hostapd_running
WVPASS ls -l /config/wifi
if is-network-box; then
# A network box has 2 radios to run at the same time
WVPASSEQ 2 $(hostapd_running | wc -l)
# On network box, check we can stop only one radio.
# On other devices, this result is undefined, so don't test it.
WVPASS wifi stop -b2.4
WVPASS hostapd_running
else
# Anything else has only a single radio
WVPASSEQ 1 $(hostapd_running | wc -l)
fi
WVPASS wifi stop
WVFAIL hostapd_running
WVPASS ls -l /config/wifi
WVSTART "primary channel selection with mixed widths"
WVPASS wifi set -b5 -c40 -w80
WVPASS hostapd_running
WVPASS grep -q vht_oper_centr_freq_seg0_idx=42 /tmp/hostapd.conf.*
WVPASS wifi set -b5 -c161 -w80
WVPASS hostapd_running
WVPASS grep -q vht_oper_centr_freq_seg0_idx=155 /tmp/hostapd.conf.*
# fail on a channel with no HT40/VHT80 companion channels
WVFAIL wifi set -b5 -c165 -w80
WVFAIL wifi set -b5 -c165 -w40
WVSTART "wifi restore"
WVPASS wifi restore
WVPASS hostapd_running
if is-network-box; then
# A network box has 2 radios to run at the same time
WVPASSEQ 2 $(hostapd_running | wc -l)
else
# Anything else has only a single radio
WVPASSEQ 1 $(hostapd_running | wc -l)
fi
WVSTART "edge case SSIDs/PSKs"
pathological="a @#$\(^.-)/;?[:_%]\"{'}=|!~\`"
WIFI_PSK="$pathological" WVPASS wifi set -b5 --ssid "$pathological"
WVPASS hostapd_running
WVPASS grep -F "ssid=$pathological" /tmp/hostapd.conf.*
WVPASS grep -F "wpa_passphrase=$pathological" /tmp/hostapd.conf.*
newline_null=$(printf "foo\n\0bar78")
WIFI_PSK="$newline_null" WVPASS wifi set -b5 --ssid "$newline_null"
WVPASS hostapd_running
WVPASS grep -F "ssid=foobar78" /tmp/hostapd.conf.*
WVPASS grep -F "wpa_passphrase=foobar78" /tmp/hostapd.conf.*
WVPASS wifi set -b5 --ssid '123'
WVPASS hostapd_running
WVPASS grep -F "ssid=123" /tmp/hostapd.conf.*
WVPASS wifi set -b5 --ssid 'foo bar'
WVPASS hostapd_running
WVPASS grep -F "ssid=foo bar" /tmp/hostapd.conf.*
# b/20460495
shown_ssid=$(wifi show | grep -F "SSID: foo bar")
WVPASS [ -n "$shown_ssid" ]
unicode="נְקֻדּוֹת"
# PSKs must be ASCII or hex.
WIFI_PSK="$unicode" WVFAIL wifi set -b5 --ssid "$unicode"
WIFI_PSK="abcdefgh" WVPASS wifi set -b5 --ssid "$unicode" -P
WVPASS wifi off
WVPASS wifi restore
WVPASS hostapd_running
WVPASS grep -F "ssid=$unicode" /tmp/hostapd.conf.*
# We can't really test client mode in a unit test because there is nothing to
# connect to, so setclient should fail...
WVSTART "client mode generates a correct wpa_supplicant.conf"
export WIFI_CLIENT_PSK=passphrase
# This will fail because (hopefully) this SSID doesn't exist.
WVFAIL wifi setclient -b2.4 -s HOPEFULLY_NONEXISTENT_SSID
# ...but we can at least check that the expected config was generated.
WVPASS grep "ctrl_interface=/var/run/wpa_supplicant" /tmp/wpa_supplicant.conf.wcli0
WVPASS grep "ap_scan=1" /tmp/wpa_supplicant.conf.wcli0
WVPASS grep "ssid=\"HOPEFULLY_NONEXISTENT_SSID\"" /tmp/wpa_supplicant.conf.wcli0
WVPASS grep "psk=59f3e4d481645275c0a76886a187025362eb606c5486cec354ae262fd62b2bb1" /tmp/wpa_supplicant.conf.wcli0
WVPASS wifi stop -P