]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/initscripts/system/wlanclient
wlanclient: Do not force using legacy interface to talk to the kernel
[people/pmueller/ipfire-2.x.git] / src / initscripts / system / wlanclient
CommitLineData
61027579
MT
1#!/bin/sh
2########################################################################
3# Begin $rc_base/init.d/wlan_client
4#
5# Description : Wireless client initscript
6#
7########################################################################
8
9. /etc/sysconfig/rc
10. ${rc_functions}
11
12eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
13
14WIRELESS_CONFIG="/var/ipfire/ethernet/wireless"
15
16function device_is_wireless() {
17 local device=${1}
18
19 if [ -d "/sys/class/net/${device}/wireless" ]; then
20 return 0
21 fi
22
23 return 1
24}
25
26function wpa_supplicant_make_config() {
27 local device=${1}
28 local config=${2}
29 shift 2
30
31 # Check if device is wireless.
32 local wireless="false"
33 if device_is_wireless ${device}; then
34 wireless="true"
35 fi
36
37 # Write a configuration file header.
38 (
39 echo "#"
40 echo "# THIS FILE IS AUTOMATICALLY GENERATED AND"
41 echo "# ANY CUSTOM CHANGES WILL BE OVERWRITTEN!"
42 echo "#"
43 echo
44 echo "ctrl_interface=/var/run/wpa_supplicant"
45 echo
46 ) > ${config}
47
48 local items=0
49
50 local line
51 while IFS="," read -ra line; do
52 # Skip commented lines.
53 [ "${line:0:1}" = "#" ] && continue
54
55 # Skip disabled entries.
56 [ "${line[2]}" = "on" ] || continue
57
58 wpa_supplicant_config_line \
59 ${device} ${config} \
60 --wireless="${wireless}" \
61 --mode="${line[3]}" \
62 --wpa-mode="${line[4]}" \
63 --ssid="${line[5]}" \
64 --psk="${line[6]}" \
f2c94780
MT
65 --priority="${line[7]}" \
66 --auth-mode="${line[8]}" \
67 --anonymous-identity="${line[9]}" \
68 --identity="${line[10]}" \
69 --password="${line[11]}"
61027579
MT
70
71 items=$(( ${items} + 1 ))
72
73 done < ${WIRELESS_CONFIG}
74
75 # Return exit code 2, when there are no entries in the
76 # configuration file.
77 if [ "${items}" = "0" ]; then
78 return 2
79 fi
80
81 return 0
82}
83
84function wpa_supplicant_config_line() {
85 local device=${1}
86 local config=${2}
87 shift 2
88
5addf347 89 local ieee80211w
f2c94780 90 local anonymous_identity
61027579 91 local auth_alg
f2c94780
MT
92 local auth_mode
93 local identity
61027579
MT
94 local proto
95 local key_mgmt
96 local pairwise
97 local group
98 local mode
f2c94780 99 local password
61027579
MT
100 local priority
101 local psk
102 local ssid
103 local wep_tx_keyidx
104 local wep_key0
105 local wireless="true"
106 local wpa_mode
107
108 while [ $# -gt 0 ]; do
109 case "${1}" in
f2c94780
MT
110 --anonymous-identity=*)
111 anonymous_identity=${1#--anonymous-identity=}
112 ;;
113 --auth-mode=*)
114 auth_mode=${1#--auth-mode=}
115 ;;
116 --identity=*)
117 identity=${1#--identity=}
118 ;;
61027579
MT
119 --mode=*)
120 mode=${1#--mode=}
121 ;;
f2c94780
MT
122 --password=*)
123 password=${1#--password=}
124 ;;
61027579
MT
125 --priority=*)
126 priority=${1#--priority=}
127 ;;
128 --psk=*)
129 psk=${1#--psk=}
130 ;;
131 --ssid=*)
132 ssid=${1#--ssid=}
133 ;;
134 --wireless=*)
135 wireless=${1#--wireless=}
136 ;;
137 --wpa-mode=*)
138 wpa_mode=${1#--wpa-mode=}
139 ;;
140 esac
141 shift
142 done
143
144 case "${mode}" in
f2c94780 145 EAP)
3403eb30 146 key_mgmt="WPA-EAP-SHA256 WPA-EAP"
f2c94780 147 ;;
5addf347
MT
148 WPA3)
149 key_mgmt="SAE"
150
151 ieee80211w="2"
152 ;;
61027579
MT
153 WPA2)
154 auth_alg="OPEN"
155 proto="RSN"
3403eb30 156 key_mgmt="WPA-PSK-SHA256 WPA-PSK"
61027579
MT
157 ;;
158 WPA)
159 auth_alg="OPEN"
160 proto="WPA"
3403eb30 161 key_mgmt="WPA-PSK-SHA256 WPA-PSK"
61027579
MT
162 ;;
163 WEP)
164 auth_alg="SHARED"
165 key_mgmt="NONE"
166
167 wep_tx_keyidx=0
168 wep_key0=${psk}
169 psk=""
170 ;;
171 NONE)
172 auth_alg="OPEN"
173 key_mgmt="NONE"
174 ;;
175 *)
176 # Unsupported mode.
177 return 1
178 ;;
179 esac
180
f2c94780 181 if [ "${mode}" = "EAP" -o "${mode}" = "WPA" -o "${mode}" = "WPA2" ]; then
61027579
MT
182 case "${wpa_mode}" in
183 CCMP-CCMP)
184 pairwise="CCMP"
185 group="CCMP"
186 ;;
187 CCMP-TKIP)
188 pairwise="CCMP"
189 group="TKIP"
190 ;;
191 TKIP-TKIP)
192 pairwise="TKIP"
193 group="TKIP"
194 ;;
195 *)
196 pairwise="CCMP TKIP"
197 group="CCMP TKIP"
198 ;;
199 esac
200 fi
201
202 (
203 echo "network={"
204
205 if [ -n "${ssid}" ]; then
206 echo " ssid=\"${ssid}\""
207 fi
208 if [ "${wireless}" = "true" ]; then
209 echo " scan_ssid=1"
210 fi
211 if [ -n "${auth_alg}" ]; then
212 echo " auth_alg=${auth_alg}"
213 fi
214 if [ -n "${key_mgmt}" ]; then
215 echo " key_mgmt=${key_mgmt}"
216 fi
217 if [ -n "${psk}" ]; then
5addf347
MT
218 if [ "${key_mgmt}" = "SAE" ]; then
219 echo " sae_password=\"${psk}\""
220 else
221 echo " psk=\"${psk}\""
222 fi
61027579
MT
223 fi
224 if [ -n "${wep_tx_keyidx}" ]; then
225 echo " wep_tx_keyidx=${wep_tx_keyidx}"
226 fi
227 if [ -n "${wep_key0}" ]; then
228 echo " wep_key0=\"${wep_key0}\""
229 fi
230 if [ -n "${proto}" ]; then
231 echo " proto=${proto}"
232 fi
233 if [ -n "${pairwise}" -a -n "${group}" ]; then
234 echo " pairwise=${pairwise}"
235 echo " group=${group}"
236 fi
237 if [ -n "${priority}" ]; then
238 echo " priority=${priority}"
239 fi
5addf347
MT
240 if [ -n "${ieee80211w}" ]; then
241 echo " ieee80211w=${ieee80211w}"
242 fi
61027579 243
f2c94780
MT
244 # EAP
245 if [ "${mode}" = "EAP" ]; then
246 if [ -n "${auth_mode}" ]; then
247 echo " eap=${auth_mode}"
248 else
249 echo " eap=PEAP TTLS"
250 fi
251
252 if [ "${auth_mode}" = "TTLS" -a -n "${anonymous_identity}" ]; then
253 echo " anonymous_identity=\"${anonymous_identity}\""
254 fi
255
256 if [ -n "${identity}" -a -n "${password}" ]; then
257 echo " identity=\"${identity}\""
258 echo " password=\"${password}\""
259 fi
260 fi
261
61027579
MT
262 echo "}"
263 echo
264 ) >> ${config}
265}
266
267function wpa_supplicant_start() {
268 local device=${1}
269 local config="/etc/wpa_supplicant.conf"
270
271 # Write configuration file.
272 wpa_supplicant_make_config ${device} ${config}
273 [ $? -eq 0 ] || return 0
274
275 # Build wpa_supplicant command line.
276 local wpa_suppl_cmd="wpa_supplicant -B -qqq -i${device} -c${config}"
277
55209df3 278 if ! device_is_wireless ${device}; then
61027579
MT
279 wpa_suppl_cmd="${wpa_suppl_cmd} -Dwired"
280 fi
281
282 # Run the shiz.
283 boot_mesg "Starting wireless client on ${RED_DEV}..."
284 loadproc ${wpa_suppl_cmd}
285
286 # Run wpa_cli to handle reconnection events.
287 boot_mesg "Starting wireless event handler on ${RED_DEV}..."
288 wpa_cli -B -a /etc/rc.d/init.d/networking/wpa_supplicant.exe
289}
290
291function wpa_supplicant_stop() {
292 boot_mesg "Stopping wireless event handler on ${RED_DEV}..."
293 killproc wpa_cli
294
71ea0d68
SS
295 # wpa_cli does not send a disconnect event when get stopped.
296 # So we manually have to send it to the wpa_supplicant.exe.
297 /etc/rc.d/init.d/networking/wpa_supplicant.exe "${RED_DEV}" DISCONNECTED
298
61027579
MT
299 boot_mesg "Stopping wireless client on ${RED_DEV}..."
300 killproc wpa_supplicant
71ea0d68
SS
301
302 # Tidy up /tmp directory.
303 rm -f /tmp/wpa_ctrl_*
61027579
MT
304}
305
306case "${1}" in
307 start)
308 if [ -n "${RED_DEV}" ] && device_is_wireless ${RED_DEV}; then
309 wpa_supplicant_start ${RED_DEV}
310 fi
311 ;;
312
313 stop)
314 if [ -n "${RED_DEV}" ] && device_is_wireless ${RED_DEV}; then
315 wpa_supplicant_stop
316 fi
317 ;;
318
319 restart)
320 ${0} stop
321 sleep 1
322 ${0} start
323 ;;
324
325 status)
326 statusproc wpa_supplicant
327 ;;
328
329 *)
330 echo "Usage: ${0} {start|stop|restart|status}"
331 exit 1
332 ;;
333esac
334
335# End $rc_base/init.d/wlan_client