summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Rayner <james@archlinux.org>2009-08-10 12:20:12 +0200
committerJames Rayner <james@archlinux.org>2009-08-10 12:20:12 +0200
commit5f43ba3cfab8851b2a380d609029b8061ae51bca (patch)
treec207b1fa3e66efdecfd6cd2da84ec5881f6b2f65 /src
parent74fe64cec00d359ce98938754e9cb1b0c96e49a8 (diff)
downloadnetctl-5f43ba3cfab8851b2a380d609029b8061ae51bca.tar.gz
netctl-5f43ba3cfab8851b2a380d609029b8061ae51bca.tar.xz
merge improved find_ap/find_essid
Diffstat (limited to 'src')
-rw-r--r--src/connections/wireless6
-rw-r--r--src/wireless63
2 files changed, 55 insertions, 14 deletions
diff --git a/src/connections/wireless b/src/connections/wireless
index 2516042..f7b4b4c 100644
--- a/src/connections/wireless
+++ b/src/connections/wireless
@@ -32,7 +32,7 @@ wireless_up() {
# Check if interface exists
if [[ ! -e /sys/class/net/"$INTERFACE" ]]; then
- if ! echo "$INTERFACE"|grep ":"; then
+ if ! echo "$INTERFACE"|grep -Fq ":"; then
report_fail "interface $INTERFACE does not exist"
return 1
fi
@@ -44,13 +44,13 @@ wireless_up() {
# 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
+ if [[ $(iwgetid -sm $INTERFACE) -ne Managed ]]; then
report_debug wireless_up iwconfig "$INTERFACE" mode managed
iwconfig $INTERFACE mode managed
fi
report_debug wireless_up ifup
- ifconfig $INTERFACE up || return 1
+ set_interface up $INTERFACE || return 1
quirk "prescan" && iwlist $INTERFACE scan &> /dev/null # bcm43xx
quirk "preessid" && eval "iwconfig $INTERFACE mode managed essid \"$ESSID\"" # ipw3945
diff --git a/src/wireless b/src/wireless
index 468e0bd..1c12a32 100644
--- a/src/wireless
+++ b/src/wireless
@@ -2,10 +2,8 @@
# wep_check interface [timeout]
wep_check()
{
- INTERFACE=$1; TIMEOUT=$2
-
- [[ -z "$TIMEOUT" ]] && TIMEOUT=15
- let timeout=0
+ local INTERFACE=$1 TIMEOUT=${2:-15} timeout=0 bssid
+
while [[ $timeout -ne $TIMEOUT ]]; do
bssid=`iwgetid $INTERFACE -ra`
[[ ! "$bssid" = "00:00:00:00:00:00" ]] && return 0
@@ -17,17 +15,60 @@ wep_check()
# 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
+find_essid() {
+ local INTERFACE="$1" ESSID="$2" 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"
+ ) && {
+ 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
- sleep 1
+ done
+ if [[ "$scanned" -ne 1 ]]; then
+ report_debug find_essid "unable to scan"
+ fi
+ return 1
+}
+
+# Check if a particular network is within range
+# find_ap interface ap
+find_ap() {
+ local INTERFACE="$1" ap=$(echo "$2" | tr 'abcdef' 'ABCDEF') 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+Cell .. - Address: ([[:xdigit:]:]+)$/ { s//\1/; N; s/(.*)\n\s+ESSID:"([^"]*)"$/\1\t\2/p }' \
+ | egrep -m1 "^$ap\t"
+ ) && {
+ scanned=1
+ report_debug find_ap "\"$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" | cut -f2 # JP: echo literal ESSID
+ return 0
+ fi
done
+ if [[ "$scanned" -ne 1 ]]; then
+ report_debug find_ap "unable to scan"
+ fi
return 1
}