# HG changeset patch # User Rohit Joshi # Date 1262623496 0 # Node ID 7512d6d485385fd12f5167b953625deb5356a9af # Parent c9296cbaaafa9f3c90464f381cd4b318a071b9fc Improve network.sh with wpa_cli; faster boot diff -r c9296cbaaafa -r 7512d6d48538 etc/init.d/network.sh --- a/etc/init.d/network.sh Tue Dec 22 12:10:13 2009 +0100 +++ b/etc/init.d/network.sh Mon Jan 04 16:44:56 2010 +0000 @@ -10,6 +10,7 @@ . $2 fi + Boot() { # Set hostname. echo -n "Setting hostname... " @@ -20,7 +21,143 @@ echo -n "Configuring loopback... " /sbin/ifconfig lo 127.0.0.1 up /sbin/route add 127.0.0.1 lo - status + status +} + + +eth() { +# use ethernet + ifconfig $INTERFACE up +} + +wifi() { + # For wifi. Users just have to enable it throught yes and usually + # essid any will work and interface is autodetected. + if [ "$WIFI" = "yes" ] || grep -q "wifi" /proc/cmdline; then + ifconfig $INTERFACE down + + # Confirm if $WIFI_INTERFACE is the wifi interface + if [ ! -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then + echo "$WIFI_INTERFACE is not a wifi interface, changing it." + WIFI_INTERFACE=$(grep : /proc/net/dev | cut -d: -f1 | \ + while read dev; do iwconfig $dev 2>&1 | \ + grep -iq "essid" && { echo $dev ; break; }; \ + done) + [ -n "$WIFI_INTERFACE" ] && sed -i "s/^WIFI_INTERFACE=.*/WIFI_INTERFACE=\"$WIFI_INTERFACE\"/" /etc/network.conf + fi + + echo -n "configuring $WIFI_INTERFACE..." + ifconfig $WIFI_INTERFACE up + if iwconfig $WIFI_INTERFACE | grep -q "Tx-Power"; then + iwconfig $WIFI_INTERFACE txpower on + fi + status + + [ -n "$WPA_DRIVER" ] || WPA_DRIVER="wext" + + + IWCONFIG_ARGS="" + [ -n "$WIFI_MODE" ] && IWCONFIG_ARGS="$IWCONFIG_ARGS mode $WIFI_MODE" + [ -n "$WIFI_CHANNEL" ] && IWCONFIG_ARGS="$IWCONFIG_ARGS channel $WIFI_CHANNEL" + + [ -n "$WIFI_KEY" ] && case "$WIFI_KEY_TYPE" in + wep|WEP) + IWCONFIG_ARGS="$IWCONFIG_ARGS key $WIFI_KEY" + iwconfig $WIFI_INTERFACE essid "$WIFI_ESSID" $IWCONFIG_ARGS +# wpa_supplicant can also deal with wep encryption but iwconfig is preferred +# Tip:Use unquoted strings for hexadecimal key in wep_key0 +# cat /etc/wpa_supplicant.conf > /tmp/wpa.conf +# cat >> /tmp/wpa.conf < /tmp/wpa.conf # load pre-configured multiple profiles + cat >> /tmp/wpa.conf < /tmp/wpa.conf + cat >> /tmp/wpa.conf <> /etc/resolv.conf + done + fi } # Stopping everything @@ -40,101 +177,26 @@ } Start() { - # For wifi. Users just have to enable it through yes and usually - # essid any will work and interface is autodetected. - if [ "$WIFI" = "yes" ] || grep -q "wifi" /proc/cmdline; then - if [ ! -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then - echo "$WIFI_INTERFACE is not a wifi interface, changing it." - WIFI_INTERFACE=$(grep : /proc/net/dev | cut -d: -f1 | \ - while read dev; do iwconfig $dev 2>&1 | \ - grep -iq "essid" && { echo $dev ; break; }; \ - done) - [ -n "$WIFI_INTERFACE" ] && sed -i "s/^WIFI_INTERFACE=.*/WIFI_INTERFACE=\"$WIFI_INTERFACE\"/" /etc/network.conf - fi - [ -n "$WPA_DRIVER" ] || WPA_DRIVER="wext" - IWCONFIG_ARGS="" - [ -n "$WIFI_MODE" ] && IWCONFIG_ARGS="$IWCONFIG_ARGS mode $WIFI_MODE" - [ -n "$WIFI_KEY" ] && case "$WIFI_KEY_TYPE" in - wep|WEP) IWCONFIG_ARGS="$IWCONFIG_ARGS key $WIFI_KEY";; - wpa|WPA) cat > /tmp/wpa.conf < /tmp/wpa.conf <> /etc/resolv.conf - done - fi + eth + wifi + dhcp + static_ip } -# Looking for arguments: +# looking for arguments: if [ -z "$1" ]; then Boot Start else case $1 in start) - Start - ;; + Start ;; stop) - Stop - ;; + Stop ;; restart) Stop - Start - ;; + Start ;; *) echo "" echo -e "\033[1mUsage:\033[0m /etc/init.d/`basename $0` [start|stop|restart]" diff -r c9296cbaaafa -r 7512d6d48538 etc/init.d/wpa_action.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/etc/init.d/wpa_action.sh Mon Jan 04 16:44:56 2010 +0000 @@ -0,0 +1,11 @@ +#!/bin/sh +INTERFACE=$1 + +# For a dynamic IP with DHCP. +if [ "$2" = "CONNECTED" ]; then + [ -f /var/run/udhcpc.$INTERFACE.pid] && killall udhcpc + /sbin/udhcpc -b -i $INTERFACE -p /var/run/udhcpc.$INTERFACE.pid +elif [ "$2" = "DISCONNECTED" ]; then + /sbin/udhcpc -b -i $INTERFACE -p /var/run/udhcpc.$INTERFACE.pid +fi +