mirror of
https://github.com/rsmarples/dhcpcd.git
synced 2024-11-23 18:14:09 +08:00
78 lines
1.8 KiB
Plaintext
78 lines
1.8 KiB
Plaintext
# Start, reconfigure and stop wpa_supplicant per wireless interface.
|
|
# This is needed because wpa_supplicant lacks hotplugging of any kind
|
|
# and the user should not be expected to have to wire it into their system
|
|
# if the base system doesn't do this itself.
|
|
|
|
if [ -z "$wpa_supplicant_conf" ]; then
|
|
for x in \
|
|
/etc/wpa_supplicant.conf \
|
|
/etc/wpa_supplicant/wpa_supplicant.conf \
|
|
; do
|
|
if [ -s "$x" ]; then
|
|
wpa_supplicant_conf="$x"
|
|
break
|
|
fi
|
|
done
|
|
fi
|
|
: ${wpa_supplicant_conf:=/etc/wpa_supplicant.conf}
|
|
|
|
wpa_supplicant_start()
|
|
{
|
|
local err errn
|
|
|
|
wpa_cli -i "$interface" status >/dev/null 2>&1 && return 0
|
|
syslog info "starting wpa_supplicant"
|
|
err=$(wpa_supplicant -B -c"$wpa_supplicant_conf" -i"$interface" 2>&1)
|
|
errn=$?
|
|
if [ $errn != 0 ]; then
|
|
syslog err "failed to start wpa_supplicant"
|
|
syslog err "$err"
|
|
fi
|
|
return $errn
|
|
}
|
|
|
|
wpa_supplicant_reconfigure()
|
|
{
|
|
local err errn
|
|
|
|
if ! wpa_cli -i "$interface" status >/dev/null 2>&1; then
|
|
wpa_supplicant_start
|
|
return $?
|
|
fi
|
|
syslog info "reconfiguring wpa_supplicant"
|
|
err=$(wpa_cli -i"$interface" reconfigure 2>&1)
|
|
errn=$?
|
|
if [ $errn != 0 ]; then
|
|
syslog err "failed to reconfigure wpa_supplicant"
|
|
syslog err "$err"
|
|
fi
|
|
return $errn
|
|
}
|
|
|
|
wpa_supplicant_stop()
|
|
{
|
|
local err errn
|
|
|
|
wpa_cli -i "$interface" status >/dev/null 2>&1 || return 0
|
|
syslog info "stopping wpa_supplicant"
|
|
err=$(wpa_cli -i"$interface" terminate 2>&1)
|
|
errn=$?
|
|
if [ $errn != 0 ]; then
|
|
syslog err "failed to start wpa_supplicant"
|
|
syslog err "$err"
|
|
fi
|
|
return $errn
|
|
}
|
|
|
|
|
|
if [ "$ifwireless" = "1" -a -s "$wpa_supplicant_conf" ] && \
|
|
type wpa_supplicant >/dev/null 2>&1 && \
|
|
type wpa_cli >/dev/null 2>&1
|
|
then
|
|
case "$reason" in
|
|
PREINIT) wpa_supplicant_start;;
|
|
RECONFIGURE) wpa_supplicant_reconfigure;;
|
|
DEPARTED) wpa_supplicant_stop;;
|
|
esac
|
|
fi
|