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]}"
67 items
=$
(( ${items} + 1 ))
69 done < ${WIRELESS_CONFIG}
71 # Return exit code 2, when there are no entries in the
73 if [ "${items}" = "0" ]; then
80 function wpa_supplicant_config_line
() {
99 while [ $# -gt 0 ]; do
105 priority
=${1#--priority=}
114 wireless
=${1#--wireless=}
117 wpa_mode
=${1#--wpa-mode=}
152 if [ "${mode}" = "WPA" -o "${mode}" = "WPA2" ]; then
153 case "${wpa_mode}" in
176 if [ -n "${ssid}" ]; then
177 echo " ssid=\"${ssid}\""
179 if [ "${wireless}" = "true" ]; then
182 if [ -n "${auth_alg}" ]; then
183 echo " auth_alg=${auth_alg}"
185 if [ -n "${key_mgmt}" ]; then
186 echo " key_mgmt=${key_mgmt}"
188 if [ -n "${psk}" ]; then
189 echo " psk=\"${psk}\""
191 if [ -n "${wep_tx_keyidx}" ]; then
192 echo " wep_tx_keyidx=${wep_tx_keyidx}"
194 if [ -n "${wep_key0}" ]; then
195 echo " wep_key0=\"${wep_key0}\""
197 if [ -n "${proto}" ]; then
198 echo " proto=${proto}"
200 if [ -n "${pairwise}" -a -n "${group}" ]; then
201 echo " pairwise=${pairwise}"
202 echo " group=${group}"
204 if [ -n "${priority}" ]; then
205 echo " priority=${priority}"
213 function wpa_supplicant_start
() {
215 local config
="/etc/wpa_supplicant.conf"
217 # Write configuration file.
218 wpa_supplicant_make_config
${device} ${config}
219 [ $?
-eq 0 ] ||
return 0
221 # Build wpa_supplicant command line.
222 local wpa_suppl_cmd
="wpa_supplicant -B -qqq -i${device} -c${config}"
224 if device_is_wireless
${device}; then
225 wpa_suppl_cmd
="${wpa_suppl_cmd} -Dwext"
227 wpa_suppl_cmd
="${wpa_suppl_cmd} -Dwired"
231 boot_mesg
"Starting wireless client on ${RED_DEV}..."
232 loadproc
${wpa_suppl_cmd}
234 # Run wpa_cli to handle reconnection events.
235 boot_mesg
"Starting wireless event handler on ${RED_DEV}..."
236 wpa_cli
-B -a /etc
/rc.d
/init.d
/networking
/wpa_supplicant.exe
239 function wpa_supplicant_stop
() {
240 boot_mesg
"Stopping wireless event handler on ${RED_DEV}..."
243 # wpa_cli does not send a disconnect event when get stopped.
244 # So we manually have to send it to the wpa_supplicant.exe.
245 /etc
/rc.d
/init.d
/networking
/wpa_supplicant.exe
"${RED_DEV}" DISCONNECTED
247 boot_mesg
"Stopping wireless client on ${RED_DEV}..."
248 killproc wpa_supplicant
250 # Tidy up /tmp directory.
251 rm -f /tmp
/wpa_ctrl_
*
256 if [ -n "${RED_DEV}" ] && device_is_wireless
${RED_DEV}; then
257 wpa_supplicant_start
${RED_DEV}
262 if [ -n "${RED_DEV}" ] && device_is_wireless
${RED_DEV}; then
274 statusproc wpa_supplicant
278 echo "Usage: ${0} {start|stop|restart|status}"
283 # End $rc_base/init.d/wlan_client