From 9997a323581c7152e67830690d80d213d7c0d2e2 Mon Sep 17 00:00:00 2001 From: James Rayner Date: Thu, 26 Feb 2009 20:42:04 +1100 Subject: Update and re-arrange examples, update wireless quirk options, stop using deprecated sys interface --- examples/deprecated/ethernet-static.example | 8 --- examples/deprecated/ethernet.example | 5 -- examples/deprecated/wep-static.example | 12 ----- examples/deprecated/wep-string-key.example | 8 --- examples/deprecated/wep.example | 8 --- examples/deprecated/wpa.example | 8 --- examples/ethernet-dhcp | 4 ++ examples/ethernet-dhcp.example | 3 -- examples/ethernet-iproute | 7 +++ examples/ethernet-iproute.example | 6 --- examples/ethernet-static | 7 +++ examples/ethernet-static.example | 6 --- examples/loopback.example | 5 -- examples/ppp | 4 ++ examples/ppp.example | 4 -- examples/wireless-dbus | 7 +++ examples/wireless-wep | 7 +++ examples/wireless-wep-string-key | 7 +++ examples/wireless-wpa | 7 +++ examples/wireless.example | 7 --- src/connections/ethernet | 10 +++- src/connections/wireless | 75 +++++++++++++---------------- src/wireless | 1 + 23 files changed, 93 insertions(+), 123 deletions(-) delete mode 100644 examples/deprecated/ethernet-static.example delete mode 100644 examples/deprecated/ethernet.example delete mode 100644 examples/deprecated/wep-static.example delete mode 100644 examples/deprecated/wep-string-key.example delete mode 100644 examples/deprecated/wep.example delete mode 100644 examples/deprecated/wpa.example create mode 100644 examples/ethernet-dhcp delete mode 100644 examples/ethernet-dhcp.example create mode 100755 examples/ethernet-iproute delete mode 100755 examples/ethernet-iproute.example create mode 100644 examples/ethernet-static delete mode 100644 examples/ethernet-static.example delete mode 100644 examples/loopback.example create mode 100644 examples/ppp delete mode 100644 examples/ppp.example create mode 100644 examples/wireless-dbus create mode 100644 examples/wireless-wep create mode 100644 examples/wireless-wep-string-key create mode 100644 examples/wireless-wpa delete mode 100644 examples/wireless.example diff --git a/examples/deprecated/ethernet-static.example b/examples/deprecated/ethernet-static.example deleted file mode 100644 index b50cf36..0000000 --- a/examples/deprecated/ethernet-static.example +++ /dev/null @@ -1,8 +0,0 @@ -CONNECTION="ethernet" -DESCRIPTION="A less basic ethernet profile, using static configuration" -INTERFACE=eth0 -IP="static" -IFOPTS="192.168.1.23 netmask 255.255.255.0 broadcast 192.168.1.255" -GATEWAY="192.168.1.1" -DNS1=192.168.1.1 -DNS2=dns1.dreamhost.com diff --git a/examples/deprecated/ethernet.example b/examples/deprecated/ethernet.example deleted file mode 100644 index 2db6072..0000000 --- a/examples/deprecated/ethernet.example +++ /dev/null @@ -1,5 +0,0 @@ -CONNECTION="ethernet" -DESCRIPTION="A very basic ethernet profile, using dhcp" -INTERFACE=eth0 -IP="dhcp" -DHCP_TIMEOUT=10 diff --git a/examples/deprecated/wep-static.example b/examples/deprecated/wep-static.example deleted file mode 100644 index 4474ba7..0000000 --- a/examples/deprecated/wep-static.example +++ /dev/null @@ -1,12 +0,0 @@ -CONNECTION="wireless" -DESCRIPTION="A wep encrypted wireless connection using static ip" -INTERFACE=wlan0 -SCAN="yes" -SECURITY="wep" -ESSID="MyNetwork" -KEY="1234567890" -IP="static" -IFOPTS="192.168.1.23 netmask 255.255.255.0 broadcast 192.168.1.255" -GATEWAY="192.168.1.1" -DNS1=192.168.1.1 -DNS2=dns1.dreamhost.com diff --git a/examples/deprecated/wep-string-key.example b/examples/deprecated/wep-string-key.example deleted file mode 100644 index 3118658..0000000 --- a/examples/deprecated/wep-string-key.example +++ /dev/null @@ -1,8 +0,0 @@ -CONNECTION="wireless" -DESCRIPTION="A simple WEP encrypted wireless connection" -INTERFACE=wlan0 -SCAN="yes" -SECURITY="wep" -ESSID="MyNetwork" -KEY="s:Some string key" -IP="dhcp" diff --git a/examples/deprecated/wep.example b/examples/deprecated/wep.example deleted file mode 100644 index 4dad0e1..0000000 --- a/examples/deprecated/wep.example +++ /dev/null @@ -1,8 +0,0 @@ -CONNECTION="wireless" -DESCRIPTION="A simple WEP encrypted wireless connection" -INTERFACE=wlan0 -SCAN="yes" -SECURITY="wep" -ESSID="MyNetwork" -KEY="1234567890" -IP="dhcp" diff --git a/examples/deprecated/wpa.example b/examples/deprecated/wpa.example deleted file mode 100644 index f165945..0000000 --- a/examples/deprecated/wpa.example +++ /dev/null @@ -1,8 +0,0 @@ -CONNECTION="wireless" -INTERFACE=wlan0 -SCAN="yes" -SECURITY="wpa" -ESSID="mynetwork" -KEY="SomePasskey" -IP="dhcp" -TIMEOUT=20 diff --git a/examples/ethernet-dhcp b/examples/ethernet-dhcp new file mode 100644 index 0000000..78edfc4 --- /dev/null +++ b/examples/ethernet-dhcp @@ -0,0 +1,4 @@ +CONNECTION="ethernet-iproute" +DESCRIPTION="A basic dhcp ethernet connection using iproute" +INTERFACE="eth0" +IP="dhcp" diff --git a/examples/ethernet-dhcp.example b/examples/ethernet-dhcp.example deleted file mode 100644 index 6f80a9e..0000000 --- a/examples/ethernet-dhcp.example +++ /dev/null @@ -1,3 +0,0 @@ -CONNECTION="ethernet-iproute" -INTERFACE="eth0" -IP="dhcp" diff --git a/examples/ethernet-iproute b/examples/ethernet-iproute new file mode 100755 index 0000000..6ac20e1 --- /dev/null +++ b/examples/ethernet-iproute @@ -0,0 +1,7 @@ +CONNECTION="ethernet-iproute" +DESCRIPTION="A more versatile static ethernet connection using iproute" +INTERFACE="eth0" +IP="static" +# Any valid iproute command can be placed in this array +IPCFG=("addr add dev eth0 192.168.1.23/24 brd +" "route add default via 192.168.1.1") +DNS=("192.168.1.1") diff --git a/examples/ethernet-iproute.example b/examples/ethernet-iproute.example deleted file mode 100755 index a368707..0000000 --- a/examples/ethernet-iproute.example +++ /dev/null @@ -1,6 +0,0 @@ -CONNECTION="ethernet-iproute" -INTERFACE="eth0" -IP="static" -# Any valid iproute command can be placed in this array -IPCFG=("addr add dev eth0 192.168.1.23/24 brd +" "route add default via 192.168.1.1") -DNS=("192.168.1.1") diff --git a/examples/ethernet-static b/examples/ethernet-static new file mode 100644 index 0000000..50756bc --- /dev/null +++ b/examples/ethernet-static @@ -0,0 +1,7 @@ +CONNECTION="ethernet-iproute" +DESCRIPTION="A basic static ethernet connection using iproute" +INTERFACE="eth0" +IP="static" +ADDR="192.168.1.23" +GATEWAY="192.168.1.1" +DNS=("192.168.1.1") diff --git a/examples/ethernet-static.example b/examples/ethernet-static.example deleted file mode 100644 index ad0c9b4..0000000 --- a/examples/ethernet-static.example +++ /dev/null @@ -1,6 +0,0 @@ -CONNECTION="ethernet-iproute" -INTERFACE="eth0" -IP="static" -ADDR="192.168.1.23" -GATEWAY="192.168.1.1" -DNS=("192.168.1.1") diff --git a/examples/loopback.example b/examples/loopback.example deleted file mode 100644 index e9dcca9..0000000 --- a/examples/loopback.example +++ /dev/null @@ -1,5 +0,0 @@ -CONNECTION="ethernet" -DESCRIPTION="A very basic ethernet profile, using dhcp" -INTERFACE=lo -IP="static" -IFOPTS="127.0.0.1" diff --git a/examples/ppp b/examples/ppp new file mode 100644 index 0000000..ca8d167 --- /dev/null +++ b/examples/ppp @@ -0,0 +1,4 @@ +CONNECTION="ppp" +INTERFACE="ignore" +PEER="provider" +PPP_TIMEOUT=10 diff --git a/examples/ppp.example b/examples/ppp.example deleted file mode 100644 index ca8d167..0000000 --- a/examples/ppp.example +++ /dev/null @@ -1,4 +0,0 @@ -CONNECTION="ppp" -INTERFACE="ignore" -PEER="provider" -PPP_TIMEOUT=10 diff --git a/examples/wireless-dbus b/examples/wireless-dbus new file mode 100644 index 0000000..7c00349 --- /dev/null +++ b/examples/wireless-dbus @@ -0,0 +1,7 @@ +CONNECTION="wireless-dbus" +DESCRIPTION="A simple WPA connection using wpa_supplicant via dbus" +INTERFACE="wlan0" +SECURITY="wpa" +ESSID="MyNetwork" +KEY="Wireless Key" +IP="dhcp" diff --git a/examples/wireless-wep b/examples/wireless-wep new file mode 100644 index 0000000..ed670d0 --- /dev/null +++ b/examples/wireless-wep @@ -0,0 +1,7 @@ +CONNECTION="wireless" +DESCRIPTION="A simple WEP encrypted wireless connection" +INTERFACE="wlan0" +SECURITY="wep" +ESSID="MyNetwork" +KEY="1234567890" +IP="dhcp" diff --git a/examples/wireless-wep-string-key b/examples/wireless-wep-string-key new file mode 100644 index 0000000..42c3210 --- /dev/null +++ b/examples/wireless-wep-string-key @@ -0,0 +1,7 @@ +CONNECTION="wireless" +DESCRIPTION="A simple WEP encrypted wireless connection" +INTERFACE="wlan0" +SECURITY="wep" +ESSID="MyNetwork" +KEY="s:Wireless Key" +IP="dhcp" diff --git a/examples/wireless-wpa b/examples/wireless-wpa new file mode 100644 index 0000000..0f5016d --- /dev/null +++ b/examples/wireless-wpa @@ -0,0 +1,7 @@ +CONNECTION="wireless" +DESCRIPTION="A simple WPA encrypted wireless connection" +INTERFACE="wlan0" +SECURITY="wpa" +ESSID="MyNetwork" +KEY="WirelessKey" +IP="dhcp" diff --git a/examples/wireless.example b/examples/wireless.example deleted file mode 100644 index 077d9df..0000000 --- a/examples/wireless.example +++ /dev/null @@ -1,7 +0,0 @@ -CONNECTION="wireless-dbus" -INTERFACE=ipw0 -SECURITY="yes" -ESSID="Your ESSID" -KEY="Your Key" -# Below can be any valid ethernet option. See ethernet-*.example -IP="dhcp" diff --git a/src/connections/ethernet b/src/connections/ethernet index ad9e870..9ec27fb 100644 --- a/src/connections/ethernet +++ b/src/connections/ethernet @@ -11,13 +11,19 @@ ethernet_up() { fi fi + # Connection check if ip link show "$INTERFACE"|grep -q "NO-CARRIER"; then err_append "no connection available" return 1 fi ifconfig "$INTERFACE" up - + + # Some hardware is not immediately ready after ifconfig up + while ip link show $INTERFACE|grep -q "state UNKNOWN"; do + sleep 0.5 + done + if checkyesno "${AUTH8021X:-no}"; then . "${SUBR_DIR}"/8021x [[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf" @@ -116,7 +122,7 @@ ethernet_down() { esac ifconfig $INTERFACE 0.0.0.0 - case "$CONNECTION" in + case "$CONNECTION" in # Keep interface up for wireless ethernet|ethernet-old) quirk "nodown" || ifconfig $INTERFACE down ;; diff --git a/src/connections/wireless b/src/connections/wireless index 27df7ca..c614c6f 100644 --- a/src/connections/wireless +++ b/src/connections/wireless @@ -7,28 +7,33 @@ wireless_up() { . ${SUBR_DIR}/wireless - if [[ ! -d /sys/class/net/$INTERFACE/wireless ]]; then + if [[ ! -d /sys/class/net/$INTERFACE/phy80211 ]]; then err_append "$INTERFACE is not a valid wireless interface." return 1 fi - - # Required by atheros and others (mac80211?) to enable device - ifconfig $INTERFACE up - - # Hack that has been required by some broadcom - quirk "prescan" && iwlist $INTERFACE scan &> /dev/null - - # Required by ipw3945 to properly re-associate - quirk "preessid" && eval "iwconfig $INTERFACE mode managed essid \"$ESSID\"" # Kill any lingering wpa_supplicants. if [[ -f /var/run/wpa_supplicant_$INTERFACE.pid ]]; then kill $(cat /var/run/wpa_supplicant_$INTERFACE.pid) fi - # Default scan off as it won't see hidden networks and some hardware's scanning is dodgy - [[ ! "$SCAN" ]] && SCAN="no" - if checkyesno $SCAN; then + # Most drivers (mac80211) need mode set before device is brought up + # Drivers generally default to managed, but set this to be sure. + if [[ "$(iwgetid -sm $INTERFACE)" -ne "Managed" ]]; then + iwconfig $INTERFACE mode managed + fi + + ifconfig $INTERFACE up + + # Some hardware is not immediately ready after ifconfig up + while ip link show $INTERFACE|grep -q "state UNKNOWN"; do + sleep 0.5 + done + + quirk "prescan" && iwlist $INTERFACE scan &> /dev/null # bcm43xx + quirk "preessid" && eval "iwconfig $INTERFACE mode managed essid \"$ESSID\"" # ipw3945 + + if checkyesno ${SCAN-no}; then if ! find_essid $INTERFACE "$ESSID"; then err_append "Network not present." return 1 @@ -36,44 +41,33 @@ wireless_up() { fi # Manually set iwconfig options - if [[ "$IWCONFIG" ]]; then - iwconfig $INTERFACE $IWCONFIG - fi + [[ "$IWCONFIG" ]] && iwconfig $INTERFACE $IWCONFIG case $SECURITY in wep|none) - # 'none' security uses iwconfig, like wep, so use same code, minus keysetting. - # Use sane default if no alternative is specified - if [[ "$SECURITY" = "wep" && "$WEP_OPTS" = "" ]]; then - WEP_OPTS="mode managed essid \"$ESSID\" key $KEY" - elif [[ "$SECURITY" = "none" && "$WEP_OPTS" = "" ]]; then - WEP_OPTS="mode managed essid \"$ESSID\"" + # 'none' uses iwconfig like wep. Use sane default if WEP_OPTS="" + if [[ "$SECURITY" = "wep" ]]; then + WEP_OPTS="essid \"$ESSID\" key $KEY" + elif [[ "$SECURITY" = "none" ]]; then + WEP_OPTS="essid \"$ESSID\"" fi - - # Add wierd quirk for some Atheros in response to FS#10585 - quirk "predown" && ifconfig $INTERFACE down + + quirk "predown" && ifconfig $INTERFACE down # madwifi FS#10585 if ! eval iwconfig $INTERFACE $WEP_OPTS; then err_append "Could not set wireless configuration." return 1 fi - quirk "postsleep" && sleep 1 - quirk "postscan" && sleep 1 && iwlist $INTERFACE scan &>/dev/null - quirk "predown" && ifconfig $INTERFACE up - - # Many devices appear to not associate until DHCP is run. - if quirk "acheck"; then - wep_check $INTERFACE $TIMEOUT|| return 1 - else - sleep ${TIMEOUT:-15} - fi + quirk "predown" && ifconfig $INTERFACE up # madwifi FS#10585 + + wep_check $INTERFACE $TIMEOUT||return 1 ;; wpa) . ${SUBR_DIR}/8021x # Quirk for broken drivers... http://bbs.archlinux.org/viewtopic.php?id=36384 - quirk "wpaessid" && eval iwconfig $INTERFACE mode managed essid "\"$ESSID\"" + quirk "wpaessid" && eval iwconfig $INTERFACE essid "\"$ESSID\"" local WPA_CONF="/tmp/wpa.${1// /}" # substitute spaces out echo "ctrl_interface=/var/run/wpa_supplicant" >> $WPA_CONF @@ -89,15 +83,14 @@ wireless_up() { fi # Connect! - [[ "$WPA_OPTS" == "" ]] && WPA_OPTS="-Dwext" + [[ -z "$WPA_OPTS" ]] && WPA_OPTS="-Dwext" start_wpa $INTERFACE $WPA_CONF $WPA_OPTS || return 1 wpa_check $INTERFACE $TIMEOUT || return 1 ;; wpa-config) - . ${SUBR_DIR}/8021x - # If user hasnt defined one, use stock config. - [[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf" - [[ "$WPA_OPTS" == "" ]] && WPA_OPTS="-Dwext" + . ${SUBR_DIR}/8021x + [[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf" # defaults + [[ -z "$WPA_OPTS" ]] && WPA_OPTS="-Dwext" start_wpa $INTERFACE $WPA_CONF $WPA_OPTS || return 1 wpa_check $INTERFACE $TIMEOUT || return 1 ;; diff --git a/src/wireless b/src/wireless index 405b86b..62454e4 100644 --- a/src/wireless +++ b/src/wireless @@ -59,3 +59,4 @@ list_networks() echo $essids return 0 } +# vim: set ts=4 et sw=4 ft=sh: -- cgit v1.2.3-24-g4f1b