relocate packages on recipes-base/recipes-enigma2/recipes-wlan.
[vuplus_openvuplus_3.0] / meta-openvuplus / recipes-connectivity / wpa-supplicant / wpa-supplicant-0.7.3 / ifupdown.sh
1 #!/bin/sh
2
3 #####################################################################
4 ## Purpose
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.
9 #
10 # /etc/wpa_supplicant/functions.sh is sourced by this file.
11 #
12 # This file is provided by the wpasupplicant package.
13
14 #####################################################################
15 # Copyright (C) 2006 - 2009 Debian/Ubuntu wpasupplicant Maintainers 
16 # <pkg-wpa-devel@lists.alioth.debian.org>
17 #
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.
22 #
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.
27 #
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.
30
31 if [ -n "$IF_WPA_MAINT_DEBUG" ]; then
32         set -x
33 fi
34
35 # quit if we're called for the loopback
36 if [ "$IFACE" = lo ]; then
37         exit 0
38 fi
39
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"
44 else
45         WPA_IFACE="$IFACE"
46 fi
47
48 # source functions
49 if [ -f /etc/wpa_supplicant/functions.sh ]; then
50         . /etc/wpa_supplicant/functions.sh
51 else
52         exit 0
53 fi
54
55 # quit if executables are not installed
56 if [ ! -x "$WPA_SUP_BIN" ] || [ ! -x "$WPA_CLI_BIN" ]; then
57         exit 0
58 fi
59
60 do_start () {
61         if test_wpa_cli; then
62                 # if wpa_action is active for this IFACE, do nothing
63                 ifupdown_locked && exit 0
64
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"
69                 fi
70                 exit 1
71         elif ! set | grep -q "^IF_WPA"; then
72                 # no wpa- option defined for IFACE, do nothing
73                 exit 0
74         fi
75
76         # ensure stale ifupdown_lock marker is purged
77         ifupdown_unlock
78
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"
83                         exit 1
84                 fi
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"
88                                 exit 1
89                         fi
90                 fi
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"
93                         exit 1
94                 fi
95                 IF_WPA_CONF="$IF_WPA_ROAM"
96                 WPA_ACTION_SCRIPT="/usr/sbin/wpa_action"
97         fi
98
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"
103                         exit 1
104                 fi      
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"
110                 else
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"
114                 fi
115         else
116                 # specify the default ctrl_interface
117                 WPA_SUP_CONF="-C $WPA_CTRL_DIR"
118         fi
119 }
120
121 do_stop () {
122         if test_wpa_cli; then
123                 # if wpa_action is active for this IFACE and calling ifdown,
124                 # do nothing
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.
129                 :
130         else
131                 exit 0
132         fi
133 }
134
135 case "$MODE" in 
136         start)
137                 do_start
138                 case "$PHASE" in
139                         pre-up)
140                                 kill_wpa_supplicant
141                                 init_wpa_supplicant     || exit 1
142                                 conf_wpa_supplicant     || { kill_wpa_supplicant; exit 1; }
143                                 ;;
144                         post-up)
145                                 init_wpa_cli            || { kill_wpa_supplicant; exit 1; }
146                                 ;;
147                 esac
148                 ;;
149
150         stop)
151                 do_stop
152                 case "$PHASE" in
153                         pre-down)
154                                 kill_wpa_cli
155                                 ;;
156                         post-down)
157                                 kill_wpa_supplicant
158                                 ;;
159                         *)
160                                 wpa_msg stderr "unknown phase: \"$PHASE\""
161                                 exit 1
162                                 ;;
163                 esac
164                 ;;
165         
166         *)
167                 wpa_msg stderr "unknown mode: \"$MODE\""
168                 exit 1
169                 ;;
170 esac
171
172 exit 0