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
() {
89 local anonymous_identity
104 local wireless
="true"
107 while [ $# -gt 0 ]; do
109 --anonymous-identity=*)
110 anonymous_identity
=${1#--anonymous-identity=}
113 auth_mode
=${1#--auth-mode=}
116 identity
=${1#--identity=}
122 password
=${1#--password=}
125 priority
=${1#--priority=}
134 wireless
=${1#--wireless=}
137 wpa_mode
=${1#--wpa-mode=}
175 if [ "${mode}" = "EAP" -o "${mode}" = "WPA" -o "${mode}" = "WPA2" ]; then
176 case "${wpa_mode}" in
199 if [ -n "${ssid}" ]; then
200 echo " ssid=\"${ssid}\""
202 if [ "${wireless}" = "true" ]; then
205 if [ -n "${auth_alg}" ]; then
206 echo " auth_alg=${auth_alg}"
208 if [ -n "${key_mgmt}" ]; then
209 echo " key_mgmt=${key_mgmt}"
211 if [ -n "${psk}" ]; then
212 echo " psk=\"${psk}\""
214 if [ -n "${wep_tx_keyidx}" ]; then
215 echo " wep_tx_keyidx=${wep_tx_keyidx}"
217 if [ -n "${wep_key0}" ]; then
218 echo " wep_key0=\"${wep_key0}\""
220 if [ -n "${proto}" ]; then
221 echo " proto=${proto}"
223 if [ -n "${pairwise}" -a -n "${group}" ]; then
224 echo " pairwise=${pairwise}"
225 echo " group=${group}"
227 if [ -n "${priority}" ]; then
228 echo " priority=${priority}"
232 if [ "${mode}" = "EAP" ]; then
233 if [ -n "${auth_mode}" ]; then
234 echo " eap=${auth_mode}"
236 echo " eap=PEAP TTLS"
239 if [ "${auth_mode}" = "TTLS" -a -n "${anonymous_identity}" ]; then
240 echo " anonymous_identity=\"${anonymous_identity}\""
243 if [ -n "${identity}" -a -n "${password}" ]; then
244 echo " identity=\"${identity}\""
245 echo " password=\"${password}\""
254 function wpa_supplicant_start
() {
256 local config
="/etc/wpa_supplicant.conf"
258 # Write configuration file.
259 wpa_supplicant_make_config
${device} ${config}
260 [ $?
-eq 0 ] ||
return 0
262 # Build wpa_supplicant command line.
263 local wpa_suppl_cmd
="wpa_supplicant -B -qqq -i${device} -c${config}"
265 if device_is_wireless
${device}; then
266 wpa_suppl_cmd
="${wpa_suppl_cmd} -Dwext"
268 wpa_suppl_cmd
="${wpa_suppl_cmd} -Dwired"
272 boot_mesg
"Starting wireless client on ${RED_DEV}..."
273 loadproc
${wpa_suppl_cmd}
275 # Run wpa_cli to handle reconnection events.
276 boot_mesg
"Starting wireless event handler on ${RED_DEV}..."
277 wpa_cli
-B -a /etc
/rc.d
/init.d
/networking
/wpa_supplicant.exe
280 function wpa_supplicant_stop
() {
281 boot_mesg
"Stopping wireless event handler on ${RED_DEV}..."
284 # wpa_cli does not send a disconnect event when get stopped.
285 # So we manually have to send it to the wpa_supplicant.exe.
286 /etc
/rc.d
/init.d
/networking
/wpa_supplicant.exe
"${RED_DEV}" DISCONNECTED
288 boot_mesg
"Stopping wireless client on ${RED_DEV}..."
289 killproc wpa_supplicant
291 # Tidy up /tmp directory.
292 rm -f /tmp
/wpa_ctrl_
*
297 if [ -n "${RED_DEV}" ] && device_is_wireless
${RED_DEV}; then
298 wpa_supplicant_start
${RED_DEV}
303 if [ -n "${RED_DEV}" ] && device_is_wireless
${RED_DEV}; then
315 statusproc wpa_supplicant
319 echo "Usage: ${0} {start|stop|restart|status}"
324 # End $rc_base/init.d/wlan_client