--- trunk/magellan-initscripts/etc/rc.d/init.d/network 2005/10/09 22:31:13 265 +++ trunk/magellan-initscripts/etc/rc.d/init.d/network 2005/10/10 18:43:03 268 @@ -1,5 +1,5 @@ #!/bin/bash -# $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/network,v 1.8 2005-10-09 22:31:13 niro Exp $ +# $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/network,v 1.9 2005-10-10 18:43:03 niro Exp $ #%rlevels: 0:k 1:k 2:k 3:s 4:s 5:s 6:k #%start: 20 @@ -131,6 +131,95 @@ echo "${devices}" } +config_wireless_wep() +{ + local iface="$1" + + if [[ -z ${iface} ]] + then + echo "WEP: no \$iface given. Aborting setup." + return 1 + fi + + iwconfig "${iface}" enc on + [[ -n ${WIRELESS_KEY_LENGTH} ]] && iwconfig "${iface}" enc "${WIRELESS_KEY_LENGTH}" + [[ -n ${WIRELESS_KEY} ]] && iwconfig "${iface}" key "${WIRELESS_KEY}" + [[ -n ${WIRELESS_KEY_ASCII} ]] && iwconfig "${iface}" key s:"${WIRELESS_KEY_ASCII}" +} + +config_wireless_wpa() +{ + local iface="$1" + + if [[ -z ${iface} ]] + then + echo "WPA: no \$iface given. Aborting setup." + return 1 + fi + + if [ ! -x /sbin/wpa_supplicant ] + then + echo "WPA: wpa_supplicant not installed. Aborting setup." + return 1 + fi + + # get default settings + [[ -f /etc/conf.d/wpa_supplicant ]] && source /etc/conf.d/wpa_supplicant + + # check the configuration + [[ -z ${WIRELESS_WPA_CONFIG} ]] && WIRELESS_WPA_CONFIG=/etc/wpa_supplicant.auto + [[ -z ${WIRELESS_WPA_SKEL} ]] && WIRELESS_WPA_SKEL=/etc/conf.d/wpa_supplicant.skel + if [[ -z ${WIRELESS_WPA_DRIVER} ]] + then + echo "WPA: WIRELESS_WPA_DRIVER given. Aborting setup." + return 1 + fi + + # write a config with the settings from net.${iface} + # only wpa-psk ! all other needs manual setup + if [[ ${WIRELESS_WPA_AUTOCONF} = true ]] + then + # write default cfg from skeleton + cat ${WIRELESS_WPA_SKEL} > ${WIRELESS_WPA_CONFIG} + + # setup the network entry + sed -i -e "s:@WIRELESS_ESSID@:${WIRELESS_ESSID}:g" \ + -e "s:@WIRELESS_KEY@:${WIRELESS_KEY}:g" \ + ${WIRELESS_WPA_CONFIG} + fi + + # now run the wpa_supplicant dameon + wpa_supplicant -B \ + -D"${WIRELESS_WPA_DRIVER}" \ + -c"${WIRELESS_WPA_CONFIG}" \ + -i"${iface}" \ + ${WIRELESS_WPA_OPTS} +} + +setup_wireless_extensions() +{ + local iface="$1" + + if [[ -z ${iface} ]] + then + echo "WIRELESS_EXTENSIONS: no \$iface given. Aborting setup." + return 1 + fi + + [[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}" + [[ -n ${WIRELESS_CHANNEL} ]] && iwconfig "${iface}" channel "${WIRELESS_CHANNEL}" + [[ -n ${WIRELESS_ESSID} ]] && iwconfig "${iface}" essid "${WIRELESS_ESSID}" + [[ -n ${WIRELESS_FREQUENCY} ]] && iwconfig "${iface}" freq "${WIRELESS_FREQUENCY}" + [[ -n ${WIRELESS_MODE} ]] && iwconfig "${iface}" mode "${WIRELESS_MODE}" + [[ -n ${WIRELESS_NICK} ]] && iwconfig "${iface}" nick "${WIRELESS_NICK}" + + case "${WIRELESS_AUTH_MODE}" in + wpa) config_wireless_wpa "${iface}" ;; + wep|on) config_wireless_wep "${iface}" ;; + off) iwconfig "${iface}" enc off ;; + esac +} + networking_start() { local iface dns @@ -188,24 +277,7 @@ # setup wlan extensions if [ -x /usr/sbin/iwconfig ] then - [[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}" - [[ -n ${WIRELESS_CHANNEL} ]] && iwconfig "${iface}" channel "${WIRELESS_CHANNEL}" - [[ -n ${WIRELESS_ESSID} ]] && iwconfig "${iface}" essid "${WIRELESS_ESSID}" - [[ -n ${WIRELESS_FREQUENCY} ]] && iwconfig "${iface}" freq "${WIRELESS_FREQUENCY}" - [[ -n ${WIRELESS_MODE} ]] && iwconfig "${iface}" mode "${WIRELESS_MODE}" - [[ -n ${WIRELESS_NICK} ]] && iwconfig "${iface}" nick "${WIRELESS_NICK}" - if [[ -n ${WIRELESS_AUTH_MODE} ]] - then - case ${WIRELESS_AUTH_MODE} in - wpa) echo "Using wpa";; - wep|on) iwconfig "${iface}" enc on ;; - off) iwconfig "${iface}" enc off ;; - *) echo "Unkown Wireless_Auth_Mode '${WIRELESS_AUTH_MODE}'." ;; - esac - fi - [[ -n ${WIRELESS_KEY_LENGTH} ]] && iwconfig "${iface}" enc "${WIRELESS_KEY_LENGTH}" - [[ -n ${WIRELESS_KEY} ]] && iwconfig "${iface}" key "${WIRELESS_KEY}" - [[ -n ${WIRELESS_KEY_ASCII} ]] && iwconfig "${iface}" key s:"${WIRELESS_KEY_ASCII}" + setup_wireless_extensions "${iface}" fi done } @@ -239,6 +311,12 @@ ${DHCP_PROG} ${DHCP_STOP} evaluate_retval fi + + # shutdown wpa_supplicant daemon + if [[ -n $(pidof wpa_supplicant) ]] + then + killall wpa_supplicant + fi done }