slitaz-boot-scripts rev 102

network.sh: enhance wifi setup
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Jul 10 12:09:16 2008 +0000 (2008-07-10)
parents de5ae88515f6
children 5661c121f569
files etc/init.d/network.sh etc/network.conf
line diff
     1.1 --- a/etc/init.d/network.sh	Thu Jun 26 22:08:18 2008 +0200
     1.2 +++ b/etc/init.d/network.sh	Thu Jul 10 12:09:16 2008 +0000
     1.3 @@ -16,6 +16,64 @@
     1.4  /sbin/route add 127.0.0.1 lo
     1.5  status
     1.6  
     1.7 +# For wifi. Users just have to enable it throught yes and usually
     1.8 +# essid any will work and interface is autodetected.
     1.9 +if [ "$WIFI" = "yes" ] || grep -q "wifi" /proc/cmdline; then
    1.10 +	if [ -n "$NDISWRAPPER_DRIVERS" -a -x /usr/sbin/ndiswrapper ]; then
    1.11 +		for i in $NDISWRAPPER_DRIVERS; do
    1.12 +			ndiswrapper -i $i
    1.13 +		done
    1.14 +		modprobe ndiswrapper
    1.15 +	fi
    1.16 +	if ! iwconfig $WIFI_INTERFACE 2>&1 | grep -iq "essid"; then
    1.17 +		WIFI_INTERFACE=$(grep : /proc/net/dev | cut -d: -f1 | \
    1.18 +			while read dev; do iwconfig $dev 2>&1 | \
    1.19 +			grep -iq "essid" && { echo $dev ; break; }; \
    1.20 +                        done)
    1.21 +                [ -n "$WIFI_INTERFACE" ] && sed -i "s/^WIFI_INTERFACE=.*/WIFI_INTERFACE=\"$WIFI_INTERFACE\"/" /etc/network.conf
    1.22 +        fi
    1.23 +        [ -n "$WPA_DRIVER" ] && WPA_DRIVER="wext"
    1.24 +	if ! iwconfig $WIFI_INTERFACE 2>&1 | grep -iq "essid"; then
    1.25 +		IWCONFIG_ARGS=""
    1.26 +		[ -n "$WIFI_MODE" ] && IWCONFIG_ARGS="$IWCONFIG_ARGS mode $WIFI_MODE"
    1.27 +		[ -n "$WIFI_KEY" ] && case "$WIFI_KEY_TYPE" in
    1.28 +		wep|WEP) IWCONFIG_ARGS="$IWCONFIG_ARGS key $WIFI_KEY";;
    1.29 +		wpa|WPA) cat > /tmp/wpa.conf <<EOF
    1.30 +ap_scan=1
    1.31 +network={
    1.32 +	ssid="$WIFI_ESSID"
    1.33 +	scan_ssid=1
    1.34 +	proto=WPA
    1.35 +	key_mgmt=WPA-PSK
    1.36 +	psk="$WIFI_KEY"
    1.37 +	priority=5
    1.38 +}
    1.39 +EOF
    1.40 +			wpa_supplicant -B -w -c/tmp/wpa.conf -D$DRIVER -i$WIFI_INTERFACE
    1.41 +			;;
    1.42 +		any|ANY) cat > /tmp/wpa.conf <<EOF
    1.43 +ap_scan=1
    1.44 +network={
    1.45 +	ssid="$WIFI_ESSID"
    1.46 +	scan_ssid=1
    1.47 +	key_mgmt=WPA-EAP WPA-PSK IEEE8021X NONE
    1.48 +	group=CCMP TKIP WEP104 WEP40
    1.49 +	pairwise=CCMP TKIP
    1.50 +	psk="$WIFI_KEY"
    1.51 +	priority=5
    1.52 +}
    1.53 +EOF
    1.54 +			wpa_supplicant -B -w -c/tmp/wpa.conf -D$WPA_DRIVER -i$WIFI_INTERFACE
    1.55 +			;;
    1.56 +		esac
    1.57 +		[ -n "$WIFI_CHANNEL" ] && IWCONFIG_ARGS="$IWCONFIG_ARGS channel $WIFI_CHANNEL"
    1.58 +		ifconfig $WIFI_INTERFACE up
    1.59 +		iwconfig $WIFI_INTERFACE txpower on
    1.60 +		iwconfig $WIFI_INTERFACE essid $WIFI_ESSID $IWCONFIG_ARGS
    1.61 +		INTERFACE=$WIFI_INTERFACE
    1.62 +        fi
    1.63 +fi
    1.64 +
    1.65  # For a dynamic IP with DHCP.
    1.66  if [ "$DHCP" = "yes" ] ; then
    1.67  	echo "Starting udhcpc client on: $INTERFACE... "
    1.68 @@ -34,23 +92,3 @@
    1.69  		echo "nameserver $NS" >> /etc/resolv.conf
    1.70  	done
    1.71  fi
    1.72 -
    1.73 -# For wifi. Users just have to enable it throught yes and usually
    1.74 -# essid any will work and interafce is wlan0.
    1.75 -if [ "$WIFI" = "yes" ] || grep -q "wifi" /proc/cmdline; then
    1.76 -	if [ -n "$NDISWRAPPER_DRIVERS" -a -x /usr/sbin/ndiswrapper ]; then
    1.77 -		for i in $NDISWRAPPER_DRIVERS; do
    1.78 -			ndiswrapper -i $i
    1.79 -		done
    1.80 -		modprobe ndiswrapper
    1.81 -	fi
    1.82 -	IWCONFIG_ARGS=""
    1.83 -	[ -n "$WIFI_MODE" ] && IWCONFIG_ARGS="$IWCONFIG_ARGS mode $WIFI_MODE"
    1.84 -	[ -n "$WIFI_KEY" ] && IWCONFIG_ARGS="$IWCONFIG_ARGS key $WIFI_KEY"
    1.85 -	[ -n "$WIFI_CHANNEL" ] && IWCONFIG_ARGS="$IWCONFIG_ARGS channel $WIFI_CHANNEL"
    1.86 -	ifconfig $WIFI_INTERFACE up
    1.87 -	iwconfig $WIFI_INTERFACE essid $WIFI_ESSID $IWCONFIG_ARGS
    1.88 -	echo "Starting udhcpc client on: $WIFI_INTERFACE... "
    1.89 -	/sbin/udhcpc -b -i $WIFI_INTERFACE \
    1.90 -		-p /var/run/udhcpc.$WIFI_INTERFACE.pid
    1.91 -fi
     2.1 --- a/etc/network.conf	Thu Jun 26 22:08:18 2008 +0200
     2.2 +++ b/etc/network.conf	Thu Jul 10 12:09:16 2008 +0000
     2.3 @@ -32,5 +32,6 @@
     2.4  WIFI_ESSID="any"
     2.5  WIFI_MODE="managed"
     2.6  WIFI_KEY=""
     2.7 +WIFI_KEY_TYPE="none"
     2.8  WIFI_CHANNEL=""
     2.9  NDISWRAPPER_DRIVERS=""