| #!/bin/sh |
| # Test script for /bin/apman |
| mydir=$(dirname "$0") |
| cd "$mydir" |
| . ../etc/wvtest.sh |
| PATH=$PATH:. |
| |
| . /etc/utils.sh |
| |
| runnable mktemp && |
| tmpdir="$(mktemp -d ipapplyXXXXXXXXXX)" || |
| tmpdir="/tmp/ipapply.$$" |
| tmpbindir="$tmpdir/test_bin" |
| mkdir -p "$tmpdir" && echo "using temp dir $tmpdir" |
| mkdir "$tmpbindir" |
| |
| hostapd_running() { |
| pgrep -f '^hostapd .* /tmp/hostapd.conf.wlan.*' >/dev/null |
| } |
| |
| binwifi_running() { |
| pgrep -f '/bin/wifi' >/dev/null |
| } |
| |
| hostapd_wait_check_running() { |
| local should_be_running="$1" |
| |
| echo 'waiting for /bin/wifi to start' |
| for x in $(seq 50); do |
| if binwifi_running; then |
| break |
| fi |
| echo -n "." |
| sleep 0.1 |
| done |
| |
| echo "waiting for /bin/wifi to finish..." |
| while binwifi_running; do |
| echo -n "." |
| sleep 0.5 |
| done |
| if hostapd_running; then echo 'hostapd running'; fi |
| if $should_be_running; then |
| WVPASS hostapd_running |
| else |
| WVFAIL hostapd_running |
| fi |
| } |
| |
| wait_route_changed() { |
| local operation="$1" |
| local route="$2" |
| local interface="$3" |
| |
| for x in $(seq 50); do |
| if grep "$operation $route" "$ip_out" | grep "dev $interface"; then |
| return 0 |
| fi |
| sleep 0.1 |
| done |
| |
| return 1 |
| } |
| |
| |
| ip_out="$tmpdir/ip.out" |
| cat >"$tmpbindir/ip" <<-EOF |
| #!/bin/sh |
| echo test_bin/ip \$@ >>$ip_out |
| if [ "x\$3" = "xshow" -a -e $tmpdir/ip_route_show ]; then |
| cat $tmpdir/ip_route_show |
| fi |
| exit 0 |
| EOF |
| chmod 777 "$tmpbindir/ip" |
| PATH="$tmpbindir:$PATH" |
| |
| |
| echo "Setting up" |
| wifi stop |
| pkill "apman$" |
| rm -f /config/conman/command* |
| rm -f /config/conman/access_point* |
| rm -f /tmp/conman/command* |
| rm -f /tmp/conman/access_point* |
| # Creating wlan0_apmantest sometimes fails if we don't reset wlan0. |
| wlan0mac=$(cat /sys/class/net/wlan0/address) |
| mac=$(mac_addr_increment $wlan0mac 100) |
| iw dev wlan0 del |
| iw dev wlan0_apmantest del |
| WVPASS iw phy phy0 interface add wlan0 type __ap |
| WVPASS ip link set dev wlan0 address "$wlan0mac" |
| WVPASS iw phy phy0 interface add wlan0_apmantest type __ap |
| WVPASS ip link set dev wlan0_apmantest address "$mac" |
| |
| # Start apman. |
| apman& |
| |
| WVSTART "access points" |
| WVFAIL hostapd_running |
| |
| touch /config/conman/access_point.5 |
| WVFAIL hostapd_running |
| |
| echo "Enable 5 GHz access point" |
| echo "env\nWIFI_PSK=password\nwifi\nset\n-b\n5\n-s\nssid" > /tmp/conman/command.5 |
| echo "Waiting to make sure hostapd doesn't start (wrong location)" |
| hostapd_wait_check_running false |
| |
| echo "Enable 5 GHz access point" |
| echo "env\nWIFI_PSK=password\nwifi\nset\n-b\n5\n-s\nssid" > /config/conman/command.5 |
| hostapd_wait_check_running true |
| |
| echo "Disable 5 GHz access point" |
| rm /config/conman/access_point.5 |
| touch /tmp/conman/access_point.5 |
| hostapd_wait_check_running false |
| |
| touch /tmp/conman/access_point._apmantest.2.4 |
| echo "Waiting to make sure hostapd doesn't start" |
| hostapd_wait_check_running false |
| |
| echo "env\nWIFI_PSK=password\nwifi\nset\n-b\n2.4\n-s\nssid" > /config/conman/command.2.4 |
| echo "Waiting to make sure hostapd doesn't start (wrong suffix)" |
| hostapd_wait_check_running false |
| |
| echo "env\nWIFI_PSK=password\nwifi\nset\n-b\n2.4\n-s\nssid" > /config/conman/command._apmantest.2.4 |
| echo "Waiting to make sure hostapd doesn't start (wrong location)" |
| hostapd_wait_check_running false |
| |
| echo "env\nWIFI_PSK=password\nwifi\nset\n-b\n2.4\n-s\nssid\n-S\n_apmantest" > /tmp/conman/command._apmantest.2.4 |
| hostapd_wait_check_running true |
| |
| rm /tmp/conman/access_point._apmantest.2.4 |
| touch /config/conman/access_point._apmantest.2.4 |
| echo "Waiting to make sure hostapd doesn't start (wrong location)" |
| hostapd_wait_check_running false |
| |
| WVSTART "route management" |
| echo "192.168.1.1" > /tmp/conman/gateway.wlan0_apmantest |
| echo "192.168.1.0/24" > /tmp/conman/subnet.wlan0_apmantest |
| WVPASS wait_route_changed "add" "default via 192.168.1.1" "wlan0_apmantest" |
| WVPASS wait_route_changed "add" "192.168.1.0/24" "wlan0_apmantest" |
| |
| # Make sure non-interfaces are ignored. |
| echo "192.168.2.1" > /tmp/conman/gateway.wlan0_apmantest.tmp |
| echo "192.168.2.0/16" > /tmp/conman/subnet.wlan0_apmantest.tmp |
| echo "192.168.3.1" > /tmp/conman/gateway.wlan0_apmantest_tmp |
| echo "192.168.3.0/16" > /tmp/conman/subnet.wlan0_apmantest_tmp |
| |
| echo "default via 192.168.1.1 dev wlan0_apmantest" > $tmpdir/ip_route_show |
| echo "192.168.1.0/24 dev wlan0_apmantest" >> $tmpdir/ip_route_show |
| |
| echo "192.168.1.0/16" > /tmp/conman/subnet.wlan0_apmantest |
| WVPASS wait_route_changed "del" "default" "wlan0_apmantest" |
| WVPASS wait_route_changed "add" "default via 192.168.1.1" "wlan0_apmantest" |
| WVPASS wait_route_changed "del" "192.168.1.0/24" "wlan0_apmantest" |
| WVPASS wait_route_changed "add" "192.168.1.0/16" "wlan0_apmantest" |
| |
| WVPASS grep "192\.168\.1\." "$ip_out" |
| WVFAIL grep "192\.168\.2\." "$ip_out" |
| WVFAIL grep "192\.168\.3\." "$ip_out" |
| |
| echo "Cleaning up" |
| WVPASS iw dev wlan0_apmantest del |
| pkill "apman$" |
| wifi off |
| rm -f /config/conman/command* |
| rm -f /config/conman/access_point* |
| rm -f /tmp/conman/command* |
| rm -f /tmp/conman/access_point* |
| rm -f /tmp/conman/gateway.br0 |
| rm -rf $tmpdir |