3 #####################################################################
5 # This file is executed by ifupdown in pre-up, post-up, pre-down and
6 # post-down phases of network interface configuration. It allows
7 # ifup(8), and ifdown(8) to manage wpa_supplicant(8) and wpa_cli(8)
8 # processes running in daemon mode.
10 # /etc/wpa_supplicant/functions.sh is sourced by this file.
12 # This file is provided by the wpasupplicant package.
14 #####################################################################
15 # Copyright (C) 2006 - 2009 Debian/Ubuntu wpasupplicant Maintainers
16 # <pkg-wpa-devel@lists.alioth.debian.org>
18 # This program is free software; you can redistribute it and/or
19 # modify it under the terms of the GNU General Public License
20 # as published by the Free Software Foundation; either version 2
21 # of the License, or (at your option) any later version.
23 # This program is distributed in the hope that it will be useful,
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 # GNU General Public License for more details.
28 # On Debian GNU/Linux systems, the text of the GPL license,
29 # version 2, can be found in /usr/share/common-licenses/GPL-2.
31 if [ -n "$IF_WPA_MAINT_DEBUG" ]; then
35 # quit if we're called for the loopback
36 if [ "$IFACE" = lo ]; then
40 # allow wpa_supplicant interface to be specified via wpa-iface
41 # useful for starting wpa_supplicant on one interface of a bridge
42 if [ -n "$IF_WPA_IFACE" ]; then
43 WPA_IFACE="$IF_WPA_IFACE"
49 if [ -f /etc/wpa_supplicant/functions.sh ]; then
50 . /etc/wpa_supplicant/functions.sh
55 # quit if executables are not installed
56 if [ ! -x "$WPA_SUP_BIN" ] || [ ! -x "$WPA_CLI_BIN" ]; then
62 # if wpa_action is active for this IFACE, do nothing
63 ifupdown_locked && exit 0
65 # if the administrator is calling ifup, say something useful
66 if [ "$PHASE" = "pre-up" ]; then
67 wpa_msg stderr "wpa_action is managing ifup/ifdown state of $WPA_IFACE"
68 wpa_msg stderr "execute \`ifdown --force $WPA_IFACE' to stop wpa_action"
71 elif ! set | grep -q "^IF_WPA"; then
72 # no wpa- option defined for IFACE, do nothing
76 # ensure stale ifupdown_lock marker is purged
79 # preliminary sanity checks for roaming daemon
80 if [ -n "$IF_WPA_ROAM" ]; then
81 if [ "$METHOD" != "manual" ]; then
82 wpa_msg stderr "wpa-roam can only be used with the \"manual\" inet METHOD"
85 if [ -n "$IF_WPA_MAPPING_SCRIPT" ]; then
86 if ! type "$IF_WPA_MAPPING_SCRIPT" >/dev/null; then
87 wpa_msg stderr "wpa-mapping-script \"$IF_WPA_MAPPING_SCRIPT\" is not valid"
91 if [ -n "$IF_WPA_MAPPING_SCRIPT_PRIORITY" ] && [ -z "$IF_WPA_MAPPING_SCRIPT" ]; then
92 wpa_msg stderr "\"wpa-mapping-script-priority 1\" is invalid without a wpa-mapping-script"
95 IF_WPA_CONF="$IF_WPA_ROAM"
96 WPA_ACTION_SCRIPT="/usr/sbin/wpa_action"
99 # master function; determines if ifupdown.sh should do something or not
100 if [ -n "$IF_WPA_CONF" ] && [ "$IF_WPA_CONF" != "managed" ]; then
101 if [ ! -s "$IF_WPA_CONF" ]; then
102 wpa_msg stderr "cannot read contents of $IF_WPA_CONF"
105 WPA_SUP_CONF_CTRL_DIR=$(sed -n -e 's/[[:space:]]*#.*//g' -e 's/[[:space:]]\+.*$//g' \
106 -e 's/^ctrl_interface=\(DIR=\)\?\(.*\)/\2/p' "$IF_WPA_CONF")
107 if [ -n "$WPA_SUP_CONF_CTRL_DIR" ]; then
108 WPA_CTRL_DIR="$WPA_SUP_CONF_CTRL_DIR"
109 WPA_SUP_CONF="-c $IF_WPA_CONF"
111 # specify the default ctrl_interface since none was defined in
112 # the given IF_WPA_CONF
113 WPA_SUP_CONF="-c $IF_WPA_CONF -C $WPA_CTRL_DIR"
116 # specify the default ctrl_interface
117 WPA_SUP_CONF="-C $WPA_CTRL_DIR"
122 if test_wpa_cli; then
123 # if wpa_action is active for this IFACE and calling ifdown,
125 ifupdown_locked && exit 0
126 elif test_wpa_supplicant; then
127 # wpa_supplicant process exists for this IFACE, but wpa_cli
128 # process does not. Allow stop mode to kill this process.
141 init_wpa_supplicant || exit 1
142 conf_wpa_supplicant || { kill_wpa_supplicant; exit 1; }
145 init_wpa_cli || { kill_wpa_supplicant; exit 1; }
160 wpa_msg stderr "unknown phase: \"$PHASE\""
167 wpa_msg stderr "unknown mode: \"$MODE\""