15
15
# On Debian GNU/Linux systems, the text of the GPL license can be
16
16
# found in /usr/share/common-licenses/GPL.
18
if [ -z "$1" -o -z "$2" ]; then
18
if [ -n "$IF_WPA_ROAM_MAINT_DEBUG" ]; then
22
if [ -z "$1" ] || [ -z "$2" ]; then
19
23
echo "Usage: $0 IFACE ACTION"
23
# network interface is first argument
25
# action in [CONNECTED|DISCONNECTED|stop|reload] is second argument
29
WPA_LOGFILE="/var/log/wpa_action.log"
30
# lock wpa_cli ACTION events
31
WPA_LOCKFILE="/var/lock/wpa_action.$IFACE.lock"
33
if [ -n "$IF_WPA_ROAM_MAINT_DEBUG" ]; then
29
# [CONNECTED|DISCONNECTED|stop|reload|check]
32
if [ -f /etc/wpa_supplicant/functions.sh ]; then
33
. /etc/wpa_supplicant/functions.sh
38
# the purpose of the following locking function is to ensure we are not
39
# interrupting the currently active action
41
# test and set lock file in an atomic action
42
if ! (umask 222; echo "$$" >"$WPA_LOCKFILE") 2>/dev/null; then
44
echo "$0 is locked on $IFACE, \"$ACTION\" ACTION aborted"
50
if [ -e "$WPA_LOCKFILE" ]; then
51
echo "Waiting for current ACTION to finish before processing \"$ACTION\" ACTION"
52
local ACTION_WAIT="0" MAX_ACTION_WAIT="60"
53
until [ ! -e "$WPA_LOCKFILE" ]; do
54
if [ "$ACTION_WAIT" -ge "$MAX_ACTION_WAIT" ]; then
57
ACTION_WAIT=$(($ACTION_WAIT+1))
66
if [ -e "$WPA_LOCKFILE" ]; then
73
exec >> "$WPA_LOGFILE" 2>&1
77
echo "########## $(date +"%H:%M:%S %Y-%m-%d") ##########"
78
echo "IFACE=$IFACE ACTION=$ACTION"
82
echo "WPA_ID=$WPA_ID WPA_ID_STR=$WPA_ID_STR"
83
echo "WPA_CTRL_DIR=$WPA_CTRL_DIR"
88
if [ -e /etc/network/interfaces ]; then
89
INTERFACES_FILE="/etc/network/interfaces"
91
echo "Cannot locate ifupdown's \"interfaces\" file, $IFACE will not be configured"
96
if [ -e /etc/network/run/ifstate ]; then
98
IFSTATE_FILE="/etc/network/run/ifstate"
99
elif [ -e /var/run/network/ifstate ]; then
100
# ifstate file lives in /var/run on Ubuntu
101
IFSTATE_FILE="/var/run/network/ifstate"
103
echo "Cannot locate ifupdown's \"ifstate\" file, $IFACE will not be configured"
111
# ensure this is not present in environment and private to function
112
local WPA_LOGICAL_IFACE
113
# If "wpa-script-priority 1" is set in /e/n/i we'll skip the id_str matching
114
if [ -z "$IF_WPA_MAPPING_SCRIPT_PRIORITY" -a -n "$WPA_ID_STR" ]; then
115
WPA_LOGICAL_IFACE="$WPA_ID_STR"
116
echo "Mapping logical interface via id_str: $WPA_LOGICAL_IFACE"
119
if [ -z "$WPA_LOGICAL_IFACE" -a -n "$IF_WPA_MAPPING_SCRIPT" ]; then
120
# find a suitable WPA_LOGICAL_IFACE by running the mapping script
121
echo "Mapping logical interface via wpa-mapping-script: $IF_WPA_MAPPING_SCRIPT"
123
# ensure this is private to function
125
WPA_MAP_STDIN=$(set | sed -n -e 's/^\(IF_WPA_MAP[0-9]*\)=.*/echo\ \$\1/p')
126
if [ -n "$WPA_MAP_STDIN" ]; then
127
WPA_LOGICAL_IFACE=$(eval "$WPA_MAP_STDIN" | "$IF_WPA_MAPPING_SCRIPT" "$IFACE")
129
WPA_LOGICAL_IFACE=$("$IF_WPA_MAPPING_SCRIPT" "$IFACE")
132
if [ -n "$WPA_LOGICAL_IFACE" ]; then
133
echo "Mapping script result: $WPA_LOGICAL_IFACE"
135
echo "Mapping script failed."
139
# use fallback mapping if present
140
if [ -z "$WPA_LOGICAL_IFACE" ]; then
141
if [ -n "$IF_WPA_ROAM_DEFAULT_IFACE" ]; then
142
# wpa-roam-default-iface
143
WPA_LOGICAL_IFACE="$IF_WPA_ROAM_DEFAULT_IFACE"
144
echo "Using wpa-roam-default-iface: $WPA_LOGICAL_IFACE"
146
WPA_LOGICAL_IFACE="default"
147
echo "Using fallback logical interface: $WPA_LOGICAL_IFACE"
151
# grep for matching LOGICAL interface stanza in interfaces file
152
if [ -n "$WPA_LOGICAL_IFACE" ]; then
153
if grep --quiet "^iface $WPA_LOGICAL_IFACE inet" "$INTERFACES_FILE"; then
154
echo "ifup $IFACE=$WPA_LOGICAL_IFACE"
155
# Map to LOGICAL and bring up the IFACE
156
if grep --quiet "^$IFACE=$IFACE" "$IFSTATE_FILE"; then
157
# Force settings over the unconfigured "master" IFACE
158
/sbin/ifup --force "$IFACE=$WPA_LOGICAL_IFACE"
160
/sbin/ifup "$IFACE=$WPA_LOGICAL_IFACE"
163
echo "No network defined for \"$WPA_LOGICAL_IFACE\" in \"$INTERFACES_FILE\""
166
echo "No suitable logical interface mapping for ifupdown to configure"
171
# grep for IFACE state in ifstate file, is it up or down?
172
if grep --quiet "^$IFACE" "$IFSTATE_FILE"; then
174
# Take down the IFACE
175
/sbin/ifdown "$IFACE"
177
echo "Ignoring request to take \"$IFACE\" down, it is not up"
182
# use iproute if installed
183
if [ -x /sbin/ip ]; then
184
# flush previous protocol address
185
# it almost never needs flushing, so keep it quiet
186
/sbin/ip addr flush dev "$IFACE" 2>/dev/null
187
# Keep IFACE in 'up' operstate
188
/sbin/ip link set "$IFACE" up
190
# Keep IFACE in 'up' operstate
191
/sbin/ifconfig "$IFACE" up
195
# wpa_cli wrapper, ctrl_iface path and interface supplied
196
# cannot be used for interactive actions, environmental variableWPA_CTRL_DIR is not present
198
LC_ALL=C /sbin/wpa_cli -p $WPA_CTRL_DIR -i $IFACE "$@"
202
WPA_CLI_PNAME="wpa_cli"
203
WPA_CLI_PIDFILE="/var/run/wpa_action.$IFACE.pid"
204
# Kill wpa_cli daemon
205
if [ -f "$WPA_CLI_PIDFILE" ]; then
206
start-stop-daemon --stop --oknodo --verbose \
207
--name "$WPA_CLI_PNAME" --pidfile "$WPA_CLI_PIDFILE"
209
if [ -f "$WPA_CLI_PIDFILE" ]; then
210
rm -f "$WPA_CLI_PIDFILE"
215
kill_wpa_supplicant () {
216
WPA_SUP_PNAME="wpa_supplicant"
217
WPA_SUP_PIDFILE="/var/run/wpa_supplicant.$IFACE.pid"
218
# Kill wpa_supplicant daemon
219
if [ -f "$WPA_SUP_PIDFILE" ]; then
220
start-stop-daemon --stop --oknodo --verbose \
221
--name "$WPA_SUP_PNAME" --pidfile "$WPA_SUP_PIDFILE"
223
if [ -f "$WPA_SUP_PIDFILE" ]; then
224
rm -f "$WPA_SUP_PIDFILE"
229
reload_wpa_supplicant () {
230
WPA_SUP_PNAME="wpa_supplicant"
231
WPA_SUP_PIDFILE="/var/run/wpa_supplicant.$IFACE.pid"
232
# Reload wpa_supplicant's configuration file
233
if [ -f "$WPA_SUP_PIDFILE" ]; then
234
echo "Reloading wpa_supplicant configuration file via HUP signal"
235
start-stop-daemon --stop --signal HUP \
236
--name "$WPA_SUP_PNAME" --pidfile "$WPA_SUP_PIDFILE"
238
echo "Cannot $ACTION, $WPA_SUP_PIDFILE does not exist"
248
if check_ifupdown; then
41
wpa_hysteresis_check || exit 1
44
if ifupdown_check; then
260
if check_ifupdown; then
53
wpa_hysteresis_check || exit 1
56
if ifupdown_check; then
63
test_wpa_supplicant || exit 1
270
if check_ifupdown; then
65
if ifupdown_check; then
273
68
kill_wpa_supplicant
278
73
"restart"|"reload")
74
test_wpa_supplicant || exit 1
279
75
reload_wpa_supplicant
81
test_wpa_supplicant || exit 1
82
test_wpa_cli || exit 1
285
echo "Unknown action: \"$ACTION\""
86
echo "Unknown action: \"$WPA_ACTION\""