/[baselayout]/branches/rc-scripts-1_6/net-scripts/net.modules.d/wpa_supplicant
Gentoo

Contents of /branches/rc-scripts-1_6/net-scripts/net.modules.d/wpa_supplicant

Parent Directory Parent Directory | Revision Log Revision Log


Revision 842 - (show annotations) (download)
Thu Jan 13 14:51:03 2005 UTC (10 years, 3 months ago) by uberlord
File size: 6014 byte(s)
wpa_supplicant forces ctrl_interface to /var/run/wpa_supplicant
and removes stale directories
clean_pidfile function no longer errors on empty pidfiles
ipppd fixes for shutdown

1 # wpa_supplicant (net-wireless/wpa_supplicant) module for net-scripts
2 # Version 1.0.0
3 # Copyright (c) 2004 Gentoo Foundation
4 # Distributed under the terms of the GNU General Public License V2
5 # Contributed by Roy Marples (uberlord@gentoo.org)
6
7 # Fix any potential localisation problems
8 # Note that LC_ALL trumps LC_anything_else according to locale(7)
9 wpa_supplicant() {
10 LC_ALL=C /usr/sbin/wpa_supplicant "$@"
11 }
12
13 wpa_cli() {
14 LC_ALL=C /usr/bin/wpa_cli "$@"
15 }
16
17 # char* wpa_supplicant_provides(void)
18 #
19 # Returns a string to change module definition for starting up
20 wpa_supplicant_provides() {
21 echo "wireless"
22 }
23
24 # void wpa_supplicant_depend(void)
25 #
26 # Sets up the dependancies for the module
27 wpa_supplicant_depend() {
28 after macchanger
29 before interface
30 }
31
32 # bool wpa_supplicant_check_installed(void)
33 #
34 # Returns 1 if isnd4k-utils is installed, otherwise 0
35 wpa_supplicant_check_installed() {
36 [[ -x /usr/sbin/wpa_supplicant ]] && return 0
37 ${1:-false} && eerror "For WPA support (wpa_supplicant) support, emerge net-wireless/wpa-supplicant"
38 return 1
39 }
40
41 # bool wpa_supplicant_check_depends(void)
42 #
43 # Checks to see if we have the needed functions
44 wpa_supplicant_check_depends() {
45 local f
46
47 for f in interface_exists interface_variable; do
48 [[ $( type -t ${f} ) == function ]] && continue
49 eerror "wpa_supplicant: missing required function ${f}\n"
50 return 1
51 done
52
53 return 0
54 }
55
56 # bool wpa_supplicant_check_extensions(char *interface)
57 #
58 # Checks to see if wireless extensions are enabled on the interface
59 wpa_supplicant_check_extensions() {
60 grep -q "${1}: " /proc/net/wireless
61 }
62
63 # char* wpa_supplicant_get_essid(char *interface)
64 #
65 # Returns the MAC address of the Access Point
66 # the interface is connected to
67 wpa_supplicant_get_essid() {
68 wpa_cli -i${1} status 2>/dev/null | awk -F= '/^ssid=/ { print $2 }'
69 }
70
71 # char* wpa_supplicant_get_ap_mac_address(char *interface)
72 #
73 # Returns the MAC address of the Access Point
74 # the interface is connected to
75 wpa_supplicant_get_ap_mac_address() {
76 wpa_cli -i${1} status 2>/dev/null | awk -F= '/^bssid=/ { print toupper($2) }'
77 }
78
79 # bool wpa_supplicant_associated(char *interface)
80 #
81 # Returns 0 if we're associated correctly or 1 if not
82 # Note that just because we are associated does not mean we are using the
83 # correct encryption keys
84 wpa_supplicant_associated() {
85 local -a status=( $( wpa_cli -i${1} status | awk -F= '/^key_mgmt|^wpa_state/ { print $2 }' ) )
86
87 if [[ ${status[0]} == NONE ]]; then
88 [[ ${status[1]} == ASSOCIATED ]]
89 else
90 [[ ${status[1]} == COMPLETED ]]
91 fi
92 return $?
93 }
94
95 # void wpa_supplicant_kill(char *interface, bool report)
96 #
97 # Kills any existing wpa_supplicant process on the interface
98 wpa_supplicant_kill() {
99 local iface=$1 report=${2:-false}
100 local pid=$( ps --no-headers -fC wpa_supplicant 2>/dev/null | awk '/-i'${iface}'/ { print $2 }' )
101
102 if [[ -n ${pid} ]]; then
103 ${report} && ebegin "Stopping wpa_supplicant on ${iface}"
104 kill -s TERM ${pid}
105 ${report} && eend 0
106 fi
107
108 # If wpa_supplicant exits uncleanly, we need to remove the stale dir
109 [[ -d /var/run/wpa_supplicant/${iface} ]] && rm -f /var/run/wpa_supplicant/${iface}
110 }
111
112 # bool wpa_supplicant_associate(char *interface)
113 #
114 # Returns 0 if wpa_supplicant associates and authenticates to an AP
115 # otherwise, 1
116 wpa_supplicant_associate() {
117 local iface=${1} ifvar=$( interface_variable ${1} ) timeout i
118
119 eval timeout=\"\$\{wpa_timeout_${ifvar}:-60\}\"
120 for (( i=0; i<${timeout}; i++ )); do
121 wpa_supplicant_associated ${iface} && break
122 sleep 1
123 done
124 if [[ ${i} == ${timeout} ]]; then
125 if ! wpa_supplicant_associated ${iface}; then
126 [[ ${background} != yes ]] && eend 1 "timed out"
127
128 # We now need to kill the process
129 wpa_supplicant_kill ${iface}
130
131 return 1
132 fi
133 fi
134 }
135
136 # bool wpa_supplicant_pre_start(char *interface)
137 #
138 # Start wpa_supplicant on an interface and wait for association
139 # Returns 0 (true) when successful, non-zero otherwise
140 wpa_supplicant_pre_start() {
141 local iface=$1 opts ifvar cfgfile=/etc/wpa_supplicant.conf timeout
142
143 # We only work on wirelesss interfaces
144 wpa_supplicant_check_extensions ${iface} || return 0
145
146 # Kill off any existing wpa_supplicant on this interface
147 # This is so we can re-read the configuration file and clean any stale
148 # directories
149 wpa_supplicant_kill ${iface} true
150
151 ebegin "Starting wpa_supplicant on ${iface}"
152
153 if [[ ! -f ${cfgfile} ]]; then
154 eend 1 "configuration file ${cfgfile} not found!"
155 return 1
156 fi
157
158 local ctrl_dir=$( awk -F# '/^ctrl_interface=/ { print $1 }' ${cfgfile} )
159 ctrl_dir=${ctrl_dir/ctrl_interface=/}
160 if [[ ${ctrl_dir} != "/var/run/wpa_supplicant" ]]; then
161 eerror "${cfgfile} must set"
162 eerror " ctrl_interface=/var/run/wpa_supplicant"
163 eend 1
164 return 1
165 fi
166
167 ifvar=$( interface_variable ${iface} )
168 eval opts=\" \$\{wpa_supplicant_${ifvar}\}\"
169 [[ ${opts} != *' -D'* ]] && ewarn "wpa_supplicant_${ifvar} does not define a driver"
170
171 # Some drivers require the interface to be up
172 interface_up ${iface}
173
174 if ! wpa_supplicant ${opts} -B -c/etc/wpa_supplicant.conf -i${iface} ; then
175 eend 1
176 return 1
177 fi
178
179 if ! wpa_cli -i${iface} status &>/dev/null ; then
180 eend 1 "wpa_supplicant has exited unexpectedly"
181 return 1
182 fi
183
184 eindent
185 veinfo "Waiting for association"
186 eend 0
187
188 wpa_supplicant_associate ${iface} || return 1
189
190 # Set ESSID for essidnet and report
191 ESSID=$( wpa_supplicant_get_essid ${iface} )
192 local -a status=( "$( wpa_cli -i${iface} status | awk -F= '/^bssid|^pairwise_cipher|^key_mgmt/ { print $2 }' )" )
193 local mac=$( echo ${status[0]} | tr '[:lower:]' '[:upper:]' )
194 einfo "${iface} connected to \"${ESSID//\\\\/\\\\}\" at ${mac}"
195
196 if [[ ${status[2]} == NONE ]]; then
197 if [[ ${status[1]} == NONE ]]; then
198 ewarn "not using any encryption"
199 else
200 veinfo "using ${status[1]}"
201 fi
202 else
203 veinfo "using ${status[2]}/${status[1]}"
204 fi
205 eoutdent
206
207 return 0
208 }
209
210 # bool wpa_supplicant_post_stop(char *iface)
211 #
212 # Stops wpa_supplicant on an interface
213 # Returns 0 (true) when successful, non-zero otherwise
214 wpa_supplicant_post_stop() {
215 wpa_supplicant_kill $1 true
216 return 0
217 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20