From 9578dda45b86acf3bd25def5de8f1d51f2ec22b2 Mon Sep 17 00:00:00 2001 From: Jim Pryor Date: Tue, 11 Aug 2009 08:05:10 -0400 Subject: Add AP argument to profile, also let ESSID arguments be regexps * AP= arguments in profiles take precedence over ESSID= arguments * ESSID= arguments regexps instead of literals. To avoid screwing up any currently working profiles, I restricted the interpretation as a regexp to just the new wireless-dbus connection types. * But a global change involved in implementing this is that the connection up/down calls will be passed a literal ESSID (which of the local networks matches the regexp) as an additional argument. Signed-off-by: Jim Pryor --- src/connections/wireless | 48 +++++++++++++++++++++++++++++++++++++++--------- src/wireless | 27 +++++++++++++++++++-------- 2 files changed, 58 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/connections/wireless b/src/connections/wireless index 644b002..430f0ab 100644 --- a/src/connections/wireless +++ b/src/connections/wireless @@ -17,6 +17,8 @@ rfkill_from_name() { wireless_up() { load_profile $1 + [[ -n "$2" ]] && ESSID="$2" # JP: use the literal ESSID (though currently we only interpret wireless-dbus ESSIDs as regexps) + . ${SUBR_DIR}/8021x . ${SUBR_DIR}/wireless @@ -51,14 +53,28 @@ wireless_up() { report_debug wireless_up ifup set_interface up $INTERFACE || return 1 - - quirk "prescan" && iwlist $INTERFACE scan &> /dev/null # bcm43xx - quirk "preessid" && eval "iwconfig $INTERFACE mode managed essid \"$ESSID\"" # ipw3945 + ## wireless_control "$INTERFACE" up || return 1 + + quirk prescan && iwlist "$INTERFACE" scan &> /dev/null # bcm43xx + if quirk preessid; then # ipw3945 + if [[ -n "$AP" ]]; then # JP: enable use of AP + iwconfig "$INTERFACE" mode managed ap "$AP" + else + eval "iwconfig \"$INTERFACE\" mode managed essid \"$ESSID\"" + fi + fi if checkyesno ${SCAN:-no}; then report_debug wireless_up scanning - if ! find_essid $INTERFACE "$ESSID"; then - report_fail "Network not present." + local OLDESSID="$ESSID" + if [[ -n "$AP" ]]; then + ESSID=$(find_ap "$INTERFACE" "$AP") + else + ESSID=$(find_essid "$INTERFACE" "$ESSID" "$CONNECTION") # JP: we could have left $3 null for default of treating ESSID as literal + # but instead we explicitly pass $CONNECTION + fi + if [[ $? -gt 0 ]]; then + report_fail "Network \"$OLDESSID\" not present." return 1 fi fi @@ -77,9 +93,17 @@ wireless_up() { # 'none' uses iwconfig like wep. Use sane default if WEP_OPTS="" if [[ -z "$WEP_OPTS" ]]; then if [[ "$SECURITY" = "wep" ]]; then - WEP_OPTS="essid \"$ESSID\" key $KEY" + if [[ -n "$AP" ]]; then + WEP_OPTS="ap \"$AP\" key $KEY" + else + WEP_OPTS="essid \"$ESSID\" key $KEY" + fi elif [[ "$SECURITY" = "none" ]]; then - WEP_OPTS="essid \"$ESSID\"" + if [[ -n "$AP" ]]; then + WEP_OPTS="ap \"$AP\"" + else + WEP_OPTS="essid \"$ESSID\"" + fi fi fi @@ -102,7 +126,13 @@ wireless_up() { wpa) # Quirk for broken drivers... http://bbs.archlinux.org/viewtopic.php?id=36384 - quirk "wpaessid" && eval iwconfig $INTERFACE essid "\"$ESSID\"" + if quirk "wpaessid"; then + if [[ -n "$AP" ]]; then + iwconfig "$INTERFACE" ap "$AP" + else + eval "iwconfig \"$INTERFACE\" essid \"$ESSID\"" + fi + fi local WPA_CONF="${TMPDIR:-/tmp}/wpa.${1// /}" # substitute spaces out # make empty tmp dir with correct permissions, rename it @@ -196,6 +226,6 @@ wireless_status() { } -wireless_$1 $2 +wireless_$1 "$2" "$3" exit $? # vim: set ts=4 et sw=4: diff --git a/src/wireless b/src/wireless index 883ea0b..99c146d 100644 --- a/src/wireless +++ b/src/wireless @@ -14,24 +14,35 @@ wep_check() } # Check if a particular network is within range -# find_essid interface essid +# find_essid interface essid connection (we treat ESSID as regexp when CONNECTION=wireless-dbus) find_essid() { - local INTERFACE="$1" ESSID="$2" RETRIES=20 try=0 res scanned + local INTERFACE="$1" ESSID="$2" CONNECTION="$3" RETRIES=20 try=0 res scanned while [[ "$try" -lt "$RETRIES" ]]; do sleep 0.5 let try++ - found=$( - res=$(iwlist "$INTERFACE" scan 2>/dev/null) - [[ -z "$res" ]] && exit 1 - # if results were non-null, process them and exit 0 - echo "$res" | sed -nr 's/^\s+ESSID:"([^"]*)"$/\1/p' | fgrep -xm1 "$ESSID" - ) && { + if [[ "$CONNECTION" == wireless-dbus ]]; then + # JP: ESSID is a regexp + found=$( + res=$(iwlist "$INTERFACE" scan 2>/dev/null) + [[ -z "$res" ]] && exit 1 + # if results were non-null, process them and exit 0 + echo "$res" | sed -nr 's/^\s+ESSID:"([^"]*)"$/\1/p' | egrep -xm1 "$ESSID" + ) + else + found=$( + res=$(iwlist "$INTERFACE" scan 2>/dev/null) + [[ -z "$res" ]] && exit 1 + # if results were non-null, process them and exit 0 + echo "$res" | sed -nr 's/^\s+ESSID:"([^"]*)"$/\1/p' | fgrep -xm1 "$ESSID" + ) + fi && { scanned=1 report_debug find_essid "\"$found\"" # we only bother with at most 5 successful scans if (( try < RETRIES-4 )); then try=$((RETRIES-4)); fi } if [[ -n "$found" ]]; then + echo "$found" # JP: echo literal ESSID return 0 # network found fi done -- cgit v1.2.3-24-g4f1b