diff options
Diffstat (limited to 'src/wireless.subr')
-rw-r--r-- | src/wireless.subr | 217 |
1 files changed, 0 insertions, 217 deletions
diff --git a/src/wireless.subr b/src/wireless.subr deleted file mode 100644 index e886b16..0000000 --- a/src/wireless.subr +++ /dev/null @@ -1,217 +0,0 @@ -#! /bin/bash - -# Uses wpa_supplicant to check for association to a network -# wpa_check interface [timeout] -wpa_check() -{ - local timeout=0 INTERFACE=$1 TIMEOUT=${2:-15} - - while [[ $timeout -lt $TIMEOUT ]]; do - ( - eval `wpa_cli status|grep wpa_state` - [[ "$wpa_state" = "COMPLETED" ]] - ) && return 0 - sleep 1 - let timeout++ - done - - wpa_cli terminate >/dev/null 2>&1 - err_append "Authentication/association failed" - return 1 -} - -# Uses wireless_tools, to check for association to a network. -# wep_check interface [timeout] -wep_check() -{ - INTERFACE=$1; TIMEOUT=$2 - - [[ -z "$TIMEOUT" ]] && TIMEOUT=15 - let timeout=0 - while [[ $timeout -ne $TIMEOUT ]]; do - bssid=`iwgetid $INTERFACE -ra` - [[ ! "$bssid" = "00:00:00:00:00:00" ]] && return 0 - sleep 1 - let timeout++ - done - - err_append "Wireless association failed" - return 1 -} - -# Check if a particular network is within range -# find_essid interface essid -find_essid() -{ - INTERFACE=$1; ESSID=$2; RETRIES=5 - try=0; - while [[ $try -ne $RETRIES ]]; do - if iwlist $INTERFACE scan|sed "s/ESSID://g"|grep -q "\"$ESSID\""; then - return 0 # network found - fi - sleep 1 - let try++ - done - return 1 -} - -# Return a filename containing a list of network ESSID's found. -# list_networks interface -list_networks() -{ - # temp file used, as keeping ESSID's with spaces in their name in arrays - # is hard, obscure and kinda nasty. This is simpler and clearer. - - [[ -z "$1" ]] && return 1 - essids=$(mktemp /tmp/essid.XXXXX) - - let try=0; - RETRIES=6; - while [[ $try -ne $RETRIES ]]; do - iwlist $1 scan 2> /dev/null|grep ESSID|sed 's/.*ESSID:"\([^"]\+\)".*/\1/' > $essids - sleep 0.5; let try++ - done - sort -u $essids -o $essids - - # File of 0 length, ie. no ssid's. - if [[ ! -s $essids ]]; then - return 1 - fi - - echo $essids - return 0 -} - -start_wpa() -{ - INTERFACE="$1"; WPA_CONF="$2"; WPA_OPTS="$3" - - wpa_supplicant -wB -P/var/run/wpa_supplicant_${INTERFACE}.pid -i"${INTERFACE}" -c "$WPA_CONF" $WPA_OPTS - sleep 1 - - if [[ ! -f "/var/run/wpa_supplicant_${INTERFACE}.pid" ]]; then - err_append "wpa_supplicant did not start, possible configuration error" - return 1 - fi -} - -wireless_up() { - - load_profile $1 - - if [[ ! -d /sys/class/net/$INTERFACE/wireless ]]; then - err_append "Interface $INTERFACE is not a 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 - quirk "test" && echo "TESTWORKS!" - # 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 - if ! find_essid $INTERFACE "$ESSID"; then - err_append "Network unavailable" - return 1 - fi - fi - - # Manually set iwconfig options - if [[ "$IWCONFIG" ]]; then - iwconfig $INTERFACE $IWCONFIG - fi - - 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\"" - fi - - # Add wierd quirk for some Atheros in response to FS#10585 - quirk "predown" && ifconfig $INTERFACE down - - 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 - - wep_check $INTERFACE $TIMEOUT|| return 1 - ;; - wpa) - # Quirk for broken drivers... http://bbs.archlinux.org/viewtopic.php?id=36384 - quirk "wpaessid" && eval iwconfig $INTERFACE mode managed essid "\"$ESSID\"" - - local WPA_CONF="/tmp/wpa.${1// /}" # substitute spaces out - chmod 600 $WPA_CONF - echo "ctrl_interface=/var/run/wpa_supplicant" >> $WPA_CONF - echo "ctrl_interface_group=0" >> $WPA_CONF - - # Generate configuration - if [[ "${#KEY}" == "64" ]]; then - echo -e 'network={ \nssid="$ESSID" \npsk=$KEY \n}'> $WPA_CONF - elif ! wpa_passphrase "$ESSID" "$KEY" >> $WPA_CONF; then - err_append "Configuration generation failed: `cat $WPA_CONF`" - return 1 - fi - - # Connect! - [[ "$WPA_OPTS" == "" ]] && WPA_OPTS="-Dwext" - start_wpa $INTERFACE $WPA_CONF $WPA_OPTS || return 1 - wpa_check $INTERFACE $TIMEOUT || return 1 - ;; - wpa-config) - # If user hasnt defined one, use stock config. - [[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf" - [[ "$WPA_OPTS" == "" ]] && WPA_OPTS="-Dwext" - start_wpa $INTERFACE $WPA_CONF $WPA_OPTS || return 1 - wpa_check $INTERFACE $TIMEOUT || return 1 - ;; - esac - - . $SUBR_DIR/ethernet.subr - if ! ethernet_up $1; then - wireless_down $1 YES - return 1 - fi -} - -wireless_down() { - PROFILE=$1 NOETHERNETDOWN=$2 - if ! checkyesno $2; then - . $SUBR_DIR/ethernet.subr - ethernet_down $1 - fi - wpa_cli terminate &> /dev/null - [[ "$SECURITY" == "wpa" ]] && rm -f "/tmp/wpa.${1// /}" # remove wpa config - iwconfig $INTERFACE essid off key off &> /dev/null - -} - -wireless_clean_scope() { - unset INTERFACE CONNECTION - unset TIMEOUT WPA_CONF WPA_OPTS KEY ESSID SECURITY WEP_OPTS - . $SUBR_DIR/ethernet.subr - ethernet_clean_scope -} - - -# vim: set ts=4 et sw=4: |