blob: 8dbff2913bec04663c27540b028ea0f40aee88cd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# Uses wpa_supplicant to check for association to a network
# wpa_check interface [timeout]
wpa_check()
{
local timeout=0 INTERFACE=$1 TIMEOUT=${2:-15}
while [[ $timeout -lt $TIMEOUT ]]; do
( # Sometimes wpa_supplicant isn't ready so silence errors for 2s only to avoid hiding real errors
if [[ $timeout -lt 2 ]]; then
eval `wpa_cli status 2> /dev/null|grep wpa_state`
else
eval `wpa_cli status|grep wpa_state`
fi
[[ "$wpa_state" = "COMPLETED" ]]
) && return 0
sleep 1
let timeout++
done
wpa_cli terminate >/dev/null 2>&1
err_append "Authentication/association failed"
return 1
}
start_wpa()
{
INTERFACE="$1"; WPA_CONF="$2"; WPA_OPTS="$3"
wpa_supplicant -B -P/var/run/wpa_supplicant_${INTERFACE}.pid -i"${INTERFACE}" -c "$WPA_CONF" $WPA_OPTS
sleep 1
if [[ ! -f "/var/run/wpa_supplicant_${INTERFACE}.pid" ]]; then
err_append "wpa_supplicant did not start, possible configuration error"
return 1
fi
}
|