2009-05-01 19:41:40 +05:30
|
|
|
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
|
2008-01-11 21:01:10 +05:30
|
|
|
# All rights reserved. Released under the 2-clause BSD license.
|
2007-11-14 20:52:04 +05:30
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
wpa_supplicant_depend()
|
|
|
|
{
|
2010-12-06 08:24:21 +05:30
|
|
|
wpas=/usr/sbin/wpa_supplicant
|
|
|
|
[ -x ${wpas} ] || wpas=/sbin/wpa_supplicant
|
|
|
|
if [ -x ${wpas} ]; then
|
|
|
|
program start ${wpas}
|
|
|
|
# bug 345281: if wpa_supplicant is built w/ USE=dbus, we need to start
|
|
|
|
# dbus before we can start wpa_supplicant.
|
|
|
|
${wpas} -h |grep DBus -sq
|
|
|
|
[ $? -eq 0 ] && need dbus
|
2007-09-25 17:50:00 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
after macnet plug
|
|
|
|
before interface
|
|
|
|
provide wireless
|
|
|
|
|
|
|
|
# Prefer us over iwconfig
|
|
|
|
after iwconfig
|
|
|
|
}
|
|
|
|
|
|
|
|
# Only set these functions if not set already
|
|
|
|
# IE, prefer to use iwconfig
|
2007-11-28 21:15:03 +05:30
|
|
|
if ! type _get_ssid >/dev/null 2>&1; then
|
2008-01-11 20:38:57 +05:30
|
|
|
_get_ssid()
|
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
local timeout=5 ssid=
|
|
|
|
|
2007-11-28 21:15:03 +05:30
|
|
|
while [ ${timeout} -gt 0 ]; do
|
2007-04-05 16:48:42 +05:30
|
|
|
ssid=$(wpa_cli -i"${IFACE}" status | sed -n -e 's/^ssid=//p')
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ -n "${ssid}" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
echo "${ssid}"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
timeout=$((timeout - 1))
|
|
|
|
done
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
_get_ap_mac_address()
|
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
wpa_cli -i"${IFACE}" status | sed -n -e 's/^bssid=\(.*\)$/\1/p' \
|
|
|
|
| tr '[:lower:]' '[:upper:]'
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
wpa_supplicant_pre_start()
|
|
|
|
{
|
2009-01-21 14:55:34 +05:30
|
|
|
local opts= cliopts= cfgfile= ctrl_dir= wireless=true
|
2007-09-25 17:50:00 +05:30
|
|
|
local wpas=/usr/sbin/wpa_supplicant wpac=/usr/bin/wpa_cli
|
2008-03-11 03:04:46 +05:30
|
|
|
local actfile=/etc/wpa_supplicant/wpa_cli.sh
|
2007-09-25 17:50:00 +05:30
|
|
|
|
|
|
|
if [ ! -x "${wpas}" ]; then
|
|
|
|
wpas=/sbin/wpa_supplicant
|
|
|
|
wpac=/bin/wpa_cli
|
|
|
|
fi
|
2007-11-21 21:09:43 +05:30
|
|
|
[ "${RC_UNAME}" = "Linux" ] || unset wpac
|
2008-03-11 03:04:46 +05:30
|
|
|
[ -e "${actfile}" ] || unset wpac
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-11-14 21:55:47 +05:30
|
|
|
eval opts=\$wpa_supplicant_${IFVAR}
|
2009-01-21 14:55:34 +05:30
|
|
|
eval cliopts=\$wpa_cli_${IFVAR}
|
|
|
|
[ -z "${cliopts}" ] && cliopts=${wpa_cli}
|
2007-11-14 21:55:47 +05:30
|
|
|
case " ${opts} " in
|
2007-12-10 21:55:29 +05:30
|
|
|
*" -Dwired "*) wireless=false;;
|
2007-11-14 21:55:47 +05:30
|
|
|
*) _is_wireless || return 0;;
|
|
|
|
esac
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
# We don't configure wireless if we're being called from
|
|
|
|
# the background unless we're not currently running
|
2007-11-22 18:58:14 +05:30
|
|
|
if yesno ${IN_BACKGROUND}; then
|
2008-01-11 20:38:57 +05:30
|
|
|
if ${wireless} && \
|
2008-03-20 01:27:24 +05:30
|
|
|
service_started_daemon "${RC_SVCNAME}" "${wpas}"; then
|
2007-04-05 16:48:42 +05:30
|
|
|
SSID=$(_get_ssid "${IFACE}")
|
2008-03-10 14:26:28 +05:30
|
|
|
SSIDVAR=$(shell_var "${SSID}")
|
2007-12-19 19:58:38 +05:30
|
|
|
service_set_value "SSID" "${SSID}"
|
2007-04-05 16:48:42 +05:30
|
|
|
metric=2000
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2007-12-19 19:58:38 +05:30
|
|
|
service_set_value "SSID" ""
|
2007-11-28 21:15:03 +05:30
|
|
|
ebegin "Starting wpa_supplicant on ${IFVAR}"
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2008-05-27 16:16:27 +05:30
|
|
|
if type iwconfig_defaults >/dev/null 2>&1; then
|
|
|
|
iwconfig_defaults
|
|
|
|
iwconfig_user_config
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
|
|
|
|
|
|
|
cfgfile=${opts##* -c}
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ -n "${cfgfile}" -a "${cfgfile}" != "${opts}" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
case "${cfgfile}" in
|
2007-11-28 21:15:03 +05:30
|
|
|
" "*) cfgfile=${cfgfile# *};;
|
2007-04-05 16:48:42 +05:30
|
|
|
esac
|
|
|
|
cfgfile=${cfgfile%% *}
|
|
|
|
else
|
|
|
|
# Support new and old style locations
|
|
|
|
cfgfile="/etc/wpa_supplicant/wpa_supplicant-${IFACE}.conf"
|
|
|
|
[ ! -e "${cfgfile}" ] \
|
|
|
|
&& cfgfile="/etc/wpa_supplicant/wpa_supplicant.conf"
|
|
|
|
[ ! -e ${cfgfile} ] \
|
|
|
|
&& cfgfile="/etc/wpa_supplicant.conf"
|
|
|
|
opts="${opts} -c ${cfgfile}"
|
|
|
|
fi
|
|
|
|
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ ! -f ${cfgfile} ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
eend 1 "/etc/wpa_supplicant/wpa_supplicant.conf not found"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Work out where the ctrl_interface dir is if it's not specified
|
2009-01-05 15:07:38 +05:30
|
|
|
local ctrl_dir=$(sed -e 's/^ *//' \
|
|
|
|
-e '/^ctrl_interface=/!d' \
|
2008-12-23 15:43:58 +05:30
|
|
|
-e 's/^ctrl_interface=//' \
|
|
|
|
-e 's/^ *//' \
|
|
|
|
-e 's/^DIR=//' \
|
|
|
|
-e 's/^ *//' \
|
|
|
|
-e 's/GROUP=.*//' \
|
2009-01-05 15:07:38 +05:30
|
|
|
-e 's/ *$//' \
|
2008-12-23 15:43:58 +05:30
|
|
|
"${cfgfile}")
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ -z "${ctrl_dir}" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
ctrl_dir=${opts##* -C}
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ -n "${ctrl_dir}" -a "${ctrl_dir}" != "${opts}" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
case "${ctrl_dir}" in
|
2007-11-28 21:15:03 +05:30
|
|
|
" "*) ctrl_dir=${ctrl_dir# *};;
|
2007-04-05 16:48:42 +05:30
|
|
|
esac
|
|
|
|
ctrl_dir=${ctrl_dir%% *}
|
|
|
|
else
|
|
|
|
ctrl_dir="/var/run/wpa_supplicant"
|
|
|
|
opts="${opts} -C ${ctrl_dir}"
|
|
|
|
fi
|
|
|
|
fi
|
2007-12-19 19:58:38 +05:30
|
|
|
service_set_value ctrl_dir "${ctrl_dir}"
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-11-21 21:09:43 +05:30
|
|
|
if [ -n "${wpac}" ]; then
|
|
|
|
opts="${opts} -W"
|
2008-03-11 03:04:46 +05:30
|
|
|
elif service_started devd; then
|
2007-12-18 23:29:29 +05:30
|
|
|
mark_service_inactive
|
2007-11-21 21:09:43 +05:30
|
|
|
fi
|
2007-09-25 17:50:00 +05:30
|
|
|
start-stop-daemon --start --exec "${wpas}" \
|
2007-04-05 16:48:42 +05:30
|
|
|
--pidfile "/var/run/wpa_supplicant-${IFACE}.pid" \
|
2007-11-21 21:09:43 +05:30
|
|
|
-- ${opts} -B -i "${IFACE}" \
|
2007-04-05 16:48:42 +05:30
|
|
|
-P "/var/run/wpa_supplicant-${IFACE}.pid"
|
|
|
|
eend $? || return 1
|
2008-03-11 03:04:46 +05:30
|
|
|
|
|
|
|
# If we don't have a working wpa_cli and action file continue
|
2007-11-21 21:09:43 +05:30
|
|
|
if [ -z "${wpac}" ]; then
|
2008-03-11 03:04:46 +05:30
|
|
|
if service_started devd; then
|
|
|
|
ebegin "Backgrounding ..."
|
2011-01-17 15:19:07 +05:30
|
|
|
exit 1
|
2008-03-11 03:04:46 +05:30
|
|
|
fi
|
|
|
|
return 0
|
2007-11-21 21:09:43 +05:30
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
# Starting wpa_supplication-0.4.0, we can get wpa_cli to
|
|
|
|
# start/stop our scripts from wpa_supplicant messages
|
|
|
|
local inact=false
|
2007-12-18 23:29:29 +05:30
|
|
|
service_inactive && inact=true
|
|
|
|
mark_service_inactive
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
ebegin "Starting wpa_cli on" "${IFACE}"
|
2007-09-25 17:50:00 +05:30
|
|
|
start-stop-daemon --start --exec "${wpac}" \
|
2007-04-05 16:48:42 +05:30
|
|
|
--pidfile "/var/run/wpa_cli-${IFACE}.pid" \
|
2009-01-21 14:55:34 +05:30
|
|
|
-- ${cliopts} -a "${actfile}" -p "${ctrl_dir}" -i "${IFACE}" \
|
2007-04-05 16:48:42 +05:30
|
|
|
-P "/var/run/wpa_cli-${IFACE}.pid" -B
|
2007-11-28 21:15:03 +05:30
|
|
|
if eend $?; then
|
2007-04-05 16:48:42 +05:30
|
|
|
ebegin "Backgrounding ..."
|
2011-01-17 15:19:07 +05:30
|
|
|
exit 1
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
|
|
|
|
|
|
|
# wpa_cli failed to start? OK, error here
|
2007-09-25 17:50:00 +05:30
|
|
|
start-stop-daemon --quiet --stop --exec "${wpas}" \
|
2007-04-05 16:48:42 +05:30
|
|
|
--pidfile "/var/run/wpa_supplicant-${IFACE}.pid"
|
2007-12-18 23:29:29 +05:30
|
|
|
${inact} || mark_service_stopped
|
2007-04-05 16:48:42 +05:30
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
wpa_supplicant_post_stop()
|
|
|
|
{
|
2007-09-25 17:50:00 +05:30
|
|
|
local wpas=/usr/sbin/wpa_supplicant wpac=/usr/bin/wpa_cli
|
|
|
|
|
|
|
|
if [ ! -x "${wpas}" ]; then
|
|
|
|
wpas=/sbin/wpa_supplicant
|
|
|
|
wpac=/bin/wpa_cli
|
|
|
|
fi
|
|
|
|
|
2007-11-22 18:58:14 +05:30
|
|
|
if yesno "${IN_BACKGROUND}"; then
|
2010-09-02 20:12:11 +05:30
|
|
|
# Only stop wpa_supplicant if it's not the controlling daemon
|
|
|
|
! service_started_daemon "${RC_SVCNAME}" "${wpas}" 1
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
|
|
|
[ $? != 0 ] && return 0
|
|
|
|
|
|
|
|
local pidfile="/var/run/wpa_cli-${IFACE}.pid"
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ -f ${pidfile} ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
ebegin "Stopping wpa_cli on ${IFACE}"
|
2007-09-25 17:50:00 +05:30
|
|
|
start-stop-daemon --stop --exec "${wpac}" --pidfile "${pidfile}"
|
2007-04-05 16:48:42 +05:30
|
|
|
eend $?
|
|
|
|
fi
|
|
|
|
|
|
|
|
pidfile="/var/run/wpa_supplicant-${IFACE}.pid"
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ -f ${pidfile} ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
ebegin "Stopping wpa_supplicant on ${IFACE}"
|
2007-09-25 17:50:00 +05:30
|
|
|
start-stop-daemon --stop --exec "${wpas}" --pidfile "${pidfile}"
|
2007-04-05 16:48:42 +05:30
|
|
|
eend $?
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If wpa_supplicant exits uncleanly, we need to remove the stale dir
|
|
|
|
[ -S "/var/run/wpa_supplicant/${IFACE}" ] \
|
|
|
|
&& rm -f "/var/run/wpa_supplicant/${IFACE}"
|
|
|
|
}
|