slitaz-boot-scripts rev 282
network.sh: Use wpa_supplicante for WEP connection and speed up using fgrep
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sat Mar 03 18:14:18 2012 +0100 (2012-03-03) |
parents | 7cb24a5569e4 |
children | 28fda57244ee |
files | etc/init.d/network.sh |
line diff
1.1 --- a/etc/init.d/network.sh Sat Feb 18 21:55:47 2012 +0100 1.2 +++ b/etc/init.d/network.sh Sat Mar 03 18:14:18 2012 +0100 1.3 @@ -31,22 +31,24 @@ 1.4 # For wifi. Users just have to enable it through yes and usually 1.5 # essid any will work and the interface is autodetected. 1.6 wifi() { 1.7 - if [ "$WIFI" = "yes" ] || grep -q "wifi" /proc/cmdline; then 1.8 + if [ "$WIFI" = "yes" ] || fgrep -q "wifi" /proc/cmdline; then 1.9 ifconfig $INTERFACE down 1.10 1.11 # Confirm if $WIFI_INTERFACE is the wifi interface 1.12 if [ ! -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then 1.13 echo "$WIFI_INTERFACE is not a wifi interface, changing it." 1.14 - WIFI_INTERFACE=$(grep : /proc/net/dev | cut -d: -f1 | \ 1.15 + WIFI_INTERFACE=$(fgrep : /proc/net/dev | cut -d: -f1 | \ 1.16 while read dev; do iwconfig $dev 2>&1 | \ 1.17 - grep -iq "essid" && { echo $dev ; break; }; \ 1.18 + fgrep -iq "essid" && { echo $dev ; break; }; \ 1.19 done) 1.20 - [ -n "$WIFI_INTERFACE" ] && sed -i "s/^WIFI_INTERFACE=.*/WIFI_INTERFACE=\"$WIFI_INTERFACE\"/" /etc/network.conf 1.21 + [ -n "$WIFI_INTERFACE" ] && sed -i \ 1.22 + "s/^WIFI_INTERFACE=.*/WIFI_INTERFACE=\"$WIFI_INTERFACE\"/" \ 1.23 + /etc/network.conf 1.24 fi 1.25 1.26 echo -n "Configuring $WIFI_INTERFACE..." 1.27 - ifconfig $WIFI_INTERFACE up 1.28 - if iwconfig $WIFI_INTERFACE | grep -q "Tx-Power"; then 1.29 + ifconfig $WIFI_INTERFACE up 2>/dev/null 1.30 + if iwconfig $WIFI_INTERFACE | fgrep -q "Tx-Power"; then 1.31 iwconfig $WIFI_INTERFACE txpower on 1.32 fi 1.33 status 1.34 @@ -62,27 +64,34 @@ 1.35 # encrypted network 1.36 [ -n "$WIFI_KEY" ] && case "$WIFI_KEY_TYPE" in 1.37 wep|WEP) 1.38 - IWCONFIG_ARGS="$IWCONFIG_ARGS key $WIFI_KEY" 1.39 - iwconfig $WIFI_INTERFACE essid "$WIFI_ESSID" $IWCONFIG_ARGS 1.40 -# wpa_supplicant can also deal with wep encryption but iwconfig is preferred 1.41 -# Tip: Use unquoted strings for hexadecimal key in wep_key0 1.42 -# cat /etc/wpa_supplicant.conf > /tmp/wpa.conf 1.43 -# cat >> /tmp/wpa.conf <<EOF 1.44 -#ctrl_interface=/var/run/wpa_supplicant 1.45 -#ctrl_interface_group=0 1.46 -#ap_scan=1 1.47 -#network={ 1.48 -# ssid="$WIFI_ESSID" 1.49 -# scan_ssid=1 1.50 -# key_mgmt=NONE 1.51 -# wep_key0="$WIFI_KEY" 1.52 -# wep_tx_keyidx=0 1.53 -# priority=5 1.54 -#} 1.55 -#EOF 1.56 -# echo "Starting wpa_supplicant for NONE/WEP..." 1.57 -# wpa_supplicant -B -W -c/tmp/wpa.conf -D$WPA_DRIVER -i$WIFI_INTERFACE 1.58 - ;; 1.59 + # 1.60 + # NOTE (20120303) struggled to connect with WEP key in 1.61 + # cooking but work with 3.0. Busybox/iwconfig seems buggy 1.62 + # but connection work with wpa_supplicant and unquoted 1.63 + # wep_key0 1.64 + # 1.65 + #IWCONFIG_ARGS="$IWCONFIG_ARGS key $WIFI_KEY" 1.66 + #iwconfig $WIFI_INTERFACE essid "$WIFI_ESSID" $IWCONFIG_ARGS 1.67 + # 1.68 + # wpa_supplicant can also deal with wep encryption 1.69 + # Tip: Use unquoted strings for hexadecimal key in wep_key0 1.70 + cat /etc/wpa_supplicant.conf > /tmp/wpa.conf 1.71 + cat >> /tmp/wpa.conf <<EOF 1.72 +ctrl_interface=/var/run/wpa_supplicant 1.73 +ctrl_interface_group=0 1.74 +ap_scan=1 1.75 +network={ 1.76 + ssid="$WIFI_ESSID" 1.77 + scan_ssid=1 1.78 + key_mgmt=NONE 1.79 + wep_key0=$WIFI_KEY 1.80 + wep_tx_keyidx=0 1.81 + priority=5 1.82 +} 1.83 +EOF 1.84 + echo "Starting wpa_supplicant for NONE/WEP..." 1.85 + wpa_supplicant -B -W -c/tmp/wpa.conf -D$WPA_DRIVER \ 1.86 + -i$WIFI_INTERFACE ;; 1.87 wpa|WPA) 1.88 # load pre-configured multiple profiles 1.89 cat /etc/wpa_supplicant.conf > /tmp/wpa.conf 1.90 @@ -176,7 +185,7 @@ 1.91 killall udhcpc 1.92 killall wpa_supplicant 2>/dev/null 1.93 1.94 - if iwconfig $WIFI_INTERFACE | grep -q "Tx-Power"; then 1.95 + if iwconfig $WIFI_INTERFACE | fgrep -q "Tx-Power"; then 1.96 echo "Shutting down wifi card" 1.97 iwconfig $WIFI_INTERFACE txpower off 1.98 fi