2 ########################################################################
3 # Begin $rc_base/init.d/wlan_client
5 # Description : Wireless client initscript
7 ########################################################################
12 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ethernet
/settings
)
14 WIRELESS_CONFIG
="/var/ipfire/ethernet/wireless"
16 function device_is_wireless
() {
19 if [ -d "/sys/class/net/${device}/wireless" ]; then
26 function wpa_supplicant_make_config
() {
31 # Check if device is wireless.
32 local wireless
="false"
33 if device_is_wireless
${device}; then
37 # Write a configuration file header.
40 echo "# THIS FILE IS AUTOMATICALLY GENERATED AND"
41 echo "# ANY CUSTOM CHANGES WILL BE OVERWRITTEN!"
44 echo "ctrl_interface=/var/run/wpa_supplicant"
51 while IFS
="," read -ra line
; do
52 # Skip commented lines.
53 [ "${line:0:1}" = "#" ] && continue
55 # Skip disabled entries.
56 [ "${line[2]}" = "on" ] ||
continue
58 wpa_supplicant_config_line \
60 --wireless="${wireless}" \
62 --wpa-mode="${line[4]}" \
65 --priority="${line[7]}" \
66 --auth-mode="${line[8]}" \
67 --anonymous-identity="${line[9]}" \
68 --identity="${line[10]}" \
69 --password="${line[11]}"
71 items
=$
(( ${items} + 1 ))
73 done < ${WIRELESS_CONFIG}
75 # Return exit code 2, when there are no entries in the
77 if [ "${items}" = "0" ]; then
84 function wpa_supplicant_config_line
() {
90 local anonymous_identity
105 local wireless
="true"
108 while [ $# -gt 0 ]; do
110 --anonymous-identity=*)
111 anonymous_identity
=${1#--anonymous-identity=}
114 auth_mode
=${1#--auth-mode=}
117 identity
=${1#--identity=}
123 password
=${1#--password=}
126 priority
=${1#--priority=}
135 wireless
=${1#--wireless=}
138 wpa_mode
=${1#--wpa-mode=}
181 if [ "${mode}" = "EAP" -o "${mode}" = "WPA" -o "${mode}" = "WPA2" ]; then
182 case "${wpa_mode}" in
205 if [ -n "${ssid}" ]; then
206 echo " ssid=\"${ssid}\""
208 if [ "${wireless}" = "true" ]; then
211 if [ -n "${auth_alg}" ]; then
212 echo " auth_alg=${auth_alg}"
214 if [ -n "${key_mgmt}" ]; then
215 echo " key_mgmt=${key_mgmt}"
217 if [ -n "${psk}" ]; then
218 if [ "${key_mgmt}" = "SAE" ]; then
219 echo " sae_password=\"${psk}\""
221 echo " psk=\"${psk}\""
224 if [ -n "${wep_tx_keyidx}" ]; then
225 echo " wep_tx_keyidx=${wep_tx_keyidx}"
227 if [ -n "${wep_key0}" ]; then
228 echo " wep_key0=\"${wep_key0}\""
230 if [ -n "${proto}" ]; then
231 echo " proto=${proto}"
233 if [ -n "${pairwise}" -a -n "${group}" ]; then
234 echo " pairwise=${pairwise}"
235 echo " group=${group}"
237 if [ -n "${priority}" ]; then
238 echo " priority=${priority}"
240 if [ -n "${ieee80211w}" ]; then
241 echo " ieee80211w=${ieee80211w}"
245 if [ "${mode}" = "EAP" ]; then
246 if [ -n "${auth_mode}" ]; then
247 echo " eap=${auth_mode}"
249 echo " eap=PEAP TTLS"
252 if [ "${auth_mode}" = "TTLS" -a -n "${anonymous_identity}" ]; then
253 echo " anonymous_identity=\"${anonymous_identity}\""
256 if [ -n "${identity}" -a -n "${password}" ]; then
257 echo " identity=\"${identity}\""
258 echo " password=\"${password}\""
267 function wpa_supplicant_start
() {
269 local config
="/etc/wpa_supplicant.conf"
271 # Write configuration file.
272 wpa_supplicant_make_config
${device} ${config}
273 [ $?
-eq 0 ] ||
return 0
275 # Build wpa_supplicant command line.
276 local wpa_suppl_cmd
="wpa_supplicant -B -qqq -i${device} -c${config}"
278 if device_is_wireless
${device}; then
279 wpa_suppl_cmd
="${wpa_suppl_cmd} -Dwext"
281 wpa_suppl_cmd
="${wpa_suppl_cmd} -Dwired"
285 boot_mesg
"Starting wireless client on ${RED_DEV}..."
286 loadproc
${wpa_suppl_cmd}
288 # Run wpa_cli to handle reconnection events.
289 boot_mesg
"Starting wireless event handler on ${RED_DEV}..."
290 wpa_cli
-B -a /etc
/rc.d
/init.d
/networking
/wpa_supplicant.exe
293 function wpa_supplicant_stop
() {
294 boot_mesg
"Stopping wireless event handler on ${RED_DEV}..."
297 # wpa_cli does not send a disconnect event when get stopped.
298 # So we manually have to send it to the wpa_supplicant.exe.
299 /etc
/rc.d
/init.d
/networking
/wpa_supplicant.exe
"${RED_DEV}" DISCONNECTED
301 boot_mesg
"Stopping wireless client on ${RED_DEV}..."
302 killproc wpa_supplicant
304 # Tidy up /tmp directory.
305 rm -f /tmp
/wpa_ctrl_
*
310 if [ -n "${RED_DEV}" ] && device_is_wireless
${RED_DEV}; then
311 wpa_supplicant_start
${RED_DEV}
316 if [ -n "${RED_DEV}" ] && device_is_wireless
${RED_DEV}; then
328 statusproc wpa_supplicant
332 echo "Usage: ${0} {start|stop|restart|status}"
337 # End $rc_base/init.d/wlan_client