/[baselayout]/trunk/net/wpa_supplicant.sh
Gentoo

Contents of /trunk/net/wpa_supplicant.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2918 - (show annotations) (download) (as text)
Tue Sep 25 12:20:00 2007 UTC (6 years, 10 months ago) by uberlord
File MIME type: text/x-sh
File size: 4718 byte(s)
Work with wpa_supplicant in /usr
1 # Copyright 2004-2007 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 wpa_supplicant_depend() {
5 if [ -x /usr/sbin/wpa_supplicant ]; then
6 program start /usr/sbin/wpa_supplicant
7 else
8 program start /sbin/wpa_supplicant
9 fi
10 after macnet plug
11 before interface
12 provide wireless
13
14 # Prefer us over iwconfig
15 after iwconfig
16 }
17
18 # Only set these functions if not set already
19 # IE, prefer to use iwconfig
20 if ! type _get_ssid >/dev/null 2>/dev/null ; then
21 _get_ssid() {
22 local timeout=5 ssid=
23
24 while [ ${timeout} -gt 0 ] ;do
25 ssid=$(wpa_cli -i"${IFACE}" status | sed -n -e 's/^ssid=//p')
26 if [ -n "${ssid}" ] ; then
27 echo "${ssid}"
28 return 0
29 fi
30 sleep 1
31 timeout=$((timeout - 1))
32 done
33
34 return 1
35 }
36
37 _get_ap_mac_address() {
38 wpa_cli -i"${IFACE}" status | sed -n -e 's/^bssid=\(.*\)$/\1/p' \
39 | tr '[:lower:]' '[:upper:]'
40 }
41 fi
42
43 wpa_supplicant_pre_start() {
44 local opts= cfgfile= ctrl_dir=
45 local wpas=/usr/sbin/wpa_supplicant wpac=/usr/bin/wpa_cli
46
47 if [ ! -x "${wpas}" ]; then
48 wpas=/sbin/wpa_supplicant
49 wpac=/bin/wpa_cli
50 fi
51
52 _is_wireless || return 0
53
54 # We don't configure wireless if we're being called from
55 # the background unless we're not currently running
56 if [ "${IN_BACKGROUND}" = "true" ] ; then
57 if service_started_daemon "${SVCNAME}" /sbin/wpa_supplicant ; then
58 SSID=$(_get_ssid "${IFACE}")
59 SSIDVAR=$(_shell_var "${SSID}")
60 save_options "SSID" "${SSID}"
61 metric=2000
62 fi
63 return 0
64 fi
65
66 save_options "SSID" ""
67 eval opts=\$wpa_supplicant_${IFVAR}
68 ebegin "Starting wpa_supplicant on" "${IFVAR}"
69
70
71 if [ -x /sbin/iwconfig ] ; then
72 local x=
73 for x in txpower rate rts frag ; do
74 iwconfig "${IFACE}" "${x}" auto 2>/dev/null
75 done
76 fi
77
78 cfgfile=${opts##* -c}
79 if [ -n "${cfgfile}" -a "${cfgfile}" != "${opts}" ] ; then
80 case "${cfgfile}" in
81 " "*) cfgfile=${cfgfile# *} ;;
82 esac
83 cfgfile=${cfgfile%% *}
84 else
85 # Support new and old style locations
86 cfgfile="/etc/wpa_supplicant/wpa_supplicant-${IFACE}.conf"
87 [ ! -e "${cfgfile}" ] \
88 && cfgfile="/etc/wpa_supplicant/wpa_supplicant.conf"
89 [ ! -e ${cfgfile} ] \
90 && cfgfile="/etc/wpa_supplicant.conf"
91 opts="${opts} -c ${cfgfile}"
92 fi
93
94 if [ ! -f ${cfgfile} ] ; then
95 eend 1 "/etc/wpa_supplicant/wpa_supplicant.conf not found"
96 return 1
97 fi
98
99 # Work out where the ctrl_interface dir is if it's not specified
100 local ctrl_dir=$(sed -n -e 's/[[:space:]]*#.*//g;s/[[:space:]]*$//g;s/^ctrl_interface=//p' "${cfgfile}")
101 if [ -z "${ctrl_dir}" ] ; then
102 ctrl_dir=${opts##* -C}
103 if [ -n "${ctrl_dir}" -a "${ctrl_dir}" != "${opts}" ] ; then
104 case "${ctrl_dir}" in
105 " "*) ctrl_dir=${ctrl_dir# *} ;;
106 esac
107 ctrl_dir=${ctrl_dir%% *}
108 else
109 ctrl_dir="/var/run/wpa_supplicant"
110 opts="${opts} -C ${ctrl_dir}"
111 fi
112 fi
113 save_options ctrl_dir "${ctrl_dir}"
114
115 actfile="/etc/wpa_supplicant/wpa_cli.sh"
116
117 start-stop-daemon --start --exec "${wpas}" \
118 --pidfile "/var/run/wpa_supplicant-${IFACE}.pid" \
119 -- ${opts} -W -B -i "${IFACE}" \
120 -P "/var/run/wpa_supplicant-${IFACE}.pid"
121 eend $? || return 1
122
123 # Starting wpa_supplication-0.4.0, we can get wpa_cli to
124 # start/stop our scripts from wpa_supplicant messages
125 local inact=false
126 service_inactive "${SVCNAME}" && inact=true
127 mark_service_inactive "${SVCNAME}"
128
129 ebegin "Starting wpa_cli on" "${IFACE}"
130 start-stop-daemon --start --exec "${wpac}" \
131 --pidfile "/var/run/wpa_cli-${IFACE}.pid" \
132 -- -a /etc/wpa_supplicant/wpa_cli.sh -p "${ctrl_dir}" -i "${IFACE}" \
133 -P "/var/run/wpa_cli-${IFACE}.pid" -B
134 if eend $? ; then
135 ebegin "Backgrounding ..."
136 exit 1
137 fi
138
139 # wpa_cli failed to start? OK, error here
140 start-stop-daemon --quiet --stop --exec "${wpas}" \
141 --pidfile "/var/run/wpa_supplicant-${IFACE}.pid"
142 ${inact} || mark_service_stopped "${SVCNAME}"
143 return 1
144 }
145
146 wpa_supplicant_post_stop() {
147 local wpas=/usr/sbin/wpa_supplicant wpac=/usr/bin/wpa_cli
148
149 if [ ! -x "${wpas}" ]; then
150 wpas=/sbin/wpa_supplicant
151 wpac=/bin/wpa_cli
152 fi
153
154 if [ "${IN_BACKGROUND}" = "true" ] ; then
155 # Only stop wpa_supplicant if it's not the controlling daemon
156 ! service_started_daemon "${SVCNAME}" "${wpas}" 1
157 fi
158 [ $? != 0 ] && return 0
159
160 local pidfile="/var/run/wpa_cli-${IFACE}.pid"
161 if [ -f ${pidfile} ] ; then
162 ebegin "Stopping wpa_cli on ${IFACE}"
163 start-stop-daemon --stop --exec "${wpac}" --pidfile "${pidfile}"
164 eend $?
165 fi
166
167 pidfile="/var/run/wpa_supplicant-${IFACE}.pid"
168 if [ -f ${pidfile} ] ; then
169 ebegin "Stopping wpa_supplicant on ${IFACE}"
170 start-stop-daemon --stop --exec "${wpas}" --pidfile "${pidfile}"
171 eend $?
172 fi
173
174 # If wpa_supplicant exits uncleanly, we need to remove the stale dir
175 [ -S "/var/run/wpa_supplicant/${IFACE}" ] \
176 && rm -f "/var/run/wpa_supplicant/${IFACE}"
177 }
178
179 # vim: set ts=4 :

  ViewVC Help
Powered by ViewVC 1.1.20